Skip to content

Commit

Permalink
[LaTeX] Inherit LaTeX from TeX
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Nov 12, 2022
1 parent e216264 commit 718926a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 73 deletions.
84 changes: 15 additions & 69 deletions LaTeX/LaTeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
name: LaTeX
scope: text.tex.latex

extends: TeX.sublime-syntax

file_extensions:
- tex
- ltx
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -246,16 +217,17 @@ contexts:
- include: else-pop

general-constants:
- meta_prepend: true
- match: (\\\\)(?:(\[)\s*-?((?:[[:digit:]]|\.)*)\s*(\w*)\s*(\]))?
captures:
1: constant.character.newline.latex
2: punctuation.definition.group.bracket.begin.newline.latex
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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -564,7 +511,6 @@ contexts:
scope: string.other.math.latex punctuation.definition.string.end.latex
pop: true
- include: math-content

- match: |-
(?x)
((\\)begin)(\{)\s*((?:
Expand Down
4 changes: 4 additions & 0 deletions LaTeX/TeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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*$)
Expand Down
15 changes: 11 additions & 4 deletions LaTeX/syntax_test_latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -704,23 +704,30 @@ \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
% ^^^^^^^ keyword.other.math.delimiter.tex
% ^^^^ 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

0 comments on commit 718926a

Please sign in to comment.