That should be the best solution for this particular case, but you are right this problem needs to be solved at a lower level in knitr or Sweave, or LyX's math mode. The difficulty on R's side is from parsing \Sexpr{} using regular expressions. In your case, the R code should be 0.5^{2} but knitr sees 0.5^{2 because } terminates the code.
Regards, Yihui -- Yihui Xie <xieyi...@gmail.com> Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Thu, Aug 16, 2012 at 2:33 PM, Michael Bach <pha...@gmail.com> wrote: > On 8/16/2012 9:25 PM, Michael Bach wrote: >> >> Dear LyX Users and Developers, >> >> today I tried to use the knitr (Rnw) module successfully when accessed >> from Insert > Custom Insets > S/R expression. >> >> When I tried to do that in inline math via \Sexpr{0.5^2} then the >> display becomes 0.5² meaning that LyX correctly thinks I want LaTeX-ish >> 0.5^{2}, but R will choke on that literal "{" in there. >> > > Ok I found a workaround for my specific issue, which is to use the > alternative \Sexpr{0.5**2} for the exponent. > > Sorry for the noise, but suggestions / ideas are welcome anyway. > >