Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LaTeX] Inherit LaTeX from TeX #3546

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Haskell/Literate Haskell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file_extensions:
- lhs

contexts:
plain-tex:
begin-end-commands:
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
- meta_prepend: true
- include: haskell-code

Expand Down
97 changes: 15 additions & 82 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 @@ -107,21 +78,8 @@ contexts:
- include: general-optional-arguments
- include: else-pop

# used in macros to prevent matching of \begin{env}...\end{env}
macro-braces:
- match: \{
scope: punctuation.definition.group.brace.begin.latex
push:
- meta_scope: meta.group.brace.latex
- match: \}
scope: punctuation.definition.group.brace.end.latex
pop: true
- include: general-constants
- include: general-commands
- 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 +204,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 +454,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 +489,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 +498,6 @@ contexts:
scope: string.other.math.latex punctuation.definition.string.end.latex
pop: true
- include: math-content

- match: |-
(?x)
((\\)begin)(\{)\s*((?:
Expand Down
26 changes: 16 additions & 10 deletions LaTeX/TeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ contexts:
- include: general-constants
- include: general-commands

# matches any nospace and pops the context
else-pop:
- match: (?=\S)
pop: true

# pops out of the current context if there is a new paragraph
paragraph-pop:
- match: ^(?=\s*$)
pop: true

general-commands:
- match: (\\){{letter}}+
scope: support.function.general.tex
Expand Down Expand Up @@ -395,3 +385,19 @@ contexts:
scope: string.other.math.tex punctuation.definition.string.end.tex
pop: true
- include: math-content

###[ PROTOTYPES ]##############################################################

# 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
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