This question closely relates to this one: Using '$' in a tikz plot generated by knitr

I am able to get tikz graphics using knitr working with math mode as in this post: Math mode in knitr

What I can't work out how to do is get both math mode working and special characters like '%' and '$' to show up as text.

Any help would be very much appreciated.

  • In TeX you need to escape those characters so \% and \$ should work. – Peter Grill Oct 31 '14 at 20:47

I have worked it out. In the character objects in R, the escape character also needs to be escaped.

For example, using sanitize=FALSE (or omitted) in the knitr chunk, and using "\\$" works:

<<fe, dev="tikz", fig.cap = "${}^{57}Fe spectrum$", echo=FALSE>>=
    plot(1:10, xlab="$\\lambda$", ylab="\\$", pch=20)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.