I adopted the bracket notation, e.g., x[i], for the discrete signal x where i is the time index. The problem occurs in a pgfplots figure but I figured, the syntax highlighting behavior is due to being math mode in a LaTeX command option, i.e., \begin{command}[option] ... \end{command}.Here is a MWE originally named demonstration.tex which compiles correctly:\documentclass{article}\usepackage{pgfplots}\pgfplotsset{compat=1.12}\begin{document}Here, I show you a not so very interesting graph\begin{figure}    \centering    \begin{tikzpicture}        \begin{axis}[                xlabel=$i$,                ylabel={$x[i]$},            ]            \addplot+[ycomb] plot coordinates            {                (1,1)                (2,2)                (3,1)            };        \end{axis}    \end{tikzpicture}    \caption{Example figure}\end{figure}\end{document}The erroneous syntax highlighting occurs in the line with ylabel={$x[i]$}. There, the closing bracket ] is matched with the opening [ two lines above. Then everything after the closing $ is displayed as if in math mode.I assume the issue can be resolved by allowing math mode in command option mode (if these are the right terms) but I wasn't able to find or comprehend the right spot in the syntax file.
How do I get Vim to correctly highlight Math mode in LaTeX command options?
syntax highlighting;filetype tex
To achieve what you ask is, I believe, quite difficult. I'm the author of vimtex, and I've added some custom syntax highlighting, see vimtex/after/syntax/tex.vim. As you might notice, the syntax highlighting syntax can become quite complex, and I think in this particular case, it will be very nontrivial.Therefore, instead of a direct answer to what you ask, I will instead suggest a workaround that I think should work well: Instead of adding the plot settings as an optional argument to the axis environment, you can add them with \pgfplotsset,\documentclass{article}\usepackage{pgfplots}\pgfplotsset{compat=1.12}\begin{document}Here, I show you a not so very interesting graph\begin{figure}    \centering    \begin{tikzpicture}             \pgfplotsset{            xlabel=$i$,            ylabel={$x[i]$},        }        \begin{axis}            \addplot+[ycomb] plot coordinates            {                (1,1)                (2,2)                (3,1)            };        \end{axis}    \end{tikzpicture}    \caption{Example figure}\end{figure}\end{document}For more information about this, see the pgfplots manual, section 4.3.