The latex.xml syntax highlight file contains the following snippets of code for identifying a multiline comment obtained by means of \iffalse ... \fi: <StringDetect String="\iffalse" attribute="Comment" context="Multiline Comment"/> <context name="Multiline Comment" attribute="Comment" lineEndContext="#stay"> <StringDetect String="\fi" attribute="Comment" context="#pop"/> <StringDetect String="\else" attribute="Comment" context="#pop"/> </context> It induces the correct highlighting in several cases, except when the part of text between \iffalse and \fi contains a command starting with "\fi", like \fill. In such a case, the comment highlighting stops at \fi of \fill and this may cause a completely wrong highlighting of the remaining part of the text, in particular when this happens inside a math mode. A possible fix for this situation is to replace the code <context name="Multiline Comment" attribute="Comment" lineEndContext="#stay"> <StringDetect String="\fi" attribute="Comment" context="#pop"/> <StringDetect String="\else" attribute="Comment" context="#pop"/> </context> with <context name="Multiline Comment" attribute="Comment" lineEndContext="#stay"> <RegExpr String="\\fi([^a-zA-Z]|$)" attribute="Comment" context="#pop"/> <RegExpr String="\\else([^a-zA-Z]|$)" attribute="Comment" context="#pop"/> </context> which prevents to match \fi and \else as termination of the multiline comment when they occur as prefix of another command (like \fi in \fill). The fix has been checked with kile 2.1.3 and kate 3.14.9 in openSUSE 13.2 as well as with kate 16.08.2 in openSUSE Leap 42.2; the shipped syntax file is the same as the one in the git repository, so it should apply there as well.
Could you try WordDetect instead of a regexp? This is faster and should do exactly what you want, see: https://docs.kde.org/stable5/en/applications/katepart/highlight.html
WordDetect indeed produces the expected highlighting, with the code: <context name="Multiline Comment" attribute="Comment" lineEndContext="#stay"> <WordDetect String="\fi" attribute="Comment" context="#pop"/> <WordDetect String="\else" attribute="Comment" context="#pop"/> </context>
Dominik, do you need a review request, or can we commit the change without further review?
As is, but the unit test needs to be adapted. Will do asap, sorry...
Git commit 4a3572b899a0796118f610252e0951b36d278e07 by Dominik Haumann. Committed on 22/04/2017 at 14:00. Pushed by dhaumann into branch 'master'. LaTeX: Fix Incorrect termination of \iffalse comments FIXED-IN: KDE Frameworks 5.34 M +5 -1 autotests/html/highlight.tex.html M +5 -1 autotests/input/highlight.tex M +5 -1 autotests/reference/highlight.tex.ref M +8 -8 data/syntax/latex.xml https://commits.kde.org/syntax-highlighting/4a3572b899a0796118f610252e0951b36d278e07