2 \ProvidesPackage{emaxima
}[2004/
12/
20]
5 % This package can be loaded with the command
6 % \usepackage[options...]{emaxima}
7 % The possible options (explained below) are:
8 % breqn, lines, listings, preview
9 % The breqn option will use the LaTeX breqn package (which must be
10 % installed) to break long maxima lines into shorter lines
12 % The preview option will enable the Emacs preview package (which
13 % must be installed) to preview the maxima environments.
14 % The lines option will put lines before and after some of the
16 % The listings option will use the LaTeX listings package (which must
17 % be installed) to typeset some of the maxima code. To use this, the
18 % file maxima.sty must be in the search path for TeX.
20 % This package provides the following environments:
25 % \begin{maximasession}
28 % (Both versions have starred forms: maxima* and maximasession*, which
29 % will be skipped when the document is typeset.)
30 % The maxima environments can be joined with [...] optional arguments
31 % (as described in the documentation).
32 % The maxima and maximasession environments are sometimes split into
33 % input and output, separated by
35 % or (if the output is in TeX form)
41 % \setlength{\maximaindent}{<len>} will set the indentation
42 % of all the maxima code
44 % \renewcommand{\maximapromptcolor}{<color>}
45 % \renewcommand{\maximainputcolor}{<color>}
46 % \renewcommand{\maximaoutputcolor}{<color>}
47 % will set the colors of the TeX output of the sessions.
49 % The top, middle and bottom of a maxima cell are determined by the
50 % commands: \maximatop, \maximamiddle, \maximabottom
51 % By default, \maximamiddle is set to \maximaoutputmarker.
52 % If the lines option is used, then \maximatop and \maximabottom
53 % are set to \maximaboxtop and \maximaboxbottom, respectively.
54 % Otherwise, \maximatop and \maximabottom are set to do nothing.
55 % The top and bottom of a maxima session are determined by
56 % \maximasessiontop and \maximasessionbottom, respectively.
57 % By default, they do nothing.
59 % The verbatim output for maxima cells is inserted with
60 % \maximaverbatiminput. This will do one of two things.
61 % If the listings option is used, this is defined by
62 % \lstinputlisting[style=emaxima]{#1}, and so can be adjusted by
63 % resetting the emaxima style. By default, this style is given by
64 % \lstdefinestyle{emaxima}
68 % xleftmargin=\maximaindent}
69 % If the listings package is not used, then \maximaverbatiminput is
70 % defined by \VerbatimInput[xleftmargin=\maximaindent]{#1}
71 % (\VerbatimInput is from the fancyvrb package.)
72 % In either case, it can be adjusted by redefining
73 % \maximaverbatiminput, which is expected to indent everything by
75 % The fonts used in the maximasessions is \maximafont, by default
80 \RequirePackage{ifthen
}
81 \RequirePackage{alltt}
84 \usepackage[pdftex
]{color}
90 \newboolean{m@ximapreview
}
91 \setboolean{m@ximapreview
}{false
}
92 \newboolean{m@ximabreqn
}
93 \setboolean{m@ximabreqn
}{false
}
94 \newboolean{m@ximalistings
}
95 \setboolean{m@ximalistings
}{false
}
96 \newboolean{m@ximalines
}
97 \setboolean{m@ximalines
}{false
}
98 \newboolean{m@ximainline
}
99 \setboolean{m@ximainline
}{false
}
101 %%%% Declaration of options
102 \DeclareOption{preview
}
103 {\setboolean{m@ximapreview
}{true
}}
105 \DeclareOption{breqn
}
106 {\setboolean{m@ximabreqn
}{true
}}
108 \DeclareOption{listings
}
109 {\setboolean{m@ximalistings
}{true
}}
111 \DeclareOption{lines
}
112 {\setboolean{m@ximalines
}{true
}}
114 \DeclareOption{inline
}
115 {\setboolean{m@ximainline
}{true
}}
117 %%%% Execution of options
125 % First of all, a command to deactivate everything except \
127 \def\m@ximadeactivate
{%
137 \catcode`\
} =
\other}
139 % Next, a comment environment which ends at the next \end,
140 % \maximaoutput or \maximasessionoutput.
141 % It does this by looking at the next token and seeing if it is
142 % one of these. If not, it discards it; if it is, it ends the
143 % comment environment.
144 % Putting \m@ximastartcomment (even inside a command) will start this.
146 \futurelet\m@xima@token
\m@ximacommentl@@k
}
147 \def\m@ximacommentl@@k
{%
148 \ifx\m@xima@token
\end
149 \let\m@xima@next=
\m@xima@endcomment
151 \ifx\m@xima@token
\maximaoutput
152 \let\m@xima@next=
\m@xima@endcomment
154 \ifx\m@xima@token
\par
155 \let\m@xima@next=
\m@ximaparcomment
157 \let\m@xima@next=
\m@ximacommenttwo
163 \def\m@ximaparcomment
#1\par{%
166 \def\m@ximacommenttwo
#1 {%
169 \def\m@ximastartcomment
{%
174 \def\m@xima@endcomment
{%
177 % Also, a comment environment which only ends with \end
178 % Putting \m@ximastartfullcomment (even inside a command) will start this.
179 \def\m@ximafullcomment
{%
180 \futurelet\m@xima@token
\m@ximafullcommentl@@k
}
181 \def\m@ximafullcommentl@@k
{%
182 \ifx\m@xima@token
\end
183 \let\m@xima@next=
\m@xima@endfullcomment
185 \ifx\m@xima@token
\par
186 \let\m@xima@next=
\m@ximaparfullcomment
188 \let\m@xima@next=
\m@ximafullcommenttwo
193 \def\m@ximaparfullcomment
#1\par{%
196 \def\m@ximafullcommenttwo
#1 {%
199 \def\m@ximastartfullcomment
{%
204 \def\m@xima@endfullcomment
{%
207 % Next, a write environment which ends at the next \maximaoutput or \end.
208 % It does this by looking at the next token and seeing if it is
209 % one of these. If not, it writes it; if it is, it ends the
211 % It can be started with \m@ximastartwrite
212 \def\m@ximatempfile
{\jobname.tmp
}
216 \def\m@ximawriteskipline
#1 {%
220 \futurelet\m@xima@token
\m@ximawritel@@k
}
222 \def\m@ximawritel@@k
{%
223 \ifx\m@xima@token
\end
224 \let\m@xima@next=
\m@xima@endwrite
226 \ifx\m@xima@token
\maximaoutput
227 \let\m@xima@next=
\m@xima@endwrite
229 \ifx\m@xima@token
\par
230 \let\m@xima@next=
\m@xima@parwrite
232 \let\m@xima@next=
\m@ximawritetwo
238 \def\m@xima@parwrite
#1\par{%
239 \immediate\write\m@ximaout
{}
242 \def\m@ximawritetwo
#1 {%
243 \immediate\write\m@ximaout
{\noexpand#1}%
246 \def\m@ximastartwriteskipline
{%
248 \immediate\openout \m@ximaout
\m@ximatempfile
250 \m@ximawriteskipline
}
252 \def\m@ximastartwrite
{%
254 \immediate\openout \m@ximaout
\m@ximatempfile
258 \def\m@xima@endwrite
{%
259 % \immediate\write\m@ximaout{ }
260 \immediate\closeout\m@ximaout
%
262 \m@ximawritetempfile
}
264 % A command to verbatim typeset the file.
265 % It is determined by the command \maximaverbatiminput,
266 % whose default value depends on the option listings.
268 \newcommand{\m@ximawritetempfile
}
271 \maximaverbatiminput{\m@ximatempfile
}
274 % The \maximaverbatiminput command depends on whether the
275 % listings option is given.
276 % The command should indent the code to \maximaindent
278 \newlength{\maximaindent}
279 \setlength{\maximaindent}{2ex
}
280 \newcommand{\m@ximaindent
}
281 {\setlength{\leftskip}{\maximaindent}
282 \setlength{\rightskip}{\maximaindent}}
285 \ifthenelse{\boolean{m@ximalistings
}}
286 {\RequirePackage{maxima
}
287 \lstdefinestyle{emaxima
}
291 xleftmargin=
\maximaindent}
292 \newcommand{\maximaverbatiminput}[1]
293 {\lstinputlisting[style=emaxima
]{#1}}}
294 {\RequirePackage{fancyvrb
}
295 \newcommand{\maximaverbatiminput}[1]
296 {\VerbatimInput[xleftmargin=
\maximaindent]{#1}}}
298 % Now, a command to see if the argument ends in a colon or not
299 % \maximaendsincolon{string} will set the boolean maximaendsincolon
300 % to be true if string ends with a colon, false otherwise.
302 \newboolean{m@ximaendsincolon
}
303 \newcommand{\maximaendsincolon}[1]
304 {\setboolean{m@ximaendsincolon
}{false
}
305 \m@ximacheckcolon
#1\end}
307 \newcommand{\m@ximacheckcolon
}[1]
311 \let\next=
\m@ximacheckcolon
313 \setboolean{m@ximaendsincolon
}{true
}
315 \setboolean{m@ximaendsincolon
}{false
}
320 \newcommand{\m@ximaremovecolon
}[1]
324 %% Now, set some environments
326 %% We need environments for maxima, maxima*, maximasession, maximasession*
327 %% Any environment that ends in * will be a comment environment
329 \newenvironment{maxima*
}[1][]
330 {\m@ximastartfullcomment
}
333 \newenvironment{maximasession*
}[1][]
334 {\m@ximastartfullcomment
}
337 %% The maxima environment should write verbatim the ``top'' part
338 %% (before an output marker) and the the bottom verbatim or TeXed.
340 %% A macro for writing Maxima in the ``proper'' font
342 \newcommand{\Maxima}{\textsf{\textsl{Maxima
}}}
344 %% The top of the box
346 \newcommand{\m@ximanoparttop
}
348 \hbox to
\hsize{\vrule depth
1ex height
.3pt width
.4pt
349 \vrule height
.4pt depth
0pt width
1.1em
350 \lower .4ex
\hbox{\tiny ~
\Maxima}
352 \vrule depth
1ex height
.3pt width
.4pt
}
355 \newcommand{\m@ximaparttop
}
357 \hbox to
\hsize{\vrule depth
1ex height
.3pt width
.4pt
358 \vrule height
.4pt depth
0pt width
1.1em
359 \lower .4ex
\hbox{\tiny ~
\Maxima}
361 \lower .4ex
\hbox{\tiny~
\m@ximapartname
}
363 \vrule depth
1ex height
.3pt width
.4pt
}
366 \newcommand{\maximaboxtop}
367 {\ifthenelse{\equal{\m@ximapartname
}{}}
371 %% The bottom of the box
373 \newcommand{\maximaboxbottom}
374 {\hbox to
\hsize{\vrule depth
0ex height
1ex width
.4pt
376 \vrule depth
0ex height
1ex width
.4pt
}}
378 %% The middle of the box
380 \newcommand{\maximaoutputmarker}
382 \hspace*
{\maximaindent}
383 \rule{.4\linewidth}{0.4pt
}
386 % \newcommand{\maximaoutputmarker}
389 % \hbox to \hsize{\hskip 1.5em
390 % \vrule height .4pt depth 0pt width 3em
391 % \lower .4ex \hbox{\tiny Output}
399 \newcommand{\m@ximasetname
}[1]
400 {\maximaendsincolon{#1}
401 \ifthenelse{\equal{#1}{}}
402 {\renewcommand{\m@ximapartname
}{}}
403 {\ifthenelse{\boolean{m@ximaendsincolon
}}
404 % {\renewcommand{\m@ximapartname}{Definition of #1}}
405 {\renewcommand{\m@ximapartname
}{Definition of
\m@ximaremovecolon
{#1}}}
406 {\renewcommand{\m@ximapartname
}{#1}}}}
408 %% Now the environments
410 \newboolean{m@ximaverbatimoutput
}
411 \newboolean{m@ximatexoutput
}
413 \newcommand{\m@ximapartname
}{}
415 % Default top, middle and bottom of the maxima environment
416 \ifthenelse{\boolean{m@ximalines
}}
417 {\newcommand{\maximatop}{\maximaboxtop}
418 \newcommand{\maximamiddle}{\maximaoutputmarker}
419 \newcommand{\maximabottom}{\maximaboxbottom}}
420 {\newcommand{\maximatop}{}
421 \newcommand{\maximamiddle}{\maximaoutputmarker}
422 \newcommand{\maximabottom}{}}
424 \newcommand{\maximaoutput}{}
426 \newenvironment{maxima
}[1][]%
427 {~
\par\renewcommand{\maximaoutput}
428 {\@ifstar
{\maximatexoutput}{\maximaverbatimoutput}}
431 \setboolean{m@ximaverbatimoutput
}{false
}
432 \setboolean{m@ximatexoutput
}{false
}
434 \ifthenelse{\equal{\m@ximapartname
}{}}
435 {\m@ximastartwrite
}{\m@ximastartwriteskipline
}}
436 {\ifthenelse{\boolean{m@ximaverbatimoutput
}}
438 {\ifthenelse{\boolean{m@ximatexoutput
}}
439 {\par\noindent} % TeX output
445 \newcommand{\maximaverbatimoutput}
446 {\setboolean{m@ximaverbatimoutput
}{true
}
450 \newcommand{\maximatexoutput}
453 \begingroup\maximafont\color{\maximaoutputcolor}
454 \begin{em@ximam@th
} #
#1 \end{em@ximam@th
}\endgroup}
457 \begingroup\maximafont\color{\maximaoutputcolor}\textcolor{\maximapromptcolor}
458 {(\%t#
#1)
}\begin{em@ximam@th
} #
#2 \end{em@ximam@th
}\endgroup}
459 \def\p{\begingroup\color{\maximaoutputcolor}
460 \setupm@ximasessionverbatim
\dom@ximasessionpreprompt
}
461 \setboolean{m@ximatexoutput
}{true
}
466 %% Some stuff to help with lists of examples
468 \newcommand{\maximaexamplesname}{List of Maxima Examples
}
470 %% Some stuff of the list of examples
471 \@ifclassloaded
{book
}
472 {\newcounter{maximaexample
}[chapter
]
473 \newcommand\listofmaximaexamples{%
475 \@restonecoltrue
\onecolumn
479 \chapter*
{\maximaexamplesname}%
480 \@mkboth
{\MakeUppercase\maximaexamplesname}%
481 {\MakeUppercase\maximaexamplesname}%
483 \if@restonecol
\twocolumn\fi
485 \newcommand{\maxcaption}[1]{\addcontentsline{lom
}{figure
}
486 {\protect\numberline{\thechapter.
\themaximaexample} {\protect\ignorespaces #1}}}}
487 {\newcounter{maximaexample
}
488 \newcommand\listofmaximaexamples{%
490 \@restonecoltrue
\onecolumn
494 \section*
{\maximaexamplesname}%
495 \@mkboth
{\MakeUppercase\maximaexamplesname}%
496 {\MakeUppercase\maximaexamplesname}%
498 \if@restonecol
\twocolumn\fi
500 \newcommand{\maxcaption}[1]{\addcontentsline{lom
}{figure
}
501 {\protect\numberline{\themaximaexample}
502 {\protect\ignorespaces #1}}}}
504 \newcommand{\l@example
}[2]{\par\noindent#1 {\itshape #2}}
507 %% The maximasession environment should ignore the ``top'' part
508 %% (before an output marker) and the the bottom verbatim or TeXed.
509 %% If TeXed, some commands need to be set up.
511 \newboolean{m@ximasessionverbatimoutput
}
512 \newboolean{m@ximasessiontexoutput
}
514 \newcommand{\maximasessiontop}{}
515 \newcommand{\maximasessionbottom}{}
517 \newenvironment{maximasession
}[1][]
518 {~
\par\renewcommand{\maximaoutput}
520 \@ifstar
{\maximasessiontexoutput}{\maximasessionverbatimoutput}}
521 \ifthenelse{\equal{#1}{}}
522 {}{\stepcounter{maximaexample
}
524 \setboolean{m@ximasessionverbatimoutput
}{false
}
525 \setboolean{m@ximasessiontexoutput
}{false
}
527 {\ifthenelse{\boolean{m@ximasessionverbatimoutput
}}
528 {\maximasessionbottom
529 \endgroup\par\noindent} % verbatim output
530 {\ifthenelse{\boolean{m@ximasessiontexoutput
}}
531 {\par\maximasessionbottom
532 \endgroup\par\noindent} % TeX output
535 \newenvironment{maximanu
}
539 \newenvironment{maximasessionnu
}
540 {\begin{maximasession
}}
541 {\end{maximasession
}}
543 \newenvironment{maximanu*
}
547 \newenvironment{maximasessionnu*
}
548 {\begin{maximasession*
}}
549 {\end{maximasession*
}}
551 \ifthenelse{\boolean{m@ximapreview
}}
552 {\RequirePackage{preview
}
553 \PreviewEnvironment[{[]}]{maxima
}
554 \PreviewEnvironment{maximasession
}}
557 \newcommand{\maximasessionverbatimoutput}
558 {\setboolean{m@ximasessionverbatimoutput
}{true
}
562 \ifthenelse{\boolean{m@ximainline
}}
563 {\newenvironment{em@ximam@th
}
566 {\ifthenelse{\boolean{m@ximabreqn
}}
567 {\RequirePackage[cmbase
]{flexisym
}
568 \RequirePackage{breqn
}
569 \newenvironment{em@ximam@th
}
572 {\newenvironment{em@ximam@th
}
573 {\begin{displaymath
}}
574 {\end{displaymath
}}}}
576 \newcommand{\maximapromptcolor}{red
}
577 \newcommand{\maximainputcolor}{blue
}
578 \newcommand{\maximaoutputcolor}{blue
}
579 \newcommand{\maximafont}{\ttfamily}
582 \def\m@ximauncatcodespecials
{\def\do#
#1{\catcode`#
#1=
12 }\dospecials}
583 \def\m@ximapercent
{\%
}
584 \def\setupm@ximasessionverbatim
{
585 \obeylines \m@ximauncatcodespecials
\obeyspaces}
586 {\obeyspaces\global\let =\
}
587 {\catcode`\|=
0 \catcode`\\=
12 %
588 |obeylines|gdef|dom@ximatexsessionverbatim
#1.
#2\\
{|maximafont|par|noindent|textcolor
{|maximapromptcolor
}{(|m@ximapercent
{}i
#1)
}#2|par|endgroup
}
589 |obeylines|gdef|dom@ximasessionpreprompt
#1\\
{|par|noindent
#1|par|endgroup
}}
591 \newcommand{\maximasessionpreoutput}{}
593 \newcommand{\m@ximasetupsessiontexoutput
}
594 {\def\i{\begingroup\color{\maximainputcolor}
595 \setupm@ximasessionverbatim
\dom@ximatexsessionverbatim
}
598 \begingroup\maximafont\color{\maximaoutputcolor}\textcolor{\maximapromptcolor}
599 {(\%o#
#1)
}\begin{em@ximam@th
} #
#2 \end{em@ximam@th
}\endgroup}
602 \begingroup\maximafont\color{\maximaoutputcolor}
603 \begin{em@ximam@th
} #
#1 \end{em@ximam@th
}\endgroup}
606 \begingroup\maximafont\color{\maximaoutputcolor}\textcolor{\maximapromptcolor}
607 {(\%t#
#1)
}\begin{em@ximam@th
} #
#2 \end{em@ximam@th
}\endgroup}
608 \def\ps{maximasessionpreoutput
}
609 \def\p{\begingroup\color{\maximaoutputcolor}
610 \setupm@ximasessionverbatim
\dom@ximasessionpreprompt
}}
612 \newcommand{\maximasessiontexoutput}
613 {\setboolean{m@ximasessiontexoutput
}{true
}
615 \m@ximasetupsessiontexoutput