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