Skip to content

Commit 135ffcb

Browse files
authored
[LaTeX] Scope macro variables in more contexts (#4405)
This PR includes `macro-variables` context everywhere, `main` (or later `expressions`) are not included in, to ensure `#1` macro variables are highlighted in any context.
1 parent 4c73d16 commit 135ffcb

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

LaTeX/LaTeX.sublime-syntax

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ contexts:
170170
- clear_scopes: 1
171171
- meta_scope: meta.function.identifier.latex
172172
- include: brace-group-end
173+
- include: macro-variables
173174
- match: (\\){{cmdname}}
174175
scope: entity.name.newcommand.latex
175176
captures:
@@ -236,6 +237,7 @@ contexts:
236237
- include: brace-group-end
237238
- include: braces
238239
- include: xparse-newcommand-single-argspec
240+
- include: macro-variables
239241
# not actually allowed, but included here to future-proof highlighting
240242
- include: general-constants
241243
- include: general-commands
@@ -308,6 +310,7 @@ contexts:
308310
xparse-newcommand-args-wrapped-token:
309311
- meta_scope: meta.group.brace.tex
310312
- include: brace-group-end
313+
- include: macro-variables
311314
# either a command
312315
- match: (\\){{cmdname}}{{endcs}}
313316
scope: constant.other.token.latex
@@ -421,6 +424,7 @@ contexts:
421424
set:
422425
- meta_scope: meta.preamble.documentclass.latex meta.group.brace.tex
423426
- include: brace-group-end
427+
- include: macro-variables
424428
- match: '[A-Za-z[:digit:]-]'
425429
scope: support.class.latex
426430
- include: immediately-pop
@@ -437,6 +441,7 @@ contexts:
437441
set:
438442
- meta_scope: meta.preamble.usepackage.latex meta.group.brace.tex
439443
- include: brace-group-end
444+
- include: macro-variables
440445
- match: '[A-Za-z[:digit:]-]*'
441446
scope: support.class.latex
442447
- include: immediately-pop
@@ -451,6 +456,7 @@ contexts:
451456
push:
452457
- meta_scope: meta.include.latex
453458
- include: brace-group-end
459+
- include: macro-variables
454460

455461
sections:
456462
- match: |-
@@ -1180,6 +1186,7 @@ contexts:
11801186
- match: '[a-zA-Z0-9\.:/*!^_-]+'
11811187
scope: constant.other.citation.latex
11821188
- include: brace-group-end
1189+
- include: macro-variables
11831190
- match: ''
11841191
pop: 1
11851192
- match: |-
@@ -1202,6 +1209,7 @@ contexts:
12021209
- match: '[a-zA-Z0-9\.:/*!^_-]+'
12031210
scope: constant.other.reference.latex
12041211
- include: brace-group-end
1212+
- include: macro-variables
12051213
- match: ''
12061214
pop: 1
12071215
- match: ((\\)label)(\{)
@@ -1214,6 +1222,7 @@ contexts:
12141222
- match: '[a-zA-Z0-9\.:/*!^_-]+'
12151223
scope: entity.name.label.latex
12161224
- include: brace-group-end
1225+
- include: macro-variables
12171226

12181227
begin-end-commands:
12191228
- match: ((\\)begin)(\{)\s*(\w*)\*?\s*(\})
@@ -2032,6 +2041,7 @@ contexts:
20322041
- meta_scope: meta.function.newcolumntype.latex
20332042
- include: brace-group-end
20342043
- include: array-preamble
2044+
- include: macro-variables
20352045
20362046
20372047
- match: |-

LaTeX/TeX.sublime-syntax

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ contexts:
597597
- include: math-operators
598598
- include: math-variables
599599
- include: math-numbers
600+
- include: macro-variables
600601
- include: boxes
601602
- include: general-constants
602603
- include: stray-brace-pop

LaTeX/tests/syntax_test_latex.tex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,45 @@
279279
\newcommandprefix
280280
%^^^^^^^^^^^^^^^^ support.function.general.latex
281281
282+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283+
% MACRO VARIABLES
284+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285+
286+
\begin{#1} \end{#1}
287+
% ^^ variable.other.readwrite.tex
288+
% ^ punctuation.definition.variable.tex
289+
% ^^ variable.other.readwrite.tex
290+
% ^ punctuation.definition.variable.tex
291+
292+
\cite{#1##2###3}
293+
% ^^^^^^^^^ variable.other.readwrite.tex
294+
% ^ punctuation.definition.variable.tex
295+
% ^^ punctuation.definition.variable.tex
296+
% ^^^ punctuation.definition.variable.tex
297+
298+
\cref{#1##2###3}
299+
% ^^^^^^^^^ variable.other.readwrite.tex
300+
% ^ punctuation.definition.variable.tex
301+
% ^^ punctuation.definition.variable.tex
302+
% ^^^ punctuation.definition.variable.tex
303+
304+
\label{#1##2###3}
305+
% ^^^^^^^^^ variable.other.readwrite.tex
306+
% ^ punctuation.definition.variable.tex
307+
% ^^ punctuation.definition.variable.tex
308+
% ^^^ punctuation.definition.variable.tex
309+
310+
$$
311+
\crot{#1} \{ { { #2 (#3) } } \}
312+
%^^^^^^^^^^^^^^^^^^^^^^^^^ meta.environment.math.block.dollar.tex markup.math.block
313+
% ^^ variable.other.readwrite.tex
314+
% ^ punctuation.definition.variable.tex
315+
% ^^ variable.other.readwrite.tex
316+
% ^ punctuation.definition.variable.tex
317+
% ^^ variable.other.readwrite.tex
318+
% ^ punctuation.definition.variable.tex
319+
$$
320+
282321
\newcolumntype{x}{>{$}c<{$}}
283322
% ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.newcolumntype.latex
284323
% ^ support.function.newcolumntype.latex

0 commit comments

Comments
 (0)