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
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.
37
36
Finally, text and \mx{} commands can be interweaved in a \mx{}
38
37
notebook mode called \emx{}.
40
39
\section{Running \mx{} Interactively}
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}.
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+.
61
\section{Running \mx{} from the minibuffer}
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
68
(global-set-key "\C-cm" 'maxima-minibuffer)
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}
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
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}.)
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%
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
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}.%
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}).%
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.
87
116
\section{\mx{} mode}
93
122
commands. A list of available commands is in Appendix
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*}
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.
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''
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
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
147
\texttt{maxima\hyph{}return\hyph{}style}, the self-explanatory options are
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.)
123
154
The indentation style, as well as many other things, are customizable;
124
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.
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:
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>
374
415
We would then need cells
376
\beginmaxima<squaresum.max:makelist>,
417
\begin{maxima}[squaresum.max:makelist],
377
418
L:makelist(k,k,1,n),
380
\beginmaxima<squaresum.max:squarelist>
421
\begin{maxima}[squaresum.max:squarelist]
381
422
<squaresum.max:definesquare>
385
\beginmaxima<squaresum.max:addlist>
426
\begin{maxima}[squaresum.max:addlist]
390
431
and then we would also need:
392
\beginmaxima<squaresum.max:definesquare>
433
\begin{maxima}[squaresum.max:definesquare]
393
434
square(k) := k^2,
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>
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
471
\begin{maximasession}
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
484
\begin{maximasession}
449
490
were updated, the result would look like
492
\begin{maximasession}
453
494
integrate(cos(x),x);
458
(C2)integrate(cos(x),x);
496
(%i1) diff(sin(x),x);
500
(%i2) integrate(cos(x),x);
464
507
which, when \TeX{}ed, would look like
508
\begin{maximasession}
467
510
integrate(cos(x),x);
472
(C2)integrate(cos(x),x);
512
(%i1) diff(sin(x),x);
516
(%i2) integrate(cos(x),x);
477
522
If it is updated in \TeX{} form, it will look like
524
\begin{maximasession}
481
526
integrate(cos(x),x);
483
\C1. diff(sin(x),x); \\
485
\C2. integrate(cos(x),x); \\
528
\i5. diff(sin(x),x); \\
530
\i6. integrate(cos(x),x); \\
490
535
which, when \TeX{}ed, will look like
536
\begin{maximasession}
493
538
integrate(cos(x),x);
495
\C1. diff(sin(x),x); \\
497
\C2. integrate(cos(x),x); \\
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.
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
521
Session cells and noshow cells cannot be part of packages.
540
\i5. diff(sin(x),x); \\
542
\i6. integrate(cos(x),x); \\
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}.
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
528
562
diff(x*sin(x),x);
568
\begin{maximasession}
535
569
diff(x*sin(x),x);
539
573
If a standard cell is a package part, its type cannot be changed.
1060
1110
Other facets of \mx{} mode can be controlled through the following
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
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}
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
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.
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)
1122
They can be turned back on with the command
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}.
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
1138
\font\maximainputfont = cmtt12
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
1146
\maximaoutputbaselineskip = 14pt
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).
1155
Session cells can be configured similarly.
1156
Lines can be placed around a \mx{} session with the command
1158
\maximasessionlinestrue
1161
and they can be turned back off with
1163
\maximasessionlinesfalse
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
1174
\def\maximainputcolor{green}
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+.
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
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
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
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.
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.
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
1200
\lstdefinestyle{emaxima}
1204
xleftmargin=\maximaindent}
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