Syntax highlighting for knitr "\Sexpr{}" in Rstudio not working

I'm working on a .Rnw file in Rstudio, using knitr to weave it. I have no problem with compiling the document, my problem is related to the syntax highlighting of the document itself in Rstudio. As soon as I include \Sexpr{} with an R function of any kind inside, it messes up the syntax highlighting for the rest of the document.

This is an example of an .Rnw file that would produce this problem:

\documentclass{article}

\begin{document}

% A comment, this is green
Everything is fine so far. \textbf{This looks fine in Rstudio}. 
However, I will now include an "Sexpr\{\}" with an R function inside, 
and it will mess up the syntax highlighting in the rest of the file. 
\Sexpr{runif(1)}.

\textit{Some italic text}
% Another comment, but no longer green 

\end{document}

This is what it looks like for me:

As you can see, "textit" and "end" are not blue, as they should be, and the comment isn't green, like it is above.

As I mentioned, it compiles just fine, but it is just frustrating when I'm working with the document, so I would love to find a solution!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.