2023-04-13 04:21:25 -04:00
|
|
|
// Track environments
|
|
|
|
|
|
|
|
@context elementContext from "./tokens.mjs"
|
|
|
|
|
|
|
|
// External tokens must be defined before normal @tokens to take precedence
|
|
|
|
// over them.
|
|
|
|
|
|
|
|
@external tokens verbTokenizer from "./tokens.mjs" {
|
|
|
|
VerbContent
|
|
|
|
}
|
|
|
|
|
|
|
|
@external tokens lstinlineTokenizer from "./tokens.mjs" {
|
|
|
|
LstInlineContent
|
|
|
|
}
|
|
|
|
|
|
|
|
@external tokens literalArgTokenizer from "./tokens.mjs" {
|
|
|
|
LiteralArgContent
|
|
|
|
}
|
|
|
|
|
|
|
|
@external tokens spaceDelimitedLiteralArgTokenizer from "./tokens.mjs" {
|
|
|
|
SpaceDelimitedLiteralArgContent
|
|
|
|
}
|
|
|
|
|
|
|
|
@external tokens verbatimTokenizer from "./tokens.mjs" {
|
|
|
|
VerbatimContent
|
|
|
|
}
|
|
|
|
|
|
|
|
// external tokenizer to read control sequence names including @ signs
|
|
|
|
// (which are often used in TeX definitions).
|
|
|
|
@external tokens csnameTokenizer from "./tokens.mjs" {
|
|
|
|
Csname
|
|
|
|
}
|
|
|
|
|
|
|
|
@external tokens trailingContentTokenizer from "./tokens.mjs" {
|
|
|
|
TrailingWhitespaceOnly,
|
|
|
|
TrailingContent
|
|
|
|
}
|
|
|
|
|
|
|
|
// It doesn't seem to be possible to access specialized tokens in the context tracker.
|
|
|
|
// They have id's which are not exported in the latex.terms.js file.
|
|
|
|
// This is a workaround: use an external specializer to explicitly choose the terms
|
|
|
|
// to use for the specialized tokens.
|
|
|
|
@external specialize {CtrlSeq} specializeCtrlSeq from "./tokens.mjs" {
|
|
|
|
Begin,
|
|
|
|
End,
|
|
|
|
RefCtrlSeq,
|
|
|
|
RefStarrableCtrlSeq,
|
|
|
|
CiteCtrlSeq,
|
|
|
|
CiteStarrableCtrlSeq,
|
|
|
|
LabelCtrlSeq,
|
|
|
|
MathTextCtrlSeq,
|
|
|
|
HboxCtrlSeq,
|
|
|
|
TitleCtrlSeq,
|
|
|
|
DocumentClassCtrlSeq,
|
|
|
|
UsePackageCtrlSeq,
|
|
|
|
HrefCtrlSeq,
|
2023-08-11 04:31:38 -04:00
|
|
|
UrlCtrlSeq,
|
2023-04-13 04:21:25 -04:00
|
|
|
VerbCtrlSeq,
|
|
|
|
LstInlineCtrlSeq,
|
|
|
|
IncludeGraphicsCtrlSeq,
|
|
|
|
CaptionCtrlSeq,
|
|
|
|
DefCtrlSeq,
|
2024-07-23 05:33:22 -04:00
|
|
|
LetCtrlSeq,
|
2023-04-13 04:21:25 -04:00
|
|
|
LeftCtrlSeq,
|
|
|
|
RightCtrlSeq,
|
|
|
|
NewCommandCtrlSeq,
|
|
|
|
RenewCommandCtrlSeq,
|
|
|
|
NewEnvironmentCtrlSeq,
|
|
|
|
RenewEnvironmentCtrlSeq,
|
|
|
|
// services/web/frontend/js/features/outline/outline-parser.js
|
|
|
|
BookCtrlSeq,
|
|
|
|
PartCtrlSeq,
|
|
|
|
ChapterCtrlSeq,
|
|
|
|
SectionCtrlSeq,
|
|
|
|
SubSectionCtrlSeq,
|
|
|
|
SubSubSectionCtrlSeq,
|
|
|
|
ParagraphCtrlSeq,
|
|
|
|
SubParagraphCtrlSeq,
|
|
|
|
InputCtrlSeq,
|
|
|
|
IncludeCtrlSeq,
|
|
|
|
ItemCtrlSeq,
|
2023-07-18 06:16:30 -04:00
|
|
|
NewTheoremCtrlSeq,
|
|
|
|
TheoremStyleCtrlSeq,
|
2023-04-13 04:21:25 -04:00
|
|
|
CenteringCtrlSeq,
|
|
|
|
BibliographyCtrlSeq,
|
|
|
|
BibliographyStyleCtrlSeq,
|
2023-04-20 05:59:43 -04:00
|
|
|
AuthorCtrlSeq,
|
2023-09-20 11:18:18 -04:00
|
|
|
AffilCtrlSeq,
|
|
|
|
AffiliationCtrlSeq,
|
2024-10-25 07:32:06 -04:00
|
|
|
DateCtrlSeq,
|
2023-07-18 06:52:57 -04:00
|
|
|
MaketitleCtrlSeq,
|
|
|
|
TextColorCtrlSeq,
|
2023-08-14 04:15:52 -04:00
|
|
|
ColorBoxCtrlSeq,
|
|
|
|
HLineCtrlSeq,
|
|
|
|
TopRuleCtrlSeq,
|
|
|
|
MidRuleCtrlSeq,
|
2023-08-24 05:19:11 -04:00
|
|
|
BottomRuleCtrlSeq,
|
2024-07-02 11:07:22 -04:00
|
|
|
MultiColumnCtrlSeq,
|
2024-08-02 03:59:11 -04:00
|
|
|
ParBoxCtrlSeq,
|
|
|
|
TextBoldCtrlSeq,
|
|
|
|
TextItalicCtrlSeq,
|
|
|
|
TextSmallCapsCtrlSeq,
|
|
|
|
TextTeletypeCtrlSeq,
|
|
|
|
TextMediumCtrlSeq,
|
|
|
|
TextSansSerifCtrlSeq,
|
|
|
|
TextSuperscriptCtrlSeq,
|
|
|
|
TextSubscriptCtrlSeq,
|
|
|
|
TextStrikeOutCtrlSeq,
|
|
|
|
EmphasisCtrlSeq,
|
2024-11-05 06:59:33 -05:00
|
|
|
UnderlineCtrlSeq,
|
|
|
|
SetLengthCtrlSeq
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@external specialize {EnvName} specializeEnvName from "./tokens.mjs" {
|
|
|
|
DocumentEnvName,
|
|
|
|
TabularEnvName,
|
|
|
|
EquationEnvName,
|
|
|
|
EquationArrayEnvName,
|
|
|
|
VerbatimEnvName,
|
|
|
|
TikzPictureEnvName,
|
|
|
|
FigureEnvName,
|
2023-08-17 04:08:41 -04:00
|
|
|
ListEnvName,
|
|
|
|
TableEnvName
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@external specialize {CtrlSym} specializeCtrlSym from "./tokens.mjs" {
|
|
|
|
OpenParenCtrlSym,
|
|
|
|
CloseParenCtrlSym,
|
|
|
|
OpenBracketCtrlSym,
|
2023-08-04 03:37:36 -04:00
|
|
|
CloseBracketCtrlSym,
|
|
|
|
LineBreakCtrlSym
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@tokens {
|
|
|
|
CtrlSeq { "\\" $[a-zA-Z]+ }
|
|
|
|
CtrlSym { "\\" ![a-zA-Z] }
|
|
|
|
|
|
|
|
// tokens for paragraphs
|
|
|
|
Whitespace { $[ \t]+ }
|
|
|
|
NewLine { "\n" }
|
|
|
|
BlankLine { "\n" "\n"+ }
|
2023-07-11 09:34:47 -04:00
|
|
|
Normal { ![\\{}\[\]$&~#^_% \t\n] ![\\{}\[\]$&~#^_%\t\n]* } // everything is normal text, except these characters
|
2023-04-13 04:21:25 -04:00
|
|
|
@precedence { CtrlSeq, CtrlSym, BlankLine, NewLine, Whitespace, Normal }
|
|
|
|
|
|
|
|
OpenBrace[closedBy=CloseBrace] { "{" }
|
|
|
|
CloseBrace[openedBy=OpenBrace] { "}" }
|
|
|
|
OpenBracket[closedBy=CloseBracket] { "[" }
|
|
|
|
CloseBracket[openedBy=OpenBracket] { "]" }
|
|
|
|
|
|
|
|
Comment { "%" ![\n]* "\n"? }
|
|
|
|
|
|
|
|
Dollar { "$" }
|
|
|
|
|
|
|
|
Number { $[0-9]+ ("." $[0-9]*)? }
|
|
|
|
MathSpecialChar { $[^_=<>()\-+/*]+ } // FIXME not all of these are special
|
2024-06-18 06:01:08 -04:00
|
|
|
MathChar { ![0-9^_=<>()\-+/*\\{}\[\]$%&~ \t\n]+ }
|
2023-04-13 04:21:25 -04:00
|
|
|
|
|
|
|
@precedence { Number, MathSpecialChar, MathChar }
|
|
|
|
|
|
|
|
Ampersand { "&" }
|
2023-07-11 09:34:47 -04:00
|
|
|
Tilde { "~" }
|
2023-04-13 04:21:25 -04:00
|
|
|
|
|
|
|
EnvName { $[a-zA-Z]+ $[*]? }
|
|
|
|
}
|
|
|
|
|
|
|
|
@top LaTeX {
|
|
|
|
Text
|
|
|
|
}
|
|
|
|
|
|
|
|
@skip { Comment }
|
|
|
|
|
|
|
|
// TEXT MODE
|
|
|
|
|
|
|
|
optionalWhitespace {
|
|
|
|
!argument Whitespace
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionalArgument {
|
|
|
|
!argument OpenBracket ShortOptionalArg CloseBracket
|
|
|
|
}
|
|
|
|
|
|
|
|
TextArgument {
|
|
|
|
!argument OpenBrace LongArg CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
SectioningArgument {
|
|
|
|
!argument OpenBrace LongArg CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
LabelArgument {
|
|
|
|
!argument ShortTextArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
RefArgument {
|
|
|
|
!argument ShortTextArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
BibKeyArgument {
|
|
|
|
!argument ShortTextArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageArgument {
|
|
|
|
!argument ShortTextArgument
|
|
|
|
}
|
|
|
|
|
2023-08-24 05:19:11 -04:00
|
|
|
TabularArgument {
|
|
|
|
!argument OpenBrace TabularContent CloseBrace
|
|
|
|
}
|
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
UrlArgument {
|
|
|
|
OpenBrace LiteralArgContent CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
FilePathArgument {
|
|
|
|
OpenBrace LiteralArgContent CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
BareFilePathArgument {
|
|
|
|
Whitespace SpaceDelimitedLiteralArgContent
|
|
|
|
}
|
|
|
|
|
|
|
|
DefinitionArgument {
|
2024-06-26 04:59:40 -04:00
|
|
|
!argument NewLine? Whitespace* OpenBrace DefinitionFragment? CloseBrace
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MacroParameter {
|
|
|
|
"#" ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9")
|
|
|
|
}
|
|
|
|
|
2023-08-15 10:23:12 -04:00
|
|
|
OptionalMacroParameter {
|
|
|
|
OpenBracket MacroParameter CloseBracket
|
|
|
|
}
|
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
// The autocompletion code in services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts
|
|
|
|
// depends on following the `KnownCommand { Command { CommandCtrlSeq [args] } }`
|
|
|
|
// structure
|
2024-06-25 04:07:47 -04:00
|
|
|
KnownCommand<ArgumentType> {
|
2023-04-13 04:21:25 -04:00
|
|
|
Title {
|
|
|
|
TitleCtrlSeq optionalWhitespace? OptionalArgument? TextArgument
|
|
|
|
} |
|
|
|
|
Author {
|
|
|
|
AuthorCtrlSeq optionalWhitespace? OptionalArgument? optionalWhitespace? TextArgument
|
|
|
|
} |
|
2023-09-20 11:18:18 -04:00
|
|
|
Affil {
|
|
|
|
AffilCtrlSeq optionalWhitespace? OptionalArgument? optionalWhitespace? TextArgument
|
|
|
|
} |
|
|
|
|
Affiliation {
|
|
|
|
AffiliationCtrlSeq optionalWhitespace? OptionalArgument? optionalWhitespace? TextArgument
|
|
|
|
} |
|
2024-10-25 07:32:06 -04:00
|
|
|
Date {
|
|
|
|
DateCtrlSeq optionalWhitespace? OptionalArgument? optionalWhitespace? ShortTextArgument
|
|
|
|
} |
|
2023-04-13 04:21:25 -04:00
|
|
|
DocumentClass {
|
|
|
|
DocumentClassCtrlSeq optionalWhitespace? OptionalArgument?
|
|
|
|
DocumentClassArgument { ShortTextArgument }
|
|
|
|
} |
|
|
|
|
BibliographyCommand {
|
|
|
|
BibliographyCtrlSeq optionalWhitespace?
|
|
|
|
BibliographyArgument { ShortTextArgument }
|
|
|
|
} |
|
|
|
|
BibliographyStyleCommand {
|
|
|
|
BibliographyStyleCtrlSeq optionalWhitespace?
|
|
|
|
BibliographyStyleArgument { ShortTextArgument }
|
|
|
|
} |
|
|
|
|
UsePackage {
|
|
|
|
UsePackageCtrlSeq optionalWhitespace? OptionalArgument?
|
|
|
|
PackageArgument
|
|
|
|
} |
|
2023-07-18 06:52:57 -04:00
|
|
|
TextColorCommand {
|
2024-06-25 04:07:47 -04:00
|
|
|
TextColorCtrlSeq optionalWhitespace? ShortTextArgument optionalWhitespace? ArgumentType
|
2023-07-18 06:52:57 -04:00
|
|
|
} |
|
|
|
|
ColorBoxCommand {
|
2024-06-25 04:07:47 -04:00
|
|
|
ColorBoxCtrlSeq optionalWhitespace? ShortTextArgument optionalWhitespace? ArgumentType
|
2023-07-18 06:52:57 -04:00
|
|
|
} |
|
2023-04-13 04:21:25 -04:00
|
|
|
HrefCommand {
|
|
|
|
HrefCtrlSeq optionalWhitespace? UrlArgument ShortTextArgument
|
|
|
|
} |
|
2023-07-18 06:16:30 -04:00
|
|
|
NewTheoremCommand {
|
|
|
|
NewTheoremCtrlSeq "*"? optionalWhitespace? ShortTextArgument ((OptionalArgument? TextArgument) | (TextArgument OptionalArgument))
|
|
|
|
} |
|
|
|
|
TheoremStyleCommand {
|
|
|
|
TheoremStyleCtrlSeq optionalWhitespace? ShortTextArgument
|
|
|
|
} |
|
2023-08-11 04:31:38 -04:00
|
|
|
UrlCommand {
|
|
|
|
UrlCtrlSeq optionalWhitespace? UrlArgument
|
|
|
|
} |
|
2023-04-13 04:21:25 -04:00
|
|
|
VerbCommand {
|
|
|
|
VerbCtrlSeq VerbContent
|
|
|
|
} |
|
|
|
|
LstInlineCommand {
|
|
|
|
LstInlineCtrlSeq optionalWhitespace? OptionalArgument? LstInlineContent
|
|
|
|
} |
|
|
|
|
IncludeGraphics {
|
|
|
|
IncludeGraphicsCtrlSeq optionalWhitespace? OptionalArgument?
|
|
|
|
IncludeGraphicsArgument { FilePathArgument }
|
|
|
|
} |
|
|
|
|
Caption {
|
2023-06-29 04:53:43 -04:00
|
|
|
CaptionCtrlSeq "*"? optionalWhitespace? OptionalArgument? TextArgument
|
2023-04-13 04:21:25 -04:00
|
|
|
} |
|
|
|
|
Label {
|
|
|
|
LabelCtrlSeq optionalWhitespace? LabelArgument
|
|
|
|
} |
|
|
|
|
Ref {
|
|
|
|
(RefCtrlSeq | RefStarrableCtrlSeq "*"?) optionalWhitespace? OptionalArgument? optionalWhitespace? OptionalArgument? optionalWhitespace? RefArgument
|
|
|
|
} |
|
|
|
|
Cite {
|
|
|
|
(CiteCtrlSeq | CiteStarrableCtrlSeq "*"?) optionalWhitespace? OptionalArgument? optionalWhitespace? OptionalArgument? optionalWhitespace? BibKeyArgument
|
|
|
|
} |
|
|
|
|
Def {
|
|
|
|
// allow more general Csname argument to \def commands, since other symbols such as '@' are often used in definitions
|
2023-08-15 10:23:12 -04:00
|
|
|
DefCtrlSeq optionalWhitespace? (Csname | CtrlSym) optionalWhitespace? (MacroParameter | OptionalMacroParameter)* optionalWhitespace? DefinitionArgument
|
2023-04-13 04:21:25 -04:00
|
|
|
} |
|
2024-07-23 05:33:22 -04:00
|
|
|
Let {
|
|
|
|
LetCtrlSeq Csname optionalWhitespace? "="? optionalWhitespace? Csname
|
|
|
|
} |
|
2023-04-13 04:21:25 -04:00
|
|
|
Hbox {
|
|
|
|
HboxCtrlSeq optionalWhitespace? TextArgument
|
|
|
|
} |
|
|
|
|
NewCommand {
|
|
|
|
NewCommandCtrlSeq optionalWhitespace?
|
|
|
|
(Csname | OpenBrace LiteralArgContent CloseBrace)
|
|
|
|
(OptionalArgument)*
|
|
|
|
DefinitionArgument
|
|
|
|
} |
|
|
|
|
RenewCommand {
|
|
|
|
RenewCommandCtrlSeq optionalWhitespace?
|
|
|
|
(Csname | OpenBrace LiteralArgContent CloseBrace)
|
|
|
|
(OptionalArgument)*
|
|
|
|
DefinitionArgument
|
|
|
|
} |
|
|
|
|
NewEnvironment {
|
|
|
|
NewEnvironmentCtrlSeq optionalWhitespace?
|
|
|
|
(OpenBrace LiteralArgContent CloseBrace)
|
|
|
|
(OptionalArgument)*
|
|
|
|
DefinitionArgument
|
|
|
|
DefinitionArgument
|
|
|
|
} |
|
|
|
|
RenewEnvironment {
|
|
|
|
RenewEnvironmentCtrlSeq optionalWhitespace?
|
|
|
|
(Csname | OpenBrace LiteralArgContent CloseBrace)
|
|
|
|
(OptionalArgument)*
|
|
|
|
DefinitionArgument
|
|
|
|
DefinitionArgument
|
|
|
|
} |
|
|
|
|
Input {
|
|
|
|
InputCtrlSeq InputArgument { ( FilePathArgument | BareFilePathArgument ) }
|
|
|
|
} |
|
|
|
|
Include {
|
|
|
|
IncludeCtrlSeq IncludeArgument { FilePathArgument }
|
|
|
|
} |
|
|
|
|
Centering {
|
|
|
|
CenteringCtrlSeq
|
|
|
|
} |
|
|
|
|
Item {
|
2024-05-03 03:45:08 -04:00
|
|
|
ItemCtrlSeq OptionalArgument? optionalWhitespace?
|
2023-04-20 05:59:43 -04:00
|
|
|
} |
|
|
|
|
Maketitle {
|
|
|
|
MaketitleCtrlSeq optionalWhitespace?
|
2023-08-08 08:14:25 -04:00
|
|
|
} |
|
2023-08-14 04:15:52 -04:00
|
|
|
HorizontalLine {
|
|
|
|
(HLineCtrlSeq | TopRuleCtrlSeq | MidRuleCtrlSeq | BottomRuleCtrlSeq) optionalWhitespace?
|
2023-08-24 05:19:11 -04:00
|
|
|
} |
|
|
|
|
MultiColumn {
|
|
|
|
MultiColumnCtrlSeq
|
|
|
|
optionalWhitespace? SpanArgument { ShortTextArgument }
|
|
|
|
optionalWhitespace? ColumnArgument { ShortTextArgument }
|
|
|
|
optionalWhitespace? TabularArgument
|
2024-06-25 04:07:47 -04:00
|
|
|
} |
|
|
|
|
MathTextCommand {
|
|
|
|
MathTextCtrlSeq optionalWhitespace? "*"? TextArgument
|
2024-07-02 11:07:22 -04:00
|
|
|
} |
|
|
|
|
ParBoxCommand {
|
|
|
|
ParBoxCtrlSeq
|
|
|
|
(optionalWhitespace? OptionalArgument)*
|
|
|
|
ShortTextArgument
|
|
|
|
optionalWhitespace? TextArgument
|
2024-08-02 03:59:11 -04:00
|
|
|
} |
|
|
|
|
TextBoldCommand {
|
|
|
|
TextBoldCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextItalicCommand {
|
|
|
|
TextItalicCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextSmallCapsCommand {
|
|
|
|
TextSmallCapsCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextTeletypeCommand {
|
|
|
|
TextTeletypeCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextMediumCommand {
|
|
|
|
TextMediumCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextSansSerifCommand {
|
|
|
|
TextSansSerifCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextSuperscriptCommand {
|
|
|
|
TextSuperscriptCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
TextSubscriptCommand {
|
|
|
|
TextSubscriptCtrlSeq TextArgument
|
|
|
|
} |
|
|
|
|
StrikeOutCommand {
|
|
|
|
TextStrikeOutCtrlSeq ArgumentType
|
|
|
|
} |
|
|
|
|
EmphasisCommand {
|
|
|
|
EmphasisCtrlSeq ArgumentType
|
|
|
|
} |
|
|
|
|
UnderlineCommand {
|
|
|
|
UnderlineCtrlSeq ArgumentType
|
2024-11-05 06:59:33 -05:00
|
|
|
} |
|
|
|
|
SetLengthCommand {
|
|
|
|
SetLengthCtrlSeq optionalWhitespace? ShortTextArgument optionalWhitespace? ShortTextArgument
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnknownCommand {
|
|
|
|
(CtrlSeq !argument Whitespace (OptionalArgument | TextArgument)+)
|
2024-06-25 04:07:47 -04:00
|
|
|
| (CtrlSeq (OptionalArgument | TextArgument)+)
|
2023-04-13 04:21:25 -04:00
|
|
|
| CtrlSeq Whitespace?
|
|
|
|
| CtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
Command {
|
2024-06-25 04:07:47 -04:00
|
|
|
KnownCommand<TextArgument>
|
2023-04-13 04:21:25 -04:00
|
|
|
| UnknownCommand
|
2023-08-04 03:37:36 -04:00
|
|
|
| KnownCtrlSym
|
2024-06-25 04:07:47 -04:00
|
|
|
// Not technically allowed in normal mode, but not worth failing the parse over
|
|
|
|
| LeftCtrlSeq
|
|
|
|
| RightCtrlSeq
|
|
|
|
|
2023-08-04 03:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
KnownCtrlSym {
|
2023-08-14 04:16:27 -04:00
|
|
|
LineBreak {
|
|
|
|
LineBreakCtrlSym OptionalArgument?
|
|
|
|
}
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
textBase {
|
|
|
|
( Command
|
|
|
|
| DollarMath
|
|
|
|
| BracketMath
|
|
|
|
| ParenMath
|
|
|
|
| NewLine
|
|
|
|
| Normal
|
|
|
|
| Whitespace
|
|
|
|
| Ampersand
|
2023-07-11 09:34:47 -04:00
|
|
|
| Tilde
|
2023-04-13 04:21:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
textWithBrackets {
|
|
|
|
( textBase
|
|
|
|
| OpenBracket
|
|
|
|
| CloseBracket
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
textWithEnvironmentsAndBlankLines {
|
|
|
|
( BlankLine
|
|
|
|
| KnownEnvironment
|
|
|
|
| Environment
|
|
|
|
| textWithBrackets
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
textWithGroupsEnvironmentsAndBlankLines {
|
|
|
|
textWithEnvironmentsAndBlankLines
|
|
|
|
| Group<Text>
|
|
|
|
}
|
|
|
|
|
|
|
|
Content<Element> {
|
|
|
|
Element
|
|
|
|
}
|
|
|
|
|
|
|
|
SectioningCommand<Command> {
|
|
|
|
Command optionalWhitespace? "*"? optionalWhitespace? OptionalArgument? optionalWhitespace? SectioningArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
documentSection<Command, Next> {
|
|
|
|
SectioningCommand<Command> Content<(sectionText | !section Next)*>
|
|
|
|
}
|
|
|
|
Book[@isGroup="$SectioningCommand"] { documentSection<BookCtrlSeq, Part | Chapter | Section | SubSection | SubSubSection | Paragraph | SubParagraph> }
|
|
|
|
Part[@isGroup="$SectioningCommand"] { documentSection<PartCtrlSeq, Chapter | Section | SubSection | SubSubSection | Paragraph | SubParagraph> }
|
|
|
|
Chapter[@isGroup="$SectioningCommand"] { documentSection<ChapterCtrlSeq, Section | SubSection | SubSubSection | Paragraph | SubParagraph> }
|
|
|
|
Section[@isGroup="$SectioningCommand"] { documentSection<SectionCtrlSeq, SubSection | SubSubSection | Paragraph | SubParagraph> }
|
|
|
|
SubSection[@isGroup="$SectioningCommand"] { documentSection<SubSectionCtrlSeq, SubSubSection | Paragraph | SubParagraph> }
|
|
|
|
SubSubSection[@isGroup="$SectioningCommand"] { documentSection<SubSubSectionCtrlSeq, Paragraph | SubParagraph> }
|
|
|
|
Paragraph[@isGroup="$SectioningCommand"] { documentSection<ParagraphCtrlSeq, SubParagraph> }
|
|
|
|
SubParagraph[@isGroup="$SectioningCommand"] { SectioningCommand<SubParagraphCtrlSeq> Content<sectionText*> }
|
|
|
|
|
|
|
|
sectioningCommand {
|
|
|
|
Book | Part | Chapter | Section | SubSection | SubSubSection | Paragraph | SubParagraph
|
|
|
|
}
|
|
|
|
|
|
|
|
sectionText {
|
|
|
|
!section (
|
|
|
|
textWithGroupsEnvironmentsAndBlankLines
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
( sectionText
|
|
|
|
| sectioningCommand)+
|
|
|
|
}
|
|
|
|
|
|
|
|
LongArg {
|
|
|
|
( textWithBrackets
|
|
|
|
| NonEmptyGroup<LongArg>
|
|
|
|
| KnownEnvironment
|
|
|
|
| Environment
|
|
|
|
| BlankLine
|
|
|
|
| "#" // macro character
|
|
|
|
| "_" | "^" // other math chars
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
ShortTextArgument {
|
|
|
|
OpenBrace ShortArg CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
ShortArg {
|
|
|
|
( textWithBrackets
|
|
|
|
| NonEmptyGroup<ShortArg>
|
|
|
|
| "#" // macro character
|
|
|
|
| "_" | "^" // other math chars
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
ShortOptionalArg {
|
|
|
|
( textBase
|
|
|
|
| NonEmptyGroup<ShortOptionalArg>
|
|
|
|
| "#" // macro character
|
2024-06-10 04:39:59 -04:00
|
|
|
| "_" // underscore is used in some parameter names
|
2023-04-13 04:21:25 -04:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
TikzPictureContent { /// same as Text but with added allowed characters
|
|
|
|
( textWithEnvironmentsAndBlankLines
|
|
|
|
| NonEmptyGroup<TikzPictureContent>
|
|
|
|
| "#" // macro character
|
|
|
|
| "_" | "^" // other math chars
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
DefinitionFragment {
|
2024-06-26 04:59:40 -04:00
|
|
|
( DefinitionFragmentCommand
|
2023-04-13 04:21:25 -04:00
|
|
|
| Begin
|
|
|
|
| End
|
2024-06-26 04:59:40 -04:00
|
|
|
| Group<DefinitionFragment>
|
2023-04-13 04:21:25 -04:00
|
|
|
| Dollar
|
|
|
|
| OpenParenCtrlSym
|
|
|
|
| CloseParenCtrlSym
|
|
|
|
| OpenBracketCtrlSym
|
|
|
|
| CloseBracketCtrlSym
|
2024-06-25 04:07:47 -04:00
|
|
|
| LeftCtrlSeq
|
|
|
|
| RightCtrlSeq
|
2023-04-13 04:21:25 -04:00
|
|
|
| BlankLine
|
|
|
|
| NewLine
|
|
|
|
| Normal
|
|
|
|
| Whitespace
|
|
|
|
| OpenBracket
|
|
|
|
| CloseBracket
|
|
|
|
| "#" // macro character
|
|
|
|
| Ampersand // for tables
|
2023-07-11 09:34:47 -04:00
|
|
|
| Tilde // unbreakable space
|
2023-04-13 04:21:25 -04:00
|
|
|
| "_" | "^" // other math chars
|
|
|
|
| SectioningCommand<
|
|
|
|
BookCtrlSeq |
|
|
|
|
PartCtrlSeq |
|
|
|
|
ChapterCtrlSeq |
|
|
|
|
SectionCtrlSeq |
|
|
|
|
SubSectionCtrlSeq |
|
|
|
|
SubSubSectionCtrlSeq |
|
|
|
|
ParagraphCtrlSeq |
|
|
|
|
SubParagraphCtrlSeq
|
|
|
|
>
|
2024-06-26 04:59:40 -04:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
DefinitionFragmentArgument {
|
|
|
|
OpenBrace DefinitionFragment? CloseBrace
|
|
|
|
}
|
2023-04-13 04:21:25 -04:00
|
|
|
|
2024-06-26 04:59:40 -04:00
|
|
|
DefinitionFragmentCommand {
|
|
|
|
KnownCommand<TextArgument>
|
2024-06-26 05:28:58 -04:00
|
|
|
| DefinitionFragmentUnknownCommand { genericUnknownCommandWithOptionalArguments<DefinitionFragmentArgument, OptionalArgument> }
|
2024-06-26 04:59:40 -04:00
|
|
|
| KnownCtrlSym
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
KnownEnvironment {
|
|
|
|
( DocumentEnvironment
|
|
|
|
| TabularEnvironment
|
|
|
|
| EquationEnvironment
|
|
|
|
| EquationArrayEnvironment
|
|
|
|
| VerbatimEnvironment
|
|
|
|
| TikzPictureEnvironment
|
|
|
|
| FigureEnvironment
|
|
|
|
| ListEnvironment
|
2023-08-17 04:08:41 -04:00
|
|
|
| TableEnvironment
|
2023-04-13 04:21:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
BeginEnv<name> {
|
|
|
|
Begin
|
|
|
|
EnvNameGroup<name>
|
|
|
|
OptionalArgument?
|
|
|
|
(!argument TextArgument)*
|
|
|
|
}
|
|
|
|
|
|
|
|
EndEnv<name> {
|
|
|
|
End
|
|
|
|
EnvNameGroup<name>
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<DocumentEnvName>
|
|
|
|
Content<Text>
|
|
|
|
EndEnv<DocumentEnvName>
|
|
|
|
(TrailingWhitespaceOnly | TrailingContent)?
|
|
|
|
}
|
|
|
|
|
2023-08-24 05:19:11 -04:00
|
|
|
TabularContent {
|
|
|
|
(textWithGroupsEnvironmentsAndBlankLines)*
|
|
|
|
}
|
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
TabularEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<TabularEnvName>
|
2023-08-24 05:19:11 -04:00
|
|
|
Content<TabularContent>
|
2023-04-13 04:21:25 -04:00
|
|
|
EndEnv<TabularEnvName>
|
|
|
|
}
|
|
|
|
|
2023-08-17 04:08:41 -04:00
|
|
|
TableEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<TableEnvName>
|
|
|
|
Content<Text>
|
|
|
|
EndEnv<TableEnvName>
|
|
|
|
}
|
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
EquationEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<EquationEnvName>
|
|
|
|
Content<Math?>
|
|
|
|
EndEnv<EquationEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
EquationArrayEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<EquationArrayEnvName>
|
|
|
|
Content<Math?>
|
|
|
|
EndEnv<EquationArrayEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
VerbatimEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<VerbatimEnvName>
|
|
|
|
Content<VerbatimContent>
|
|
|
|
EndEnv<VerbatimEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
TikzPictureEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<TikzPictureEnvName>
|
|
|
|
Content<TikzPictureContent>
|
|
|
|
EndEnv<TikzPictureEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
FigureEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<FigureEnvName>
|
|
|
|
Content<Text>
|
|
|
|
EndEnv<FigureEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
ListEnvironment[@isGroup="$Environment"] {
|
|
|
|
BeginEnv<ListEnvName>
|
|
|
|
Content<Text>
|
|
|
|
EndEnv<ListEnvName>
|
|
|
|
}
|
|
|
|
|
|
|
|
EnvNameGroup<name> {
|
|
|
|
OpenBrace name CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
Environment[@isGroup="$Environment"] {
|
2023-09-11 05:53:22 -04:00
|
|
|
BeginEnv<EnvName?>
|
2023-04-13 04:21:25 -04:00
|
|
|
Content<Text>
|
2023-09-11 05:53:22 -04:00
|
|
|
EndEnv<EnvName?>
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Group<GroupContent> {
|
|
|
|
OpenBrace GroupContent? CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
NonEmptyGroup<GroupContent> {
|
|
|
|
OpenBrace GroupContent CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MATH MODE
|
|
|
|
|
2024-11-15 04:03:16 -05:00
|
|
|
DollarMath[@isGroup="$MathContainer"] {
|
2023-04-13 04:21:25 -04:00
|
|
|
Dollar (InlineMath | DisplayMath) Dollar
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineMath {
|
|
|
|
Math
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayMath {
|
|
|
|
Dollar Math? Dollar
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OpenParenMath[closedBy=CloseParenMath] {
|
|
|
|
OpenParenCtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseParenMath[openedBy=OpenParenMath] {
|
|
|
|
CloseParenCtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
// alternative syntax \( math \) for inline math, it is the same as $ math $
|
2024-11-15 04:03:16 -05:00
|
|
|
ParenMath[@isGroup="$MathContainer"] {
|
2023-04-13 04:21:25 -04:00
|
|
|
OpenParenMath
|
|
|
|
Math?
|
|
|
|
CloseParenMath
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenBracketMath[closedBy=CloseBracketMath] {
|
|
|
|
OpenBracketCtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseBracketMath[openedBy=OpenBracketMath] {
|
|
|
|
CloseBracketCtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
// alternative syntax \[ math \] for display math, it is the same as $$ math $$
|
2024-11-15 04:03:16 -05:00
|
|
|
BracketMath[@isGroup="$MathContainer"] {
|
2023-04-13 04:21:25 -04:00
|
|
|
OpenBracketMath
|
|
|
|
Math?
|
|
|
|
CloseBracketMath
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: we should have separate math modes for inline and display math,
|
|
|
|
// because display math can contain blank lines while inline math cannot.
|
|
|
|
|
|
|
|
Math {
|
2024-06-18 06:01:08 -04:00
|
|
|
( MathCommand
|
|
|
|
| Group<Math>
|
2023-04-13 04:21:25 -04:00
|
|
|
| MathDelimitedGroup
|
|
|
|
| MathSpecialChar
|
|
|
|
| Number
|
|
|
|
| NewLine
|
2024-06-18 06:01:08 -04:00
|
|
|
| Whitespace
|
2023-04-13 04:21:25 -04:00
|
|
|
| KnownEnvironment
|
|
|
|
| Environment
|
|
|
|
| MathChar
|
|
|
|
| OpenBracket
|
|
|
|
| CloseBracket
|
|
|
|
| Ampersand
|
2023-07-11 09:34:47 -04:00
|
|
|
| Tilde
|
2023-04-13 04:21:25 -04:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
2024-06-18 06:01:08 -04:00
|
|
|
|
|
|
|
MathCommand {
|
2024-06-25 04:07:47 -04:00
|
|
|
KnownCommand<MathArgument>
|
2024-06-26 04:59:40 -04:00
|
|
|
| MathUnknownCommand { genericUnknownCommand<MathArgument> }
|
2024-06-25 04:07:47 -04:00
|
|
|
| KnownCtrlSym
|
2023-04-13 04:21:25 -04:00
|
|
|
}
|
|
|
|
|
2024-06-25 04:09:05 -04:00
|
|
|
@external tokens argumentListTokenizer from "./tokens.mjs" {
|
|
|
|
hasMoreArguments,
|
2024-06-18 06:01:08 -04:00
|
|
|
endOfArguments
|
|
|
|
}
|
2023-04-13 04:21:25 -04:00
|
|
|
|
2024-06-26 04:59:40 -04:00
|
|
|
@external tokens argumentListWithOptionalTokenizer from "./tokens.mjs" {
|
|
|
|
hasMoreArgumentsOrOptionals,
|
|
|
|
endOfArgumentsAndOptionals
|
|
|
|
}
|
|
|
|
|
|
|
|
genericUnknownCommand<ArgumentType> {
|
|
|
|
CtrlSeq (hasMoreArguments optionalWhitespace? ArgumentType)* endOfArguments
|
|
|
|
| CtrlSym
|
|
|
|
}
|
|
|
|
|
|
|
|
genericUnknownCommandWithOptionalArguments<ArgumentType, OptionalArgumentType> {
|
|
|
|
CtrlSeq (hasMoreArgumentsOrOptionals optionalWhitespace? (ArgumentType | OptionalArgumentType))* endOfArgumentsAndOptionals
|
2024-06-18 06:01:08 -04:00
|
|
|
| CtrlSym
|
|
|
|
}
|
2023-04-13 04:21:25 -04:00
|
|
|
|
2024-06-18 06:01:08 -04:00
|
|
|
MathArgument {
|
2023-04-13 04:21:25 -04:00
|
|
|
OpenBrace Math? CloseBrace
|
|
|
|
}
|
|
|
|
|
|
|
|
MathDelimitedGroup {
|
|
|
|
MathOpening Math? MathClosing
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: we have the same problem with specialize on \left,\right as the delimiters
|
|
|
|
MathOpening {
|
|
|
|
LeftCtrlSeq optionalWhitespace? MathDelimiter
|
|
|
|
}
|
|
|
|
|
|
|
|
MathClosing {
|
|
|
|
RightCtrlSeq optionalWhitespace? MathDelimiter
|
|
|
|
}
|
|
|
|
|
2024-06-25 04:05:41 -04:00
|
|
|
MathDelimiter {
|
|
|
|
// Allowed delimiters, from the LaTeX manual, table 3.10
|
|
|
|
"/" | "|" | "(" | ")" | "[" | "]" |
|
|
|
|
"\\{" | "\\}" | "\\|" |
|
|
|
|
"\\lfloor" | "\\rfloor" |
|
|
|
|
"\\lceil" | "\\rceil" |
|
|
|
|
"\\langle" | "\\rangle" |
|
|
|
|
"\\backslash" | "\\uparrow" |
|
|
|
|
"\\Uparrow" | "\\Downarrow" |
|
|
|
|
"\\updownarrow" | "\\Updownarrow" |
|
|
|
|
"\\downarrow" | "\\lvert" |
|
|
|
|
"\\lVert" | "\\rVert" |
|
|
|
|
"\\rvert" | "\\vert" | "\\Vert" |
|
|
|
|
"\\lbrace" | "\\rbrace" |
|
|
|
|
"\\lbrack" | "\\rbrack" |
|
|
|
|
// Also allow the empty match
|
|
|
|
"."
|
|
|
|
}
|
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
// NOTE: precedence works differently for rules and token, in the rule
|
|
|
|
// you have to give a specifier !foo which is defined in the @precedence
|
|
|
|
// block here.
|
|
|
|
|
|
|
|
@precedence {
|
|
|
|
section @left,
|
|
|
|
argument @left // make CtrlSeq arguments left associative
|
|
|
|
}
|