I started using the awesome knitr package, and whilst I love the idea of using tikz graphics, it's not always very practical (time consuming). Thus, I end up switching back and forth between the good old pdf device, and tikz. Mathematical expressions are generally not handled in the same way in both devices; I find it much preferable to use LaTeX syntax in tikz, but it becomes hard to read in pdf, and vice-versa.
Have there been attempts at providing a framework to seamlessly switch from one notation to another? Something like a translate(x, from="plotmath", to="tex", ams=TRUE, ...) function, that could be hooked internally with knitr to the device in use. How would one go about doing it?
This sounds hard to me. Translation from
plotmathto LaTeX may be easier, e.g. replacealphawith\alpha, andx[i]withx_{i}, etc, but the other way can be difficult sinceplotmathis only a "subset" of LaTeX expressions.If the time-consuming generation of tikz graphics is an issue for you, you may consider turning on the cache (as I did in the
knitrmanual and many other example documents). Once a tikz figure is generated, it will not be regenerated the next time ifcache=TRUE, so it will be pretty fast, and it will be even faster if you also convert tikz to pdf by the chunk optionexternal=TRUE.The only reason that I may not use tikz is when the plot is too large in size, as I explained in the manual. Other than that, tikz is always preferable to me. This is slightly off-topic, though.