How can I use my defined commands in LyX? I have seen that this can be done in math mode but I have found no way to do it globally.


1 Answer 1


The most fundamental way you can include \newcommands you have in your Document > Settings... > LaTeX Preamble is to use an ERT (Insert > TeX Code or Ctrl+L):

enter image description here

With you preamble containing (say)

\newcommand{\quadratic}{ax^2 + bx + c}

the output resembles

enter image description here

Within math mode (Insert > Math), typing backslash \ automatically initiates an ERT.

  • This works generally not in math mode only doesn't it?
    – Adam
    Nov 1, 2016 at 18:50
  • @Adam: This works generally, yes. In math mode the use of \ automatically assumes an ERT. Outside of math mode, a \ is converted to \textbackslash.
    – Werner
    Nov 1, 2016 at 18:57
  • Thank you! One last thing...Is there live preview for defined commands as when you write equations?
    – Adam
    Nov 1, 2016 at 18:58
  • 1
    @Adam: Not natively, as you can technically have arbitrary content within a \newcommand, which doesn't have an HTML visual equivalent within the LyX display. You'll have to view the output - Ctrl+R - to see the rendered interpretation.
    – Werner
    Nov 1, 2016 at 19:00
  • @Adam you might be interested in LyX's "math macros". See Help > Math and go to the section User-defined Commands > Math Macros.
    – scottkosty
    Nov 1, 2016 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .