1 % \iffalse meta-comment
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
25 %% Copyright 1996 1997 1998 1999 2002 2003 2004 2016
26 %% David Carlisle Frank Mittelbach
28 %% Development of this package was commissioned by Y&Y Inc.
29 %% http://www.yandy.com
35 %<package>\NeedsTeXFormat{LaTeX2e}
36 %<package>\ProvidesPackage{bm}
37 %<driver>\ProvidesFile{bm.drv}
39 % \ProvidesFile{bm.dtx}
40 [2016/02/27 v1.2a Bold Symbol Support (DPC/FMi)]
44 \documentclass{ltxdoc}
53 % \GetFileInfo{bm.dtx}
55 % \title{The \textsf{bm} package\thanks{This file
56 % has version number \fileversion, last
57 % revised \filedate.}\ \thanks{Development of this package
58 % was commissioned by Y\&Y.}}
61 % \author{David Carlisle with support by Frank Mittelbach}
62 % \MaintainedByLaTeXTeam{tools}
65 % \section{Introduction}
67 % This package defines commands to access bold math
68 % symbols. The basic command is |\bm| which may be used to make the
69 % math expression in its argument be typeset using bold fonts.
71 % The syntax of |\bm| is:\\
72 % |\bm|\marg{math expression}\\
73 % So |$\alpha \not= \bm{\alpha}$| produces $\alpha \not= \bm{\alpha}$.
75 % |\bm| goes to some trouble to preserve the spacing, so that for
76 % instance |\bm<| is a bold $\bm<$ but with the correct |\mathrel|
77 % spacing that \TeX\ gives to $<$. The calculations that \TeX\ needs to
78 % do for |\bm| can be quite involved and so a definition form is
81 % |\DeclareBoldMathCommand|%^^A
82 % \oarg{math version}\marg{cmd}\marg{math expression}
84 % Defines |\cmd| to be the bold form of the math expression.
85 % The \meta{math version} defaults to `bold' (i.e., |\boldmath|).
87 % For relatively simple expressions, the resulting definitions are very
88 % efficient, for instance after:\\
89 % |\DeclareBoldMathCommand\balpha{\alpha}|\\
90 % |\balpha| is a single `mathchardef' token producing a bold alpha,
91 % and so is just as fast to execute as |\alpha|.
93 % The above command is mainly intended for use in packages.
94 % For occasional use in \LaTeX\ documents, and for compatibility
95 % with the plain \TeX\ support for the mathtime fonts, a `user-level'
96 % version, |\bmdefine| is provided that is equivalent to:\\
97 % |\DeclareBoldMathCommand[bold]|.
99 % If there is a `heavy' math version defined (usually accessed by a
100 % user-command |\heavymath|) then a similar command |\hm|
101 % is defined which access these `ultra bold' fonts. Currently this is
102 % probably only useful with the `mathtime plus' font collection.
103 % Definitions of commands that use these fonts may be made by
104 % specifying the optional argument `heavy' to |\DeclareBoldMathCommand|.
105 % Again an abbreviation, |\hmdefine|, is provided, equivalent to:\\
106 % |\DeclareBoldMathCommand[heavy]|.
108 % The command names (but not the implementation) are taken from Michael
109 % Spivak's macros to support the mathtime fonts for plain \TeX. In those
110 % original macros, the syntax for |\bmdefine| was
111 % |\bmdefine\balpha{\bm\alpha}| (with a nested |\bm|). This syntax also
112 % works with this package.
114 % \section{Font allocation}
115 % In order to access bold fonts in the simplest and quickest possible
116 % manner, the package normally allocates symbol fonts for bold
117 % (and possibly heavy) fonts into the `normal' math version.
118 % By default it allocates at most four fonts for |\bm| and at most
119 % three fonts for |\hm|. This means that if the mathtime plus font set
120 % is being used, seven additional symbol fonts will be used, in addition
121 % to the basic four that \LaTeX\ already declares. The mathtime
122 % package also declares an extra symbol font, bringing the total to
123 % twelve. The maximum number of symbol \emph{and} math alphabet fonts
124 % that can be used in a math version is sixteen. So the above allocation
125 % scheme does not leave room for many extra math symbols (such as the
126 % AMS symbols) or math alphabets (such as |\mathit|).
128 % Before loading the \textsf{bm} package you may define |\bmmax|
129 % and |\hmmax| to be suitable values, for instance you may want
130 % to set |\newcommand\hmmax{0}| if you will not be using |\hm|
131 % much, but you do have a heavy math version defined.
133 % Even if |\bmmax| is set to zero, |\bm| will still access the correct
134 % bold fonts (by accessing the fonts via |\boldmath|) but this method
135 % is slower, and does not work with delimiters. Delimiters can only be
136 % made bold if the bold font has been allocated.
138 % Conversely if you have a non standard font set that makes available
139 % extra math delimiters and accents in bold and medium weights you may
140 % want to \emph{increase} |\bmmax| so that fonts are allocated for
144 % In most cases this package should work in a fairly self explanatory
145 % way, but there are some things that might not be obvious.
147 % \subsection{Interaction with Math Alphabet Commands}
149 % As mentioned above, |\bm| goes to some trouble to try to make a
150 % command that is just like its argument, but using a bold font.
151 % This does not always produce the effect that you might expect.
154 % $2 \mathrm{g \bm{g}}$
156 % $4 \mathrm{{g} \bm{{g}}}$
157 % $5 \mathrm{g} \bm{\mathrm{g}}$
159 % produces the following:
162 % $2 \mathrm{g \bm{g}}$
164 % $4 \mathrm{{g} \bm{{g}}}$
165 % $5 \mathrm{g} \bm{\mathrm{g}}$
167 % In math mode `g' is effectively a command that produces the letter `g'
168 % from the `letters' alphabet, unless a Math Alphabet command is in
169 % effect, in which case the `g' comes from the specified alphabet.
170 % |\bm{g}| makes an equivalent command, but which defaults to a bold
171 % letter alphabet. So in the first example |\bm{g}| is bold math italic,
172 % but in the second example the |\mathrm| applies to both |g| and
173 % |\bm{g}| in the same way, and so they are both roman.
175 % |\bm| only inspects the `top level' definition of a command, for more
176 % complicated expressions, and anything inside a |{ }| group, |\bm|
177 % forces bold fonts by essentially the same (slow) technique used by the
178 % AMS |\boldsymbol| command (but |\bm| still takes more care of the
179 % spacing). So the third example produces identical output to the first
180 % (but \TeX\ takes more time producing it).
182 % In the fourth example the |\mathrm{\bm{g}}| is essentially
183 % equivalent to |\mathrm{\mbox{\boldmath$g$}}|. Currently math alphabet
184 % settings are not passed down to `nested' math lists, and so in this
185 % example, the |\mathrm| has no effect, and a bold math italic $\bm g$
188 % Similarly the last example is equivalent to
189 % |$\mbox{\boldmath$\mathrm{g}$}}| and so in this case, one obtains a
190 % bold roman \textbf{g}.
192 % \subsection{Delimiters}
193 % \TeX\ can treat character tokens in two\footnote
194 % {Well more than two really.}
195 % ways. If there is a preceding
196 % |\left| or |\right| it can treat them as a delimiter, otherwise it can
197 % treat them as a standard character. For example |\left<\right>|
198 % produces $\left<\right>$, which is totally different from |<>|, which
201 % \TeX\ can only do this for character tokens. Commands such as
202 % |\langle| do not act in this way. This means that |\bm| has to decide
203 % whether to treat a character as a delimiter or not. The rule it uses
204 % is, it makes a delimiter command for a character if the previous
205 % token in the argument was |\left| or |\right|. So |\left\bm{<}| does
206 % not work, but |\bm{\left<}| does.
208 % \subsection{Command Arguments}
210 % Normally if a command takes arguments the full command, including
211 % any arguments, should be included in |\bm|.
213 % So |\bm{\overbrace{abc}}| (producing \smash{$\bm{\overbrace{abc}}$})
215 % |\bm{\overbrace}{abc}|. If you do not include all the arguments you
216 % will typically get the error message:\\
217 % |Runaway argument?|\\
218 % |! Forbidden control sequence found while scanning use of|
221 % However commands defined in terms of the \TeX\ accent and
222 % radical primitives \emph{may} be used without their arguments.
223 % So |\bm{\hat}{a}| produces $\bm{\hat}{a}$, a bold accent over a
224 % non-bold $a$ (compare $\hat{a}$)
225 % whereas |\bm{\hat{a}}| makes both the $a$ and the accent bold,
227 % Similarly, although the \LaTeX\ command |\sqrt| must be used with its
228 % arguments, |\sqrtsign| may be used as in |\bm\sqrtsign{abc}| to
229 % produce $\bm\sqrtsign{abc}$ rather than $\sqrtsign{abc}$ or
230 % $\bm{\sqrtsign{abc}}$
232 % If you really need to make a command with arguments use bold fonts
233 % without making all of the arguments bold, you can explicitly
234 % reset the math version in the argument, eg:\\
235 % $\begin{array}{ccc}
236 % |\sqrt{xyz}|&|\bm{\sqrt{xyz}}|&|\bm{\sqrt{\mbox{\unboldmath$xyz$}}}|\\
237 % \sqrt{xyz}& \bm{\sqrt{xyz}}& \bm{\sqrt{\mbox{\unboldmath$xyz$}}}
240 % \subsection{Bold fonts}
241 % This package interrogates the font allocations of the bold and heavy
242 % math versions, to determine which bold fonts are available.
243 % This means that it is best to load the package \emph{after}
244 % any packages that define new symbol fonts, or (like the
245 % \textsf{mathtime} package) completely change the symbol font
248 % If no bold font appears to be available for a particular symbol,
249 % |\bm| will use `poor man's bold' that is, overprinting the same
250 % character in slightly offset
251 % positions to give an appearance of boldness.
253 % In the standard Computer Modern font set, there is no bold
254 % `large symbols' font. In the `mathptm' and (standard) mathtime
255 % font sets there are no bold math fonts. In the `mathtime plus'
256 % font set there are suitable fonts for bold and heavy math setting,
257 % and so |\bm| and |\hm| work well. Similarly in the basic Lucida
258 % New Math font set there are no bold math fonts, so |\bm| will
259 % use `poor man's bold. However if the Lucida Expert set is used,
260 % Then |\bm| will detect, and use the bold math fonts that are
263 % As discussed above, one may set |\bmmax| higher or lower than its
264 % default value of four to control the font allocation system. Finer
265 % control may be gained by explicitly declaring bold symbol fonts.
266 % Suppose you have a symbol font `xyz' that is available in medium and
267 % bold weights, then you would declare this to \LaTeX\ via:\\
268 % |\DeclareSymbolFont{extras} {OMS}{xyz}{m}{n}|\\
269 % |\SetSymbolFont{extras}{bold}{OMS}{xyz}{bx}{n}|\\
270 % At this point the symbols will be available in the normal math
271 % version, and their bold variants in |\boldmath|. If you also
273 % |\DeclareSymbolFont{boldextras}{OMS}{xyz}{bx}{n}|\\
274 % That is, declare a symbol font whose name is formed by prefixing
275 % `bold' (or `heavy') to an existing symbol font, then |\bm| (or
276 % |\hm|) will use this font directly, rather then accessing the
277 % `extras' symbol font via |\boldmath|.
279 % \subsection{Strange failures}
280 % In order to get the correct spacing, |\bm| has to `investigate' the
281 % definition of the commands in its argument. It is possible that
282 % some strange constructions could `confuse' this investigation.
283 % If this happens then \LaTeX\ will almost certainly stop with a strange
284 % error. This should not happen with any of the math symbols
285 % defined in the base \LaTeX\ or AMS distributions, or any commands
286 % defined in terms of those symbols using normal \LaTeX\ math
287 % constructs. However if some command does fail to work inside |\bm|
288 % you should always be able to surround it with an extra set of braces
289 % |\bm{{\cmd}}| rather than |\bm{\cmd}|. |\bm| will not then attempt
290 % to set the correct spacing, so you may need to set it explicitly,
291 % for instance, for a relation, |\bm{\mathrel{\cmd}}|.
293 % \subsection{AMS package \textsf{amsbsy}}
294 % The |\bm| command shares some functionality with the |\boldsymbol|
295 % command from the AMS \LaTeX\ collection. To aid in moving documents
296 % between these two packages, this package defines |\boldsymbol| and
297 % |\heavysymbol| as alternative names for |\bm| and |\hm|.
301 % \section{Implementation}
303 % \changes{v0.01}{1996/12/01}
304 % {Initial DPC attempt,
305 % remove all assumptions about mathtime encoding}
306 % \changes{v0.02}{1996/12/02}
307 % {Add \cs{mathchoice} stuff}
308 % \changes{v0.03}{1996/12/12}
309 % {Completely reimplement (again). Add \cs{bmdefine}.}
310 % \changes{v0.04}{1996/12/12}
311 % {Add \cs{hm} and support for special active mathcode.}
312 % \changes{v0.05}{1996/12/12}
314 % \changes{v0.99}{1997/01/16}
315 % {First public version}
316 % \changes{v1.0a}{1997/02/14}
317 % {First ctan version (same as 0.99b)}
318 % \changes{v1.0b}{1997/04/14}
319 % {Add to tools bundle.}
320 % \changes{v1.0g}{1999/07/05}
321 % {minor doc changes latex/3058}
325 % The commands |\bm| and |\hm| work by defining a number of additional
326 % symbol fonts corresponding to the standard ones
327 % `operators', `letters', `symbols', and `largesymbols'.
328 % The names for these symbols fonts are produced by prefixing the usual
329 % name with `bold' or `heavy'.
331 % For maximum flexibility we get the font definitions by looking in the
332 % corresponding math versions, i.e., into |\mv@bold| and if defined into
338 % \changes{v0.09}{1996/12/19}
339 % {Always define \cs{bm} even if no bold math}
341 % \begin{macro}{\bm@table}
342 % \changes{v0.10}{1997/01/04}
344 % \changes{v0.12}{1997/01/10}
345 % {Ensure do not allocate too many math group slots.}
346 % \changes{v0.99a}{1997/01/17}
347 % {Let \cs{hm} use font allocated for \cs{bm}}
348 % \changes{v0.99b}{1997/01/19}
349 % {Restore NFSS internals}
350 % \begin{macro}{\bm@boldtable}
351 % \begin{macro}{\bm@heavytable}
352 % The table, |\bm@table|, (which is locally |\let| to either the bold
353 % or heavy version) defines, for each \meta{math group} (\meta{fam}),
354 % the `offset' to the bold version of the specified symbol font.
355 % If there is no bold symbol font defined, the offset will be
356 % set to zero if there is a bold font assigned to this slot in the
357 % bold math version, or $-1$ if the font in the bold math version
358 % is the same as the one in the normal math version. In this case
359 % a `poor man's bold' system of overprinting is used to achieve
360 % boldness where this is possible.
362 % The settings are made at the time this package is read, and so
363 % it is best to load this package late, after any font loading packages
364 % have been loaded. Symbol fonts loaded after this package will get the
365 % offset of zero, so they will still be made bold by |\bm| as long as an
366 % appropriate font is declared for the bold math version.
368 % |\bm@boldtable| and |\bm@heavytable| are set up using very similar
369 % code, which is temporarily defined to |\bm|, to save wasting a csname.
370 % Similarly |\bm@pmb|\ldots\ (which will be defined later) are used
373 % The general plan. Run through the fonts allocated to the normal math
374 % version. Ignore \meta{math alphabet} allocations\footnote{For now?}
375 % but for each math symbol font, look in the math version specified by
376 % |#1| (bold or heavy). If the font there is different, then allocate
377 % a new symbol font in the normal math version to access that bold font
378 % and place the numerical difference between the allocations of the bold
379 % and normal font into the table being built (|\bm@boldtable|, if |#1|
380 % is bold). If the symbol allocation is already greater than |\bmmax|
381 % do not allocate a new symbol font, but rather set the offset in the
382 % table to zero. |\bm| will detect this, and use |\boldmath| on its
383 % argument in this case, so the bold font will be accessed but more
384 % slowly than using a direct access to a bold font allocated into the
385 % normal math version. If the font allocated in the bold math version is
386 % the same as the font in the normal math version, set the offset to
387 % $-1$, which is a flag value that causes |\bm| to use `poor man's bold'
388 % overprinting three copies of the symbol, offset slightly to give an
389 % appearance of boldness.
391 % Fonts containing delimiters and math accents \emph{must} be allocated
392 % into the normal math version if they are to be used with |\bm|. (In
393 % these cases |\bm| will produce the normal weight symbol, rather than
394 % using |\boldmath| or poor man's bold.)
399 % This code can not work inside a group, as that would affect any symbol
400 % font allocations, so instead use some scratch macros to save and
401 % restore the definitions of commands we need to change locally.
403 \let\bm@pmb\install@mathalphabet
404 \let\bm@pmb@\getanddefine@fonts
406 \edef\bm@general{\f@encoding/\f@family/\f@series/\f@shape/\f@size}%
409 % |#2| specifies the maximum number of fonts to allocate
410 % (either |\bmmax| or |\hmmax|). First check against |\count18|
411 % that there are that many slots left, and if not reduce accordingly.
412 % Put the resulting value in |\@tempcnta|.
416 \advance\count@-\@tempcnta
417 \advance\count@15\relax
419 \advance\@tempcnta\count@
422 % Make |\or| non-expandable, so we can build an |\ifcase| bit-by-bit
423 % in a sequence of |\edef|s.
428 % Initialise the table (to |\@gobble| to remove the first |\or|).
430 \expandafter\let\csname bm@#1table\endcsname\@gobble
433 % Helper macro that adds the next entry to the table being built.
436 \expandafter\xdef\csname bm@#1table\endcsname{%
437 \csname bm@#1table\endcsname\or##1}}%
440 % Each symbol font is recorded in the math version list by a sequence
442 % | \getanddefine@fonts \symsymbols \OMS/cmsy/m/n|\\
443 % Where the first argument is a chardef token carrying the number
444 % allocated (to symbols, in this example), and the second argument is a
445 % csname whose \emph{name} denotes the font used.
446 % So locally redefine |\getanddefine@fonts| to compare |#2| with
447 % the name in the appropriate slot in the bold math version.
449 \def\getanddefine@fonts##1##2{%
454 \def\@tempb####1##1####2####3\@nil{\def\@tempb{####2}}%
458 \expandafter\expandafter\expandafter
459 \@tempb\csname mv@#1\endcsname\@nil
462 % Now |\@tempa| and |\@tempb| contain the names of the fonts allocated
463 % to this slot in the two math versions.
467 % If they are the same, set this offset to $-1$, as a flag to use
473 % Else make a new name by adjoining |#1| to the name of the symbol font
474 % eg, |\symboldsymbols| to match |\symsymbols|. If that font has already
475 % been allocated, or if |\@tempcnta| is positive so we can allocate a
476 % new slot for this font, then the table will be
477 % set with the offset between the two fonts. otherwise set the offset to
478 % zero (so |\boldmath| will be used to access the font).
480 \edef\@tempa{sym#1\expandafter\@gobblefour\string##1}%
482 \expandafter\ifx\csname\@tempa\endcsname\relax
494 % If the font is not yet allocated, allocate it now, using
495 % an internal hack into |\DeclareMathSymbolFont|.
497 % However before allocating it look in the bold math version
498 % to see if it is the same, and if so use that. For example
499 % with Mathtime the `operators' font in the `heavy' math version
500 % is different from that in `normal', but it is the same as
501 % the font in `bold' (Times bold). So rather than allocate
502 % |\symheavyoperators| just set it equal to |\symboldoperators|.
504 \expandafter\ifx\csname\@tempa\endcsname\relax
507 \edef\@tempb{\endgroup
509 \expandafter\string\@tempb}%
515 \csname symbold\expandafter\@gobblefour\string##1\endcsname
518 % If no font has been allocated for |\bm| yet, then allocate it now.
520 \expandafter\new@mathgroup\csname\@tempa\endcsname
521 \expandafter\new@symbolfont\csname\@tempa\endcsname
522 \f@encoding\f@family\f@series\f@shape
524 % Reduce by one the number of fonts we can still allocate.
526 \advance\@tempcnta\m@ne
532 % Else do a similar look into the bold mathgroup.
533 % Use |\bm@expand| as a scratch macro to save on string space.
535 \def\bm@expand####1##1####2####3\@nil{\def\bm@expand{####2}}%
536 \expandafter\expandafter\expandafter
537 \bm@expand\csname mv@bold\endcsname\@nil
541 \ifx\bm@expand\@tempb
543 % If the font just found (in heavy) is the same as the font in bold
544 % use the slot (in normal) previously allocated for the bold font.
547 \expandafter\let\csname\@tempa\expandafter\endcsname
548 \csname symbold\expandafter
549 \@gobblefour\string##1\endcsname
555 % Otherwise allocate a new slot for it.
557 \expandafter\new@mathgroup\csname\@tempa\endcsname
558 \expandafter\new@symbolfont\csname\@tempa\endcsname
559 \f@encoding\f@family\f@series\f@shape
560 \advance\@tempcnta\m@ne
571 % If the font has been allocated already, use the existing allocation.
574 {Symbol font \@tempa\space already defined.\MessageBreak
578 % Whether the font has just been allocated, or whether it was previously
579 % allocated, compute the offset and add it to the table.
581 \count@\csname\@tempa\endcsname
583 \bm@define{\the\count@\relax}%
588 % The math version list also contains information about math alphabet
589 % commands, but we want to ignore those here, so \ldots
591 \let\install@mathalphabet\@gobbletwo
594 % Having set up the local definitions, execute the list for the normal
600 % So now the offsets are all entered into the table, separated by
602 % Finish off the definition by making this an |\ifcase|. Add a default
603 % value of zero, so that any symbol fonts declared later will also
604 % work, as long as a bold version is assigned to the bold math version.
606 \expandafter\xdef\csname bm@#1table\endcsname{%
607 \noexpand\ifcase\@tempcnta
608 \csname bm@#1table\endcsname
614 % Put things back as they were.
616 \expandafter\split@name\bm@general\@nil
617 \let\install@mathalphabet\bm@pmb
618 \let\getanddefine@fonts\bm@pmb@
625 % \begin{macro}{\bmmax}
626 % To save declaring too many symbol fonts, do not auto-declare
627 % any more than |\bmmax| bold symbol fonts into the normal math
628 % version. Any bold fonts not so allocated will be accessed via
629 % |\boldmath| which is slower and doesn't work for delimiters
630 % and accents. It may be set in the preamble with |\newcommand|
631 % but use |\chardef| here for a slight efficiency gain.
633 % If this is set to a higher value before this
634 % package is loaded, keep that value.
636 \ifx\bmmax\@undefined
641 % If there is no bold math version, It is very easy to set up
642 % the table, no need to use all the tricky code above.
643 % Also, at the end of the package redefine the internal macro
644 % that |\bm| uses to call |\boldmath|, to use poor man's bold
647 \ifx\mv@bold\@undefined
648 \def\bm@boldtable{\m@ne}
654 % Otherwise use the definition of |\bm| above to set up |\bm@boldtable|
655 % by comparing the fonts available in the normal and bold math versions.
660 % \begin{macro}{\mathbf}
661 % As the bold font has been defined as a symbol font, make |\mathbf|
662 % access that rather than have it allocate a new math group for the
663 % same font. (Just in case there were no free slots wrap this
666 \@ifundefined{symboldoperators}
668 {\DeclareSymbolFontAlphabet\mathbf{boldoperators}}
677 % \begin{macro}{\hmmax}
679 % Same for heavy (but default to three this time (enough for mathtime
680 % plus, as no heavy operators font).
682 \ifx\hmmax\@undefined
687 % Similarly if there is a heavy math version, set up |\bm@heavytable|.
688 % (If there is no heavy math version, do nothing here, as |\hm| will be
689 % set to |\bm| later, once that is defined.)
691 \ifx\mv@heavy\@undefined
699 % \begin{macro}{\bm@general}
700 % \changes{v1.0d}{1997/11/15}
701 % {extra code to support prime lookahead and breqn}
702 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
704 % |\bm| is pretty much |\bmdefine\bm@command| followed by executing
705 % |\bm@command|. It would in principle be possible to execute the
706 % emboldened tokens directly, rather than building up a macro first,
707 % but (as I learned the hard way) it's difficult to do this in the midst
708 % of all these nested |\if| constructs.
709 % First extract the central bit of code for |\hm| |\bm| |\hmdefine| and
710 % |\bmdefine|. Note that in the case of the inline versions they take
711 % an argument and brace it, rather than relying on |\bm@general| to pick
712 % up the argument. This makes the code robust with respect to premature
717 \@firstofone{\endgroup
718 \def\bm@general#1#2#3#4#5{%
721 % \changes{v1.0d}{1997/11/15}
722 % {make nested \cs{bm} vanish completely, not leave a brace group}
723 % First locally disable |\bm| and |\hm|, as they would mess things
724 % up terribly, and the original Spivak versions used the syntax
725 % |\bmdefine\balpha{\bm\alpha}|.
730 % Now initialise the commands used to save the tokens constructed.
732 \global\let\bm@command\@empty
733 \let\@let@token\@empty
735 % As we want to expand the macros to look at their definition
736 % turn off protection. Otherwise the |\protect| will be carried over
737 % and apply to the wrong token, eg |{|.
740 \let\@typeset@protect\@empty
742 % Set up either bold or heavy
744 \def\bm@mathchoice{\bm@m@thchoice#1}%
745 \def\bm@group{\bm@gr@up#1}%
748 % Make sure |\left| and |\right| are really non expandable,
749 % and not |\ifx| equal to anything else.
750 % \changes{v1.0d}{1997/11/15}
751 % {make sure \cs{left} is primitive}
753 \let\left\holdinginserts
755 % These three save on the number of |\ifx| tests below.
756 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
762 % Definition of |'| locally modified so as not to use |\futurelet|
763 % in the look ahead, but to make the |\prime| available at the top level
764 % to be made bold, or heavy or whatever.
765 % |'| is locally active for this definition.
766 % \changes{v1.0d}{1997/11/15}
770 \def'{\bm@prime\prime\relax}%
772 % For optional argument commands. This expandable version of
773 % |\@ifnextchar| is not 100\% safe, but works for |\sqrt| unless
774 % you put something really strange in the arguments.
775 % \changes{v0.11}{1997/01/06}
776 % {\cs{@ifnextchar} made safe.}
778 \def\@ifnextchar##1##2##3##4{%
780 \expandafter\@firstoftwo
782 \expandafter\@secondoftwo
786 % For Vladimir Volovich\ldots
787 % \changes{v1.0f}{1998/12/10}
788 % {Errors and warnings made safe. tools/2917}
790 \def\GenericWarning##1##2{%
791 \unvcopy{\GenericWarning{##1}{##2}}}%
792 \def\GenericError##1##2##3##4{%
793 \unvcopy{\GenericError{##1}{##2}{##3}{##4}}}%
795 % For AMS definitions.
800 \global\let\bm@first\@empty
802 % For AMS version of |\sqrt|: don't expand just wrap in brace group
803 % so that it can be made bold in a safe but slow way. Do the same for
804 % internal accent command
805 % \changes{v1.1b}{2003/10/05}{AMS \cs{sqrt} not working}
807 % \changes{v1.1c}{2004/02/26}{\cs{accentV} made safe (pr/3625)}
808 % Code for AMS accent allows bm to be used (just) with accent
809 % but stops the nested accents stacking correctly, this can be
810 % corrected by using an extra brace group as usual.
811 % |\bm{{\hat{\hat{F}}}}|
813 \ifx\uproot@\undefined\else
814 \def\root##1\of##2{{\root##1\of{##2}}}%
816 \def\mathaccentV##1{\mathaccent"\accentclass@}%
818 % For breqn definitions.
820 \let\@ifnext\@ifnextchar
821 \let\measure@lhs\copy
824 \let \after@open\copy
825 \let \after@close\copy
827 % Make sure things like |\pounds| take the `math branch' even
828 % in |\bmdefine| (which is not executed in math mode).
832 % We have to ensure that the math alphabets have definitions that
833 % correspond the the ``bold'' math version we are going to switch
834 % to. As these definitions are globally assigned when a math
835 % version is changed it is likely that right now we have those of
836 % the normal math version active. Argument |#3| holds either
837 % |\mv@bold| or |\mv@heavy| and we execute that after redefining
838 % |\install@mathalphabet| and |\getanddefine@fonts| suitably.
839 % The definitions are reverted back to their original the moment
840 % the scanning is done
841 % \changes{v1.0h}{2002/11/22}{Get math alphabets right (pr/3476)}
843 \let\install@mathalphabet\def
844 \let\getanddefine@fonts\@gobbletwo
847 % The last redefinition just makes |\mathit| type commands re-insert
848 % themselves (more or less) as if they are allowed to expand
849 % they die horribly if the expansions are put into |\mathchoice|
850 % and so executed more than once.
852 \def\select@group##1##2##3##4{{%
854 \def\use@mathgroup##1##2##3{{%
855 \protect\use@mathgroup##1{##2}{##3}}}%
858 % So now start looking at the argument.
859 % \changes{v0.10}{1997/01/04}
866 % Finally outside the group either execute |\bm@command| (for |\bm|)
867 % or save its definition (for |\bmdefine|).
871 % End of the |\@firstofone| above, and the scope of the active |'|.
878 % \changes{v1.0d}{1997/11/15}
879 % {Make \cs{bm} grab its argument even when protected}
880 % Set up the bold (rather than heavy) version, and run |\bm@command|
881 % right at the end, to execute the emboldened argument.
882 % The argument is grabbed by the top level function, and explicitly
883 % braced, so that |\bm| works even if the braces are omitted round
884 % its argument in a `moving argument'.
885 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
887 \DeclareRobustCommand\bm{%
888 \bm@general\boldmath\bm@boldtable\mv@bold\bm@command}
889 \protected@edef\bm#1{\bm{#1}}
893 % \begin{macro}{\DeclareBoldMathCommand}
894 % \changes{v0.07}{1996/12/14}
896 % \begin{macro}{\bm@declare}
897 % \changes{v0.07}{1996/12/14}
899 % |DeclareBoldMathCommand|%^^A
900 % \oarg{mathversion}\marg{command}\marg{math expression}\\
901 % looks like |\bm| except at the end the specified command is
902 % globally defined to be |\bm@command|.
903 % The \meta{mathversion} defaults to `bold'.
905 \def\DeclareBoldMathCommand{\@testopt\bm@declare{bold}}
908 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
910 \def\bm@declare[#1]#2{%
911 \expandafter\bm@general
912 \csname #1math\expandafter\endcsname
913 \csname bm@#1table\expandafter\endcsname
914 \csname mv@#1\endcsname
920 % \begin{macro}{\bmdefine}
921 % |\bmdefine| Shorthand for |\DeclareBoldMathCommand[bold]|.
923 % |\bm| is empty within the definition, so that either\\
924 % |\bmdefine\balpha{\bm\alpha}| or |\bmdefine\balpha{\alpha}| \\
925 % may be used. (The former just for compatibility with the original
926 % version for plain \TeX).
928 \def\bmdefine{\DeclareBoldMathCommand[bold]}
933 % \changes{v1.0d}{1997/11/15}
934 % {Make \cs{hm} grab its argument even when protected}
935 % \begin{macro}{\hmdefine}
936 % Same again for |\hm|.
938 \ifx\mv@heavy\@undefined
941 % If there is no heavy math version defined, let |\hm| be defined
942 % as |\bm|. Currently there is no warning given, perhaps there should
943 % be, or even an error?
946 \let\heavymath\boldmath
947 \let\bm@heavytable\bm@boldtable
954 % Otherwise define |\hm| and |\hmdefine| in direct analogy with the
956 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
958 \DeclareRobustCommand\hm{%
959 \bm@general\heavymath\bm@heavytable\mv@heavy\bm@command}
960 \protected@edef\hm#1{\hm{#1}}
964 \def\hmdefine{\DeclareBoldMathCommand[heavy]}
973 % \begin{macro}{\bm@end}
974 % \changes{v0.10}{1997/01/04}
976 % Normally speaking |\outer| declarations should be avoided at all
977 % costs. (\LaTeX\ redefines all of plain \TeX's allocation macros
978 % to be non-outer.) However this is one place where it seems like a
979 % good idea. If a command taking an argument is put in |\bm| without
980 % its argument, then the |\@@end| terminating token would be taken as
981 % the argument, and so the rest of the paragraph would be gobbled up
982 % and the \LaTeX\ would die horribly. So make the internal terminating
983 % token |\outer|. (The actual test for termination is made against
984 % |\@@end| not |\bm@end| as this macro will be expanded by the look-ahead
987 \outer\def\bm@end{\@@end}
991 % \begin{macro}{\bm@expand}
992 % \changes{v0.11}{1997/01/06}
994 % \begin{macro}{\bm@exp@nd}
995 % \changes{v0.11}{1997/01/06}
997 % |\afterassignment| trick to fully expand the following tokens until
998 % the first non-expandable token is revealed. This may discard a space
999 % token (which is what \TeX\ is looking for) but that doesn't matter in
1000 % math mode. The expansion lookahead is done twice in case any stray
1001 % space tokens have crept in.\footnote{The need for this was noticed
1002 % while testing \cs{sqrt}. The definition of \cs{root} inherited from
1003 % plain \TeX\ has an anomalous space token, that is normally harmless
1004 % (just wastes memory), but which killed earlier versions of this
1007 \def\bm@expand{\afterassignment\bm@exp@nd\count@`\a}
1011 \def\bm@exp@nd{\afterassignment\bm@test\count@`\a}
1016 % \begin{macro}{\bm@test}
1017 % Normally we will grab the non-expandable token as a macro argument
1018 % but better check it is not |{| first. Save the previous token
1019 % so we can check later if it was |\left|, in which case use the delcode
1020 % rather than the mathcode if the current token is a character.
1023 \let\bm@previous\@let@token
1024 \futurelet\@let@token\bm@test@}
1028 % \begin{macro}{\bm@test@}
1029 % If looking at a single token, switch to |\bm@test@token|, else if
1030 % looking at a |{ }| group, grab the whole group with |\bm@group|.
1031 % A |\bgroup| token will take the wrong branch here (currently not
1035 \ifx\@let@token\bgroup
1036 \expandafter\bm@group
1038 \expandafter\bm@test@token
1043 % \begin{macro}{\bm@gr@up}
1044 % \changes{v1.0c}{1997/10/09}
1045 % {Extra brace around argument for \cs{over}}
1046 % If faced with a group,
1047 % If we are in math mode, stick it in a |\boldsymbol| like construct
1048 % and then recurse on |\bm@expand|.
1049 % Otherwise just use |\bfseries\boldmath|.
1050 % The actual test is deferred till `run time'.
1051 % Here and elsewhere could deal with the inner list with an inner call
1052 % to |\bm|, but that doesn't seem to gain very much, and complicates the
1055 % |#1| is either |\boldmath| or |\heavymath|.
1056 % Need to add an extra set of explicit braces around |#2| as otherwise
1057 % the math style commands applied in |\mathchoice| might only apply
1058 % to the first half of an |\over| construction.
1061 \bm@add{{\bm@gr@@p#1{{#2}}}}}
1065 % \begin{macro}{\bm@gr@@p}
1066 % |#1| is either |\boldmath| or |\heavymath|.
1070 \bm@mchoice#1{#2}{#2}{#2}{#2}%
1077 % \begin{macro}{\bm@test@token}
1078 % If not facing a |{ }| group then test to see what we have.
1079 % Basic idea: Trap |\mathchardef| tokens, character tokens, and calls to
1080 % |\mathchar|, |\mathaccent|, etc, and change the \emph{math-group}
1081 % (fam) to point at the bold version.
1082 % Other things just copy straight over to the command being built.
1083 % (Anything inside a |\mathop| or similar will end up being made bold
1084 % as the |\mathop| will be copied over, but its argument will be made
1085 % bold by the group code above.
1087 \def\bm@test@token#1{%
1091 % Stop here. Note that it is vital that the terminating token
1092 % is non-expandable and defined, rather than the usual \LaTeX\
1093 % terminators |\@nil| or |\@@|. (Worse still would be a `quark'
1094 % like |docstrip|'s |\qStop|.)
1099 % |\bm@mathchoice| uses macro arguments, so need to make the tail
1100 % recursion explicit here. All the other cases recurse by way of
1101 % |\afterassignment| which means all the trailing |\fi| are eaten
1102 % while making the assignment.
1104 \else\ifx#1\mathchoice
1105 \let\bm@next\bm@mathchoice
1108 % The main point: Find these expressions, and change the mathgroup.
1110 \else\ifx#1\mathchar
1111 \afterassignment\bm@mathchar\count@
1112 \else\ifx#1\mathaccent
1113 \afterassignment\bm@mathaccent\count@
1114 \else\ifx#1\delimiter
1115 \afterassignment\bm@delimiter\count@
1117 \afterassignment\bm@radical\count@
1120 % Need to trap spaces otherwise digits will get turned to bold
1122 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
1125 \bm@register#1{\muskip\z@}%
1127 \bm@register#1\skip@
1129 \bm@register#1\count@
1132 % \changes{v1.0f}{1998/12/10}
1133 % {Add possibility to copy brace group unmodified. tools/2917}
1134 % |\vcopy| is a flag to copy the next group unchanged to the
1142 \else\ifcat\noexpand#1\relax
1144 % Other command, look if it's a mathchardef token (otherwise just add
1146 % \changes{v1.2a}{2016/02/27}
1147 % {Additional quotes for testing \cs{Umathchar}}
1149 \xdef\meaning@{\meaning#1}%
1150 \expandafter\bm@mchar@test\meaning@""""\@nil#1%
1152 % \changes{v1.0d}{1997/11/15}
1153 % {New active \cs{mathcode} code.}
1155 % If it is of catcode 11 or 12, get its mathcode.
1156 % If that is |"8000| replace the token by its active version, and then
1157 % let bm expansion look again at the character. Being really active
1158 % this time, it will expand away (probably).
1160 % If the previous token was |\left| or |\right|, get the delcode
1161 % instead of the mathcode.
1163 \else\ifcat.\ifcat a#1.\else#1\fi
1164 \count@\mathcode`#1\relax
1165 \ifnum\count@=\mathcode`\'%
1166 \begingroup\uccode`\~`#1\uppercase{\endgroup
1167 \def\bm@next{\bm@expand~}}%
1169 \ifx\bm@previous\left
1170 \count@\delcode`#1\relax
1178 % And final possibility:
1179 % a character token of catcode other than 11 or 12.
1182 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1188 % \begin{macro}{\bm@define}
1189 % \changes{v0.08}{1996/12/18}
1190 % {Defined commands now always robust}
1191 % End code for |\bmdefine|. Define the given command name to the
1192 % robust form of the accumulated code.
1194 % If |\bm@command| is equal to |\@gtempa| then it is a macro whose
1195 % expansion is a single call to |\mathchar|, so that can be optimised
1196 % with a |\mathchardef|.
1200 \ifx\bm@command\@gtempa
1201 \def\mathchar{\global\mathchardef#1}%
1205 % Rather than simply |\let#1\bm@command|, make the defined command
1206 % robust. |\bm@first| is normally empty, but might be something like
1207 % |\DOTSI| which needs to be lifted to the top level, in front
1208 % of any |\protect| because of the lookahead mechanism used
1209 % in the \textsf{amsmath} package.
1211 \toks@\expandafter{\bm@command}%
1212 \xdef#1{\bm@first\noexpand\bm@protect\noexpand#1{\the\toks@}}%
1219 % \begin{macro}{\bm@protect}
1220 % \changes{v0.08}{1996/12/18}
1222 % Commands defined by |\bmdefine| re-insert themselves
1223 % if protection is enabled.
1226 \ifx\protect\@typeset@protect
1227 \expandafter\@firstofone
1229 \protect#1\expandafter\@gobble
1234 % \begin{macro}{\bm@mchoice}
1235 % |\boldsymbol|, more or less.
1236 % |#1| is either |\boldmath| or |\heavymath|.
1238 \def\bm@mchoice#1#2#3#4#5{%
1239 \mathchoice{\hbox{#1$\displaystyle\m@th#2$}}%
1240 {\hbox{#1$\textstyle\m@th#3$}}%
1241 {\hbox{#1$\scriptstyle\m@th#4$}}%
1242 {\hbox{#1$\scriptscriptstyle\m@th#5$}}}
1246 % \begin{macro}{\bm@m@thchoice}
1247 % Action if you find a |\mathchoice|. Add the bold version to
1248 % |\bm@command| then recurse.
1250 % |#1| is either |\boldmath| or |\heavymath|.
1252 \def\bm@m@thchoice#1#2#3#4#5{%
1253 \bm@add{\bm@mchoice#1{#2}{#3}{#4}{#5}}}
1257 % \begin{macro}{\bm@register}
1258 % \changes{v0.07}{1996/12/14}
1260 % Combined code for setting up |\bm@r@gister| with the correct
1263 \def\bm@register#1#2{%
1264 \def\@tempa{#1\the#2}%
1265 \afterassignment\bm@r@gister#2}
1269 % \begin{macro}{\bm@r@gister}
1270 % \changes{v0.06}{1996/12/12}
1271 % {Support \cs{mskip}}
1272 % \changes{v0.07}{1996/12/14}
1273 % {Combine all register macros}
1274 % |\mkern| itself would transfer to |\bm@command| without any special
1275 % test, but any explicit dimension following would be converted to
1276 % |\mathchar|. So trap this and grab the muskip as a muskip.
1277 % This is used in |\iiint|. |\penalty| was needed for the
1278 % AMS version of |\colon|, and so do most of the others as well.
1281 \bm@xadd{\@tempa\space}}
1286 % \begin{macro}{\bm@mathchar}
1287 % \changes{v0.10}{1997/01/04}
1288 % {Modify to use \cs{boldmath} or \cs{pmb} if needed.}
1289 % Change the family (math group) of a mathcode and then
1290 % use the modified code with |\mathchar|. If there is no
1291 % suitable bold font in the current math version, use the original
1292 % unmodified mathcode, but switch to |\boldmath| (if there is a bold
1293 % font there) or use `poor man's bold'. Note that these other
1294 % possibilities are only possible here, not for the otherwise similar
1295 % code for |\delimiter| or |\mathaccent|, as those commands
1296 % must work with fonts from the same math version.
1298 % Finally recurse down the list.
1305 \let\@tempa\bm@group
1308 % |\bm@changefam| will isolate the math group from the mathcode
1309 % and look up the offset in the current table.
1314 % If the mathcode has changed, then just add the new |\mathchar|
1315 % (saving |\@gtempa| allows |\bmdefine| to optimise this to a
1316 % mathchardef if it turns out to be the only symbol in the argument).
1318 \ifnum\count@>\@tempcntb
1322 \ifx\bm@command\@empty
1323 \xdef\@gtempa{\mathchar\the\count@\space}%
1325 \bm@xadd{\mathchar\the\count@\space}%
1329 % Otherwise grab the math class from the math code
1330 % and add that (locally zapping |\bm@expand| as we don't want
1331 % to recurse at this point).
1335 \let\bm@expand\relax
1339 % |\@tempa| will be |\bm@group| (which applies |\boldmath| and
1340 % |\mathchoice|) unless it was changed by |\bm@changefam| to |\bm@pmb|
1341 % (which applies a `poor man's bold' construction in a |\mathchoice|).
1344 \noexpand\@tempa{\mathchar\the\count@\space}}%
1350 % \begin{macro}{\bm@umathchar}
1351 % \changes{v1.2a}{2016/02/27}
1353 % Version of \verb|\bm@mathchar| for \verb|\Umathchar|, this is easier
1354 % as no need to take apart the number, the match class and fam are provided
1355 % as distinct arguments.
1357 \def\bm@umathchar#1#2#3{%
1363 \advance\@tempcnta\count@
1365 \bm@xadd{\Umathchar#1\space
1366 \the\@tempcnta\space\space
1371 % \begin{macro}{\bm@pmb}
1372 % \changes{v0.10}{1997/01/04}
1374 % Add a poor man's bold construction to the list being built.
1377 \bm@add{\bm@pmb@{#1}}}
1381 % \begin{macro}{\bm@pmb@}
1382 % \changes{v0.10}{1997/01/04}
1384 % |\pmb| variant. (See \TeX{}Book, or AMS \textsf{amsbsy} package).
1385 % This one takes a bit more care to use smaller offsets in subscripts.
1388 \setbox\tw@\hbox{$\m@th\mkern.4mu$}%
1390 \bm@pmb@@\displaystyle\@empty{#1}%
1391 \bm@pmb@@\textstyle\@empty{#1}%
1392 \bm@pmb@@\scriptstyle\defaultscriptratio{#1}%
1393 \bm@pmb@@\scriptscriptstyle\defaultscriptscriptratio{#1}}}
1397 % \begin{macro}{\bm@pmb@@}
1398 % \changes{v0.10}{1997/01/04}
1400 % Helper macro. Box |#3| and set it three times in the style |#1|,
1401 % offset by an amount reduced by the ratio specified in |#2|.
1403 \def\bm@pmb@@#1#2#3{{%
1404 \setbox\z@\hbox{$\m@th#1#3$}%
1408 \raise1.5\dimen@\rlap{\copy\z@}%
1414 % \begin{macro}{\bm@class}
1415 % \changes{v0.10}{1997/01/04}
1417 % Convert a numeric math class back to a math class command.
1418 % |\mathord| is omitted in class $0$ and $7$ to save space and so
1419 % things work out right in constructions such as |x^a| where
1420 % |x^\mathord{a}| would not work.
1435 % \begin{macro}{\bm@add}
1436 % \changes{v0.07}{1996/12/14}
1438 % A version of |\g@addto@macro| that internally uses a |\begingroup|
1439 % rather than a brace group\footnote{This bug is fixed in the \LaTeX\
1440 % kernel of 1996/12/01}, to save creating a mathord.
1442 % As need to redefine it anyway, save some tokens by making
1443 % it specific to |\bm@command|, and to execute |\bm@expand|
1444 % to continue the loop.
1448 \toks@\expandafter{\bm@command#1}%
1449 \xdef\bm@command{\the\toks@}%
1455 % \begin{macro}{\bm@xadd}
1456 % An |\xdef| version of |\bm@add|.
1460 \toks@\expandafter{\bm@command}%
1461 \xdef\bm@command{\the\toks@#1}%
1467 % \begin{macro}{\bm@mathaccent}
1468 % \changes{v1.0e}{1997/11/21}
1469 % {Use bm on argument group, as spotted on c.t.t.}
1470 % |\mathaccent| version of |\bm@mathchar|.
1472 \def\bm@mathaccent{%
1475 % The next four lines were added a v1.0e. Without them |\bm{\hat{A}}|
1476 % makes the accent bold using |\bm| but the group |{A}| is made bold
1477 % via a |\mathchoice| construction as for any other group, as |\bm|
1478 % does not attempt to parse inside brace groups. While that produces
1479 % something acceptable for lower case letters, it produces
1480 % $\bm{\hat{{A}}}$ which is not too good. The braces may simply be
1482 % |\bm{\hat A}| would work, producing $\bm{\hat A}$, however I did not
1483 % want to document such a restriction, so now modify bm so that such
1484 % brace groups are handled gracefully.
1486 % It would be possible to locally make mathaccents take an argument
1487 % during the bm look-ahead, so the brace groups would then vanish
1488 % during expansion, however I would then need to explicitly skip past
1489 % \meta{filler} and also make sure that the end of parse token
1490 % was not gobbled in marginal cases like |$\bm\hat$|.
1492 % So instead do the following which gets rid of \meta{filler}
1493 % with a redefinition of |\relax|, and just locally changes
1494 % |\bm@group| so that instead of doing a |\mathchoice| it simply adds
1495 % |\bgroup| and |\egroup| around the tokens, and lets bm modify the
1496 % tokens of the `argument'. This means that |\bm{\hat{A}}| now produces
1498 % \mathaccent 29790 \bgroup \mathchar 30017 \egroup
1500 % The inner math list is a single mathchar, and so \TeX\ will not box
1501 % it, and the math accent will correctly position, taking into account
1502 % the skewchar information.
1504 % As the normal bm lookahead is used, it is automatic that the parse
1505 % will end without trying to go past |\bm@end|.
1507 % One disadvantage is that the group will mean that |\bm@previous|
1508 % will not be correctly updated. However that is only used for
1509 % delimiter checking, so can not matter here.
1512 \def\bm@group##1{\endgroup\bm@xadd{\bgroup}##1\egroup}%
1513 \def\bm@test@token{\endgroup\bm@test@token}%
1518 \bm@xadd{\mathaccent\the\count@\space}}
1522 % \begin{macro}{\bm@delimiter}
1523 % \changes{v1.0d}{1997/11/15}
1524 % {Support \cs{left}. null delimiter.}
1525 % Change both families (math groups) of a delcode and then
1526 % use the modified code with |\delimiter|. Don't change code `0'
1527 % as that denotes a null delimiter.
1534 \bm@xadd{\delimiter\the\count@\space}}%
1538 % \begin{macro}{\bm@radical}
1539 % Same for |\radical|.
1544 \bm@xadd{\radical\the\count@\space}}%
1548 % \begin{macro}{\bm@mchar@}
1549 % Catcode 12 |\mathchar|, for |\ifx| tests.
1551 \edef\bm@mchar@{\meaning\mathchar}
1555 % \begin{macro}{\bm@umchar@}
1556 % \changes{v1.2a}{2016/02/27}
1558 % Catcode 12 |\Umathchar|, for |\ifx| tests.
1560 \edef\bm@umchar@{\string\U\expandafter\@gobble\meaning\mathchar}
1564 % \begin{macro}{\bm@mchar@test}
1565 % Test if the |\meaning| starts with |\mathchar|. If it does, grab the
1566 % value into |\count@| and call |\bm@mathchar|, else just copy the
1567 % command into the accumulated tokens.
1568 % |#1|, |#2|, |#3| are all |\meaning| produced tokens, or `dummy tokens'
1569 % added at the time this is called. |#4| is the original token, in case
1570 % decide not to use the |\meaning|.
1571 % \changes{v1.2a}{2016/02/27}
1572 % {Additional arguments added}
1574 \def\bm@mchar@test#1"#2"#3"#4"#5\@nil#6{%
1576 \ifx\meaning@\bm@mchar@
1581 % Test for \verb|\Umathchar|.
1583 \ifx\meaning@\bm@umchar@
1584 \bm@umathchar{"#2}{"#3}{"#4}%
1587 % Some other command: copy it straight over. If it is the first thing
1588 % added, and it is a |\relax| token, save it in |\bm@first| for use
1591 \ifx\bm@previous\@empty
1602 % \begin{macro}{\bm@changefam}
1603 % \changes{v0.10}{1997/01/04}
1604 % {Rewrite for new \cs{bm@table} system}
1605 % Pull out one specified hex digit and passes
1606 % it to |\bm@modify| to change. argument is empty normally but |000| to
1607 % access the second math group in a delimiter code.
1609 \def\bm@changefam#1{%
1611 \divide\@tempcnta"1000#1 %
1612 \multiply\@tempcnta"1000#1 %
1613 \advance\@tempcnta-\count@
1614 \divide\@tempcnta-"100#1 %
1616 % Having isolated the required math group (fam), look up
1617 % the offset in the current table.
1621 % If the offset is $-1$, keep |\count@| unchanged, but set |\@tempa|
1622 % to use poor man's bold. Otherwise increment |\count@| to change the
1623 % math group specified.
1625 \ifnum\@tempcnta=\m@ne
1628 \multiply\@tempcnta"100#1 %
1629 \advance\count@\@tempcnta
1634 % \begin{macro}{\bm@prime}
1635 % \changes{v1.0d}{1997/11/15}
1637 % Support |'|. Earlier versions did not make the prime bold in a'.
1639 % |\bm{a''}| will now produce (with the normal encodings)
1642 % \bm@prime \mathchar 1584 \relax
1643 % \bm@prime \mathchar 1584 \relax
1645 % So |\bm@prime| does essentially the same as the active definition of
1646 % |'|, which is to start a superscript group then keep adding |\prime|
1647 % for each |'| (or |\bm@prime|) following. Here modified to grab a
1648 % |\relax| delimited argument and use that instead of |\prime|.
1649 % |\bm@prime| is locally |\let| to |'| so the |\ifx| tests in |\pr@m@s|
1650 % don't need changing.
1652 \def\bm@prime{^\bgroup
1654 \def\prim@s##1\relax{##1\futurelet\@let@token\pr@m@s}%
1659 % \begin{macro}{\boldsymbol}
1660 % \changes{v1.0b}{1997/04/14}
1662 % \begin{macro}{\heavysymbol}
1663 % Finally, to ease conversion of documents between this package and
1664 % the \textsf{amsbsy} package: