The problem I am having is I cannot have full "monospaced font" ERT code in LyX math-mode. In the picture below, you can see that in math-mode there is no red box and the argument in the curly brackets { } defaults to blue math text. Normally this is fine and a workaround would to be add a redundant \text{ } command with ctrl + m in this example.

ERT Example

However, the problem I'm having now is that I'm trying to do something fancy with Knitr using the Sexpr{ } command. Since the expression in the { } is in math-mode not ERT, LyX adds additional curly brackets etc. which throw errors when compiling.


Does anyone know what a suitable work around would be to get full ERT in math-mode? I do not want to leave math-mode and write equations in full ERT just for the Sexpr command as this wold defeat the purpose of using LyX..

Disclaimer: I'm proficient with TeX, but I prefer using LyX because I can essentially touch type formulae in LaTeX during lectures using LyX shortcuts and instant preview. So, I'm not looking for solutions of "go to LaTeX" or "export and manually make changes in TeXWorks".

Also, no MWE since you need to follow these steps by Yihui Xie here to configure LyX for knitr in the first place. But if you want to try Sexpr it should be straight forward to try yourself afterwards. Thanks in advance!

  • 1
    I don't think that it works. Lyx insist on adding braces around the sub- and supscripts. You could ask on the lyx mailing list for confirmation and then make a feature request but in the meantime you will probably have to write the complete equation as code. – Ulrike Fischer Nov 1 '17 at 11:01
  • 1
    This is a commonly requested LyX feature: lyx.org/trac/ticket/2579 – scottkosty Nov 1 '17 at 23:54
  • Thanks for that! I guess you both confirmed my worst fears - I'll be using a lot of ERT Sexpr{temp=...} then in math mode Sexpr{temp} until it's introduced into LyX. Although, given that ticket was opened 11 year ago and ERT in math mode kind of defeats the WYSIWYG spirt of LYX I don't have particularly high hopes.. – Alwin Nov 2 '17 at 10:43
  • 1
    @Alwin We just fixed a 15-year-old ticket (lyx.org/trac/ticket/808), so don't give up all hope, but yes you are right to not be too hopeful for immediate future. – scottkosty Dec 21 '17 at 0:33

Your Answer

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

Browse other questions tagged or ask your own question.