1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
#This file was created by <ale> Wed Oct 29 15:21:35 1997
#LyX 0.11 (C) 1995-1997 Matthias Ettrich and the LyX Team
\lyxformat 2.15
\textclass article
\language default
\inputencoding default
\fontscheme default
\graphics default
\paperfontsize 12
\spacing single
\papersize Default
\paperpackage a4
\use_geometry 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default
\layout Title
User defined macros in math mode
\layout Author
Alejandro Aguilar Sierra
\layout Date
25-October-1997
\layout Section
Introduction
\layout 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:
\begin_inset FormulaMacro
\newcommand{\macro}{a+b}
\end_inset
\layout Standard
Now, to use this macro in other math boxes just type the name in TeX mode,
in this case
\family typewriter
\backslash
macro
\family default
, and it will be automatically expanded:
\begin_inset Formula \( c=\macro \)
\end_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
\family typewriter
c =
\backslash
macro.
\layout Standard
However the cursor could go inside of some kind of macros, those that have
\emph on
arguments
\emph default
.
In a macro definition box an argument looks like a
\family typewriter
#
\family default
followed by the argument number:
\begin_inset FormulaMacro
\newcommand{\macrowarg}[1]{2+\sqrt{#1 }}
\end_inset
\layout Standard
Once expanded, this macro includes the usual empty rectangle to indicate
that you can insert there whatever you want:
\family typewriter
\backslash
macrowarg =
\begin_inset Formula \( \macrowarg{} \)
\end_inset
\family default
.
Example:
\begin_inset Formula \( b=\macrowarg{x-2} \)
\end_inset
.
\layout Standard
When exported to LaTeX, a macro definition will produce the command
\family typewriter
\backslash
newcommand.
\layout Section
Directions on using macros
\layout Subsection
How to create them
\layout Standard
To create a macro definition box use this syntax in the minibuffer:
\layout Standard
\family typewriter
math-macro <macro name> [number of arguments]
\layout Standard
Par example
\family typewriter
\backslash
macro
\family default
was created with
\begin_inset Quotes eld
\end_inset
\family typewriter
math-macro macro
\family default
\begin_inset Quotes erd
\end_inset
, and
\family typewriter
\backslash
macrowarg
\family default
was created with
\begin_inset Quotes eld
\end_inset
\family typewriter
math-macro macrowarg 1
\family default
\begin_inset Quotes erd
\end_inset
.
\layout Standard
To insert an argument mark (only inside a macro definition box) use this:
\layout Standard
\family typewriter
math-macro-arg <number>
\layout Standard
The argument mark in
\family typewriter
\backslash
macrowarg
\family default
was introduced with
\begin_inset Quotes eld
\end_inset
\family typewriter
math-macro-arg 1
\family default
\begin_inset Quotes erd
\end_inset
.
\layout 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.
\layout Subsection
How to navigate
\layout Description
With
\protected_separator
the
\protected_separator
arrow
\protected_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.
\layout Description
With
\protected_separator
the
\protected_separator
mouse: As usual, click on the desired argument box.
Sometimes this fails if the box is empty or too small.
\layout Standard
Currently the user can only define command macros, but internally it's possible
to define also environment macros.
\layout Standard
\cursor 358
There are several predefined macros, mainly to allow AMS-LaTeX users to
use AMS macros in a WYSIWYM way, like
\family typewriter
\backslash
cases
\family default
and
\family typewriter
\backslash
binom
\family default
.
[
\emph on
Pre 0.12 Note:
\family typewriter
\backslash
cases
\family 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
\emph default
.
AAS]
\the_end
|