LaTeX.ebnf 1.43 KB
Newer Older
Eckhart Arnold's avatar
Eckhart Arnold committed
1
2
# latex Grammar

3
@ whitespace = /[ \t]*\n?(?!\s*\n)[ \t]*/  # whitespace, including at most one linefeed
4
@ comment    = /%.*(?:\n|$)/
Eckhart Arnold's avatar
Eckhart Arnold committed
5

6
7
8
9
latexdoc   = preamble document
preamble   = { command }+

genericenv = beginenv sequence §endenv
10
11
beginenv   = "\begin" §( "{" NAME "}" )
endenv     = "\end" §( "{" ::NAME "}" )
Eckhart Arnold's avatar
Eckhart Arnold committed
12

13
command    = CMDNAME [ config ] block
14
config     = "[" cfgtext §"]"
Eckhart Arnold's avatar
Eckhart Arnold committed
15

16
17
18
blockcmd   = "\section" | "\subsection"
plaincmd   = !blockcmd

19
sequence   = { partext | parblock }
Eckhart Arnold's avatar
Eckhart Arnold committed
20

21
22
parblock   = "{" { partext | parblock } §"}"
block      = "{" { text | block } §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
23

24
partext    = text | PARSEP
25
26
27
28
29
30
31
32
text       = cfgtext | BRACKETS
cfgtext    = TEXTCHUNK | ESCAPED | WSPC

blockcmd   = "\subsection" | "\section" | "\chapter" | "\subsubsection"
             | "\paragraph" | "\subparagraph" | "\begin{enumerate}" | "\begin{itemize}"

CMDNAME    = /\\\w+/~
NAME       = /\w+/~
Eckhart Arnold's avatar
Eckhart Arnold committed
33

Eckhart Arnold's avatar
Eckhart Arnold committed
34
ESCAPED    = /\\[%$&]/
35
BRACKETS   = /[\[\]]/                   # left or right square bracket: [ ]
Eckhart Arnold's avatar
Eckhart Arnold committed
36
TEXTCHUNK  = /[^\\%$&\{\}\[\]\s\n]+/    # some piece of text excluding whitespace,
37
                                        # linefeed and special characters
38
39
40
WSPC       = /[ \t]*\n?(?!\s*\n)[ \t]*/ # whitespace, including at most one linefeed
LF         = /[ \t]*\n(?!\s*\n)/        # a linefeed, but not an empty line (i.e. par)
PARSEP     = /\s*\n\s*\n/               # at least one empty line, i.e.
41
                                        # [whitespace] linefeed [whitespace] linefeed
Eckhart Arnold's avatar
Eckhart Arnold committed
42