2

I am unable to render maths notation inside a knitr chunk in Lyx although it renders fine using \Sexpr or in an ERT box while using Lyx 2.0.5 and knitr 1.1

The following code was adapted from the manual:

<<cars-demo,dev='svg',fig.width=4,fig.height=2.8,out.width='.45\\textwidth',message=TRUE,cache=TRUE>>=
fit=lm(dist~speed,data=cars) # linear regression
par(mar=c(4, 4, 1, .1), mgp=c(2,1,0))
with(cars,plot(speed,dist,panel.last=abline(fit)))
text(10,100,'$\alpha_{1}$+$\beta^{2}$')

The plot is fine but the text notation appears exactly as: $\alpha_{1}$+$\beta^{2}$

I cannot run tikz for some reason so the original dev = tikz had to be converted to svg.

Thanks in advance. Great combination Lyx and knitr.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • 1
    I don't think latex math works in plots using any device other than tikz. – Ramnath Mar 26 '13 at 17:19
  • Yes, `tikz` is the only choice if you want LaTeX math in plots. – Yihui Xie Mar 26 '13 at 18:22
  • omg its yihui the god of knitr – Green Demon Mar 26 '13 at 18:25
  • Inkscape can process svg to latex http://tex.stackexchange.com/questions/2099/how-to-include-svg-diagrams-in-latex -- you could post process the graphics like this. – mnel Mar 27 '13 at 00:12
  • Thanks but the problem continues. I have already put a tikz figure in the same document and it renders fine but the moment I replace dev='svg' with dev='tikz' I get the following error message in a grey box with no error message from lyx. Lyx merely indicates a warning to have a larger side margin. – user2004198 Mar 27 '13 at 17:41
  • sorry the above went off before I could finish:An error occurred while running: Rscript --verbose --no-save --no-restore "/usr/local/share/lyx/scripts/lyxknitr.R" "/tmp/lyx_tmpdir.T27306/lyx_tmpbuf4/""01KnitrManual.Rnw" "/tmp/lyx_tmpdir.T27306/lyx_tmpbuf4/""01KnitrManual.tex" ISO-8859-15 "/home/samar/Desktop/NewProjectsDone/coursera/DataAnalysis/LearningR/" – user2004198 Mar 27 '13 at 17:42

0 Answers0