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] Math scopes #3608

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 15 additions & 7 deletions LaTeX/LaTeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,22 @@ contexts:
- include: inline-math-ensuremath

inline-math-ensuremath:
- match: ((\\)ensuremath)(\{)
- match: (\\)ensuremath{{endcs}}
scope: support.function.ensuremath.latex
captures:
1: support.function.ensuremath.latex
2: punctuation.definition.backslash.latex
3: punctuation.definition.group.brace.begin.tex
push: inline-math-ensuremath-body
1: punctuation.definition.backslash.latex
push: inline-math-ensuremath-begin

inline-math-ensuremath-begin:
- meta_scope: meta.function.ensuremath.latex
- match: \{
scope: punctuation.definition.group.brace.begin.tex
set: inline-math-ensuremath-body
- include: paragraph-pop

inline-math-ensuremath-body:
- meta_scope: meta.function.ensuremath.latex
- meta_content_scope: meta.environment.math.inline.ensuremath.latex
- meta_content_scope: meta.environment.math.inline.ensuremath.latex markup.math.inline
- include: brace-group-end
- include: math-content

Expand All @@ -601,6 +607,7 @@ contexts:

inline-math-parens-body:
- meta_scope: meta.environment.math.inline.paren.latex
- meta_content_scope: markup.math.inline
- include: inline-math-parens-end
- include: math-content

Expand Down Expand Up @@ -631,7 +638,7 @@ contexts:
push: block-math-begin-end-command-body

block-math-begin-end-command-body:
- meta_content_scope: meta.environment.math.block.be.latex
- meta_content_scope: meta.environment.math.block.be.latex markup.math.block
- include: block-math-begin-end-command-end
- include: math-content

Expand All @@ -652,6 +659,7 @@ contexts:

block-math-brackets-body:
- meta_scope: meta.environment.math.block.bracket.latex
- meta_content_scope: markup.math.block
- include: block-math-brackets-end
- include: math-content

Expand Down
30 changes: 19 additions & 11 deletions LaTeX/TeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ contexts:

tex-constants:
- match: (\\){{constants}}{{endcs}}
scope: constant.language.tex
scope: support.function.tex
captures:
1: punctuation.definition.backslash.tex
push:
- tex-dimension-value
- tex-assignment
- match: (\\){{macroconst}}{{endcs}}
scope: constant.language.tex
scope: support.function.tex
captures:
1: punctuation.definition.backslash.tex

Expand Down Expand Up @@ -543,6 +543,7 @@ contexts:

inline-math-dollar-body:
- meta_scope: meta.environment.math.inline.dollar.tex
- meta_content_scope: markup.math.inline
- include: inline-math-dollar-end
- include: math-content

Expand All @@ -558,6 +559,7 @@ contexts:

block-math-dollar-body:
- meta_scope: meta.environment.math.block.dollar.tex
- meta_content_scope: markup.math.block
- include: block-math-dollar-end
- include: math-content

Expand Down Expand Up @@ -649,14 +651,16 @@ contexts:
1: punctuation.definition.backslash.tex

math-operators:
- match: '[<>]=?'
# note: in math notation, = usually denotes that two terms are equal, instead
# of an assignment.
- match: '[<>]=?|='
scope: keyword.operator.comparison.tex
- match: '[-+*/^!]'
- match: '[-+*/!]'
scope: keyword.operator.arithmetic.tex
- match: =
scope: keyword.operator.assignment.tex
- match: _
scope: punctuation.separator.indice.tex
scope: punctuation.separator.subscript.tex
- match: \^
scope: punctuation.separator.superscript.tex

math-braces:
- match: \{
Expand All @@ -677,10 +681,14 @@ contexts:
scope: punctuation.section.brackets.begin.tex
- match: \]
scope: punctuation.section.brackets.end.tex
- match: (\\)[{}]
scope: constant.character.escape.tex
- match: (\\){
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
scope: punctuation.section.braces.begin.tex constant.character.escape.tex
captures:
1: punctuation.definition.escape.tex
1: punctuation.definition.backslash.tex
- match: (\\)}
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
scope: punctuation.section.braces.end.tex constant.character.escape.tex
captures:
1: punctuation.definition.backslash.tex

math-numbers:
- match: \d*(\.)\d+
Expand All @@ -692,7 +700,7 @@ contexts:

math-variables:
- match: '[A-Za-z]+'
scope: variable.other.math.tex
scope: variable.other.math.tex markup.italic.math.tex

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

Expand Down
File renamed without changes.
83 changes: 50 additions & 33 deletions LaTeX/tests/syntax_test_latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -762,47 +762,58 @@ \subsubsection{name}

% Check we have always a shared environment

$f(x) = x^2$
% <- meta.environment.math.inline.dollar.tex string.other.math.tex punctuation.definition.string.begin.tex
%^^^^^^^^^^ meta.environment.math.inline.dollar.tex - string
% ^ meta.environment.math.inline.dollar.tex string.other.math.tex punctuation.definition.string.end.tex
% ^ - meta.environment.math

$$f(x) = x^2$$
% <- meta.environment.math.block.dollar.tex string.other.math.tex punctuation.definition.string.begin.tex
%^ meta.environment.math.block.dollar.tex string.other.math.tex punctuation.definition.string.begin.tex
% ^^^^^^^^^^ meta.environment.math.block.dollar.tex - string
% ^^ meta.environment.math.block.dollar.tex string.other.math.tex punctuation.definition.string.end.tex
% ^ - meta.environment.math

\(f(x) = x^2\)
% <- meta.environment.math.inline.paren.latex string.other.math.latex punctuation.definition.string.begin.latex
%^ meta.environment.math.inline.paren.latex string.other.math.latex punctuation.definition.string.begin.latex
% ^^^^^^^^^^ meta.environment.math.inline.paren.latex - string
% ^^ meta.environment.math.inline.paren.latex string.other.math.latex punctuation.definition.string.end.latex
% ^ - meta.environment.math

\[
% <- meta.environment.math.block.bracket.latex string.other.math.latex punctuation.definition.string.begin.latex
%^ meta.environment.math.block.bracket.latex string.other.math.latex punctuation.definition.string.begin.latex
% ^ meta.environment.math.block.bracket.latex - string
$f(x) = x^2$
%^ string.other.math.tex punctuation.definition.string.begin.tex
%^^^^^^^^^^^^ meta.environment.math.inline.dollar.tex
% ^^^^^^^^^^ markup.math.inline - string
% ^ punctuation.definition.string.end.tex - markup.math.inline

$$f(x) = x^2$$
%^^ string.other.math.tex punctuation.definition.string.begin.tex
%^^^^^^^^^^^^^^ meta.environment.math.block.dollar.tex
% ^^^^^^^^^^ markup.math.block - string
% ^^ string.other.math.tex punctuation.definition.string.end.tex - markup.math.block

\(f(x) = x^2\)
%^^^^^^^^^^^^^^ meta.environment.math.inline.paren.latex
% ^^^^^^^^^^ markup.math.inline - string
%^^ string.other.math.latex punctuation.definition.string.begin.latex
% ^^ string.other.math.latex punctuation.definition.string.end.latex - markup.math.inline


\[
%^^ string.other.math.latex punctuation.definition.string.begin.latex
f(x) = x^2 \text{ $f$ is a function}
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.environment.math.block.bracket.latex
\]
% <- meta.environment.math.block.bracket.latex string.other.math.latex punctuation.definition.string.end.latex
%^ meta.environment.math.block.bracket.latex string.other.math.latex punctuation.definition.string.end.latex
% ^ - meta.environment.math
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.environment.math.block.bracket.latex markup.math.block
% ^^^^^^^^^^ - string
\]
%^^ meta.environment.math.block.bracket.latex punctuation.definition.string.end.latex - markup.math.inline
% ^ - meta.environment.math

\ensuremath{f(x) = x^2}
% <- meta.function.ensuremath.latex support.function.ensuremath.latex punctuation.definition.backslash.latex
%^^^^^^^^^^ meta.function.ensuremath.latex
% ^ meta.function.ensuremath.latex - meta.environment.math
% ^^^^^^^^^^ meta.function.ensuremath.latex meta.environment.math.inline.ensuremath.latex
% ^ meta.function.ensuremath.latex - meta.environment.math
%^^^^^^^^^^^^^^^^^^^^^^ meta.function.ensuremath.latex
% ^ - meta.environment.math - markup.math
% ^^^^^^^^^^ meta.environment.math.inline.ensuremath.latex markup.math.inline
% ^ - meta.environment.math - markup.math
%^^^^^^^^^^ support.function.ensuremath.latex
% ^ punctuation.definition.group.brace.begin.tex
% ^ punctuation.definition.group.brace.end.tex

\ensuremath %
%^^^^^^^^^^^^^ meta.function.ensuremath.latex
%^^^^^^^^^^ support.function.ensuremath.latex
% ^^ comment.line.percentage.tex
{x^2}{normal text}
%^^^^^^^^^ meta.function.ensuremath.latex
% ^ punctuation.definition.group.brace.begin.tex
% ^^^ meta.environment.math.inline.ensuremath.latex markup.math.inline
% ^ punctuation.definition.group.brace.end.tex
% ^^^^^^^^^^^^^ - meta.function.ensuremath.latex

\ensuremaths{5}
% ^ - meta.function.ensuremath.latex

\begin{equation}
% <- support.function.begin.latex keyword.control.flow.begin.latex punctuation.definition.backslash.latex
%^^^^^ support.function.begin.latex keyword.control.flow.begin.latex
Expand All @@ -820,6 +831,12 @@ \subsubsection{name}
% ^ punctuation.definition.group.brace.end.tex


$\verb!$! \alpha$
%^^^^^^^^^^^^^^^ meta.environment.math.inline.dollar.tex markup.math.inline
% ^ markup.raw.verb.latex
% ^^^^^^ keyword.other.math.greek.tex


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Boxes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
4 changes: 2 additions & 2 deletions LaTeX/tests/syntax_test_latex.xparse.tex
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@
% ^^ variable.parameter.tex
% ^ punctuation.definition.placeholder.tex
% ^ meta.number.integer.decimal.tex constant.numeric.value.tex
% ^^^^^ constant.language.tex
% ^^^^^^^^ constant.language.tex
% ^^^^^ support.function.tex
% ^^^^^^^^ support.function.tex
% ^ punctuation.definition.backslash.tex
% ^ punctuation.definition.backslash.tex
% ^^^ meta.number.integer.decimal.tex
Expand Down
Loading