1 % \iffalse meta-comment
3 % Copyright (C) 1997-2003 by Michael J. Downes
4 % Copyright (C) 2007 by Morten Hoegholm <mh.ctan@gmail.com>
6 % This work may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either
8 % version 1.3 of this license or (at your option) any later
9 % version. The latest version of this license is in
10 % http://www.latex-project.org/lppl.txt
11 % and version 1.3 or later is part of all distributions of
12 % LaTeX version 2005/12/01 or later.
14 % This work has the LPPL maintenance status "maintained".
16 % This Current Maintainer of this work is Morten Hoegholm.
18 % This work consists of the main source file mathstyle.dtx
19 % and the derived files
20 % mathstyle.sty, mathstyle.pdf, mathstyle.ins, mathstyle.drv.
23 % CTAN:macros/latex/contrib/mh/mathstyle.dtx
24 % CTAN:macros/latex/contrib/mh/mathstyle.pdf
27 % (a) If mathstyle.ins is present:
29 % (b) Without mathstyle.ins:
31 % (c) If you insist on using LaTeX
32 % latex \let\install=y\input{mathstyle.dtx}
33 % (quote the arguments according to the demands of your shell)
36 % (a) If mathstyle.drv is present:
38 % (b) Without mathstyle.drv:
39 % latex mathstyle.dtx; ...
40 % The class ltxdoc loads the configuration file ltxdoc.cfg
41 % if available. Here you can specify further options, e.g.
42 % use A4 as paper format:
43 % \PassOptionsToClass{a4paper}{article}
45 % Programm calls to get the documentation (example):
46 % pdflatex mathstyle.dtx
47 % makeindex -s gind.ist mathstyle.idx
48 % pdflatex mathstyle.dtx
49 % makeindex -s gind.ist mathstyle.idx
50 % pdflatex mathstyle.dtx
53 % TDS:tex/latex/mh/mathstyle.sty
54 % TDS:doc/latex/mh/mathstyle.pdf
55 % TDS:source/latex/mh/mathstyle.dtx
61 \ifcase 0\ifx\install y1\fi\expandafter
62 \ifx\csname processbatchFile\endcsname\relax\else1\fi
63 \ifx\fmtname\x\else 1\fi\relax
64 \else\csname fi\endcsname
68 \Msg{************************************************************************}
70 \Msg{* Package: mathstyle 2007/12/19 v0.84 Mathstyle (MH)}
71 \Msg{************************************************************************}
78 This is a generated file.
80 Copyright (C) 1997-2003 by Michael J. Downes
81 Copyright (C) 2007 by Morten Hoegholm <mh.ctan@gmail.com>
83 This work may be distributed and/or modified under the
84 conditions of the LaTeX Project Public License, either
85 version 1.3 of this license or (at your option) any later
86 version. The latest version of this license is in
87 http://www.latex-project.org/lppl.txt
88 and version 1.3 or later is part of all distributions of
89 LaTeX version 2005/12/01 or later.
91 This work has the LPPL maintenance status "maintained".
93 This Current Maintainer of this work is Morten Hoegholm.
95 This work consists of the main source file mathstyle.dtx
97 mathstyle.sty, mathstyle.pdf, mathstyle.ins, mathstyle.drv.
102 \file{mathstyle.ins}{\from{mathstyle.dtx}{install}}%
103 \file{mathstyle.drv}{\from{mathstyle.dtx}{driver}}%
104 \usedir{tex/latex/mh}%
105 \file{mathstyle.sty}{\from{mathstyle.dtx}{package}}%
109 \Msg{************************************************************************}
111 \Msg{* To finish the installation you have to move the following}
112 \Msg{* file into a directory searched by TeX:}
114 \Msg{* mathstyle.sty}
116 \Msg{* To produce the documentation run the file `mathstyle.drv'}
117 \Msg{* through LaTeX.}
119 \Msg{* Happy TeXing!}
121 \Msg{************************************************************************}
129 \NeedsTeXFormat{LaTeX2e}
130 \ProvidesFile{mathstyle.drv}%
131 [2007/12/19 v0.84 mathstyle (MH)]
132 \documentclass{ltxdoc}
135 \setcounter{IndexColumns}{2}
136 \providecommand*\pkg[1]{\textsf{#1}}
138 \DocInput{mathstyle.dtx}
143 % \title{The \textsf{mathstyle} package}
144 % \date{2007/12/19 v0.84}
145 % \author{Morten H\o gholm \\\texttt{mh.ctan@gmail.com}}
150 % \part*{User's guide}
152 % This package exists for two reasons:
154 % \item The primitive operations for creating a super- or subscript in
155 % \TeX\ work almost as if \verb|^| and \verb|_| are macros taking an
156 % argument. However, that is not quite the case, and
157 % some things that you'd expect to work don't (e.g., \verb|^\cong|)
158 % whereas others which you'd think shouldn't work actually
159 % do (such as |^\mathsf{s}|). We do everyone a favor if it behaves
160 % consistently, i.e., if the superscript and subscript operations
161 % act as if they are macros taking exactly one argument.
163 % \item Because the \TeX\ math typesetting engine uses infix notation
164 % for fractions, one has to use \cs{mathchoice} or \cs{mathpalette}
165 % whenever trying to do anything requiring boxing or measuring
166 % math. This creates problems for loading fonts on demand as the
167 % font loading mechanism has to load fonts for all styles without
168 % even knowing if the font is going to be used. Getting the timing
169 % of \cs{mathchoice} right can be tricky as well. Since \LaTeX\ does
170 % not promote the primitive infix notation, this package keeps track
171 % of a current mathstyle parameter.
175 % \section{Some usage tips}
177 % If you want to use this package with \pkg{amsmath}, it is important
178 % \pkg{mathstyle} is loaded \emph{after} \pkg{amsmath}.
180 % The current mathstyle is stored in the variable \cs{mathstyle}. The
181 % command \cs{currentmathstyle} can be used to switch to the mode
182 % currently active. Below is shown how the macro \cs{mathrlap} from
183 % \pkg{mathtools} is implemented without knowing about the current
184 % mathstyle using \cs{mathpalette}.
186 % \providecommand*\mathrlap[1][]{%
187 % \ifx\@empty#1\@empty
188 % \expandafter \mathpalette \expandafter \@mathrlap
190 % \expandafter \@mathrlap \expandafter #1%
192 % \providecommand*\@mathrlap #1#2{{}\rlap{$\m@th#1{#2}$}}
194 % The same definition using \cs{currentmathstyle} from this package.
196 % \providecommand*\mathrlap[2][]{%
197 % #1 {}\rlap{$\m@th \currentmathstyle {#2}$}}
203 % \part*{Implementation}
209 \ProvidesPackage{mathstyle}[2007/12/19 v0.84]
211 % \begin{macro}{\@saveprimitive}
212 % A straight copy from \pkg{breqn}, see implementation details
213 % there. Of course, with a recent pdf\TeX\ (v1.40+), one can just
214 % use \cs{primitive} to get the original. We will implement that
217 \providecommand\@saveprimitive[2]{%
219 \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
220 \ifx\@tempa\@tempb \global\let#2#1%
222 \edef\@tempb{\meaning#2}%
224 \else \@saveprimitive@a#1#2%
229 \providecommand\@saveprimitive@a[2]{%
231 \def\@tempb##1#1##2{\edef\@tempb{##2}\@car{}}%
232 \@tempb\nullfont{select font nullfont}%
233 \topmark{\string\topmark:}%
234 \firstmark{\string\firstmark:}%
235 \botmark{\string\botmark:}%
236 \splitfirstmark{\string\splitfirstmark:}%
237 \splitbotmark{\string\splitbotmark:}%
239 \edef\@tempa{\expandafter\strip@prefix\meaning\@tempb}%
240 \edef\@tempb{\meaning#1}%
241 \ifx\@tempa\@tempb \global\let#2#1%
243 \PackageError{mathstyle}%
244 {Unable to properly define \string#2; primitive
245 \noexpand#1no longer primitive}\@eha
252 % Do initial \cs{chardef} of \cs{mathstyle}.
254 \chardef\mathstyle=\z@
256 % Save the four style changing primitives, \cs{mathchoice} and the
259 \@saveprimitive\displaystyle\@@displaystyle
260 \@saveprimitive\textstyle\@@textstyle
261 \@saveprimitive\scriptstyle\@@scriptstyle
262 \@saveprimitive\scriptscriptstyle\@@scriptscriptstyle
263 \@saveprimitive\mathchoice\@@mathchoice
264 \@saveprimitive\over\@@over
265 \@saveprimitive\atop\@@atop
266 \@saveprimitive\above\@@above
267 \@saveprimitive\overwithdelims\@@overwithdelims
268 \@saveprimitive\atopwithdelims\@@atopwithdelims
269 \@saveprimitive\abovewithdelims\@@abovewithdelims
271 % Then we redeclare the four style changing primitives.
273 \DeclareRobustCommand{\displaystyle}{%
274 \@@displaystyle \chardef\mathstyle\z@}
275 \DeclareRobustCommand{\textstyle}{%
276 \@@textstyle \chardef\mathstyle\@ne}
277 \DeclareRobustCommand{\scriptstyle}{%
278 \@@scriptstyle \chardef\mathstyle\tw@}
279 \DeclareRobustCommand{\scriptscriptstyle}{%
280 \@@scriptscriptstyle \chardef\mathstyle\thr@@}
282 % First we get the primitive operations. These should have been
283 % control sequences in \TeX\ just like operations for begin math, end
284 % math, begin display, end display.
286 \begingroup \catcode`\^=7\relax \catcode`\_=8\relax % just in case
288 \let\@@superscript=^ \let\@@subscript=_
291 % If we enter a sub- or superscript the \cs{mathstyle} must be
292 % adjusted. Since all is happening in a group, we do not have to worry
296 \ifnum\mathstyle<\tw@ \chardef\mathstyle\tw@
297 \else \chardef\mathstyle\thr@@
301 % Provide commands with meaningful names for the two primitives, cf.\
304 \let\mathsup=\@@superscript
305 \let\mathsub=\@@subscript
307 % \cs{sb} and \cs{sp} are then defined as macros.
309 \def\sb#1{\mathsub{\protect\subsupstyle#1}}%
310 \def\sp#1{\mathsup{\protect\subsupstyle#1}}%
312 % \cs{mathchoice} is now just a switch. Note that this redefinition
313 % does not allow the arbitrary \meta{filler} of the \TeX\
314 % primitive. Very rarely used anyway.
317 \relax\ifcase\mathstyle
318 \expandafter\@firstoffour
320 \expandafter\@secondoffour
322 \expandafter\@thirdoffour
324 \expandafter\@fourthoffour
330 \providecommand\@firstoffour[4]{#1}
331 \providecommand\@secondoffour[4]{#2}
332 \providecommand\@thirdoffour[4]{#3}
333 \providecommand\@fourthoffour[4]{#4}
335 % The fractions. Note that this uses the same names as in
336 % \pkg{amsmath}. Much the same except here they call \cs{fracstyle}.
338 \DeclareRobustCommand\genfrac[6]{%
340 {\begingroup #5\endgroup
341 \csname @@\ifx\maxdimen#4\maxdimen over\else above\fi
342 \if @#2@\else withdelims\fi\endcsname #2#3#4\relax
346 \renewcommand{\frac}{\genfrac{}{}{}{}}
347 \providecommand{\dfrac}{}
348 \providecommand{\tfrac}{}
349 \renewcommand{\dfrac}{\genfrac\displaystyle{}{}{}}
350 \renewcommand{\tfrac}{\genfrac\textstyle{}{}{}}
351 \providecommand{\binom}{}
352 \providecommand{\tbinom}{}
353 \providecommand{\dbinom}{}
354 \renewcommand{\binom}{\genfrac{}(){0pt}}
355 \renewcommand{\dbinom}{\genfrac\displaystyle(){0pt}}
356 \renewcommand{\tbinom}{\genfrac\textstyle(){0pt}}
358 % The \cs{fracstyle} command is a switch to go one level down but no
359 % further than three.
361 \def\fracstyle{\ifcase\mathstyle
362 \chardef\mathstyle=\@ne
364 \chardef\mathstyle=\tw@
366 \chardef\mathstyle=\thr@@
370 % The \cs{currentmathstyle} checks the value of \cs{mathstyle} and
371 % switches to it so it is in essence the opposite of \cs{displaystyle}
374 \def\currentmathstyle{%
385 % Finally, we declare the package options.
387 \DeclareOption{mathactivechars}{\catcode`\^=7\relax \catcode`\_=8\relax }
388 \DeclareOption{activechars}{\catcode`\^=13\relax \catcode`\_=13\relax }
389 \ProcessOptions\relax
390 \ifnum\catcode`\^=13\relax
393 \mathcode`\^="8000\relax \mathcode`\_="8000\relax
394 \begingroup \catcode`\^=\active \catcode`\_=\active
395 \global\let^=\sp \global\let_=\sb