# Defined Commands in LyX

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.

• What commands? Are you talking about a number of `\newcommand`s that you have in your LaTeX preamble? – Werner Nov 1 '16 at 18:11
• @Werner Yes that's right. – Adam Nov 1 '16 at 18:12
• – Anton Tarasenko Oct 24 '19 at 15:08

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

With you preamble containing (say)

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

the output resembles

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 '16 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 '16 at 18:57
• Thank you! One last thing...Is there live preview for defined commands as when you write equations? – Adam Nov 1 '16 at 18:58
• @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 '16 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 '16 at 23:07