summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bosisio/mathcmd.dtx
blob: 57efb18447a21596c032ae461ac0cb3315dfbf80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
%\iffalse % MetaComment
%%
%% + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
%% |            Copyright(C) 1997-2010 by F. Bosisio             |
%% |                                                             |
%% | This program can be redistributed and/or modified under	 |
%% | the terms of the LaTeX Project Public License, either       |
%% | version 1.3 of this license or (at your option) any later   |
%% | version. The latest version of this license is in           |
%% |   http://www.latex-project.org/lppl.txt                     |
%% | and version 1.3 or later is part of all LaTeX distributions |
%% | version 2005/12/01 or later.                                |
%% |                                                             |
%% | This work has the LPPL maintenance status `maintained'.     |
%% | The Current Maintainer of this work is F. Bosisio.          |
%% |                                                             |
%% | This work consists of files mathcmd.dtx and mathcmd.html    |
%% | and of the derived files mathcmd.sty and mathcmd.pdf.       |
%% |                                                             |
%% | E-mail:   fbosisio@bigfoot.com                              |
%% | CTAN location: macros/latex/contrib/bosisio/                |
%% + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
%%
%%      If you make any improvment, find any bug or have
%%      any suggestion, please let me know about it.
%%
%<*package,driver>
%\fi
%
\def\FileName{mathcmd}
%\iffalse % MetaComment
%</package,driver>
%<*package>
%\fi
\def\fileversion{2.2}
\def\filedate{1997/12/20}
\def\docdate{2005/04/09}
\def\filedescr{Extensions to math environments (FB)}
%
%\iffalse % MetaComment
%</package>
%<*dtx>
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%		This section is the installation driver
%
\def\batchfile{\FileName.dtx}
%
\input docstrip
%
\keepsilent
% \askforoverwritefalse
%
\generateFile{\FileName.sty}{f}{\from{\FileName.dtx}{package}}
%
\generateFile{\FileName.drv}{f}{\from{\FileName.dtx}{driver}}
%
\Msg{******************************************************}
\Msg{*}
\Msg{* To produce the documentation run the}
\Msg{* file `\FileName.drv' through LaTeX.}
\Msg{*}
\Msg{******************************************************}
%
\endbatchfile
%
%		End of the installation driver
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%</dtx>
%
%		This section is the documentation driver
%
%<+driver>\documentclass[12pt,a4paper]{ltxdoc}
%<+driver>  \EnableCrossrefs
%<+driver>  \CodelineIndex
%<+driver>  \RecordChanges
%<+driver>  %\OnlyDescription   % Uncomment not to see the implementation
%<+driver>\begin{document}
%<+driver>  \DocInput{\FileName.dtx}
%<+driver>  \PrintIndex
%<+driver>  \PrintChanges
%<+driver>\end{document}
%
%		End of the documentation driver
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%<*package>
%\fi
%
% \changes{v0.1}{20 April 1997}{First release (basic environments)}
% \changes{v0.2}{3 May 1997}{Added package options}
% \changes{v1.0}{24 May 1997}{Documentation added}
% \changes{v2.0}{20 December 1997}{Separated from package ``mathenv''}
% \changes{v2.1}{5 March 1999}{Added copyright notice and changed addresses}
% \changes{v2.2}{9 April 2005}{Usage of the double-quote character (") avoided}
%
% \MakeShortVerb{\|}
%
% \title{Package \texttt{\FileName}\thanks{This is version \fileversion,
% last revised \filedate; documentation date \docdate}}
% \author{F. Bosisio\\\normalsize E-mail: \texttt{fbosisio@bigfoot.com}}
% \date{\filedate}
% \maketitle
%
% \begin{abstract}
%	Documentation for the package \texttt{\FileName}.
% \end{abstract}
%
% \section{Introduction}
%	This package provides some useful math-commands which are simpler
%	to use and prettier then their standard \LaTeX{} counterpart.
%
%	In particular the ``|\d|'' command is redefined, so
%	care should be taken, expecially when including this package in an
%	already existent \LaTeX{} file.
%
%	\noindent
%	The original work of ``|\d|'' (i.e. place a dot under its argument)
%	is now done by the ``|\UnderDot|'' command.
%
% \section{The options}
%	At now, six options are available with the \texttt{\FileName}
%	package, which comes out in matched pairs.
%
%	\noindent
%	The ``|ThreeSubscrSum|'' and ``|TwoSubscrSum|'' options control the
%	placement of subscripts for the ``|\Sum|'' command: the latter
%	(which is the default) puts the index under the simbol toghether
%	with the starting point, while the former puts the index on the
%	lower right corner.
%
%	\noindent
%	The ``|ProdVettWedge|'' and ``|ProdVettTimes|'' options select
%	which symbol is to be used for the \emph{vector product}: the first
%	one uses a ``|\wedge|'' (default), whilst the second uses a
%	``|\times|''.
%
%	\noindent
%	Finally, the ``|VectOpStr|'' and ``|VectOpSymb|'' options controls
%	whether the vector-operator commands ``|\Grad|'', ``|\Div|'' and
%	``|\Rot|'' should produce a roman string (default) or a
%	``|\nabla|'' symbol followed by an operator, respectively.
%
% \section{Math-mode commands}
%	The \texttt{\FileName} package defines a number of math-mode
%	commands.
%
%	\subsection{The \texttt{text} command}
%		The ``|\text{|\ldots|}|'' command is defined to be
%		equivalent to ``|\mbox|'' (except when the ``|amstext|''
%		package is also used, since this package already defines
%		this command in a better way).
%
%		\noindent
%		It is intended for inserting pieces of text in a formula.
%
%	\subsection{Commands for doing integrals}
%		The ``|\Int|'' (capitalized) differs from the \LaTeX{}
%		command ``|\int|'' in that it is always printed in
%		|displaystyle| and if it has only a subscript, this is
%		somewhat lowered so that it looks better.
%		\begin{verbatim}
%		   \Int_{...}^{...}	  ...	   \d{...}
%		\end{verbatim}
%
%		The ``|\d{|\ldots|}|'' command is for making the
%		differential symbol at the end of integrals: it simply
%		prints a ``|d|'' followed by its argument and preceded by
%		a little space, which seems prettier.
%
%	\subsection{Commands for making sums}
%		The ``|\Sum{|$\cdots=\cdots,\cdots$|}|'' command works
%		differently, depending on which option between
%		``|TwoSubscrSum|'' (default) and ``|ThreeSubscrSum|'' has
%		been specified.
%
%		\noindent
%		In the first case, it expands to
%		``|\displaystyle\sum_{...=...}^{...}|'', whereas in the
%		second case the second and third argument are treated
%		in the same way as before (i.e. as a subscript and
%		superscript, respectively), but the first argument
%		(the one before the ``='') is placed near
%		the lower-left edge of the ``|\sum|'' symbol and the ``=''
%		is not printed.
%
%		There is also a ``|\SUM{|\ldots|}|'' command which is useful
%		when only a subscript is desired, irrespectively of the
%		option specified: in fact, is is equivalent to
%		``|\displaystyle\sum_{|\ldots|}|''.
%
%	\subsection{Derivatives symbols}
%		The commands ``|\DerTot{|\ldots|}{|\ldots|}|'',
%		``|\DerPar{|\ldots|}{|\ldots|}|'' and ``|\DerNorm{|\ldots|}|''
%		generate the symbols of total derivative, partial derivative
%		and normal derivative, respectively.
%
%		\noindent
%		In other words, they are the same as:
%		\begin{verbatim}
%		   \displaystyle\frac{d...}{d...}
%		   \displaystyle\frac{\partial ...}{\partial ...}
%		   \displaystyle\frac{\partial ...}{\partial n}
%		\end{verbatim}
%
%	\subsection{Arrow-limits commands}
%		The command ``|\TendsTo|[$\cdots,\cdots$]'' generates a
%		right-arrow with optionally an underscript wich is another
%		smaller right-arrow between the two comma-separeted
%		arguments inside the square brackets.
%
%		\noindent
%		For example, the command ``|f(x) \TendsTo[x,0] 1|'' generates
%		the following output:
%		$f(x) \mathop{\longrightarrow}\limits_{x \rightarrow 0} 1$.
%
%	\subsection{Vector-operators commands}
%		Finally, the commands ``|\Grad|'', ``|\Div|'' and
%		``|\Rot|'' generates the strings ``grad'', ``div'' and ``rot''
%		in roman type and with small spaces added before and after,
%		if the ``VectOpStr'' option is in effect (default).
%		If, instead, the option ``VectOpSymb'' was specified, they
%		generate ``|\nabla|'', ``|\nabla\cdot|'' and
%		``|\nabla\ProdVett|'' respectively.
%
%		The command ``|\ProdVett|'' is intended for making the
%		symbol of vector product, and evaluates to ``|\times|''
%		with the option ``ProdVettTimes'' and to ``|\wedge|'' with
%		the (default) option ``ProdVettWedge''.
%
%		\begin{tabular}{lcccc}
%			&	&  |VectOpStr|	& \multicolumn{2}{c}{|VectOpSymb|}	\\
%			&		&		&|ProdVettWedge|&|ProdVettTimes|\\
%		 |\Grad|& $\Rightarrow$ & $\mathrm{grad}$& $\nabla$	& $\nabla$	\\
%		 |\Div|	& $\Rightarrow$ & $\mathrm{div}$& $\nabla\cdot$	& $\nabla\cdot$	\\
%		 |\Rot|	& $\Rightarrow$	& $\mathrm{rot}$& $\nabla\wedge$& $\nabla\times$
%		\end{tabular}
%
%
% \StopEventually{}
% \newpage
% \section{Implementation}
%
%    \begin{macrocode}
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{\FileName}[\filedate\space v\fileversion\space\filedescr]
%%
\newif\if@ThreeSubscrSum
\DeclareOption{ThreeSubscrSum}{\@ThreeSubscrSumtrue}
\DeclareOption{TwoSubscrSum}{\@ThreeSubscrSumfalse}
%%
\DeclareOption{ProdVettWedge}{\let\ProdVett=\wedge}
\DeclareOption{ProdVettTimes}{\let\ProdVett=\times}
%%
\newif\if@VectOper@Symbol
\DeclareOption{VectOpStr}{\@VectOper@Symbolfalse}
\DeclareOption{VectOpSymb}{\@VectOper@Symboltrue}
%%
\ExecuteOptions{TwoSubscrSum,ProdVettWedge,VectOpStr}
%    \end{macrocode}
%
%    The ``|\ProcessOptions*|'' command was used here instead of
%    ``|\ProcessOptions*|'' in order to process the options in the
%    ``|\usepackage|'' order, rather than in the declaration order
%    \begin{macrocode}
%%
\ProcessOptions*
%    \end{macrocode}
%
% \begin{macro}{\text}
%	The definition of |\text| is deferred at the |\begin{document}|,
%	so that if the \texttt{amstext} package is loaded (even after this
%	package), its definition of text will be used, since it seems
%	better.
%    \begin{macrocode}
%%
\AtBeginDocument{\ifx\undefined\text \def\text#1{\ \mbox{#1}\ } \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Int}
%	The command |\@INT@sub@SUP| has one argument and then a mandatory
%	superscript: il typesets an integral symbol (in |\displaystyle|)
%	with the argument as a lower-bound and the superscript as an
%	upper-bound.
%    \begin{macrocode}
%%
\def\@INT@sub@SUP#1^#2{{\displaystyle\int_{#1}^{#2}}}
%    \end{macrocode}
%	The command |\@INT@subONLY| has only an argument, which is used as
%	as a subscript for a |displaystyle| |\int|, but lowered of |0.2ex|.
%    \begin{macrocode}
\def\@INT@subONLY#1{{\displaystyle\int_{\raisebox{-0.2ex}{$_{#1}$}}}}
%    \end{macrocode}
%	The command |\@INT@sub| must have a subscript and may optionally be
%	followed by a superscript.
%    \begin{macrocode}
\def\@INT@sub_#1{\@ifnextchar^{\@INT@sub@SUP{#1}}{\@INT@subONLY{#1}}}
%    \end{macrocode}
%	The command |\@INT@SUP@sub| must have a superscript and a subscript,
%	in that order: they are passed to a |displaystyle| |\int| command.
%    \begin{macrocode}
\def\@INT@SUP@sub^#1_#2{{\displaystyle\int_{#2}^{#1}}}
%    \end{macrocode}
%	The |\Int| command invokes |\@INT@SUP@sub| or |\@INT@sub| or simply
%	expands to |\displaystyle\int| depending on what follows (|^|, |_|
%	or neither of them).
%    \begin{macrocode}
\newcommand{\Int}{\@ifnextchar^{\@INT@SUP@sub}{\@ifnextchar_{\@INT@sub}{\displaystyle\int}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\d}
%	The original |\d| command is saved in |\UnderDot|, then (at the
%	|\begin{document}| to avoid conflicts with other packages) it is
%	redefined as a ``|d|'' preceeded by some space an followed by its
%	argument (it is intended for printing the differential symbol at
%	the end of an integral).
%    \begin{macrocode}
%%
\AtBeginDocument{ \let\UnderDot=\d \renewcommand{\d}[1]{\:\:d#1} }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Sum}
%	The command |\INNER@SUM| is defined differently depending on the
%	selected option. It has 3 or 2 orguments, ended by an exclamation
%	mark and separated by an equal sign and a comma.
%	The two last arguments are passed as a subscrit and as a superscript
%	to a |displaystyle| |\sum|, whereas the first argument (if they are
%	3) is typeset in |scriptstyle| and lowered so that it occours at the
%	lower right corner of the |sum| symbol.
%    \begin{macrocode}
%%
\if@ThreeSubscrSum
  \def\INNER@SUM#1=#2,#3!{{\displaystyle\sum_{#2}^{#3}\raisebox{-0.6ex}{$_{\!#1}$}}}
\else
  \def\INNER@SUM#1,#2!{{\displaystyle\sum_{#1}^{#2}}}
\fi
%    \end{macrocode}
%	The |\Sum| command is then simply a call to |\INNER@SUM|, with a
%	question mark added to denote the end of the argument.
%    \begin{macrocode}
\newcommand{\Sum}[1]{\INNER@SUM#1!}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SUM}
%	The |\SUM| command has one only argument which is used as a
%	subscript and, again, is always printed in |\displaystyle|.
%    \begin{macrocode}
\newcommand{\SUM}[1]{{\displaystyle\sum_{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DerPar}
%	The commands ``|\DerPar|'', ``|\DerTot|'' and ``|\DerNorm|'' generate a
%	|displaystyle| |\frac| command, with a ``|\partial|'' or ``|d|'' or
%	``|\partial n|'' added to its arguments and followed by a little space.
%    \begin{macrocode}
%%
\newcommand\DerPar[2]{{\displaystyle\frac{\partial #1}{\partial #2}\:}}
\newcommand\DerTot[2]{{\displaystyle\frac{d#1}{d#2}\:}}
\newcommand\DerNorm[1]{{\displaystyle\frac{\partial #1}{\partial n}\:}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TendsTo}
%	The command |\@TendeQuando| must be followed by a pair of square
%	brackets, which enclose two arguments separated by a comma.
%	It place a |\rightarrow| command between them and puts the whole
%	under a bigger |\rightarrow|.
%	The |\mathop| allows the |\limits| command, which, in turn, place
%	the subscript \emph{under} the symbol.
%    \begin{macrocode}
%%
\def\@TendeQuando[#1,#2]{ \mathop{\longrightarrow}\limits_{#1 \rightarrow #2} }
%    \end{macrocode}
%	The |\TendsTo| command invokes |\@TendeQuando| if followed by
%	a ``['', or |\longrightarrow| otherwise.
%    \begin{macrocode}
\def\TendsTo{\@ifnextchar[{\@TendeQuando}{\longrightarrow}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Grad}
%	The |\Grad|, |\Div| and |\Rot| commands generates a symbol or a
%	roman word, depending on the selected option.
%    \begin{macrocode}
%%
\if@VectOper@Symbol
  \newcommand\Grad{\nabla}
  \newcommand\Div{\nabla\cdot}
  \newcommand\Rot{\nabla\ProdVett}
\else
  \newcommand\Grad{\:\mathrm{grad}\,}
  \newcommand\Div{\:\mathrm{div}\,}
  \newcommand\Rot{\:\mathrm{rot}\,}
\fi
%    \end{macrocode}
% \end{macro}
%
%\iffalse % MetaComment
%<*package>
%\fi
%
% \CheckSum{153}
% \Finale
%
\endinput