Skip to content

Commit 213d4bb

Browse files
nibagschristoph-cullmann
authored andcommitted
LaTeX: fix math parentheses in optional labels
Summary: BUG: 418979 Single parentheses within `[...]` were highlighted as math text, but the math text is `\(...\)`. Reviewers: #framework_syntax_highlighting, dhaumann, cullmann, jpoelen Reviewed By: #framework_syntax_highlighting, cullmann Subscribers: kwrite-devel, kde-frameworks-devel Tags: #kate, #frameworks Differential Revision: https://phabricator.kde.org/D28303
1 parent 517dccc commit 213d4bb

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

autotests/folding/highlight.tex.fold

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,7 @@ text<beginfold id='1'>\begin</beginfold id='1'>{a}text<endfold id='1'>\end</endf
273273
% Close brackets correctly in some commands (see bug #415384)
274274
\input{\a{}}
275275
\cites{ text { text } text }
276+
277+
% Parentheses within [ ... ] (see bug #418979)
278+
\cite[eq. (1.1)]{some_reference}
279+
\cite[eq. \(x^n + y^n = z^n\)]{some reference}

autotests/html/highlight.tex.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,8 @@
279279
<span style="color:#898887;">% Close brackets correctly in some commands (see bug #415384)</span>
280280
<span style="color:#644a9b;">\input</span>{<span style="color:#644a9b;">\a</span>{}}
281281
<span style="font-weight:bold;">\cites</span>{<span style="color:#0095ff;font-weight:bold;"> text </span>{<span style="color:#0095ff;font-weight:bold;"> text </span>}<span style="color:#0095ff;font-weight:bold;"> text </span>}
282+
283+
<span style="color:#898887;">% Parentheses within [ ... ] (see bug #418979)</span>
284+
<span style="font-weight:bold;">\cite</span>[eq. (1.1)]{<span style="color:#0095ff;font-weight:bold;">some_reference</span>}
285+
<span style="font-weight:bold;">\cite</span>[eq. <span style="color:#ff5500;">\(x^n + y^n = z^n\)</span>]{<span style="color:#0095ff;font-weight:bold;">some reference</span>}
282286
</pre></body></html>

autotests/input/highlight.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,7 @@ \section*{Notes for My Paper}
273273
% Close brackets correctly in some commands (see bug #415384)
274274
\input{\a{}}
275275
\cites{ text { text } text }
276+
277+
% Parentheses within [ ... ] (see bug #418979)
278+
\cite[eq. (1.1)]{some_reference}
279+
\cite[eq. \(x^n + y^n = z^n\)]{some reference}

autotests/reference/highlight.tex.ref

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,7 @@
273273
<Comment>% Close brackets correctly in some commands (see bug #415384)</Comment><br/>
274274
<Macro>\input</Macro><Normal Text>{</Normal Text><Macro>\a</Macro><Normal Text>{}}</Normal Text><br/>
275275
<Structure>\cites</Structure><Normal Text>{</Normal Text><Environment> text </Environment><Normal Text>{</Normal Text><Environment> text </Environment><Normal Text>}</Normal Text><Environment> text </Environment><Normal Text>}</Normal Text><br/>
276+
<Normal Text></Normal Text><br/>
277+
<Comment>% Parentheses within [ ... ] (see bug #418979)</Comment><br/>
278+
<Structure>\cite</Structure><Normal Text>[eq. (1.1)]{</Normal Text><Reference>some_reference</Reference><Normal Text>}</Normal Text><br/>
279+
<Structure>\cite</Structure><Normal Text>[eq. </Normal Text><Math>\(x^n + y^n = z^n\)</Math><Normal Text>]{</Normal Text><Reference>some reference</Reference><Normal Text>}</Normal Text><br/>

data/syntax/latex.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!ENTITY envname "[a-zA-Z]+\*?">
66
<!ENTITY regionmarker "&#037;\s*(?:BEGIN|END)">
77
]>
8-
<language name="LaTeX" version="12" section="Markup" kateversion="5.0" priority="10" extensions="*.tex;*.ltx;*.dtx;*.sty;*.cls;*.bbx;*.cbx;*.lbx;*.tikz;*.pgf" mimetype="text/x-tex" casesensitive="1" author="Jeroen Wijnhout ([email protected])+Holger Danielsson ([email protected])+Michel Ludwig ([email protected])+Thomas Braun ([email protected])" license="LGPL" >
8+
<language name="LaTeX" version="13" section="Markup" kateversion="5.0" priority="10" extensions="*.tex;*.ltx;*.dtx;*.sty;*.cls;*.bbx;*.cbx;*.lbx;*.tikz;*.pgf" mimetype="text/x-tex" casesensitive="1" author="Jeroen Wijnhout ([email protected])+Holger Danielsson ([email protected])+Michel Ludwig ([email protected])+Thomas Braun ([email protected])" license="LGPL" >
99
<highlighting>
1010
<!-- NOTE: Keywords of kind "\something" do not need a delimiter before "\".
1111
Using a DetectChar rule with lookAhead to detect "\" at the beginning
@@ -437,7 +437,7 @@
437437

438438
<context name="LabelOption" attribute="Normal Text" lineEndContext="#stay">
439439
<DetectSpaces/>
440-
<DetectChar char="(" attribute="Math" context="MathModeTex" />
440+
<Detect2Chars char="\" char1="(" attribute="Math" context="MathModeLatex"/>
441441
<DetectChar char="\" attribute="Macro" context="ContrSeq"/>
442442
<DetectChar char="$" attribute="Math" context="MathModeTex" />
443443
<DetectChar char="%" attribute="Comment" context="Comment"/>
@@ -461,7 +461,7 @@
461461

462462
<context name="FancyLabelParameter" attribute="Environment" lineEndContext="#stay">
463463
<DetectSpaces/>
464-
<DetectChar char="(" attribute="Math" context="MathModeTex" />
464+
<Detect2Chars char="\" char1="(" attribute="Math" context="MathModeLatex"/>
465465
<DetectChar char="\" attribute="Macro" context="ContrSeq"/>
466466
<DetectChar char="$" attribute="Math" context="MathModeTex" />
467467
<DetectChar char="%" attribute="Comment" context="Comment"/>
@@ -492,7 +492,7 @@
492492

493493
<context name="SpecialCommandParameterOption" attribute="Option Text" lineEndContext="#stay">
494494
<DetectSpaces/>
495-
<Detect2Chars char="\" char1="(" attribute="Math" context="MathModeTex" />
495+
<Detect2Chars char="\" char1="(" attribute="Math" context="MathModeLatex" />
496496
<DetectChar char="\" attribute="Macro" context="ContrSeq"/>
497497
<DetectChar char="$" attribute="Math" context="MathModeTex" />
498498
<DetectChar char="%" attribute="Comment" context="Comment"/>

0 commit comments

Comments
 (0)