# Fix syntax highlighting after unmatched parentheses

I have a parenthesis in my LaTeX document that is intentionally unmatched. This breaks syntax highlighting for all of the following text.

Is there some way to reset syntax highlighting after this point?

The %stopzone trick that works for other LaTeX syntax breakages doesn't work here. Neither does inserting a matching paren in a comment.

Here's a small example that exhibits the problem:

\documentclass{article}

\begin{document}

\begin{itemize}
\item \textit{properly} highlighted
\end{itemize}

(

\begin{itemize}
\item \textit{improperly} highlighted
\end{itemize}

\end{document}

• Not an answer, but maybe a starting point: opening a ( starts a texParen syntax region: see section starting at " Try to flag {} and () mismatches: in tex.vim. You could probably apply a fix similar to this one. Nov 28, 2015 at 17:57
• This seems like a good lead. I tried adding %stopzone to the end conditions of texParen, but that doesn't seem to work. Nov 28, 2015 at 19:54
• It works if, in the stock tex.vim, oneline is added at the end of each of the two syn region texParen ...  lines. Nov 29, 2015 at 0:17
• What is the drawback of adding oneline? You can also change this locally by doing a syn clear texParen in ~/.vim/after/syntax/tex.vim and then copying and modifying the corresponding lines from the stock tex.vim. I tried this and it seems to work great for my use case, and it also seems to still support paren matching over multiple lines. Nov 29, 2015 at 5:14
• What kind of support? Normally you just lost the ability to see if you have unmatched parens between multiple lines. Nov 29, 2015 at 16:18

This is a very difficult problem. It is such a corner case of what people need, that I would not personally want to support it directly. Thus I also won't try to come with a direct answer to your question.

Instead, I want to propose two indirect solutions:

• Put the unmatched paranthesis inside a verbatim command, e.g. \verb+(+.
• Create a new command for the unmatched paranthesis, e.g. \newcommand{\unMatchedParen}{(}.

Which of these to choose depends on the reason you need the unmatched paranthesis, but both of them will work in that they will not break syntax highlighting.

• In my real use case, the parens are actually matched. But there are a lot of intervening formatting macros that seem to stump the syntax highlighter. Rather than try to fix this, I figured it would be easier to just reset highlighting after the broken point. (Waiting a bit longer before accepting in case a better solution comes up.) Nov 28, 2015 at 20:06

Upon seeing your comment that the parentheses were actually matched but there was a lot of intervening macros, it is possible that there is a synchronization issue -- does

syn sync fromstart