diff --git a/LaTeX/LaTeX.sublime-syntax b/LaTeX/LaTeX.sublime-syntax index 0f1adb8955..a76bf2ad83 100644 --- a/LaTeX/LaTeX.sublime-syntax +++ b/LaTeX/LaTeX.sublime-syntax @@ -4,6 +4,8 @@ name: LaTeX scope: text.tex.latex +extends: TeX.sublime-syntax + file_extensions: - tex - ltx @@ -14,18 +16,13 @@ first_line_match: |- ) contexts: - prototype: - - include: comments main: - - include: unique-latex + - meta_prepend: true + - include: latex - include: packages - - include: plain-tex - - include: begin-end-commands - - include: general-commands - - include: global-braces - unique-latex: + latex: - include: preamble - include: structure - include: includes @@ -39,19 +36,7 @@ contexts: - include: graphics - include: lists - plain-tex: - - include: macros - - include: scope:text.tex#controls - - include: scope:text.tex#catcode - - include: boxes - - include: block-math - - include: inline-math - - include: general-constants - - comments: - - include: scope:text.tex#comments - - global-braces: + braces: - match: \{ scope: punctuation.definition.group.brace.begin.latex push: @@ -72,7 +57,7 @@ contexts: pop: true - include: general-constants - include: general-commands - - include: global-braces + - include: braces - match: '[A-Za-z[:digit:]-]*(?=\s*\=)' scope: variable.parameter.bracket.latex @@ -83,20 +68,6 @@ contexts: pop: true - include: main - # matches any nospace and pops the context - else-pop: - - match: (?=\S) - pop: true - - immediately-pop: - - match: '' - pop: true - - # pops out of the current context if there is a new paragraph - paragraph-pop: - - match: ^(?=\s*$) - pop: true - argument: - match: \{ scope: punctuation.definition.group.brace.begin.latex @@ -121,7 +92,7 @@ contexts: - include: macro-braces macros: - - include: scope:text.tex#macros + - meta_append: true - match: (\\)(?:new|renew|provide)command(?:\*|(?![A-Za-z@])) scope: keyword.declaration.function.latex storage.modifier.newcommand.latex captures: @@ -246,6 +217,7 @@ contexts: - include: else-pop general-constants: + - meta_prepend: true - match: (\\\\)(?:(\[)\s*-?((?:[[:digit:]]|\.)*)\s*(\w*)\s*(\]))? captures: 1: constant.character.newline.latex @@ -253,9 +225,9 @@ contexts: 3: constant.numeric.newline.latex 4: keyword.other.newline.latex 5: punctuation.definition.group.bracket.begin.newline.latex - - include: scope:text.tex#general-constants general-commands: + - include: begin-end-commands - match: (\\)[A-Za-z@]+ scope: support.function.general.latex captures: @@ -495,33 +467,16 @@ contexts: - include: math-content math-content: - # unique to latex + - meta_prepend: true + - match: (?=\}) + pop: true - include: verb - include: text-decorators - include: references - include: begin-end-commands - # extended from tex - - include: scope:text.tex#math-builtin - - include: scope:text.tex#math-brackets - - include: math-braces - - include: boxes - - include: scope:text.tex#math-commands - - include: scope:text.tex#math-operators - - include: scope:text.tex#math-characters - - include: scope:text.tex#math-numerics - - include: general-constants - - match: (?=\}) - pop: true inline-math: - - match: \$ - scope: string.other.math.latex punctuation.definition.string.begin.latex - push: - - meta_scope: meta.environment.math.inline.dollar.latex - - match: \$ - scope: string.other.math.latex punctuation.definition.string.end.latex - pop: true - - include: math-content + - meta_append: true - match: ((\\)ensuremath)(\{) captures: 1: support.function.ensuremath.latex @@ -547,15 +502,7 @@ contexts: - include: math-content block-math: - - match: \$\$ - scope: string.other.math.latex punctuation.definition.string.begin.latex - push: - - meta_scope: meta.environment.math.block.dollar.latex - - match: \$\$ - scope: string.other.math.latex punctuation.definition.string.end.latex - pop: true - - include: math-content - + - meta_append: true - match: (\\\[) scope: string.other.math.latex punctuation.definition.string.begin.latex push: @@ -564,7 +511,6 @@ contexts: scope: string.other.math.latex punctuation.definition.string.end.latex pop: true - include: math-content - - match: |- (?x) ((\\)begin)(\{)\s*((?: diff --git a/LaTeX/TeX.sublime-syntax b/LaTeX/TeX.sublime-syntax index 667f1e5388..4a7277cbf6 100644 --- a/LaTeX/TeX.sublime-syntax +++ b/LaTeX/TeX.sublime-syntax @@ -85,6 +85,10 @@ contexts: - match: (?=\S) pop: true + immediately-pop: + - match: '' + pop: true + # pops out of the current context if there is a new paragraph paragraph-pop: - match: ^(?=\s*$) diff --git a/LaTeX/syntax_test_latex.tex b/LaTeX/syntax_test_latex.tex index 390a7bbfc0..7e051ca234 100644 --- a/LaTeX/syntax_test_latex.tex +++ b/LaTeX/syntax_test_latex.tex @@ -704,16 +704,16 @@ \subsubsection{name} % <- - meta.environment.math $f(x) = \} {} y$ -% ^^^^^^^^^^^^^ meta.environment.math.inline.dollar.latex +% ^^^^^^^^^^^^^ meta.environment.math.inline.dollar.tex $\alpha \cdot \beta \leq \cos( 5 )$ %^ punctuation.definition.backslash.tex %^^^^^^ keyword.other.math.greek.tex -% ^ punctuation.definition.backslash.tex +% ^ punctuation.definition.backslash.tex % ^^^^^ keyword.other.math.binary-operator.tex % ^^^^ keyword.other.math.relation.tex -% -$s \gets \sum_{\imath = 0}^10 \langle \hat{x}, x \rangle$ +% +$s \gets \sum_{\imath = 0}^10 \langle \hat{x}, x \rangle$ % ^^^^^ keyword.other.math.arrow.tex % ^^^^ keyword.other.math.large-operator.tex % ^^^^^^ keyword.other.math.symbol.tex @@ -721,6 +721,13 @@ \subsubsection{name} % ^^^^ keyword.other.math.accent.tex % ^^^^^^^ keyword.other.math.delimiter.tex +$$ + \begin{foo} +% ^^^^^^ keyword.control.flow.begin.latex + \end{foo} +% ^^^^ keyword.control.flow.end.latex +$$ + \end{document} % ^ support.function.end.latex keyword.control.flow.end.latex % ^ variable.parameter.function.latex