Ignore build-html-index.log and maxima-index-html.lisp
[maxima.git] / doc / emaxima / EMaximaIntro.tex
blob85df415787ffeb8b41484c61fae0323d5421cbe3
1 %-*-EMaxima-*-
2 \documentclass{article}
3 \usepackage[lines]{emaxima}
4 \usepackage{url}
6 \newcommand{\emx}{\textsl{\sffamily EMaxima}}
7 \newcommand{\mx}{\textsl{\sffamily Maxima}}
8 \newcommand{\hyph}{-\hspace{0pt}}
9 \newdimen\firstcol
10 \firstcol=.35\textwidth
11 \newdimen\secondcol
12 \secondcol=.65\textwidth
14 \title{\mx{} and Emacs}
15 \author{Jay Belanger}
16 \date{}
18 \begin{document}
20 \maketitle
22 \section{Using \mx{} and Emacs}
24 Emacs, while nominally a text editor, is an extensible environment for
25 interacting with text in various ways. As such, it provides a
26 convenient interface for many text-based utilities. For example,
27 users of Emacs can interact with \mx{} from within their favorite
28 editor\footnote{Emacs.} in a number of ways. The most basic way is to
29 use Emacs as a shell and run a \mx{} process interactively from
30 within a buffer. Emacs can interact with this process from other
31 buffers, and thus interact with the \mx{} process in less
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 program can also be sent automatically to a \mx{} program.
36 Finally, text and \mx{} commands can be interweaved in a \mx{}
37 notebook mode called \emx{}.
39 \section{Running \mx{} Interactively}
41 To run \mx{} interactively in a buffer, type \texttt{M-x maxima}. A
42 buffer named \texttt{*Maxima*} should start up in which a \mx{}
43 process is running.%
44 \footnote{In XEmacs, a double input prompt will sometimes appear in
45 the \texttt{*Maxima*} buffer. If this occurs, the customizable
46 variable \texttt{maxima\hyph{}fix\hyph{}double\hyph{}prompt} can be set to \texttt{t}
47 to take care of this.}
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}.
55 If this is the only way that \mx{} is to be used from within Emacs,
56 then the \textsl{Imaxima} package should be considered. It allows the
57 user to work with \mx{} interactively, and produces the output in
58 visually nice form. It is available from
59 \verb+http://memberss3.jcom.home.ne.jp/imaxima/Site/Welcome.html+.
61 \section{Running \mx{} from arbitrary buffers}
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.
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.
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.
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%
103 \footnote{In GNU Emacs, the output will be in 2D form if the
104 customizable variable \texttt{maxima\hyph{}minibuffer\hyph{}2d} is non-nil. Since
105 XEmacs does not have a resizable minibuffer, this cannot be done in
106 XEmacs.}.
107 You can scroll through previous minibuffer inputs using the arrow keys.
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}).%
112 \footnote{If the output is 2D, this won't look nice.}
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.
116 \section{\mx{} mode}
118 \mx{} mode is a major mode for writing \mx{} code. While in this
119 mode, Emacs provides commands for moving around in the code, syntax
120 highlighting, indenting lines to an appropriate level, sending
121 portions of the code to a \mx{} process, and providing help on \mx{}
122 commands. A list of available commands is in Appendix
123 \ref{app:mxmode}.
125 When something is sent to a \mx{} process, the \texttt{*Maxima*}
126 buffer will
127 appear. (If a \mx{} process is not running, one will be started.) It
128 can also be made to appear by using the command \texttt{C-c C-p}. If
129 an argument is given to a command to send information to \mx{}, the
130 region will first be checked to make sure the parentheses are
131 balanced. The Maxima process can be killed, after asking for
132 confirmation, with \texttt{C-c C-k}. To kill without confirmation, give
133 \texttt{C-c C-k} an argument.
135 By default, a newline will be indented to the same level as the
136 previous line, with an additional space added for open parentheses. A
137 tab will add extra spaces, by default, this is 2. The behaviour of
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
141 to guess an appropriate indentation, based on open parentheses, ``do''
142 loops, etc.
144 A \texttt{RET} will, by default, insert a new line, and indent the new
145 line an appropriate amount. This behavior can be changed by setting
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
151 behavior is to let \texttt{RET} only insert a newline, and
152 \texttt{LFD} or \texttt{C-j} insert a newline and indent it.)
154 The indentation style, as well as many other things, are customizable;
155 see Appendix \ref{app:custmxmode}.
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.
163 \section{\emx}
165 \emx{} is a major mode for Emacs that allows the user to write
166 documents while interacting with \mx. It is based on Dan Dill's
167 \TeX{}/\textit{Mathematica} package\footnote{\TeX/\textit{Mathematica}
168 is available from \url{ftp://chem.bu.edu/pub/tex-mathematica-2.0}.},
169 and uses a modified version of William Schelter's \texttt{maxima.el}.
170 While the \mx{} mode provided by \texttt{maxima.el} is designed to
171 help write \mx{} programs, \emx{} is designed to help write documents
172 that include \mx{} code. \emx{} is an extension of the \LaTeX{} mode
173 provided by AUC\TeX{}\footnote{This can be configured so that \emx{}
174 extends the standard \TeX{} mode provided by Emacs, or just text
175 mode.}, and so has the \LaTeX{} mode commands available. The
176 resulting document can be processed by \LaTeX{}; this requires putting
177 \begin{verbatim}
178 \usepackage{emaxima}
179 \end{verbatim}
180 \noindent
181 in the preamble.
183 \subsection{Cells}
185 The basic unit of \mx{} code in \emx{} is a \textbf{cell}. A cell
186 consists of text between the delimiters
187 \begin{verbatim}
188 \begin{maxima}
189 \end{verbatim}
190 \noindent
192 \begin{verbatim}
193 \end{maxima}
194 \end{verbatim}
195 \noindent
196 A cell can be created by typing \texttt{C-c C-o}. (The \texttt{C-o} in this
197 case stands for \textbf{o}pening a cell.) The delimiters will then be
198 placed in the buffer, and the point will be placed between them.
200 When working with several cells, you can jump between them by using
201 \texttt{C-c +} to go to the next cell and \texttt{C-c -} to go to the
202 previous cell.
204 \subsection{Evaluating cells}
206 \noindent
207 To evaluate the contents of a cell, the command
208 \texttt{C-c C-u c} (\texttt{emaxima\hyph{}update\hyph{}cell})\footnote{Sending the
209 cells contents to a \mx{} process and returning the results is
210 called \textbf{updating} the cell, the prefix
211 \texttt{C-c C-u} will be used to update cells in different ways.}
212 will send the contents
213 of the cell to a \mx{} process (if there is no \mx{} process running,
214 one will be started) and return the results to the cell,
215 separated from the input by the marker
216 \begin{verbatim}
217 \maximaoutput
218 \end{verbatim}
219 \noindent
220 To differentiate
221 $\sin(x^2)$, for example, type
222 \texttt{diff(sin(x\^{}2),x);} in a cell:
223 \begin{verbatim}
224 \begin{maxima}
225 diff(sin(x^2),x);
226 \end{maxima}
227 \end{verbatim}
228 \noindent
229 After typing \texttt{C-c C-u c}, it will look like
230 \begin{verbatim}
231 \begin{maxima}
232 diff(sin(x^2),x);
233 \maximaoutput
235 2 x cos(x )
236 \end{maxima}
237 \end{verbatim}
238 \noindent
239 To delete the output and return the cell to its original form, you can
240 use the command \texttt{C-c C-d}.
241 If the document is to be \TeX{}ed, the above cell will look like:
242 \newpage
243 \begin{maxima}
244 diff(sin(x^2),x);
245 \end{maxima}
246 and the cell with output will look like:
247 \begin{maxima}
248 diff(sin(x^2),x);
249 \maximaoutput
251 2 x cos(x )
252 \end{maxima}
254 \emx{} mode can take advantage of the fact that \mx{} can give its
255 output in \LaTeX{} form. The command \texttt{C-c C-u C}
256 works the same as \texttt{C-c C-u c}, except now the output is in \LaTeX{}
257 form, ready to be formatted by \LaTeX{}. In general, if
258 \texttt{C-c C-u }\textsl{letter} returns \mx{} output, then
259 \texttt{C-c C-u }\textsl{capital letter} will return the output in
260 \TeX{} form. The above cell would become
261 \begin{verbatim}
262 \begin{maxima}
263 diff(sin(x^2),x);
264 \maximaoutput*
265 \m 2\,x\,\cos x^2 \\
266 \end{maxima}
267 \end{verbatim}
268 \noindent
269 which, when \LaTeX{}ed, would become
270 \begin{maxima}
271 diff(sin(x^2),x);
272 \maximaoutput*
273 \m 2\,x\,\cos x^2 \\
274 \end{maxima}
275 \noindent
276 (Note that whenever a cell is updated, any old output is discarded and
277 replaced with new output.) The command \texttt{C-c C-u a} will update all
278 of the cells in your document,
279 stopping at each one to ask if you indeed want it updated. Given an
280 argument, \texttt{C-u C-c C-u a}, it will update all of the cells in your
281 document without asking. The command \texttt{C-c C-u A} behaves
282 similarly, except now all the output is returned in \LaTeX{} form.
284 \subsection{Referencing Other Cells}
286 \noindent
287 Instead of \mx{} code, a cell can contain a reference to another cell,
288 and when the original cell is sent to \mx{}, the reference is replaced
289 by the referenced cell's contents (but only in the \mx{} process
290 buffer, the cell's
291 content in the document's buffer is not changed). In order to do
292 this, the original cell must be marked by having a label of the form
293 \texttt{<}\textsl{filename}\texttt{:}\textsl{cell label}\texttt{>}.
294 (The reason for the \textsl{filename} will become apparent later, and
295 \textsl{cell label} is optional for the referencing cell.)
296 The referenced cell must also be labeled, with the same
297 \textsl{filename} but a unique \textsl{cell label}. To reference the
298 other cell, the original cell need only contain the marker for the
299 referenced cell. For example, given cell 1:
300 \begin{verbatim}
301 \begin{maxima}[filename:optional]
302 <filename:definef>
303 diff(f(x),x);
304 \end{maxima}
305 \end{verbatim}
306 \noindent
307 and cell 2:
308 \begin{verbatim}
309 \begin{maxima}[filename:definef]
310 f(x):=sin(x^2);
311 \end{maxima}
312 \end{verbatim}
313 \noindent
314 then the result of updating cell 1 (\texttt{C-c C-u c}) will be:
315 \begin{verbatim}
316 \begin{maxima}[filename:optional]
317 <filename:definef>
318 diff(f(x),x);
319 \maximaoutput
322 f(x) := sin(x )
325 2 x cos(x )
326 \end{maxima}
327 \end{verbatim}
328 \noindent
329 When \LaTeX{}ed, the top line will contain a copy of the marker.
331 \begin{maxima}[filename:optional]
332 <filename:definef>
333 diff(f(x),x);
334 \maximaoutput
337 f(x) := sin(x )
340 2 x cos(x )
341 \end{maxima}
343 A cell can contain more than one reference, and referenced cells can
344 themselves contain references.
346 To aid in labelling the cells, the command \texttt{C-c C-x}
347 will prompt for a label name and label the
348 cell. To aid in calling references, the command \texttt{C-c C-TAB}
349 can be used for completing the
350 the \textsl{filename} and \textsl{cell label} parts of a reference,
351 based on the current labels.
352 Another option is to set the Emacs variable
353 \texttt{emaxima\hyph{}abbreviations\hyph{}allowed} to \texttt{t}, say, by putting
354 the line
355 \begin{verbatim}
356 (setq emaxima-abbreviations-allowed t)
357 \end{verbatim}
358 \noindent
359 in your \texttt{.emacs} file. This will allow the \textsl{filename}
360 and \textsl{cell label} parts of a reference to be abbreviated by enough
361 of a prefix to uniquely identify it, followed by ellipses
362 \texttt{...}
363 For example, if there are cells labelled
364 \begin{verbatim}
365 [filename:long description]
366 [filename:lengthy description]
367 \end{verbatim}
368 \noindent
369 Then the reference
370 \begin{verbatim}
371 <...:le...>
372 \end{verbatim}
373 \noindent
374 will suffice to refer to the second label above.
376 If you want the references in a cell to be replaced by the actual
377 code, the command \texttt{C-c @} will expand all the
378 references and put the code into a separate buffer (so it will not
379 affect the original document).
381 \subsection{WEB}
383 \noindent
384 The reason for the ability to reference other cells is so that you can
385 write what Donald Knuth calls literate programs. The idea is that the
386 program is written in a form natural to the author rather than natural
387 to the computer. (Another aspect of Knuth's system is that the code
388 is carefully documented, hence the name ``literate programming'', but
389 that is done naturally in \emx{}.) Knuth called his original
390 literate programming tool \texttt{WEB}, since, as he puts it,
391 ``the structure of a software program may be thought of as a web that
392 is made up of many interconnected pieces.''
393 \emx{}'s ability in this respect is taken directly from
394 \TeX{}/\textit{Mathematica}, and is ultimately based on
395 \texttt{WEB}. To create a
396 program, the ``base cell'' or ``package cell'' should contain
397 a label of the form \texttt{[}\textsl{filename}\texttt{:]}
398 (no cell label), and can
399 contain references of the form
400 \texttt{<}\textsl{filename}\texttt{:}\textsl{part}\texttt{>}
401 (same file name as the base cell).
403 As a simple (and rather silly) example, suppose we want to create a
404 program to sum the first $n$ squares. We could start:
405 \begin{verbatim}
406 \begin{maxima}[squaresum.max:]
407 squaresum(n) := (
408 <squaresum.max:makelist>
409 <squaresum.max:squarelist>
410 <squaresum.max:addlist>
412 \end{maxima}
413 \end{verbatim}
414 \noindent
415 We would then need cells
416 \begin{verbatim}
417 \begin{maxima}[squaresum.max:makelist],
418 L:makelist(k,k,1,n),
419 \end{maxima}
421 \begin{maxima}[squaresum.max:squarelist]
422 <squaresum.max:definesquare>
423 L:map(square,L),
424 \end{maxima}
426 \begin{maxima}[squaresum.max:addlist]
427 lsum(k,k,L)
428 \end{maxima}
429 \end{verbatim}
430 \noindent
431 and then we would also need:
432 \begin{verbatim}
433 \begin{maxima}[squaresum.max:definesquare]
434 square(k) := k^2,
435 \end{maxima}
436 \end{verbatim}
437 \noindent
438 When \TeX{}ed, the header of the cell will say that it determines the
439 file \texttt{squaresum.mu}.
440 \begin{maxima}[squaresum.max:]
441 squaresum(n) := (
442 <squaresum.max:makelist>
443 <squaresum.max:squarelist>
444 <squaresum.max:addlist>
446 \end{maxima}
448 The command
449 \texttt{C-u C-c @} will put all the pieces
450 together in the file it determines. The resulting file, in this case,
451 will be \texttt{squaresum.max} and will look like:
452 \begin{verbatim}
453 squaresum(n) := (
454 L:makelist(k,k,1,n),
455 square(k) := k^2,
456 L:map(square,L),
457 lsum(k,k,L)
459 \end{verbatim}
460 \noindent
461 (Although the idea is that only the computer need look at this file.)
463 \subsection{Other types of cells}
465 \noindent
466 When a cell is \TeX{}ed, the input and output are kept separate. To
467 have the results look like a \mx{} session, there are, in addition to
468 the standard cells, special cells called \emph{session cells}. A
469 session cell is delimited by
470 \begin{verbatim}
471 \begin{maximasession}
472 \end{verbatim}
473 \noindent
475 \begin{verbatim}
476 \end{maximasession}
477 \end{verbatim}
478 \noindent
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,
482 with the \mx{} prompts. For example, if the session cell
483 \begin{verbatim}
484 \begin{maximasession}
485 diff(sin(x),x);
486 integrate(cos(x),x);
487 \end{maximasession}
488 \end{verbatim}
489 \noindent
490 were updated, the result would look like
491 \begin{verbatim}
492 \begin{maximasession}
493 diff(sin(x),x);
494 integrate(cos(x),x);
495 \maximaoutput
496 (%i1) diff(sin(x),x);
499 (%o1) cos(x)
500 (%i2) integrate(cos(x),x);
503 (%o2) sin(x)
504 \end{maximasession}
505 \end{verbatim}
506 \noindent
507 which, when \TeX{}ed, would look like
508 \begin{maximasession}
509 diff(sin(x),x);
510 integrate(cos(x),x);
511 \maximaoutput
512 (%i1) diff(sin(x),x);
515 (%o1) cos(x)
516 (%i2) integrate(cos(x),x);
519 (%o2) sin(x)
520 \end{maximasession}
521 \noindent
522 If it is updated in \TeX{} form, it will look like
523 \begin{verbatim}
524 \begin{maximasession}
525 diff(sin(x),x);
526 integrate(cos(x),x);
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}
533 \end{verbatim}
534 \noindent
535 which, when \TeX{}ed, will look like
536 \begin{maximasession}
537 diff(sin(x),x);
538 integrate(cos(x),x);
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}
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.
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}.
557 If the command to create one type of cell is called while inside
558 another type of cell, the type of cell will be changed. So, for
559 example, the command \texttt{C-c C-a} from inside the cell
560 \begin{verbatim}
561 \begin{maxima}
562 diff(x*sin(x),x);
563 \end{maxima}
564 \end{verbatim}
565 \noindent
566 will result in
567 \begin{verbatim}
568 \begin{maximasession}
569 diff(x*sin(x),x);
570 \end{maximasession}
571 \end{verbatim}
572 \noindent
573 If a standard cell is a package part, its type cannot be changed.
575 \subsection{\emx{} and \texttt{Preview-LaTeX}}
577 For users of \texttt{preview-latex}, the \emx{} cells can be
578 previewed.\footnote{Currently, this only works in GNU Emacs.}
579 This requires using the \texttt{preview} option to the
580 \texttt{emaxima} package; i.e., putting
581 \begin{verbatim}
582 \usepackage[preview]{emaxima}
583 \end{verbatim}
584 in the preamble.
585 The cells will be un-previewed whenever they are updated.
586 If the customizable variable \texttt{emaxima\hyph{}preview\hyph{}after\hyph{}update\hyph{}all}
587 is non-nil, then the buffer will be re-previewed whenever an
588 update-all command is called.
591 \subsection{Miscellaneous}
593 \noindent
594 Some \mx{} commands can be used even outside of cells. The command
595 \texttt{C-c C-u l} send the current line to a
596 \mx{} process, comment out the current line, and insert the \mx{}
597 output in the current buffer. The command
598 \texttt{C-c C-u L} will do the same, but
599 return the result in \LaTeX{} form.
601 The command \texttt{C-c C-h} will provide
602 information on a prompted for function (like \mx's \texttt{describe}),
603 and \texttt{C-c C-i} will give the \mx{} info manual.
605 Finally, the \mx{} process can be killed with \texttt{C-c C-k}.
607 A list of the commands for \emx{} are in Appendix \ref{app:emx}, and
608 the customizability options are in Appendix \ref{app:custemx}.
610 \newpage
611 \appendix
613 \section{Installation}
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
617 somewhere in the Emacs load path. To be able to automatically run
618 \mx{} or use \mx{} mode or minor mode, add the lines\\
619 \begin{verbatim}
620 (autoload 'maxima "maxima" "Run Maxima interactively" t)
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)
624 \end{verbatim}
625 \noindent
626 in your \texttt{.emacs} file.
627 To ensure that files ending in \texttt{.max} start up in \mx{} mode,
628 add the line
629 \begin{verbatim}
630 (setq auto-mode-alist (cons '("\\.max" . maxima-mode) auto-mode-alist))
631 \end{verbatim}
632 to \texttt{.emacs}.
634 For the \emx{} package, in addition to the above files, the files
635 \texttt{emaxima.el} and \texttt{emaxima.lisp} need to be somewhere in
636 the Emacs load path\footnote{If Emacs cannot find
637 \texttt{emaxima.lisp}, then the \TeX{} output functions will not
638 work, any attempts to get \TeX{} output will result in an error.},
639 and if you want to run \LaTeX{} on the resulting document,
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}.
643 To make sure that \texttt{emaxima.el} is loaded when necessary, the line
644 \begin{verbatim}
645 (autoload 'emaxima-mode "emaxima" "EMaxima" t)
646 \end{verbatim}
647 \noindent
648 can be inserted into your \texttt{.emacs} file. Then typing
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
651 \begin{verbatim}
652 %-*-EMaxima-*-
653 \end{verbatim}
654 \noindent
655 at the beginning of the file, if it isn't there already, and will ensure
656 that the next time the file is opened, it will be in \texttt{emaxima\hyph{}mode}.
657 This can be done automatically everytime a file is put in
658 \texttt{emaxima\hyph{}mode} by putting the line
659 \begin{verbatim}
660 (add-hook 'emaxima-mode-hook 'emaxima-mark-file-as-emaxima)
661 \end{verbatim}
662 \noindent
663 somewhere in your \texttt{.emacs} file.
666 \section{\mx{} help commands}
668 The following commands can be used in any Maxima related buffer. (For
669 Maxima minor mode, replace \texttt{C-c C-d} with \texttt{C-= d}.)
671 \smallskip
673 \noindent
674 \begin{tabular}{p{\firstcol}p{\secondcol}}
675 \hline
676 \textbf{Key} & \textbf{Description}\\
677 \hline
678 \texttt{C-c C-d h}
679 %& \texttt{maxima-help}
680 & Get help on a (prompted for) subject.\\
681 \texttt{C-c C-d d} \\
682 \texttt{C-c C-d C-d}
683 %& \texttt{maxima-apropos}
684 & Get help with the symbol under point.\\
685 \texttt{C-c C-d a}\\
686 \texttt{C-c C-d a} & Apropos.\\
687 \texttt{C-c C-d p}\\
688 \texttt{C-c C-d C-p} & Get apropos with the symbol under point.\\
689 \texttt{C-c C-d m}\\
690 \texttt{C-c C-d C-m}\\
691 \texttt{C-c C-d i}\\
692 \texttt{C-c C-d C-i} & Read the Maxima info manual.
693 \end{tabular}
695 \section{Interactive \mx{} commands}
696 \label{app:intmx}
698 \smallskip
700 \begin{tabular}{p{\firstcol}p{\secondcol}}
701 \hline
702 \textbf{Key} & \textbf{Description}\\
703 \hline
704 \texttt{M-TAB} & Complete the Maxima symbol as much as possible, providing
705 a completion buffer if there is more than one possible
706 completion.\\
707 \texttt{C-M-TAB} & Complete the input line, based on previous input lines.\\
708 \texttt{C-c C-k} & Kill the process and the buffer, after asking for
709 confirmation. To kill without confirmation, give \texttt{C-c C-k} an
710 argument.\\
711 \texttt{M-p} & Bring the previous input to the current prompt.\\
712 \texttt{M-n} & Bring the next input to the prompt.\\
713 \texttt{M-r} & Bring the previous input matching
714 a regular expression to the prompt.\\
715 \texttt{M-s} & Bring the next input matching
716 a regular expression to the prompt.
717 \end{tabular}
719 \section{\mx{} minor mode commands}
720 \label{app:intmxmin}
722 \smallskip
724 \begin{tabular}{p{\firstcol}p{\secondcol}}
725 \hline
726 \textbf{Key} & \textbf{Description}\\
727 \hline
728 \texttt{C-c=e} & Run Maxima on the region between
729 \texttt{maxima\hyph{}minor\hyph{}prefix} and \texttt{maxima\hyph{}minor\hyph{}postfix}. By
730 default, these are blank lines.\\
731 \texttt{C-c=r} & Run Maxima on the current region. \\
732 \texttt{C-c=l} & Run Maxima on the current line.\\
733 \texttt{C-c=f} & Run Maxima on the current form.\\
734 \texttt{C-c=m} & Prompt for Maxima input in the minibuffer.\\
735 \texttt{C-c=o} & Insert the last Maxima output in the current
736 buffer.\\
737 \texttt{C-c=t} & Insert the last Maxima output in \TeX{} form in the
738 current buffer.
739 \end{tabular}
742 \section{\mx{} mode commands}
743 \label{app:mxmode}
745 \smallskip
747 \noindent
748 \textbf{Motion}
750 \smallskip
752 \noindent
753 \begin{tabular}{p{\firstcol}p{\secondcol}}
754 \hline
755 \textbf{Key} & \textbf{Description}\\
756 \hline
757 \texttt{M-C-a} & Go to the beginning of the form.\\
758 \texttt{M-C-e} & Go to the end of the form.\\
759 \texttt{M-C-b} & Go to the beginning of the sexp.\\
760 \texttt{M-C-f} & Go to the end of the sexp.
761 \end{tabular}
763 \smallskip
765 \noindent
766 \textbf{Process}
768 \smallskip
770 \noindent
771 \begin{tabular}{p{\firstcol}p{\secondcol}}
772 \hline
773 \textbf{Key} & \textbf{Description}\\
774 \hline
775 \texttt{C-c C-p} & Start a \mx{} process.\\
776 \texttt{C-c C-r} & Send the region to the \mx{} process.\\
777 \texttt{C-c C-b} & Send the buffer to the \mx{} process.\\
778 \texttt{C-c C-c} & Send the line to the \mx{} process.\\
779 \texttt{C-c C-e} & Send the form to the \mx{} process.\\
780 \texttt{C-c C-k} & Kill the \mx{} process.\\
781 \texttt{C-c C-p} & Display the \mx{} buffer.
782 \end{tabular}
784 \smallskip
786 \noindent
787 \textbf{Completion}
789 \smallskip
791 \noindent
792 \begin{tabular}{p{\firstcol}p{\secondcol}}
793 \hline
794 \textbf{Key} & \textbf{Description}\\
795 \hline
796 \texttt{M-TAB} & Complete the \mx{} symbol.\\
797 \end{tabular}
799 %\smallskip
800 \newpage
802 \noindent
803 \textbf{Comments}
805 \smallskip
807 \noindent
808 \begin{tabular}{p{\firstcol}p{\secondcol}}
809 \hline
810 \textbf{Key} & \textbf{Description}\\
811 \hline
812 \texttt{C-c ;} & Comment the region.\\
813 \texttt{C-c :} & Uncomment the region.\\
814 \texttt{M-;} & Insert a short comment.\\
815 \texttt{C-c *} & Insert a comment environment.
816 \end{tabular}
819 \smallskip
821 \noindent
822 \textbf{Indentation}
824 \smallskip
826 \noindent
827 \begin{tabular}{p{\firstcol}p{\secondcol}}
828 \hline
829 \textbf{Key} & \textbf{Description}\\
830 \hline
831 \texttt{TAB} & Indent line.\\
832 \texttt{M-C-q} & Indent form.
833 \end{tabular}
836 \smallskip
838 \noindent
839 \textbf{Miscellaneous}
841 \smallskip
843 \noindent
844 \begin{tabular}{p{\firstcol}p{\secondcol}}
845 \hline
846 \textbf{Key} & \textbf{Description}\\
847 \hline
848 \texttt{M-h} & Mark the form.\\
849 \texttt{C-c )} & Check the region for balanced parentheses.\\
850 \texttt{C-c C-)} & Check the form for balanced parentheses.
851 \end{tabular}
853 \section{\emx{} mode commands}
854 \label{app:emx}
856 \noindent
857 \begin{tabular}{p{\firstcol}p{\secondcol}}
858 \hline
859 \textbf{Key} & \textbf{Description}\\
860 \hline
861 \texttt{C-c C-o} & Create a (standard) cell.\\
862 \texttt{C-c C-a} & Create a session cell.\\
863 \texttt{C-c C-n} & Toggle starred cells.\\
864 \texttt{C-c +} & Go the the next cell.\\
865 \texttt{C-c -} & Go to the previous cell.\\
866 \texttt{C-c C-u a} &
867 Update all of the cells. With an argument, don't ask before updating.\\
868 \texttt{C-c C-u A}
869 & Update all of the cells in \TeX{} form. With an argument don't ask
870 before updating.\\
871 \texttt{C-c C-u s}
872 & Update all of the session cells in \TeX{} form. With an
873 argument, don't ask before updating.
874 \end{tabular}
876 %\smallskip
877 \newpage
879 \noindent
880 \textbf{Commands only available in cells.}
882 \smallskip
884 \noindent
885 \begin{tabular}{p{\firstcol}p{\secondcol}}
886 \hline
887 \textbf{Key} & \textbf{Description}\\
888 \hline
889 \texttt{C-c C-v}
890 %& \texttt{emaxima-send-cell}
891 & Send the current cell to the \mx{} process.\\
892 \texttt{C-c C-u c}
893 %& \texttt{emaxima-update-cell}
894 & Update the current cell.\\
895 \texttt{C-c C-u C}
896 %& \texttt{emaxima-tex-update-cell}
897 & Update the current cell in \TeX{} form.\\
898 \texttt{C-c C-d}
899 %& \texttt{emaxima-delete-output}
900 & Delete the output from the current cell.\\
901 \texttt{C-c C-x}
902 %& \texttt{emaxima-package-part}
903 & Insert a heading for the cell indicating that it's part of a
904 package. \\
905 \texttt{C-c @}
906 %& \texttt{emaxima-assemble}
907 & Assemble the references contained in the cell. With an argument,
908 assemble the package that the cell defines.\\
909 \texttt{C-c C-\texttt{TAB}}
910 %& \texttt{emaxima-insert-complete-name}
911 & Complete a reference within a cell.
912 \end{tabular}
914 \smallskip
916 \noindent
917 \textbf{Commands only available outside of cells.}
919 \smallskip
921 \noindent
922 \begin{tabular}{p{\firstcol}p{\secondcol}}
923 \hline
924 \textbf{Key} & \textbf{Description}\\
925 \hline
926 \texttt{C-c C-u l}
927 %& \texttt{emaxima-replace-line}
928 & Send the current line to \mx{}, and replace the line with the
929 \mx{} output.\\
930 \texttt{C-c C-u L}
931 %& \texttt{emaxima-replace-line-with-tex}
932 & Send the current line to \mx{}, and replace the line with the
933 \mx{} output in \TeX{} form.
934 \end{tabular}
937 \section{AUC\TeX{} commands}
939 \smallskip
941 \noindent
942 \textbf{Inserting commands}
944 \smallskip
946 \noindent
947 \begin{tabular}{p{\firstcol}p{\secondcol}}
948 \hline
949 \textbf{Key} & \textbf{Description}\\
950 \hline
951 \texttt{C-c C-e}
952 & Insert an environment.\\
953 \texttt{C-c C-s}
954 & Insert a section.\\
955 \texttt{C-c ]}
956 & Close an environment.\\
957 \texttt{C-c C-j}
958 & Insert an item into a list.\\
959 \texttt{"}
960 & Smart quote.\\
961 \texttt{\$}
962 & Smart dollar sign.\\
963 \texttt{C-c @}
964 & Insert double brace.\\
965 \texttt{C-c C-m}
966 & Insert \TeX{} macro.\\
967 \texttt{M-TAB}
968 & Complete \TeX{} macro.\\
969 \end{tabular}
971 \smallskip
973 \noindent
974 \textbf{Formatting}
976 \smallskip
978 \noindent
979 \begin{tabular}{p{\firstcol}p{\secondcol}}
980 \hline
981 \textbf{Key} & \textbf{Description}\\
982 \hline
983 \texttt{C-c C-q C-r}
984 & Format region.\\
985 \texttt{C-c C-q C-s}
986 & Format section.\\
987 \texttt{C-c C-q C-e}
988 & Format environment.\\
989 \texttt{C-c .}
990 & Mark an environment.\\
991 \texttt{C-c *}
992 & Mark a section.
993 \end{tabular}
995 %\smallskip
996 \newpage
998 \noindent
999 \textbf{Commenting}
1001 \smallskip
1003 \noindent
1004 \begin{tabular}{p{\firstcol}p{\secondcol}}
1005 \hline
1006 \textbf{Key} & \textbf{Description}\\
1007 \hline
1008 \texttt{C-c ;}
1009 & Comment a region.\\
1010 \texttt{C-u C-c ;}
1011 & Uncomment a region.\\
1012 \texttt{C-c \%}
1013 & Comment a paragraph.\\
1014 \texttt{C-u C-c \%}
1015 & Uncomment a paragraph.
1016 \end{tabular}
1018 \smallskip
1020 \noindent
1021 \textbf{Font selection}
1023 \smallskip
1025 \noindent
1026 \begin{tabular}{p{\firstcol}p{\secondcol}}
1027 \hline
1028 \textbf{Key} & \textbf{Description}\\
1029 \hline
1030 \texttt{C-c C-f C-b}
1031 & Bold.\\
1032 \texttt{C-c C-f C-i}
1033 & Italics.\\
1034 \texttt{C-c C-f C-r}
1035 & Roman.\\
1036 \texttt{C-c C-f C-e}
1037 & Emphasized.\\
1038 \texttt{C-c C-f C-t}
1039 & Typewriter.\\
1040 \texttt{C-c C-f C-s}
1041 & Slanted.\\
1042 \texttt{C-c C-f C-d}
1043 & Delete font.\\
1044 \texttt{C-u C-c C-f}
1045 & Change font.
1046 \end{tabular}
1048 \noindent
1049 \textbf{Running \TeX{}}
1051 \smallskip
1053 \noindent
1054 (Commands: \texttt{TeX}, \texttt{TeX Interactive}, \texttt{LaTeX},
1055 \texttt{LaTeX Interactive}, \texttt{SliTeX}, \texttt{View},
1056 \texttt{Print}, \texttt{BibTeX}, \texttt{Index}, \texttt{Check},
1057 \texttt{File}, \texttt{Spell}.)
1059 \smallskip
1061 \noindent
1062 \begin{tabular}{p{\firstcol}p{\secondcol}}
1063 \hline
1064 \textbf{Key} & \textbf{Description}\\
1065 \hline
1066 \texttt{C-c C-c}
1067 & Run a command on the master file.\\
1068 \texttt{C-c C-r}
1069 & Run a command on the current region.\\
1070 \texttt{C-c C-b}
1071 & Run a command on the buffer.\\
1072 \texttt{C-c `}
1073 & Go to the next error.\\
1074 \texttt{C-c C-k}
1075 & Kill the \TeX{} process.\\
1076 \texttt{C-c C-l}
1077 & Center the output buffer.\\
1078 \texttt{C-c C-\^{}}
1079 & Switch to the master file.\\
1080 \texttt{C-c C-w}
1081 & Toggle debug of overful boxes.\\
1082 \end{tabular}
1084 \section{Customization}
1086 \subsection{Customizing \mx{} mode}
1087 \label{app:custmxmode}
1089 Indentation in \mx{} mode can be controlled with the following
1090 variables:
1091 \begin{description}
1092 \item[maxima-indent-style] This determines how hard \mx{} mode will
1093 try to compute an appropriate indentation. The options are
1094 \texttt{'standard} and \texttt{'perhaps-smart}, the default is
1095 \texttt{'perhaps-smart}.
1096 \item[maxima-indent-amount] This is the default indentation for each
1097 level in \mx{} mode. By default, it is 2.
1098 \item[maxima-paren-indent-amount] This is the amount of extra
1099 indentation to be added for each parenthetical nesting. By default,
1100 it is 1, so that the lines following an open parenthesis will start
1101 in the first column past the parenthesis.
1102 \item[maxima-blockparen-indent-amount] This is the amount of extra
1103 indentation to be added after a \texttt{block(}. By default, this
1104 is $-3$, so that the following lines won't be indented too far.
1105 \item[maxima-continuation-indent-amount] This is the amount of
1106 indentation to be added when a line is the continuation of the
1107 expression begun on the previous line. By default, it is 2.
1108 \item[maxima-multiline-comment-indent-amount] This is the amount of
1109 extra indentation to be given to comments. By default, it is 2.
1110 \item[maxima-if-extra-indent-amount] This is the amount of extra
1111 indentation to give a then which follows an if, assuming the then
1112 starts on its own line. By default, it is 0, so the then will begin
1113 right under the if.
1114 \end{description}
1116 Other facets of \mx{} mode can be controlled through the following
1117 options:
1118 \begin{description}
1119 \item[maxima-return-style] This determines how \mx{} mode will handle
1120 \texttt{RET}. The options are \texttt{'newline},
1121 \texttt{'newline\hyph{}and\hyph{}indent}, and
1122 \texttt{'reindent\hyph{}then\hyph{}newline\hyph{}and\hyph{}indent}, the default is
1123 \texttt{'reindent\hyph{}then\hyph{}newline\hyph{}and\hyph{}indent}.
1124 \end{description}
1126 Some other options that may occasionally need to be set are:
1127 \begin{description}
1128 \item[maxima-command] The command used to start \mx{}. By default,
1129 it is \texttt{maxima}.
1130 \item[maxima-args] Extra arguments to pass to the \mx{} command. By
1131 default, it is \texttt{nil}.
1132 \item[maxima-use-tabs] If this is non-nil, the indentation will use
1133 TABS as well as spaces. By default, it is \texttt{nil}.
1134 \end{description}
1137 \subsection{Customizing \emx{}}
1138 \label{app:custemx}
1140 There are a few (very few) things that you can do to customize \emx{}.
1142 By default, \emx{} is an extension of AUC\TeX{} mode. This can be
1143 changed by changing the variable \texttt{emaxima\hyph{}use\hyph{}tex}. The possible
1144 values are \texttt{'auctex}, \texttt{'tex} and \texttt{nil}. Setting
1145 \texttt{emaxima\hyph{}use\hyph{}tex} (the default) to \texttt{'auctex} will make \emx{}
1146 an extension of AUC\TeX{}, setting it to \texttt{'tex} will make \emx{} an
1147 extension of Emacs's default \TeX{} mode, and setting
1148 \texttt{emaxima\hyph{}use\hyph{}tex} to \texttt{nil} will make \emx{} an extension of
1149 text-mode. So, for example, putting
1150 \begin{verbatim}
1151 (setq emaxima-use-tex nil)
1152 \end{verbatim}
1153 \noindent
1154 in your \texttt{.emacs} file will make \emx{} default to an extension of
1155 text mode.
1157 Whether or not the dots (\dots{}) abbreviation is allowed in cell
1158 references is controlled by the elisp variable
1159 \texttt{emaxima\hyph{}abbreviations\hyph{}allowed}, which is set to \texttt{t} by
1160 default. Setting this to \texttt{nil} will disallow the abbreviations,
1161 but will speed up package assembly.
1163 The variable \texttt{emaxima\hyph{}preview\hyph{}after\hyph{}update\hyph{}all} will determine
1164 whether or not the buffer will be previewed (when preview-latex is
1165 being used) after an update-all command. By default, it is \texttt{t}.
1168 The \LaTeX{}ed output can be customized somewhat. The
1169 \texttt{emaxima} LaTeX{} package can take some options, namely
1170 \texttt{breqn}, \texttt{lines}, \texttt{listings} and \texttt{preview}.
1171 The \texttt{breqn} option will use the \LaTeX{} \texttt{breqn} package
1172 (which must be installed) to break long \mx{} lines into shorter lines
1173 automatically.
1174 The \texttt{preview} option will enable the Emacs preview package
1175 (which must be installed) to preview the \mx{} environments.
1176 The \texttt{lines} option will put lines before and after some of the
1177 environments.
1178 The \texttt{listings} option will use the \LaTeX{} \texttt{listings}
1179 package (which must be installed) to typeset some of the \mx{} code.
1180 To use this, the file \texttt{maxima.sty} must be in the search path
1181 for \TeX.
1183 The indentation of the \mx{} code can be reset by resetting the
1184 \LaTeX{} length \verb+\maximaindent+.
1185 The colors of the prompts, inputs and outputs can be reset by renewing
1186 the commands \verb+\maximapromptcolor+, \verb+\maximainputcolor+
1187 and \verb+\maximaoutputcolor+ to appropriate colors.
1189 The top, middle and bottom of a maxima cell are determined by the
1190 commands \verb+\maximatop+, \verb+\maximamiddle+ and \verb+\maximabottom+.
1191 By default, \verb+\maximamiddle+ is set to \verb+\maximaoutputmarker+.
1192 If the \texttt{lines} option is used, then \verb+\maximatop+ and
1193 \verb+\maximabottom+ are set to \verb+\maximaboxtop+ and
1194 \verb+\maximaboxbottom+, respectively.
1195 Otherwise, \verb+\maximatop+ and \verb+\maximabottom+ are set to do nothing.
1196 The top and bottom of a maxima session are determined by
1197 \verb+\maximasessiontop+ and \verb+\maximasessionbottom+, respectively.
1198 By default, they do nothing.
1200 The verbatim output for maxima cells is inserted with
1201 \verb+\maximaverbatiminput+. This will do one of two things.
1202 If the listings option is used, this is defined by
1203 \verb+\lstinputlisting[style=emaxima]{#1}+, and so can be adjusted by
1204 resetting the emaxima style. By default, this style is given by
1205 \begin{verbatim}
1206 \lstdefinestyle{emaxima}
1207 {language=maxima,
1208 aboveskip=0pt,
1209 belowskip=0pt,
1210 xleftmargin=\maximaindent}
1211 \end{verbatim}
1212 \noindent
1213 If the listings package is not used, then \verb+\maximaverbatiminput+ is
1214 defined by \verb+\VerbatimInput[xleftmargin=\maximaindent]{#1}+
1215 (\verb+\VerbatimInput+ is from the fancyvrb package.)
1216 In either case, it can be adjusted by redefining
1217 \verb+\maximaverbatiminput+, which is expected to indent everything by
1218 \verb+\maximaindent+.
1219 The fonts used in the maximasessions is \verb+\maximafont+, by default
1220 \verb+\ttfamily+.
1222 \end{document}