Title
User defined macros in math mode Author
Alejandro Aguilar Sierra Date
25-October-1997 Section
Introduction Standard
LyX version 0.12 allows the user to define macros. An user defined macro in math mode is not a red colored name that LyX didn't know how to draw (formerly known as macro mode, now simply TeX mode). A macro definition box appears on screen as a grayed button with the name of the macro in blue (math color). But if you click on it, it will appear as a normal math box to allow you edit it. Just try it: _inset FormulaMacro
inset
Standard
Now, to use this macro in other math boxes just type the name in TeX mode, in this case typewriter
macro default , and it will be automatically expanded: _inset Formula c = a + b inset
. As you can verify, the cursor can't go inside the macro, the whole macro is like a single character, and the TeX generated code of this expression is typewriter c = macro. Standard
However the cursor could go inside of some kind of macros, those that have
on arguments default . In a macro definition box an argument looks like a typewriter # default followed by the argument number: _inset FormulaMacro
inset
Standard
Once expanded, this macro includes the usual empty rectangle to indicate that you can insert there whatever you want: typewriter
macrowarg = _inset Formula 2 + inset
default . Example: _inset Formula b = 2 + inset
.
Standard
When exported to LaTeX, a macro definition will produce the command typewriter
newcommand. Section
Directions on using macros Subsection
How to create them Standard
To create a macro definition box use this syntax in the minibuffer: Standard
typewriter math-macro <macro name> [number of arguments] Standard
Par example typewriter
macro default was created with _inset Quotes eld inset
typewriter math-macro macro default
_inset Quotes erd inset
, and typewriter
macrowarg default was created with _inset Quotes eld inset
typewriter math-macro macrowarg 1 default
_inset Quotes erd inset
. Standard
To insert an argument mark (only inside a macro definition box) use this: Standard
typewriter math-macro-arg <number> Standard
The argument mark in typewriter
macrowarg default was introduced with _inset Quotes eld inset
typewriter math-macro-arg 1 default
_inset Quotes erd inset
. Standard
You can use no more than 9 arguments, numbered from 1 to 9. An argument can be repeated inside the macro definition box, but of course can be edited only once. A number can't be greater than the number of arguments originally allowed for the macro.
Subsection
How to navigate Description
With _separator the _separator arrow _separator keys: Opening a macro form the left side will put the cursor in the first argument, to move to the second argument use the TAB key. Remember that pressing the Space bar will get the cursor out and at the right side of the macro. Description
With _separator the _separator mouse: As usual, click on the desired argument box. Sometimes this fails if the box is empty or too small. Standard
Currently the user can only define command macros, but internally it's possible to define also environment macros. Standard 358 There are several predefined macros, mainly to allow AMS-LaTeX users to use AMS macros in a WYSIWYM way, like typewriter
cases default and typewriter
binom default . [ on Pre 0.12 Note: typewriter
cases default are currently disabled because after some simplification and improving of the macro stuff, the only valid arguments are subparagraphs (neither tabs nor newlines). Perhaps they will be again included before 0.12 default . AAS] _end