+
+\end_layout
+
+\begin_layout Standard
+The number of arguments is an integer in the range 0
+\begin_inset space \thinspace{}
+\end_inset
+
+-
+\begin_inset space \thinspace{}
+\end_inset
+
+9 and specifies how many arguments the new command should have.
+ With the optional value a value for an optional argument can be predefined.
+ When this is done, the
+\emph on
+first
+\emph default
+
+\emph on
+a
+\emph default
+rgument of the new command is automatically an optional one.
+\end_layout
+
+\begin_layout Standard
+Here are some examples:
+\end_layout
+
+\begin_layout Itemize
+To define the command
+\series bold
+
+\backslash
+gr
+\series default
+ for
+\series bold
+
+\backslash
+Longrightarrow
+\series default
+, the LaTeX-preamble line is:
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+newcommand{
+\backslash
+gr}{
+\backslash
+Longrightarrow}
+\end_layout
+
+\begin_layout Itemize
+To define the command
+\series bold
+
+\backslash
+us
+\series default
+ for
+\series bold
+
+\backslash
+underline
+\series default
+, the argument (that should be underlined) must be taken into account.
+ For this the preamble line is:
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+newcommand{
+\backslash
+us}[1]{
+\backslash
+underline{#1}}
+\series default
+
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+The character
+\series bold
+#
+\series default
+ acts as argument placeholder, the
+\series bold
+1
+\series default
+ behind it denotes that it is the placeholder for the first argument.
+\end_layout
+
+\begin_layout Itemize
+For
+\series bold
+
+\backslash
+framebox
+\series default
+ one can e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.
+\begin_inset space \space{}
+\end_inset
+
+define the command
+\series bold
+
+\backslash
+fb
+\series default
+:
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+newcommand{
+\backslash
+fb}[3]{
+\backslash
+framebox#1#2{$#3$}}
+\series default
+
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+The two Dollar signs creates the extra formula needed for
+\series bold
+
+\backslash
+framebox
+\series default
+, see
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:Boxes-with-Frame"
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Itemize
+To create a new command for
+\series bold
+
+\backslash
+fcolorbox
+\series default
+ where the color for the box needn't to be specified, the argument for the
+ color is defined optional:
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+newcommand{
+\backslash
+cb}[3][white]{
+\backslash
+fcolorbox{#2}{#1}{$#3$}}
+\series default
+
+\begin_inset VSpace medskip
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+When the color is not specified when using
+\series bold
+
+\backslash
+cb
+\series default
+, the predefined color
+\series bold
+white
+\series default
+ will be used.
+\end_layout
+
+\begin_layout Standard
+A test of the new defined commands:
+\end_layout
+
+\begin_layout Standard
+\align center
+\begin_inset Tabular
+<lyxtabular version="3" rows="6" columns="2">
+<features tabularvalignment="middle">
+<column alignment="center" valignment="top" width="0">
+<column alignment="center" valignment="top" width="0">
+<row>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+Command
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+Result
+\begin_inset Note Note
+status collapsed
+
+\begin_layout Plain Layout
+
+\series bold
+
+\backslash
+raisebox
+\series default
+ is only used as spacer.
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+A
+\backslash
+gr
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+
+\backslash
+spce
+\end_layout
+
+\end_inset
+
+B
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $A\gr B$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\backslash
+us{ABcd
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\raisebox{4.5mm}{}\us{ABcd}\raisebox{-2mm}{}$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\backslash
+fb{[2cm]
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{
+\backslash
+int
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+
+\backslash
+spce
+\end_layout
+
+\end_inset
+
+A=B
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\raisebox{6mm}{}\fb{[2cm]}{}{\int A=B}\raisebox{-4mm}{}$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\backslash
+cb{red
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{
+\backslash
+int
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+
+\backslash
+spce
+\end_layout
+
+\end_inset
+
+A=B
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\raisebox{6mm}{}\cb{red}{\int A=B}\raisebox{-4mm}{}$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\backslash
+cb[green]
+\backslash
+{red
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{
+\backslash
+int
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+
+\backslash
+spce
+\end_layout
+
+\end_inset
+
+A=B
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset Formula $\raisebox{6mm}{}\cb[green]{red}{\int A=B}\raisebox{-4mm}{}$
+\end_inset
+
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection
+Math Macros
+\begin_inset Index idx
+status collapsed
+
+\begin_layout Plain Layout
+User-defined commands! Math macros
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index idx
+status collapsed
+
+\begin_layout Plain Layout
+Macros
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+User-defined commands are especially convenient for complex expressions.
+ When you are for example dealing in a document with quadratic equations,
+ the same solution type occurs several times.
+ The general form of a quadratic equation is
+\begin_inset Formula
+\[
+0=\lambda^{2}+p\lambda+q
+\]
+
+\end_inset
+
+The general form of the solution is
+\begin_inset Formula
+\[
+\lambda_{1,2}=-\frac{p}{2}\pm\sqrt{\frac{p²}{4}-q}
+\]
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+To define a command for the solution formula where only the three parameters
+
+\begin_inset Formula $\lambda$
+\end_inset
+
+,
+\begin_inset Formula $p$
+\end_inset
+
+ and
+\begin_inset Formula $q$
+\end_inset
+
+ need to be specified and the index of
+\begin_inset Formula $\lambda$
+\end_inset
+
+ can be given optionally, the LaTeX-preamble line is
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+newcommand{
+\backslash
+qG}[4][1,
+\backslash
+,2]{#2_{#1}=-
+\backslash
+frac{#3}{2}
+\backslash
+pm
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Phantom HPhantom
+status open
+
+\begin_layout Plain Layout
+
+\series bold
+
+\backslash
+newcommand
+\end_layout
+
+\end_inset
+
+
+\backslash
+sqrt{
+\backslash
+frac{#3^{2}}{4}-#4}}
+\end_layout
+
+\begin_layout Standard
+To create with this the solution formula, the command
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+
+\backslash
+qG{
+\backslash
+lambda
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{p
+\begin_inset Formula $\to$
+\end_inset
+
+
+\backslash
+{q
+\series default
+ is inserted to a formula
+\series bold
+.
+\end_layout
+
+\begin_layout Standard
+The definition of the new command is unintuitive because one has to know
+ the schemes of all used LaTeX commands, e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.
+\begin_inset space \space{}
+\end_inset
+
+that a fraction is inserted in LaTeX as
+\series bold
+
+\backslash
+frac{numerator}{denominator}
+\series default
+.
+ Furthermore one can easily forget a brace in the definition and cannot
+ see in LyX what the new command is doing.
+ To avoid these problems LyX offers the possibility to use math macros instead
+ of the command
+\series bold
+
+\backslash
+newcommand
+\series default
+.
+\end_layout
+
+\begin_layout Standard
+A math macro is created by using the menu
+\family sans
+Insert\SpecialChar \menuseparator
+Math\SpecialChar \menuseparator
+Macro
+\family default
+ or the toolbar button
+\begin_inset Graphics
+ filename ../images/math-macro_newmacroname_newcommand.png
+ scale 85
+
+\end_inset
+
+.
+ The math macro toolbar appears together with the following box where the
+ macro is defined:
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset space \hspace*{\fill}
+\end_inset
+
+
+\begin_inset Graphics
+ filename clipart/macrobox.png
+
+\end_inset
+
+
+\begin_inset space \hspace*{\fill}
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset FormulaMacro
+\newcommand{\qG}[4][1,\,2]{#2_{#1}=-\frac{#3}{2}\pm\sqrt{\frac{#3^{2}}{4}-#4}}
+\end_inset
+
+
+\backslash
+newmacroname is the default name of the macro that should be changed to
+ something sensible.
+ The wanted formula is inserted in the first blue box.
+ An argument placeholder is inserted with the command
+\series bold
+
+\backslash
+#argumentnumber
+\series default
+, e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g
+\begin_inset space \space{}
+\end_inset
+
+
+\series bold
+
+\backslash
+#1
+\series default
+ or by using the macro toolbar button
+\begin_inset Graphics
+ filename ../images/math-macro-add-param.png
+ scale 85
+
+\end_inset
+
+.
+ Argument placeholders are displayed red.
+ Maximum 9 arguments are possible.
+ Optional arguments are created with the toolbar button
+\begin_inset Graphics
+ filename ../images/math-macro-add-optional-param.png
+ scale 85
+
+\end_inset
+
+.
+ The first non-optional argument can be transformed to an optional one with
+ the toolbar button
+\begin_inset Graphics
+ filename ../images/math-macro-make-optional.png
+ scale 85
+
+\end_inset
+
+.
+ In the second blue box the appearance of the macro in LyX can be defined.
+ Normally you want to see it as it is defined, so the box is kept empty.
+ But when you have created a macro that needs lot of space on the screen,
+ you can insert in the box for example
+\begin_inset Newline newline
+\end_inset
+
+
+\series bold
+qG:
+\backslash
+#1
+\series default
+
+\series bold
+,
+\series default
+
+\series bold
+
+\backslash
+#2
+\series default
+
+\series bold
+,
+\series default
+
+\series bold
+
+\backslash
+#3,
+\backslash
+#4
+\begin_inset Newline newline
+\end_inset
+
+
+\series default
+For the macro only the arguments with the macro name in front of them will
+ then be displayed in LyX, leading to a better overview.
+ The formula appears in the output as defined in the first box.
+\begin_inset Newline newline
+\end_inset
+
+The appearance of macros in formulas can furthermore be changed for single
+ macros by setting the cursor in the macro and using the menu
+\family sans
+View\SpecialChar \menuseparator
+(Un)fold
+\begin_inset space ~
+\end_inset
+
+Math
+\begin_inset space ~
+\end_inset
+
+Macro
+\family default
+.
+\end_layout
+
+\begin_layout Standard
+To use a macro, the macro name is inserted as command to a formula, in our
+ case
+\series bold
+
+\backslash
+qG
+\series default
+.
+ Our macro looks in LyX like this:
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset space \hspace*{\fill}
+\end_inset
+
+
+\begin_inset Graphics
+ filename clipart/macrouse.png
+
+\end_inset
+
+
+\begin_inset space \hspace*{\fill}
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+Here is our macro example with the arguments
+\begin_inset Formula $x$
+\end_inset
+
+,
+\begin_inset Formula $\ln(x)$
+\end_inset
+
+ and
+\begin_inset Formula $B$
+\end_inset
+
+:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Formula
+\[
+\qG x{\ln(x)}B
+\]
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+LyX offers in the menu
+\family sans
+Tools\SpecialChar \menuseparator
+Preferences\SpecialChar \menuseparator
+Editing\SpecialChar \menuseparator
+Control
+\family default
+ different styles to edit macros.
+ To find the style that suits you the most, choose a style and set the cursor
+ in a macro formula to see the difference.
+\end_layout
+
+\begin_layout Standard
+A math macro is transformed internally to a
+\series bold
+
+\backslash
+newcommand
+\series default
+ command when exporting the document.
+ The created
+\series bold
+
+\backslash
+newcommand
+\series default
+ command is not placed in the LaTeX-preamble, therefore macros can only
+ be used in formulas that are in the document below the macro definition
+ box.
+\end_layout
+
+\begin_layout Standard
+Math macros can also be directly be created from a
+\series bold
+
+\backslash
+newcommand
+\series default
+ command.
+ When writing for example the command
+\series bold
+
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+newcommand{
+\backslash
+larrow}[2]{
+\backslash
+xleftarrow[#2]{#1}}
+\begin_inset Newline newline
+\end_inset
+
+
+\series default
+in LyX as normal text, highlighting it completely and using then the shortcut
+
+\family sans
+Ctrl+M
+\family default
+, the command will be transformed to a math macro.
+ Using this method you need to be careful that the
+\series bold
+
+\backslash
+newcommand
+\series default
+ command is typed correctly, otherwise you get a faulty macro leading to
+ LaTeX errors.