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