~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to doc/emaxima/EMaximaIntro.tex

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%-*-EMaxima-*-
2
2
\documentclass{article}
3
 
\usepackage{emaxima}
 
3
\usepackage[lines]{emaxima}
4
4
\usepackage{url}
5
5
 
6
6
\newcommand{\emx}{\textsl{\sffamily EMaxima}}
7
7
\newcommand{\mx}{\textsl{\sffamily Maxima}}
 
8
\newcommand{\hyph}{-\hspace{0pt}}
8
9
\newdimen\firstcol
9
10
\firstcol=.35\textwidth
10
11
\newdimen\secondcol
22
23
 
23
24
Emacs, while nominally a text editor, is an extensible environment for
24
25
interacting with text in various ways.  As such, it provides a
25
 
convenient interface for many text-based utilities.  Users of Emacs
26
 
can interact with \mx{} from within their favorite
 
26
convenient interface for many text-based utilities.  For example,
 
27
users of Emacs can interact with \mx{} from within their favorite
27
28
editor\footnote{Emacs.} in a number of ways.  The most basic way is to
28
 
use Emacs as a shell, and run a \mx{} process interactively from
 
29
use Emacs as a shell and run a \mx{} process interactively from
29
30
within a buffer.  Emacs can interact with this process from other
30
31
buffers, and thus interact with the \mx{} process in less
31
 
straightforward ways.
32
 
 
33
 
\mx{} programs can be written using a special mode, which will take
34
 
care of syntax highlighting, indentation, etc..  Portions of the
 
32
straightforward ways.  Emacs can also be used to write
 
33
\mx{} programs.  A special mode is provided which will take
 
34
care of syntax highlighting, indentation, etc.  Portions of the
35
35
program can also be sent automatically to a \mx{} program.
36
 
 
37
36
Finally, text and \mx{} commands can be interweaved in a \mx{}
38
37
notebook mode called \emx{}.
39
38
 
40
39
\section{Running \mx{} Interactively}
41
40
 
42
41
To run \mx{} interactively in a buffer, type \texttt{M-x maxima}.  A
43
 
buffer named \texttt{*Maxima*} should start up, in which a \mx{}
 
42
buffer named \texttt{*Maxima*} should start up in which a \mx{}
44
43
process is running.%
45
44
\footnote{In XEmacs, a double input prompt will sometimes appear in
46
45
  the \texttt{*Maxima*} buffer.  If this occurs, the customizable
47
 
  variable \texttt{maxima-fix-double-prompt} can be set to \texttt{t}
 
46
  variable \texttt{maxima\hyph{}fix\hyph{}double\hyph{}prompt} can be set to \texttt{t}
48
47
  to take care of this.}
49
 
In the \texttt{*Maxima*} buffer, \texttt{RET}
50
 
will check the line for balanced parentheses, and send line as input.
51
 
\texttt{C-RET} will send the line as input without checking for
52
 
balanced parentheses.  A list of available commands are listed in
53
 
Appendix \ref{app:intmx}.
 
48
A history of input commands can be saved across Maxima sessions by
 
49
setting the variable \texttt{maxima\hyph{}save\hyph{}input\hyph{}history} to \texttt{t}.
 
50
In the \texttt{*Maxima*} buffer, \texttt{RET} will check the line for
 
51
balanced parentheses, and send line as input.  \texttt{C-RET} will
 
52
send the line as input without checking for balanced parentheses.  A
 
53
list of available commands are listed in Appendix \ref{app:intmx}.
54
54
 
55
55
If this is the only way that \mx{} is to be used from within Emacs,
56
56
then the \textsl{Imaxima} package should be considered.  It allows the
58
58
visually nice form.  It is available from
59
59
\verb+http://www.ifa.au.dk/~harder/imaxima.html+.
60
60
 
61
 
\section{Running \mx{} from the minibuffer}
62
 
 
63
 
The command \texttt{M-x maxima-minibuffer} will use the minibuffer to
64
 
prompt for an expression to send to a \mx{} process, and the result
65
 
will appear in the minibuffer.  If this is used frequently, it may be
66
 
useful to add the line
67
 
\begin{verbatim}
68
 
(global-set-key "\C-cm" 'maxima-minibuffer)
69
 
\end{verbatim}
70
 
(or something similar) to your \texttt{.emacs}, so that this can be
71
 
called with \texttt{C-c m}.%
 
61
\section{Running \mx{} from arbitrary buffers}
 
62
 
 
63
Several commands will access the \mx{} process from outside of the
 
64
\texttt{*Maxima*} buffer; these commands are given  convenient key
 
65
bindings  with the \mx{} minor mode (which can be started
 
66
with \texttt{M-x maxima-minor-mode}), but are available without the
 
67
minor mode.  In the following, the minor mode keybindings are given in
 
68
parentheses.
 
69
 
 
70
The command \texttt{M-x maxima-minibuffer-on-determined-region}
 
71
(\texttt{C-c = e}) will send part of the current buffer containing
 
72
the point to the \mx{} process and return the result in the
 
73
minibuffer.  The region that is sent is the region bounded above and
 
74
below by blank lines (although the delimiters can be changed by
 
75
changing the regexps \texttt{maxima\hyph{}minor\hyph{}prefix} and 
 
76
\texttt{maxima\hyph{}minor\hyph{}postfix}).  Given an argument, this command 
 
77
will also insert the output into the current buffer, after the symbol
 
78
\texttt{~==>~}.   (The output indicator \texttt{~==>~} is the value of
 
79
the customizable variable \texttt{maxima\hyph{}minor\hyph{}output}.)
 
80
When calling
 
81
\texttt{maxima\hyph{}minibuffer\hyph{}on\hyph{}determined\hyph{}region} on a region
 
82
which already has some output displayed, everything 
 
83
after the indicator \texttt{~==>~} will be ignored, and, if the new
 
84
output is to be inserted, everything after the indicator will be
 
85
assumed to be old output and deleted.
 
86
 
 
87
The commands \texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}region} (\texttt{C-c = r}),
 
88
\texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}line} (\texttt{C-c = l}) and 
 
89
\texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}form} (\texttt{C-c = f}) work
 
90
similarly to \texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}determined\hyph{}region}, but
 
91
send the current region (respectively, the current line, current form%
 
92
\footnote{The region between the preceding \texttt{;} or \texttt{\$}
 
93
  and the subsequent \texttt{;} or \texttt{\$}.})
 
94
to \mx{} and display the result in the minibuffer.
 
95
Care must be taken when inserting the output into the current buffer
 
96
with \texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}region} or 
 
97
\texttt{M-x maxima\hyph{}minibuffer\hyph{}on\hyph{}form}, since new output will
 
98
be inserted without the old output being deleted.
 
99
 
 
100
The command \texttt{M-x maxima\hyph{}minibuffer} (\texttt{C-c = m}) will use
 
101
the minibuffer to prompt for an expression to send to a \mx{} process,
 
102
and the result will appear in the minibuffer%
72
103
\footnote{In GNU Emacs, the output will be in 2D form if the
73
 
customizable variable \texttt{maxima-minibuffer-2d} is non-nil.  Since
 
104
customizable variable \texttt{maxima\hyph{}minibuffer\hyph{}2d} is non-nil.  Since
74
105
XEmacs does not have a resizable minibuffer, this cannot be done in
75
 
XEmacs.} 
76
 
The latest output from a minibuffer command can be placed in the
77
 
current buffer with the command
78
 
\texttt{M-x maxima-insert-last-minibuffer-output}.%
 
106
XEmacs.}.
 
107
You can scroll through previous minibuffer inputs using the arrow keys.
 
108
 
 
109
The latest \mx{} output (whether from a minibuffer command or not) can
 
110
be placed in the current buffer with the command
 
111
\texttt{M-x maxima\hyph{}insert\hyph{}last\hyph{}output} (\texttt{C-c = o}).%
79
112
\footnote{If the output is 2D, this won't look nice.}
80
 
With an argument, \texttt{C-u M-x
81
 
  maxima-insert-last-minibuffer-tex-output}, this will insert the last
82
 
output in \TeX{} form.%
83
 
\footnote{If this is never going to be used, the customizable variable 
84
 
\texttt{maxima-minibuffer-get-tex} can be set to \texttt{nil}, and
85
 
Emacs won't keep track of the \TeX{} output.}
 
113
The command \texttt{M-x maxima\hyph{}insert\hyph{}last\hyph{}output\hyph{}tex} (\texttt{C-c = t})
 
114
will insert the last output in \TeX{} form.
86
115
 
87
116
\section{\mx{} mode}
88
117
 
93
122
commands.  A list of available commands is in Appendix
94
123
\ref{app:mxmode}.
95
124
 
96
 
When something is sent to a \mx{} process, the \texttt{*Maxima*} will
 
125
When something is sent to a \mx{} process, the \texttt{*Maxima*}
 
126
buffer will
97
127
appear.  (If a \mx{} process is not running, one will be started.)  It
98
128
can also be made to appear by using the command \texttt{C-c C-p}.  If
99
129
an argument is given to a command to send information to \mx{}, the
100
130
region will first be checked to make sure the parentheses are
101
131
balanced.  The Maxima process can be killed, after asking for
102
 
confirmation with \texttt{C-c C-k}.  To kill without confirmation, give
 
132
confirmation, with \texttt{C-c C-k}.  To kill without confirmation, give
103
133
\texttt{C-c C-k} an argument.
104
134
 
105
135
By default, a newline will be indented to the same level as the
106
136
previous line, with an additional space added for open parentheses.  A
107
137
tab will add extra spaces, by default, this is 2.  The behaviour of
108
 
the automatic indentation can be changed by the command \texttt{M-x
109
 
  maxima-change-indent-style}.  The possibilities are
110
 
\texttt{'standard}, as above, and \texttt{'perhaps-smart}, which tries
 
138
the automatic indentation can be changed by the command 
 
139
\texttt{M-x maxima\hyph{}change\hyph{}indent\hyph{}style}.  The possibilities are
 
140
\texttt{'standard}, as above, and \texttt{'perhaps\hyph{}smart}, which tries
111
141
to guess an appropriate indentation, based on open parentheses, ``do''
112
142
loops, etc.
113
143
 
114
144
A \texttt{RET} will, by default, insert a new line, and indent the new
115
145
line an appropriate amount.  This behavior can be changed by setting
116
 
the value of 
117
 
\texttt{maxima-return-style}, the self-explanatory options are
118
 
\texttt{'newline}, \texttt{'newline-and-indent}, and
119
 
\texttt{'reindent-then-newline-and-indent}.  (Note that standard Emacs
 
146
the value of
 
147
\texttt{maxima\hyph{}return\hyph{}style}, the self-explanatory options are
 
148
\texttt{'newline},
 
149
 \texttt{'newline\hyph{}and\hyph{}indent}, and
 
150
\texttt{'reindent\hyph{}then\hyph{}newline\hyph{}and\hyph{}indent}.  (Note that standard Emacs
120
151
behavior is to let \texttt{RET} only insert a newline, and
121
152
\texttt{LFD} or \texttt{C-j} insert a newline and indent it.)
122
153
 
123
154
The indentation style, as well as many other things, are customizable;
124
155
see Appendix \ref{app:custmxmode}.
125
156
 
 
157
To help writing \mx{} code in \texttt{Noweb},
 
158
\texttt{maxima\hyph{}noweb\hyph{}mode} is a modification of \texttt{maxima\hyph{}mode}
 
159
that will work nicely with \texttt{noweb\hyph{}mode}; namely, it will limit
 
160
any relevant searches to the current chunk and treat
 
161
\texttt{<<\ldots>>} as word parts.
126
162
 
127
163
\section{\emx}
128
164
 
149
185
The basic unit of \mx{} code in \emx{} is a \textbf{cell}.  A cell
150
186
consists of text between the delimiters
151
187
\begin{verbatim}
152
 
\beginmaxima
 
188
\begin{maxima}
153
189
\end{verbatim}
154
190
\noindent
155
191
and
156
192
\begin{verbatim}
157
 
\endmaxima
 
193
\end{maxima}
158
194
\end{verbatim}
159
195
\noindent
160
196
A cell can be created by typing \texttt{C-c C-o}.  (The \texttt{C-o} in this
169
205
 
170
206
\noindent
171
207
To evaluate the contents of a cell, the command
172
 
\texttt{C-c C-u c} (\texttt{emaxima-update-cell})\footnote{Sending the
 
208
\texttt{C-c C-u c} (\texttt{emaxima\hyph{}update\hyph{}cell})\footnote{Sending the
173
209
  cells contents to a \mx{} process and returning the results is
174
210
  called \textbf{updating} the cell, the prefix 
175
211
\texttt{C-c C-u} will be used to update cells in different ways.} 
185
221
$\sin(x^2)$, for example, type 
186
222
\texttt{diff(sin(x\^{}2),x);} in a cell:
187
223
\begin{verbatim}
188
 
\beginmaxima
 
224
\begin{maxima}
189
225
diff(sin(x^2),x);
190
 
\endmaxima
 
226
\end{maxima}
191
227
\end{verbatim}
192
228
\noindent
193
229
After typing \texttt{C-c C-u c}, it will look like
194
230
\begin{verbatim}
195
 
\beginmaxima
 
231
\begin{maxima}
196
232
diff(sin(x^2),x);
197
233
\maximaoutput
198
234
                                           2
199
 
                                  2 x COS(x )
200
 
\endmaxima
 
235
                                  2 x cos(x )
 
236
\end{maxima}
201
237
\end{verbatim}
202
238
\noindent
203
239
To delete the output and return the cell to its original form, you can
204
240
use the command \texttt{C-c C-d}.
205
241
If the document is to be \TeX{}ed, the above cell will look like:
206
 
\beginmaxima
 
242
\newpage
 
243
\begin{maxima}
207
244
diff(sin(x^2),x);
208
 
\endmaxima
 
245
\end{maxima}
209
246
and the cell with output will look like:
210
 
\beginmaxima
 
247
\begin{maxima}
211
248
diff(sin(x^2),x);
212
249
\maximaoutput
213
250
                                           2
214
 
                                  2 x COS(x )
215
 
\endmaxima
 
251
                                  2 x cos(x )
 
252
\end{maxima}
216
253
 
217
254
\emx{} mode can take advantage of the fact that \mx{} can give its
218
255
output in \LaTeX{} form.  The command \texttt{C-c C-u C}
222
259
\texttt{C-c C-u }\textsl{capital letter} will return the output in
223
260
\TeX{} form.  The above cell would become
224
261
\begin{verbatim}
225
 
\beginmaxima
 
262
\begin{maxima}
226
263
diff(sin(x^2),x);
227
 
\maximatexoutput
228
 
$$   2\*x\*\cos x^{2} $$
229
 
\endmaxima
 
264
\maximaoutput*
 
265
\m  2\,x\,\cos x^2 \\
 
266
\end{maxima}
230
267
\end{verbatim}
231
268
\noindent
232
269
which, when \LaTeX{}ed, would become
233
 
\beginmaxima
 
270
\begin{maxima}
234
271
diff(sin(x^2),x);
235
 
\maximatexoutput
236
 
\[   2\*x\*\cos x^{2} \]
237
 
\endmaxima
 
272
\maximaoutput*
 
273
\m  2\,x\,\cos x^2 \\
 
274
\end{maxima}
238
275
\noindent
239
276
(Note that whenever a cell is updated, any old output is discarded and
240
277
replaced with new output.)  The command \texttt{C-c C-u a} will update all
261
298
other cell, the original cell need only contain the marker for the
262
299
referenced cell.  For example, given cell 1:
263
300
\begin{verbatim}
264
 
\beginmaxima<filename:optional>
 
301
\begin{maxima}[filename:optional]
265
302
<filename:definef>
266
303
diff(f(x),x);
267
 
\endmaxima
 
304
\end{maxima}
268
305
\end{verbatim}
269
306
\noindent
270
307
and cell 2:
271
308
\begin{verbatim}
272
 
\beginmaxima<filename:definef>
 
309
\begin{maxima}[filename:definef]
273
310
f(x):=sin(x^2);
274
 
\endmaxima
 
311
\end{maxima}
275
312
\end{verbatim}
276
313
\noindent
277
314
then the result of updating cell 1 (\texttt{C-c C-u c}) will be:
278
315
\begin{verbatim}
279
 
\beginmaxima<filename:optional>
 
316
\begin{maxima}[filename:optional]
280
317
<filename:definef>
281
318
diff(f(x),x);
282
319
\maximaoutput
 
320
 
283
321
                                             2
284
 
                                f(x) := SIN(x )
 
322
                                f(x) := sin(x )
 
323
 
285
324
                                           2
286
 
                                  2 x COS(x )
287
 
\endmaxima
 
325
                                  2 x cos(x )
 
326
\end{maxima}
288
327
\end{verbatim}
289
328
\noindent
290
329
When \LaTeX{}ed, the top line will contain a copy of the marker.
291
330
 
292
 
\beginmaxima<filename:optional>
 
331
\begin{maxima}[filename:optional]
293
332
<filename:definef>
294
333
diff(f(x),x);
295
334
\maximaoutput
 
335
 
296
336
                                             2
297
 
                                f(x) := SIN(x )
 
337
                                f(x) := sin(x )
 
338
 
298
339
                                           2
299
 
                                  2 x COS(x )
300
 
\endmaxima
 
340
                                  2 x cos(x )
 
341
\end{maxima}
301
342
 
302
343
A cell can contain more than one reference, and referenced cells can
303
344
themselves contain references.  
309
350
the \textsl{filename} and \textsl{cell label} parts of a reference, 
310
351
based on the current labels.  
311
352
Another option is to set the Emacs variable
312
 
\texttt{emaxima-abbreviations-allowed} to \texttt{t}, say, by putting
 
353
\texttt{emaxima\hyph{}abbreviations\hyph{}allowed} to \texttt{t}, say, by putting
313
354
the line
314
355
\begin{verbatim}
315
356
(setq emaxima-abbreviations-allowed t)
321
362
\texttt{...}
322
363
For example, if there are cells labelled
323
364
\begin{verbatim}
324
 
<filename:long description>
325
 
<filename:lengthy description>
 
365
[filename:long description]
 
366
[filename:lengthy description]
326
367
\end{verbatim}
327
368
\noindent
328
369
Then the reference
353
394
\TeX{}/\textit{Mathematica}, and is ultimately based on
354
395
\texttt{WEB}. To create a 
355
396
program, the ``base cell'' or ``package cell'' should contain 
356
 
a label of the form \texttt{<}\textsl{filename}\texttt{:>} 
 
397
a label of the form \texttt{[}\textsl{filename}\texttt{:]} 
357
398
(no cell label), and can
358
399
contain references of the form 
359
400
\texttt{<}\textsl{filename}\texttt{:}\textsl{part}\texttt{>}
362
403
As a simple (and rather silly) example, suppose we want to create a
363
404
program to sum the first $n$ squares.  We could start:
364
405
\begin{verbatim}
365
 
\beginmaxima<squaresum.max:>
 
406
\begin{maxima}[squaresum.max:]
366
407
squaresum(n) := (
367
408
  <squaresum.max:makelist>
368
409
  <squaresum.max:squarelist>
369
410
  <squaresum.max:addlist>
370
411
  );        
371
 
\endmaxima
 
412
\end{maxima}
372
413
\end{verbatim}
373
414
\noindent
374
415
We would then need cells
375
416
\begin{verbatim}
376
 
\beginmaxima<squaresum.max:makelist>,
 
417
\begin{maxima}[squaresum.max:makelist],
377
418
L:makelist(k,k,1,n),
378
 
\endmaxima
 
419
\end{maxima}
379
420
 
380
 
\beginmaxima<squaresum.max:squarelist>
 
421
\begin{maxima}[squaresum.max:squarelist]
381
422
<squaresum.max:definesquare>
382
423
L:map(square,L),
383
 
\endmaxima
 
424
\end{maxima}
384
425
 
385
 
\beginmaxima<squaresum.max:addlist>
 
426
\begin{maxima}[squaresum.max:addlist]
386
427
lsum(k,k,L)
387
 
\endmaxima
 
428
\end{maxima}
388
429
\end{verbatim}
389
430
\noindent
390
431
and then we would also need:
391
432
\begin{verbatim}
392
 
\beginmaxima<squaresum.max:definesquare>
 
433
\begin{maxima}[squaresum.max:definesquare]
393
434
square(k) := k^2,
394
 
\endmaxima
 
435
\end{maxima}
395
436
\end{verbatim}
396
437
\noindent
397
438
When \TeX{}ed, the header of the cell will say that it determines the
398
439
file \texttt{squaresum.mu}.  
399
 
\beginmaxima<squaresum.max:>
 
440
\begin{maxima}[squaresum.max:]
400
441
squaresum(n) := (
401
442
  <squaresum.max:makelist>
402
443
  <squaresum.max:squarelist>
403
444
  <squaresum.max:addlist>
404
445
  );        
405
 
\endmaxima
 
446
\end{maxima}
406
447
 
407
448
The command 
408
449
\texttt{C-u C-c @} will put all the pieces
427
468
the standard cells, special cells called \emph{session cells}.   A
428
469
session cell is delimited by
429
470
\begin{verbatim}
430
 
\beginmaximasession
 
471
\begin{maximasession}
431
472
\end{verbatim}
432
473
\noindent
433
474
and
434
475
\begin{verbatim}
435
 
\endmaximasession
 
476
\end{maximasession}
436
477
\end{verbatim}
437
478
\noindent
438
 
The command \texttt{C-c C-p} will create a session cell.  When a
439
 
session cell is updated, the output will be marked off with
440
 
\verb+\maximasession+, and will contain both the input and the output,
 
479
The command \texttt{C-c C-a} will create a session cell.  When a
 
480
session cell is updated, the portion of the cell after the
 
481
\verb+\maximaoutput+  will contain both the input and the output,
441
482
with the \mx{} prompts.  For example, if the session cell
442
483
\begin{verbatim}
443
 
\beginmaximasession
 
484
\begin{maximasession}
444
485
diff(sin(x),x);
445
 
int(cos(x),x);
446
 
\endmaximasession
 
486
integrate(cos(x),x);
 
487
\end{maximasession}
447
488
\end{verbatim}
448
489
\noindent
449
490
were updated, the result would look like
450
491
\begin{verbatim}
451
 
\beginmaximasession
 
492
\begin{maximasession}
452
493
diff(sin(x),x);
453
494
integrate(cos(x),x);
454
 
\maximasession
455
 
(C1)diff(sin(x),x);
456
 
 
457
 
(D1)                                COS(x)
458
 
(C2)integrate(cos(x),x);
459
 
 
460
 
(D2)                                SIN(x)
461
 
\endmaximasession
 
495
\maximaoutput
 
496
(%i1) diff(sin(x),x);
 
497
 
 
498
 
 
499
(%o1)                               cos(x)
 
500
(%i2) integrate(cos(x),x);
 
501
 
 
502
 
 
503
(%o2)                               sin(x)
 
504
\end{maximasession}
462
505
\end{verbatim}
463
506
\noindent
464
507
which, when \TeX{}ed, would look like
465
 
\beginmaximasession
 
508
\begin{maximasession}
466
509
diff(sin(x),x);
467
510
integrate(cos(x),x);
468
 
\maximasession
469
 
(C1)diff(sin(x),x);
470
 
 
471
 
(D1)                                COS(x)
472
 
(C2)integrate(cos(x),x);
473
 
 
474
 
(D2)                                SIN(x)
475
 
\endmaximasession
 
511
\maximaoutput
 
512
(%i1) diff(sin(x),x);
 
513
 
 
514
 
 
515
(%o1)                               cos(x)
 
516
(%i2) integrate(cos(x),x);
 
517
 
 
518
 
 
519
(%o2)                               sin(x)
 
520
\end{maximasession}
476
521
\noindent
477
522
If it is updated in \TeX{} form, it will look like
478
523
\begin{verbatim}
479
 
\beginmaximasession
 
524
\begin{maximasession}
480
525
diff(sin(x),x);
481
526
integrate(cos(x),x);
482
 
\maximatexsession
483
 
\C1.  diff(sin(x),x); \\
484
 
\D1.   \cos x \\
485
 
\C2.  integrate(cos(x),x); \\
486
 
\D2.   \sin x \\
487
 
\endmaximasession
 
527
\maximaoutput*
 
528
\i5.  diff(sin(x),x); \\
 
529
\o5.  \cos x \\
 
530
\i6.  integrate(cos(x),x); \\
 
531
\o6.  \sin x \\
 
532
\end{maximasession}
488
533
\end{verbatim}
489
534
\noindent
490
535
which, when \TeX{}ed, will look like
491
 
\beginmaximasession
 
536
\begin{maximasession}
492
537
diff(sin(x),x);
493
538
integrate(cos(x),x);
494
 
\maximatexsession
495
 
\C1.  diff(sin(x),x); \\
496
 
\D1.   \cos x \\
497
 
\C2.  integrate(cos(x),x); \\
498
 
\D2.   \sin x \\
499
 
\endmaximasession
500
 
 
501
 
For particularly long output lines inside the \verb+\maximatexsession+
502
 
part of a session cell, the command \verb+\DD+ will typeset anything
503
 
between the command and \verb+\\+.  Unfortunately, to take advantage
504
 
of this, the output has to be broken up by hand.
505
 
If a session cell has not been updated, or has no output for some
506
 
other reason, it will not appear when the document is \TeX{}ed.
507
 
 
508
 
There is one other type of cell, a \emph{noshow cell}, which can be
509
 
used to send \mx{} a command, but won't appear in the \TeX{}ed
510
 
output. A noshow cell can be created with \texttt{C-c C-n}, and will
511
 
be delimited by
512
 
\begin{verbatim}
513
 
\beginmaximanoshow
514
 
\end{verbatim}
515
 
\noindent
516
 
and
517
 
\begin{verbatim}
518
 
\endmaximanoshow
519
 
\end{verbatim}
520
 
 
521
 
Session cells and noshow cells cannot be part of packages.
 
539
\maximaoutput*
 
540
\i5.  diff(sin(x),x); \\
 
541
\o5.  \cos x \\
 
542
\i6.  integrate(cos(x),x); \\
 
543
\o6.  \sin x \\
 
544
\end{maximasession}
 
545
 
 
546
% For particularly long output lines inside the \verb+\maximaoutput*+
 
547
% part of a session cell, the command \verb+\DD+ will typeset anything
 
548
% between the command and \verb+\\+.  Unfortunately, to take advantage
 
549
% of this, the output has to be broken up by hand.
 
550
% If a session cell has not been updated, or has no output for some
 
551
% other reason, it will not appear when the document is \TeX{}ed.
 
552
 
 
553
If a cell is \emph{starred}, that is, if the environment ends with an
 
554
asterisk, then the output will not appear in the \TeX{}ed output.
 
555
The star can be toggled with \texttt{C-c C-n}.
522
556
 
523
557
If the command to create one type of cell is called while inside
524
558
another type of cell, the type of cell will be changed.  So, for
525
 
example, the command \texttt{C-c C-p} from inside the cell
 
559
example, the command \texttt{C-c C-a} from inside the cell
526
560
\begin{verbatim}
527
 
\beginmaxima
 
561
\begin{maxima}
528
562
diff(x*sin(x),x);
529
 
\endmaxima
 
563
\end{maxima}
530
564
\end{verbatim}
531
565
\noindent
532
566
will result in
533
567
\begin{verbatim}
534
 
\beginmaximasession
 
568
\begin{maximasession}
535
569
diff(x*sin(x),x);
536
 
\endmaximasession
 
570
\end{maximasession}
537
571
\end{verbatim}
538
572
\noindent
539
573
If a standard cell is a package part, its type cannot be changed.
549
583
\end{verbatim}
550
584
in the preamble.  
551
585
The cells will be un-previewed whenever they are updated.
552
 
If the customizable variable \texttt{emaxima-preview-after-update-all}
 
586
If the customizable variable \texttt{emaxima\hyph{}preview\hyph{}after\hyph{}update\hyph{}all}
553
587
is non-nil, then the buffer will be re-previewed whenever an
554
588
update-all command is called.
555
589
 
578
612
 
579
613
\section{Installation}
580
614
 
581
 
To run \mx{} interactively or use \mx{} mode, the files
582
 
\texttt{maxima.el} and \texttt{maxima-font-lock.el} need to be
 
615
To run \mx{} interactively or use \mx{} mode or minor mode, the files
 
616
\texttt{maxima.el} and \texttt{maxima\hyph{}font\hyph{}lock.el} need to be
583
617
somewhere in the Emacs load path.  To be able to automatically run
584
 
\mx{} or use \mx{} mode, add the lines\\
 
618
\mx{} or use \mx{} mode or minor mode, add the lines\\
585
619
\begin{verbatim}
586
620
(autoload 'maxima "maxima" "Run Maxima interactively" t)
587
621
(autoload 'maxima-mode "maxima" "Major mode for writing Maxima programs" t)
 
622
(autoload 'maxima-minor-mode "maxima" "Minor mode for working with Maxima" t)
 
623
 
588
624
\end{verbatim}
589
625
\noindent
590
626
in your \texttt{.emacs} file.  
593
629
\begin{verbatim}
594
630
(setq auto-mode-alist (cons '("\\.max" . maxima-mode) auto-mode-alist))
595
631
\end{verbatim}
596
 
to \texttt{.emacs}.  To be able to interact with \mx{} from the
597
 
minibuffer, add the line
598
 
\begin{verbatim}
599
 
(autoload 'maxima-minibuffer "maxima" "Run Maxima from the minibuffer" t)
600
 
\end{verbatim}
601
 
\noindent
602
632
to \texttt{.emacs}.
603
633
 
604
634
For the \emx{} package, in addition to the above files, the files
607
637
  \texttt{emaxima.lisp}, then the \TeX{} output functions will not
608
638
  work, any attempts to get \TeX{} output will result in an error.},
609
639
  and if you want to run \LaTeX{} on the resulting document,
610
 
\texttt{emaxima.sty} needs to be in the \TeX{} inputs path.  If you
611
 
use pdflatex, you'll also need \texttt{pdfcolmk.sty}.
 
640
\texttt{emaxima.sty} and \texttt{maxima.sty} need to be in the \TeX{}
 
641
inputs path.  If you use pdflatex, you'll also need \texttt{pdfcolmk.sty}.
612
642
 
613
643
To make sure that \texttt{emaxima.el} is loaded when necessary, the line
614
644
\begin{verbatim}
616
646
\end{verbatim}
617
647
\noindent
618
648
can be inserted into your \texttt{.emacs} file.  Then typing
619
 
\texttt{M-x emaxima-mode} will start \emx{} mode.  The command 
620
 
\texttt{M-x emaxima-mark-file-as-emaxima} will put the line
 
649
\texttt{M-x emaxima\hyph{}mode} will start \emx{} mode.  The command 
 
650
\texttt{M-x emaxima\hyph{}mark\hyph{}file\hyph{}as\hyph{}emaxima} will put the line
621
651
\begin{verbatim}
622
652
%-*-EMaxima-*-
623
653
\end{verbatim}
624
654
\noindent
625
655
at the beginning of the file, if it isn't there already, and will ensure
626
 
that the next time the file is opened, it will be in \texttt{emaxima-mode}.  
 
656
that the next time the file is opened, it will be in \texttt{emaxima\hyph{}mode}.  
627
657
This can be done automatically everytime a file is put in
628
 
\texttt{emaxima-mode} by putting the line
 
658
\texttt{emaxima\hyph{}mode} by putting the line
629
659
\begin{verbatim}
630
660
(add-hook 'emaxima-mode-hook 'emaxima-mark-file-as-emaxima)
631
661
\end{verbatim}
643
673
\hline
644
674
\texttt{M-TAB} & Complete the Maxima symbol as much as possible, providing
645
675
     a completion buffer if there is more than one possible
646
 
     completion.  (If the variable
647
 
     \texttt{maxima-use-dynamic-complete} is non-nil, then
648
 
     \texttt{M-TAB} will cycle through possible completions.\\
 
676
     completion.\\
649
677
\texttt{C-M-TAB} & Complete the input line, based on previous input lines.\\
650
678
\texttt{C-c C-d} & Get help on a Maxima topic.\\
651
679
\texttt{C-c C-m} & Bring up the Maxima info manual.\\
660
688
  a regular expression to the prompt.
661
689
\end{tabular}
662
690
 
 
691
\section{\mx{} minor mode commands}
 
692
\label{app:intmxmin}
 
693
 
 
694
\smallskip
 
695
 
 
696
\begin{tabular}{p{\firstcol}p{\secondcol}}
 
697
\hline
 
698
\textbf{Key} & \textbf{Description}\\
 
699
\hline
 
700
\texttt{C-c=e} & Run Maxima on the region between
 
701
\texttt{maxima\hyph{}minor\hyph{}prefix} and \texttt{maxima\hyph{}minor\hyph{}postfix}.  By
 
702
default, these are blank lines.\\
 
703
\texttt{C-c=r} & Run Maxima on the current region. \\
 
704
\texttt{C-c=l} & Run Maxima on the current line.\\
 
705
\texttt{C-c=f} & Run Maxima on the current form.\\
 
706
\texttt{C-c=m} & Prompt for Maxima input in the minibuffer.\\
 
707
\texttt{C-c=o} & Insert the last Maxima output in the current
 
708
buffer.\\
 
709
\texttt{C-c=t} & Insert the last Maxima output in \TeX{} form in the
 
710
current buffer.
 
711
\end{tabular}
 
712
 
663
713
 
664
714
\section{\mx{} mode commands}
665
715
\label{app:mxmode}
803
853
\textbf{Key} & \textbf{Description}\\
804
854
\hline
805
855
\texttt{C-c C-o} & Create a (standard) cell.\\
806
 
\texttt{C-c C-p} & Create a session cell.\\
807
 
\texttt{C-c C-n} & Create a noshow cell.\\
 
856
\texttt{C-c C-a} & Create a session cell.\\
 
857
\texttt{C-c C-n} & Toggle starred cells.\\
808
858
\texttt{C-c +} & Go the the next cell.\\
809
859
\texttt{C-c -} & Go to the previous cell.\\
810
860
\texttt{C-c C-u a} & 
1060
1110
Other facets of \mx{} mode can be controlled through the following
1061
1111
options: 
1062
1112
\begin{description}
1063
 
\item[maxima-use-dynamic-complete] If this is non-nil, then
1064
 
  \texttt{M-TAB} will cycle through completions of the current word,
1065
 
  rather than pop up a buffer with the completions.  By default, it is
1066
 
  \texttt{nil}.
1067
1113
\item[maxima-return-style] This determines how \mx{} mode will handle
1068
1114
  \texttt{RET}.  The options are \texttt{'newline},
1069
 
  \texttt{'newline-and-indent}, and
1070
 
  \texttt{'reindent-then-newline-and-indent}, the default is
1071
 
  \texttt{'reindent-then-newline-and-indent}.
 
1115
  \texttt{'newline\hyph{}and\hyph{}indent}, and
 
1116
  \texttt{'reindent\hyph{}then\hyph{}newline\hyph{}and\hyph{}indent}, the default is
 
1117
  \texttt{'reindent\hyph{}then\hyph{}newline\hyph{}and\hyph{}indent}.
1072
1118
\end{description}
1073
1119
 
1074
1120
Some other options that may occasionally need to be set are:
1075
1121
\begin{description}
1076
 
\item[maxima-info-dir] The directory which contains the \mx{} info
1077
 
  files.  By default, it is \texttt{/usr/local/info/}.
1078
 
\item[maxima-info-index-file] The \mx{} info file which contains the
1079
 
  index.  By default, it is \texttt{maxima.info-15}.
1080
1122
\item[maxima-command]  The command used to start \mx{}.  By default,
1081
1123
  it is \texttt{maxima}.
1082
1124
\item[maxima-args] Extra arguments to pass to the \mx{} command.  By
1092
1134
There are a few (very few) things that you can do to customize \emx{}.  
1093
1135
 
1094
1136
By default, \emx{} is an extension of AUC\TeX{} mode.  This can be
1095
 
changed by changing the variable \texttt{emaxima-use-tex}.  The possible
 
1137
changed by changing the variable \texttt{emaxima\hyph{}use\hyph{}tex}.  The possible
1096
1138
values are \texttt{'auctex}, \texttt{'tex} and \texttt{nil}.  Setting
1097
 
\texttt{emaxima-use-tex} (the default) to \texttt{'auctex} will make \emx{}
 
1139
\texttt{emaxima\hyph{}use\hyph{}tex} (the default) to \texttt{'auctex} will make \emx{}
1098
1140
an extension of AUC\TeX{}, setting it to \texttt{'tex} will make \emx{} an
1099
1141
extension of Emacs's default \TeX{} mode, and setting
1100
 
\texttt{emaxima-use-tex} to \texttt{nil} will make \emx{} an extension of
 
1142
\texttt{emaxima\hyph{}use\hyph{}tex} to \texttt{nil} will make \emx{} an extension of
1101
1143
text-mode.  So, for example, putting 
1102
1144
\begin{verbatim}
1103
1145
(setq emaxima-use-tex nil)
1108
1150
 
1109
1151
Whether or not the dots (\dots{}) abbreviation is allowed in cell
1110
1152
references is controlled by the elisp variable
1111
 
\texttt{emaxima-abbreviations-allowed}, which is set to \texttt{t} by
 
1153
\texttt{emaxima\hyph{}abbreviations\hyph{}allowed}, which is set to \texttt{t} by
1112
1154
default.  Setting this to \texttt{nil} will disallow the abbreviations,
1113
1155
but will speed up package assembly.
1114
1156
 
1115
 
The \LaTeX{}ed output can also be configured in a couple of ways.
1116
 
The lines that appear around cells when the document is \TeX{}ed can be
1117
 
turned off with the command (in the \LaTeX{} document)
1118
 
\begin{verbatim}
1119
 
\maximalinesfalse
1120
 
\end{verbatim}
1121
 
\noindent
1122
 
They can be turned back on with the command
1123
 
\begin{verbatim}
1124
 
\maximalinestrue
1125
 
\end{verbatim}
1126
 
\noindent
1127
 
 
1128
 
The variable \texttt{emaxima-preview-after-update-all} will determine
 
1157
The variable \texttt{emaxima\hyph{}preview\hyph{}after\hyph{}update\hyph{}all} will determine
1129
1158
whether or not the buffer will be previewed (when preview-latex is
1130
1159
being used) after an update-all command.  By default, it is \texttt{t}.
1131
1160
 
1132
1161
 
1133
 
The fonts used to display the \mx{} input and output in a cell are by
1134
 
default \texttt{cmtt10}.  They can be changed, seperately, by changing the
1135
 
\TeX{} values of \verb+\maximainputfont+ and \verb+\maximaoutputfont+.
1136
 
So, for example, to use \texttt{cmtt12} as the input font, use the command
1137
 
\begin{verbatim}
1138
 
\font\maximainputfont = cmtt12
1139
 
\end{verbatim}
1140
 
\noindent
1141
 
The spacing in the cells can be controlled by changing the \TeX{}
1142
 
variables \verb+\maximainputbaselineskip+ and
1143
 
\verb+\maximaoutputbaselineskip+, and so to increase the space between
1144
 
the lines of the output, the command
1145
 
\begin{verbatim}
1146
 
\maximaoutputbaselineskip = 14pt
1147
 
\end{verbatim}
1148
 
\noindent
1149
 
could be used.
1150
 
The amount of space that appears before a cell can be changed by changing
1151
 
the value of \verb+\premaximaspace+ (by default, 0pt), and that after
1152
 
a cell can be changed by changing the value of \verb+\postmaximaspace+
1153
 
(by default, 1.5 ex).
1154
 
 
1155
 
Session cells can be configured similarly.  
1156
 
Lines can be placed around a \mx{} session with the command
1157
 
\begin{verbatim}
1158
 
\maximasessionlinestrue
1159
 
\end{verbatim}
1160
 
\noindent
1161
 
and they can be turned back off with
1162
 
\begin{verbatim}
1163
 
\maximasessionlinesfalse
1164
 
\end{verbatim}
1165
 
\noindent
1166
 
The font can be changed by changing the value of
1167
 
\verb+\maximasessionfont+.  The color of the prompts when the session
1168
 
is in \TeX{} form is controlled by \\
1169
 
\verb+\maximapromptcolor+, by
1170
 
default red, the colors of the input lines and output lines are
1171
 
controlled by \verb+\maximainputcolor+ and \verb+\maximaoutputcolor+,
1172
 
respectively. So the command
1173
 
\begin{verbatim}
1174
 
\def\maximainputcolor{green}
1175
 
\end{verbatim}
1176
 
\noindent
1177
 
would make the input in a \TeX{}ed session green.  
1178
 
The session can be \TeX{}ed without the colors by using the command
1179
 
\verb+\maximasessionnocolor+.
1180
 
The baselineskip is
1181
 
set by \verb+\maximasessionbaselineskip+ for normal session cells, and
1182
 
by \verb+\maixmatexsessionbaselineskip+ for \TeX{} sessions.  The
1183
 
amount of space that appears before a session cell can be changed by
1184
 
changing the value of \verb+\premaximasessionspace+ (by default, 0pt),
1185
 
and that after a cell can be changed by changing the value of
1186
 
\verb+\postmaximasessionspace+ (by default, 1.5 ex).
 
1162
The \LaTeX{}ed output can be customized somewhat.  The
 
1163
\texttt{emaxima} LaTeX{} package can take some options, namely 
 
1164
\texttt{breqn}, \texttt{lines}, \texttt{listings} and \texttt{preview}.
 
1165
The \texttt{breqn} option will use the \LaTeX{} \texttt{breqn} package
 
1166
(which must be installed) to break long \mx{} lines into shorter lines
 
1167
automatically.
 
1168
The \texttt{preview} option will enable the Emacs preview package
 
1169
(which must be installed) to preview the \mx{} environments. 
 
1170
The \texttt{lines} option will put lines before and after some of the
 
1171
environments. 
 
1172
The \texttt{listings} option will use the \LaTeX{} \texttt{listings}
 
1173
package (which must be installed) to typeset some of the \mx{} code.
 
1174
To use this, the file \texttt{maxima.sty} must be in the search path
 
1175
for \TeX. 
 
1176
 
 
1177
The indentation of the \mx{} code can be reset by resetting the
 
1178
\LaTeX{} length \verb+\maximaindent+.
 
1179
The colors of the prompts, inputs and outputs can be reset by renewing
 
1180
the commands \verb+\maximapromptcolor+, \verb+\maximainputcolor+
 
1181
and \verb+\maximaoutputcolor+ to appropriate colors.
 
1182
 
 
1183
The top, middle and bottom of a maxima cell are determined by the
 
1184
commands \verb+\maximatop+, \verb+\maximamiddle+ and \verb+\maximabottom+.
 
1185
By default, \verb+\maximamiddle+ is set to \verb+\maximaoutputmarker+.
 
1186
If the \texttt{lines} option is used, then \verb+\maximatop+ and 
 
1187
\verb+\maximabottom+ are set to \verb+\maximaboxtop+ and
 
1188
\verb+\maximaboxbottom+,  respectively.
 
1189
Otherwise, \verb+\maximatop+ and \verb+\maximabottom+ are set to do nothing.
 
1190
The top and bottom of a maxima session are determined by
 
1191
\verb+\maximasessiontop+ and \verb+\maximasessionbottom+, respectively.
 
1192
By default, they do nothing.
 
1193
 
 
1194
The verbatim output for maxima cells is inserted with
 
1195
\verb+\maximaverbatiminput+.  This will do one of two things.
 
1196
If the listings option is used, this is defined by
 
1197
\verb+\lstinputlisting[style=emaxima]{#1}+, and so can be adjusted by
 
1198
resetting the emaxima style.   By default, this style is given by
 
1199
\begin{verbatim}
 
1200
\lstdefinestyle{emaxima}
 
1201
               {language=maxima,
 
1202
                aboveskip=0pt,
 
1203
                belowskip=0pt,
 
1204
                xleftmargin=\maximaindent}
 
1205
\end{verbatim}
 
1206
\noindent
 
1207
If the listings package is not used, then \verb+\maximaverbatiminput+ is 
 
1208
defined by \verb+\VerbatimInput[xleftmargin=\maximaindent]{#1}+
 
1209
(\verb+\VerbatimInput+ is from the fancyvrb package.)
 
1210
In either case, it can be adjusted by redefining
 
1211
\verb+\maximaverbatiminput+, which is expected to indent everything by
 
1212
\verb+\maximaindent+.
 
1213
The fonts used in the maximasessions is \verb+\maximafont+, by default
 
1214
\verb+\ttfamily+.
1187
1215
 
1188
1216
\end{document}