Debian Codegraph @

texmf-dist/source/latex/onlyamsmath/onlyamsmath.dtx

raw
1 % \iffalse meta comment
2 % File: onlyamsmath.dtx Copyright (C) 2001, 2012, 2016 Harald Harders
3 % \fi
4 %
5 % \iffalse
6 %
7 %<*driver>
8 \documentclass[fleqn]{ltxdoc}
9 \usepackage{amsmath}
10 \newlength{\tempdima}%
11 \makeatletter
12 \renewenvironment{table}[1][]{%
13 \@float{table}[#1]%
14 \centering%
15 \setlength{\tempdima}{\abovecaptionskip}%
16 \setlength{\abovecaptionskip}{\belowcaptionskip}%
17 \setlength{\belowcaptionskip}{\tempdima}%
18 }{%
19 \end@float
20 }
21 \makeatother
22 \newcommand{\PrintBibliography}{%
23 \begin{thebibliography}{9}
24 \bibitem{amsmath1999}
25 {\em User's Guide for the amsmath Package}.
26 \newblock American Mathematical Society, 1999/12/13.
27 \end{thebibliography}
28 }
29 \EnableCrossrefs
30 \CodelineIndex
31 \DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
32 \DoNotIndex{\setcounter,\space,\begingroup,\endgroup}
33 \CodelineNumbered
34 \RecordChanges
35 \CheckSum{98}
36 \input{onlyamsmath-v.tex}
37 \GetFileInfo{onlyamsmath-v.tex}
38 \title{The \texttt{onlyamsmath} package}
39 \author{Harald Harders\\\texttt{[email protected]}}
40 \date{Version \fileversion, \filedate, printed \today}
41 \begin{document}
42 \DocInput{onlyamsmath.dtx}
43 \end{document}
44 %</driver>
45 % \fi
46 %
47 % \changes{0.20}{2016/12/18}{Added switch \texttt{nodollardollar} again
48 % (prevent from changing catcode to avoid issues with TikZ/PGF)}%
49 % \changes{0.10}{2012/01/01}{Explicitly state date and version in
50 % \cs{ProvidesPackage} statement}
51 % \changes{0.10}{2012/01/01}{Update documentation}
52 % \changes{0.10}{2012/01/01}{Update e-mail address}
53 % \changes{0.01}{2001/09/21}{First version}
54 %
55 % \maketitle
56 % \begin{abstract}
57 % \noindent
58 % This package inhibits the usage of plain \TeX\ and on demand of
59 % standard \LaTeX\ math environments.
60 % This is useful for class writers who want to force their clients to
61 % use the environments provided by the amsmath package.
62 % \end{abstract}
63 %
64 % \tableofcontents
65 %
66 % \section*{Copyright}
67 % Copyright 2001, 2012, 2016 Harald Harders.
68 %
69 % This program can be redistributed and/or modified under the terms
70 % of the LaTeX Project Public License Distributed from CTAN
71 % archives in directory macros/latex/base/lppl.txt; either
72 % version 1 of the License, or any later version.
73 %
74 % \section{Usage of the package}
75 %
76 % Just load the package using |\usepackage[|options|]{onlyamsmath}|.
77 % If no option is given only the plain \TeX\ environment |$$|\dots|$$|
78 % is ``destroyed''.
79 % This environment leads to centred equations even with the global
80 % option |fleqn| (\emph{f}orce \emph{l}eft \emph{eq}uatio\emph{n}s)
81 % switched on:
82 % $$
83 % a=b\,.
84 % $$
85 %
86 % \DescribeMacro{eqnarray}
87 % One further option is \verb|eqnarray| to switch off
88 % the |eqnarray| and |eqnarray*| environments that add an unwished
89 % space before and after the aligned part of the formula as shown
90 % here:
91 % \begin{eqnarray*}
92 % a&=&b\,.
93 % \end{eqnarray*}
94 % A better result is achieved using the |align| environment provided
95 % by |amsmath.sty|:
96 % \begin{align*}
97 % a&=b\,.
98 % \end{align*}
99 %
100 % \DescribeMacro{all}
101 % The most brutal option is |all| that inhibits the writer to use any
102 % of the \TeX\ and \LaTeX\ math environments for non-inlined equations
103 % I know (|$$|\dots|$$|, |eqnarray|, |eqnarray*|, |displaymath|.
104 % The inlined mathematical modes (|$|\dots|$|, |\(|\dots|\)|) still
105 % work.
106 %
107 % Then instead use the environments provided by |amsmath.sty|:
108 % |equation|, |align|, |gather|, |flalign|, |multiline|, |alignat|,
109 % and |split|. All environments except |split| have a starred
110 % variant. See the User's Guide of the |amsmath| package for further
111 % details \cite{amsmath1999}.
112 %
113 % \DescribeMacro{error}
114 % There are two more options that control the behaviour of the package
115 % if you still use one of the ``forbidden'' environments.
116 % If using |error| which is the default \LaTeX\ generates an error
117 % message that reminds you to use the environments of the |amsmath|
118 % package.
119 %
120 % \DescribeMacro{warning}
121 % If using |warning| \LaTeX\ only produces warnings and proceeds.
122 %
123 % \DescribeMacro{nodollardollar}
124 % If |nodollardollar| is used, the |$| catcode is not changed.
125 % This way, the plain \TeX\ |$$| macro can still be used.
126 % This option helps to avoid issues with recent versions of TikZ/PGF but might
127 % have other side effects.
128 %
129 % \section*{Acknowledgement}
130 %
131 % David Kastrup ([email protected]) has
132 % written the part handling |$$|.
133 % I just have changed the call of the command producing the error
134 % message.
135 % Since I do not understand his code please don't ask me things
136 % regarding it.
137 %
138 % Reinhard Kotucha has reported the problem with recent TikZ/PGF and also
139 % identified that changing the |$| catcode caused the issues.
140 % The class option |nodollardollar| has been introduced to resolve this
141 % incompatibility.
142 %
143 % \StopEventually{\PrintBibliography \PrintChanges \PrintIndex}
144 %
145 % \section{The implementation}
146 %
147 % Package header:
148 % \begin{macrocode}
149 %<package>\ProvidesPackage{onlyamsmath}
150 %<version>\ProvidesFile{onlyamsmath-v.tex}
151 %<package,version> [2016/12/18 v0.20 Destroy the standard math environments]
152 % \end{macrocode}
153 % \iffalse
154 %<*package>
155 % \fi
156 % Load |amsmath| package:
157 % \begin{macrocode}
158 \RequirePackage{amsmath}
159 % \end{macrocode}
160 % \subsection{Options}
161 % All options set a boolean variable which is named simular to the
162 % option name.
163 %
164 % \changes{0.02}{2001/09/21}{Added switch \texttt{nodollardollar}}%
165 % \changes{0.03}{2001/09/22}{Removed switches \texttt{dollardollar}
166 % and \texttt{nodollardollar}}%
167 % Define the |eqnarray| option:
168 % \begin{macrocode}
169 \newif\ifonlyams@eqnarray
170 \DeclareOption{eqnarray}{\onlyams@eqnarraytrue}
171 % \end{macrocode}
172 % Define the |all| option:
173 % \begin{macrocode}
174 \newif\ifonlyams@all
175 \DeclareOption{all}{
176 \onlyams@alltrue
177 \onlyams@eqnarraytrue
178 }
179 % \end{macrocode}
180 % Define the |error| and |warning| options:
181 % \begin{macrocode}
182 \newif\ifonlyams@error
183 \onlyams@errortrue
184 \DeclareOption{error}{\onlyams@errortrue}
185 \DeclareOption{warning}{\onlyams@errorfalse}
186 % \end{macrocode}
187 % Define the |nodollardollar| option:
188 % \begin{macrocode}
189 \newif\ifonlyams@nodollardollar
190 \DeclareOption{nodollardollar}{\onlyams@nodollardollartrue}
191 % \end{macrocode}
192 % Set the default options:
193 % \begin{macrocode}
194 \ExecuteOptions{error}
195 % \end{macrocode}
196 % Process the options:
197 % \begin{macrocode}
198 \ProcessOptions\relax
199 % \end{macrocode}
200 % \subsection{Commands}
201 %
202 % \begin{macro}{\onlyams@error}
203 % Define a command that produces the error resp.\ warning messages.
204 % The argument specifies the name of the environment that produced the
205 % message.
206 % \begin{macrocode}
207 \newcommand{\onlyams@error}[1]{%
208 \ifonlyams@error
209 \PackageError{onlyamsmath}{Environment #1 used}{Please use only the
210 environments provided by the amsmath package.}%
211 \else
212 \PackageWarning{onlyamsmath}{Environment #1 used, please use
213 \MessageBreak only the environments provided by the amsmath
214 \MessageBreak package}%
215 \fi
216 }
217 % \end{macrocode}
218 % \end{macro}
219 % \changes{0.04}{2001/09/23}{Removed code that forbids
220 % \texttt{\textbackslash [}\dots\texttt{\textbackslash ]}}%
221 %
222 % Here follows the part that is only executed when one of the options
223 % |eqnarray| or |all| is used:
224 % \begin{macrocode}
225 \ifonlyams@eqnarray
226 % \end{macrocode}
227 % \begin{macro}{\onlyams@eqnarray}
228 % Copy the original |\eqnarray| command which is called by the commands
229 % |\begin{eqnarray}| and |\begin{eqnarray*}| to be able to call it
230 % after producing the correspondig error message:
231 % \begin{macrocode}
232 \let\onlyams@eqnarray\eqnarray
233 % \end{macrocode}
234 % \end{macro}
235 % \begin{environment}{eqnarray}
236 % Redefine the |\eqnarray| command:
237 % \begin{macrocode}
238 \def\eqnarray{%
239 % \end{macrocode}
240 % First generate an error or warning message:
241 % \begin{macrocode}
242 \onlyams@error{eqnarray or eqnarray*}%
243 % \end{macrocode}
244 % Then call the original |eqnarray| environment:
245 % \begin{macrocode}
246 \onlyams@eqnarray}
247 \fi
248 % \end{macrocode}
249 % \end{environment}
250 % Here follows the part that is only executed when the option |all| is
251 % used:
252 % \begin{macrocode}
253 \ifonlyams@all
254 % \end{macrocode}
255 % \begin{environment}{displaymath}
256 % Redefine the |\displaymath| command:
257 % \begin{macrocode}
258 \def\displaymath{%
259 % \end{macrocode}
260 % First generate an error or warning message:
261 % \begin{macrocode}
262 \onlyams@error{displaymath}%
263 % \end{macrocode}
264 % Then call the |\[| environment which normally is called by the
265 % |displaymath| environment:
266 % \begin{macrocode}
267 \[}
268 % \end{macrocode}
269 % \end{environment}
270 % \begin{macrocode}
271 \fi
272 % \end{macrocode}
273 % Redefine the |$$| environment.
274 % This part wass written by David Kastrup. Please don't ask me anything
275 % about it.
276 % \changes{0.03}{2001/09/22}{Changed definition of
277 % \texttt{\textbackslash dollarcode}, by David Kastrup}%
278 % \begin{macro}{\dollarcode}
279 % \begin{macrocode}
280 \def\dollarcode{\ifx\protect\@typeset@protect
281 \expandafter\futurelet\expandafter\next\expandafter\checkdsp
282 \else \expandafter$\fi}
283 % \end{macrocode}
284 % \end{macro}
285 % \begin{macrocode}
286 \begingroup
287 \lccode`\~=`\$
288 \lowercase{\endgroup\let~}\dollarcode
289 % \end{macrocode}
290 % \begin{macro}{\defdsp}
291 % \begin{macrocode}
292 \def\checkdsp{\ifx\next\dollarcode\expandafter\dspcomplain
293 \else\expandafter$\fi}
294 % \end{macrocode}
295 % \end{macro}
296 % Now comes the part that I understand and in which I have made
297 % changes.
298 % \begin{macro}{\dspcomplain}
299 % This command controls the complaint when using |$$|.
300 % \begin{macrocode}
301 \def\dspcomplain#1{%
302 % \end{macrocode}
303 % If mathmode is active the code has found the second |$$| of the
304 % environment.
305 % The complaint has already made and it is not necessary to do
306 % generate one.
307 % The environment has to be closed by using |\]|:
308 % \begin{macrocode}
309 \ifmmode
310 \expandafter \]%
311 \else
312 % \end{macrocode}
313 % If the mathmode isn't active the first |$$| of a mathematical
314 % environment has been found.
315 % First generate the warning or error message:
316 % \begin{macrocode}
317 \onlyams@error{$$ $$}%
318 % \end{macrocode}
319 % Then start the mathmode by using |\[|:
320 % \begin{macrocode}
321 \expandafter \[
322 \fi}
323 % \end{macrocode}
324 % \end{macro}
325 % Activate the complaining behaviour at |\begin{document}| to ensure
326 % that packages that internally use |$$| can do that without an error:
327 % \begin{macrocode}
328 \ifonlyams@nodollardollar
329 \else
330 \AtBeginDocument{\catcode`\$=13 }
331 \fi
332 % \end{macrocode}
333 % \iffalse
334 %</package>
335 % \fi
336 % \Finale
337