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 2017
26 %% David Carlisle Frank Mittelbach
28 %% Development of this package was commissioned by Y&Y Inc.
34 %<package>\NeedsTeXFormat{LaTeX2e}
35 %<package>\ProvidesPackage{bm}
36 %<driver>\ProvidesFile{bm.drv}
38 % \ProvidesFile{bm.dtx}
39 [2017/01/16 v1.2c Bold Symbol Support (DPC/FMi)]
43 \documentclass{ltxdoc}
52 % \GetFileInfo{bm.dtx}
54 % \title{The \textsf{bm} package\thanks{This file
55 % has version number \fileversion, last
56 % revised \filedate.}\ \thanks{Development of this package
57 % was commissioned by Y\&Y.}}
60 % \author{David Carlisle with support by Frank Mittelbach}
61 % \MaintainedByLaTeXTeam{tools}
64 % \section{Introduction}
66 % This package defines commands to access bold math
67 % symbols. The basic command is |\bm| which may be used to make the
68 % math expression in its argument be typeset using bold fonts.
70 % The syntax of |\bm| is:\\
71 % |\bm|\marg{math expression}\\
72 % So |$\alpha \not= \bm{\alpha}$| produces $\alpha \not= \bm{\alpha}$.
74 % |\bm| goes to some trouble to preserve the spacing, so that for
75 % instance |\bm<| is a bold $\bm<$ but with the correct |\mathrel|
76 % spacing that \TeX\ gives to $<$. The calculations that \TeX\ needs to
77 % do for |\bm| can be quite involved and so a definition form is
80 % |\DeclareBoldMathCommand|%^^A
81 % \oarg{math version}\marg{cmd}\marg{math expression}
83 % Defines |\cmd| to be the bold form of the math expression.
84 % The \meta{math version} defaults to `bold' (i.e., |\boldmath|).
86 % For relatively simple expressions, the resulting definitions are very
87 % efficient, for instance after:\\
88 % |\DeclareBoldMathCommand\balpha{\alpha}|\\
89 % |\balpha| is a single `mathchardef' token producing a bold alpha,
90 % and so is just as fast to execute as |\alpha|.
92 % The above command is mainly intended for use in packages.
93 % For occasional use in \LaTeX\ documents, and for compatibility
94 % with the plain \TeX\ support for the mathtime fonts, a `user-level'
95 % version, |\bmdefine| is provided that is equivalent to:\\
96 % |\DeclareBoldMathCommand[bold]|.
98 % If there is a `heavy' math version defined (usually accessed by a
99 % user-command |\heavymath|) then a similar command |\hm|
100 % is defined which access these `ultra bold' fonts. Currently this is
101 % probably only useful with the `mathtime plus' font collection.
102 % Definitions of commands that use these fonts may be made by
103 % specifying the optional argument `heavy' to |\DeclareBoldMathCommand|.
104 % Again an abbreviation, |\hmdefine|, is provided, equivalent to:\\
105 % |\DeclareBoldMathCommand[heavy]|.
107 % The command names (but not the implementation) are taken from Michael
108 % Spivak's macros to support the mathtime fonts for plain \TeX. In those
109 % original macros, the syntax for |\bmdefine| was
110 % |\bmdefine\balpha{\bm\alpha}| (with a nested |\bm|). This syntax also
111 % works with this package.
113 % \section{Font allocation}
114 % In order to access bold fonts in the simplest and quickest possible
115 % manner, the package normally allocates symbol fonts for bold
116 % (and possibly heavy) fonts into the `normal' math version.
117 % By default it allocates at most four fonts for |\bm| and at most
118 % three fonts for |\hm|. This means that if the mathtime plus font set
119 % is being used, seven additional symbol fonts will be used, in addition
120 % to the basic four that \LaTeX\ already declares. The mathtime
121 % package also declares an extra symbol font, bringing the total to
122 % twelve. The maximum number of symbol \emph{and} math alphabet fonts
123 % that can be used in a math version is sixteen. So the above allocation
124 % scheme does not leave room for many extra math symbols (such as the
125 % AMS symbols) or math alphabets (such as |\mathit|).
127 % Before loading the \textsf{bm} package you may define |\bmmax|
128 % and |\hmmax| to be suitable values, for instance you may want
129 % to set |\newcommand\hmmax{0}| if you will not be using |\hm|
130 % much, but you do have a heavy math version defined.
132 % Even if |\bmmax| is set to zero, |\bm| will still access the correct
133 % bold fonts (by accessing the fonts via |\boldmath|) but this method
134 % is slower, and does not work with delimiters. Delimiters can only be
135 % made bold if the bold font has been allocated.
137 % Conversely if you have a non standard font set that makes available
138 % extra math delimiters and accents in bold and medium weights you may
139 % want to \emph{increase} |\bmmax| so that fonts are allocated for
143 % In most cases this package should work in a fairly self explanatory
144 % way, but there are some things that might not be obvious.
146 % \subsection{Interaction with Math Alphabet Commands}
148 % As mentioned above, |\bm| goes to some trouble to try to make a
149 % command that is just like its argument, but using a bold font.
150 % This does not always produce the effect that you might expect.
153 % $2 \mathrm{g \bm{g}}$
155 % $4 \mathrm{{g} \bm{{g}}}$
156 % $5 \mathrm{g} \bm{\mathrm{g}}$
158 % produces the following:
161 % $2 \mathrm{g \bm{g}}$
163 % $4 \mathrm{{g} \bm{{g}}}$
164 % $5 \mathrm{g} \bm{\mathrm{g}}$
166 % In math mode `g' is effectively a command that produces the letter `g'
167 % from the `letters' alphabet, unless a Math Alphabet command is in
168 % effect, in which case the `g' comes from the specified alphabet.
169 % |\bm{g}| makes an equivalent command, but which defaults to a bold
170 % letter alphabet. So in the first example |\bm{g}| is bold math italic,
171 % but in the second example the |\mathrm| applies to both |g| and
172 % |\bm{g}| in the same way, and so they are both roman.
174 % |\bm| only inspects the `top level' definition of a command, for more
175 % complicated expressions, and anything inside a |{ }| group, |\bm|
176 % forces bold fonts by essentially the same (slow) technique used by the
177 % AMS |\boldsymbol| command (but |\bm| still takes more care of the
178 % spacing). So the third example produces identical output to the first
179 % (but \TeX\ takes more time producing it).
181 % In the fourth example the |\mathrm{\bm{g}}| is essentially
182 % equivalent to |\mathrm{\mbox{\boldmath$g$}}|. Currently math alphabet
183 % settings are not passed down to `nested' math lists, and so in this
184 % example, the |\mathrm| has no effect, and a bold math italic $\bm g$
187 % Similarly the last example is equivalent to
188 % |$\mbox{\boldmath$\mathrm{g}$}}| and so in this case, one obtains a
189 % bold roman \textbf{g}.
191 % \subsection{Delimiters}
192 % \TeX\ can treat character tokens in two\footnote
193 % {Well more than two really.}
194 % ways. If there is a preceding
195 % |\left| or |\right| it can treat them as a delimiter, otherwise it can
196 % treat them as a standard character. For example |\left<\right>|
197 % produces $\left<\right>$, which is totally different from |<>|, which
200 % \TeX\ can only do this for character tokens. Commands such as
201 % |\langle| do not act in this way. This means that |\bm| has to decide
202 % whether to treat a character as a delimiter or not. The rule it uses
203 % is, it makes a delimiter command for a character if the previous
204 % token in the argument was |\left| or |\right|. So |\left\bm{<}| does
205 % not work, but |\bm{\left<}| does.
207 % \subsection{Command Arguments}
209 % Normally if a command takes arguments the full command, including
210 % any arguments, should be included in |\bm|.
212 % So |\bm{\overbrace{abc}}| (producing \smash{$\bm{\overbrace{abc}}$})
214 % |\bm{\overbrace}{abc}|. If you do not include all the arguments you
215 % will typically get the error message:\\
216 % |Runaway argument?|\\
217 % |! Forbidden control sequence found while scanning use of|
220 % However commands defined in terms of the \TeX\ accent and
221 % radical primitives \emph{may} be used without their arguments.
222 % So |\bm{\hat}{a}| produces $\bm{\hat}{a}$, a bold accent over a
223 % non-bold $a$ (compare $\hat{a}$)
224 % whereas |\bm{\hat{a}}| makes both the $a$ and the accent bold,
226 % Similarly, although the \LaTeX\ command |\sqrt| must be used with its
227 % arguments, |\sqrtsign| may be used as in |\bm\sqrtsign{abc}| to
228 % produce $\bm\sqrtsign{abc}$ rather than $\sqrtsign{abc}$ or
229 % $\bm{\sqrtsign{abc}}$
231 % If you really need to make a command with arguments use bold fonts
232 % without making all of the arguments bold, you can explicitly
233 % reset the math version in the argument, eg:\\
234 % $\begin{array}{ccc}
235 % |\sqrt{xyz}|&|\bm{\sqrt{xyz}}|&|\bm{\sqrt{\mbox{\unboldmath$xyz$}}}|\\
236 % \sqrt{xyz}& \bm{\sqrt{xyz}}& \bm{\sqrt{\mbox{\unboldmath$xyz$}}}
239 % \subsection{Bold fonts}
240 % This package interrogates the font allocations of the bold and heavy
241 % math versions, to determine which bold fonts are available.
242 % This means that it is best to load the package \emph{after}
243 % any packages that define new symbol fonts, or (like the
244 % \textsf{mathtime} package) completely change the symbol font
247 % If no bold font appears to be available for a particular symbol,
248 % |\bm| will use `poor man's bold' that is, overprinting the same
249 % character in slightly offset
250 % positions to give an appearance of boldness.
252 % In the standard Computer Modern font set, there is no bold
253 % `large symbols' font. In the `mathptm' and (standard) mathtime
254 % font sets there are no bold math fonts. In the `mathtime plus'
255 % font set there are suitable fonts for bold and heavy math setting,
256 % and so |\bm| and |\hm| work well. Similarly in the basic Lucida
257 % New Math font set there are no bold math fonts, so |\bm| will
258 % use `poor man's bold. However if the Lucida Expert set is used,
259 % Then |\bm| will detect, and use the bold math fonts that are
262 % As discussed above, one may set |\bmmax| higher or lower than its
263 % default value of four to control the font allocation system. Finer
264 % control may be gained by explicitly declaring bold symbol fonts.
265 % Suppose you have a symbol font `xyz' that is available in medium and
266 % bold weights, then you would declare this to \LaTeX\ via:\\
267 % |\DeclareSymbolFont{extras} {OMS}{xyz}{m}{n}|\\
268 % |\SetSymbolFont{extras}{bold}{OMS}{xyz}{bx}{n}|\\
269 % At this point the symbols will be available in the normal math
270 % version, and their bold variants in |\boldmath|. If you also
272 % |\DeclareSymbolFont{boldextras}{OMS}{xyz}{bx}{n}|\\
273 % That is, declare a symbol font whose name is formed by prefixing
274 % `bold' (or `heavy') to an existing symbol font, then |\bm| (or
275 % |\hm|) will use this font directly, rather then accessing the
276 % `extras' symbol font via |\boldmath|.
278 % \subsection{Strange failures}
279 % In order to get the correct spacing, |\bm| has to `investigate' the
280 % definition of the commands in its argument. It is possible that
281 % some strange constructions could `confuse' this investigation.
282 % If this happens then \LaTeX\ will almost certainly stop with a strange
283 % error. This should not happen with any of the math symbols
284 % defined in the base \LaTeX\ or AMS distributions, or any commands
285 % defined in terms of those symbols using normal \LaTeX\ math
286 % constructs. However if some command does fail to work inside |\bm|
287 % you should always be able to surround it with an extra set of braces
288 % |\bm{{\cmd}}| rather than |\bm{\cmd}|. |\bm| will not then attempt
289 % to set the correct spacing, so you may need to set it explicitly,
290 % for instance, for a relation, |\bm{\mathrel{\cmd}}|.
292 % \subsection{AMS package \textsf{amsbsy}}
293 % The |\bm| command shares some functionality with the |\boldsymbol|
294 % command from the AMS \LaTeX\ collection. To aid in moving documents
295 % between these two packages, this package defines |\boldsymbol| and
296 % |\heavysymbol| as alternative names for |\bm| and |\hm|.
300 % \section{Implementation}
302 % \changes{v0.01}{1996/12/01}
303 % {Initial DPC attempt,
304 % remove all assumptions about mathtime encoding}
305 % \changes{v0.02}{1996/12/02}
306 % {Add \cs{mathchoice} stuff}
307 % \changes{v0.03}{1996/12/12}
308 % {Completely reimplement (again). Add \cs{bmdefine}.}
309 % \changes{v0.04}{1996/12/12}
310 % {Add \cs{hm} and support for special active mathcode.}
311 % \changes{v0.05}{1996/12/12}
313 % \changes{v0.99}{1997/01/16}
314 % {First public version}
315 % \changes{v1.0a}{1997/02/14}
316 % {First ctan version (same as 0.99b)}
317 % \changes{v1.0b}{1997/04/14}
318 % {Add to tools bundle.}
319 % \changes{v1.0g}{1999/07/05}
320 % {minor doc changes latex/3058}
324 % The commands |\bm| and |\hm| work by defining a number of additional
325 % symbol fonts corresponding to the standard ones
326 % `operators', `letters', `symbols', and `largesymbols'.
327 % The names for these symbols fonts are produced by prefixing the usual
328 % name with `bold' or `heavy'.
330 % For maximum flexibility we get the font definitions by looking in the
331 % corresponding math versions, i.e., into |\mv@bold| and if defined into
337 % \changes{v0.09}{1996/12/19}
338 % {Always define \cs{bm} even if no bold math}
340 % \begin{macro}{\bm@table}
341 % \changes{v0.10}{1997/01/04}
343 % \changes{v0.12}{1997/01/10}
344 % {Ensure do not allocate too many math group slots.}
345 % \changes{v0.99a}{1997/01/17}
346 % {Let \cs{hm} use font allocated for \cs{bm}}
347 % \changes{v0.99b}{1997/01/19}
348 % {Restore NFSS internals}
349 % \begin{macro}{\bm@boldtable}
350 % \begin{macro}{\bm@heavytable}
351 % The table, |\bm@table|, (which is locally |\let| to either the bold
352 % or heavy version) defines, for each \meta{math group} (\meta{fam}),
353 % the `offset' to the bold version of the specified symbol font.
354 % If there is no bold symbol font defined, the offset will be
355 % set to zero if there is a bold font assigned to this slot in the
356 % bold math version, or $-1$ if the font in the bold math version
357 % is the same as the one in the normal math version. In this case
358 % a `poor man's bold' system of overprinting is used to achieve
359 % boldness where this is possible.
361 % The settings are made at the time this package is read, and so
362 % it is best to load this package late, after any font loading packages
363 % have been loaded. Symbol fonts loaded after this package will get the
364 % offset of zero, so they will still be made bold by |\bm| as long as an
365 % appropriate font is declared for the bold math version.
367 % |\bm@boldtable| and |\bm@heavytable| are set up using very similar
368 % code, which is temporarily defined to |\bm|, to save wasting a csname.
369 % Similarly |\bm@pmb|\ldots\ (which will be defined later) are used
372 % The general plan. Run through the fonts allocated to the normal math
373 % version. Ignore \meta{math alphabet} allocations\footnote{For now?}
374 % but for each math symbol font, look in the math version specified by
375 % |#1| (bold or heavy). If the font there is different, then allocate
376 % a new symbol font in the normal math version to access that bold font
377 % and place the numerical difference between the allocations of the bold
378 % and normal font into the table being built (|\bm@boldtable|, if |#1|
379 % is bold). If the symbol allocation is already greater than |\bmmax|
380 % do not allocate a new symbol font, but rather set the offset in the
381 % table to zero. |\bm| will detect this, and use |\boldmath| on its
382 % argument in this case, so the bold font will be accessed but more
383 % slowly than using a direct access to a bold font allocated into the
384 % normal math version. If the font allocated in the bold math version is
385 % the same as the font in the normal math version, set the offset to
386 % $-1$, which is a flag value that causes |\bm| to use `poor man's bold'
387 % overprinting three copies of the symbol, offset slightly to give an
388 % appearance of boldness.
390 % Fonts containing delimiters and math accents \emph{must} be allocated
391 % into the normal math version if they are to be used with |\bm|. (In
392 % these cases |\bm| will produce the normal weight symbol, rather than
393 % using |\boldmath| or poor man's bold.)
398 % This code can not work inside a group, as that would affect any symbol
399 % font allocations, so instead use some scratch macros to save and
400 % restore the definitions of commands we need to change locally.
402 \let\bm@pmb\install@mathalphabet
403 \let\bm@pmb@\getanddefine@fonts
405 \edef\bm@general{\f@encoding/\f@family/\f@series/\f@shape/\f@size}%
408 % |#2| specifies the maximum number of fonts to allocate
409 % (either |\bmmax| or |\hmmax|). First check against |\count18|
410 % that there are that many slots left, and if not reduce accordingly.
411 % Put the resulting value in |\@tempcnta|.
415 \advance\count@-\@tempcnta
416 \advance\count@15\relax
418 \advance\@tempcnta\count@
421 % Make |\or| non-expandable, so we can build an |\ifcase| bit-by-bit
422 % in a sequence of |\edef|s.
427 % Initialise the table (to |\@gobble| to remove the first |\or|).
429 \expandafter\let\csname bm@#1table\endcsname\@gobble
432 % Helper macro that adds the next entry to the table being built.
435 \expandafter\xdef\csname bm@#1table\endcsname{%
436 \csname bm@#1table\endcsname\or##1}}%
439 % Each symbol font is recorded in the math version list by a sequence
441 % | \getanddefine@fonts \symsymbols \OMS/cmsy/m/n|\\
442 % Where the first argument is a chardef token carrying the number
443 % allocated (to symbols, in this example), and the second argument is a
444 % csname whose \emph{name} denotes the font used.
445 % So locally redefine |\getanddefine@fonts| to compare |#2| with
446 % the name in the appropriate slot in the bold math version.
448 \def\getanddefine@fonts##1##2{%
453 \def\@tempb####1##1####2####3\@nil{\def\@tempb{####2}}%
457 \expandafter\expandafter\expandafter
458 \@tempb\csname mv@#1\endcsname\@nil
461 % Now |\@tempa| and |\@tempb| contain the names of the fonts allocated
462 % to this slot in the two math versions.
466 % If they are the same, set this offset to $-1$, as a flag to use
472 % Else make a new name by adjoining |#1| to the name of the symbol font
473 % eg, |\symboldsymbols| to match |\symsymbols|. If that font has already
474 % been allocated, or if |\@tempcnta| is positive so we can allocate a
475 % new slot for this font, then the table will be
476 % set with the offset between the two fonts. otherwise set the offset to
477 % zero (so |\boldmath| will be used to access the font).
479 \edef\@tempa{sym#1\expandafter\@gobblefour\string##1}%
481 \expandafter\ifx\csname\@tempa\endcsname\relax
493 % If the font is not yet allocated, allocate it now, using
494 % an internal hack into |\DeclareMathSymbolFont|.
496 % However before allocating it look in the bold math version
497 % to see if it is the same, and if so use that. For example
498 % with Mathtime the `operators' font in the `heavy' math version
499 % is different from that in `normal', but it is the same as
500 % the font in `bold' (Times bold). So rather than allocate
501 % |\symheavyoperators| just set it equal to |\symboldoperators|.
503 \expandafter\ifx\csname\@tempa\endcsname\relax
506 \edef\@tempb{\endgroup
508 \expandafter\string\@tempb}%
514 \csname symbold\expandafter\@gobblefour\string##1\endcsname
517 % If no font has been allocated for |\bm| yet, then allocate it now.
519 \expandafter\new@mathgroup\csname\@tempa\endcsname
520 \expandafter\new@symbolfont\csname\@tempa\endcsname
521 \f@encoding\f@family\f@series\f@shape
523 % Reduce by one the number of fonts we can still allocate.
525 \advance\@tempcnta\m@ne
531 % Else do a similar look into the bold mathgroup.
532 % Use |\bm@expand| as a scratch macro to save on string space.
534 \def\bm@expand####1##1####2####3\@nil{\def\bm@expand{####2}}%
535 \expandafter\expandafter\expandafter
536 \bm@expand\csname mv@bold\endcsname\@nil
540 \ifx\bm@expand\@tempb
542 % If the font just found (in heavy) is the same as the font in bold
543 % use the slot (in normal) previously allocated for the bold font.
546 \expandafter\let\csname\@tempa\expandafter\endcsname
547 \csname symbold\expandafter
548 \@gobblefour\string##1\endcsname
554 % Otherwise allocate a new slot for it.
556 \expandafter\new@mathgroup\csname\@tempa\endcsname
557 \expandafter\new@symbolfont\csname\@tempa\endcsname
558 \f@encoding\f@family\f@series\f@shape
559 \advance\@tempcnta\m@ne
570 % If the font has been allocated already, use the existing allocation.
573 {Symbol font \@tempa\space already defined.\MessageBreak
577 % Whether the font has just been allocated, or whether it was previously
578 % allocated, compute the offset and add it to the table.
580 \count@\csname\@tempa\endcsname
582 \bm@define{\the\count@\relax}%
587 % The math version list also contains information about math alphabet
588 % commands, but we want to ignore those here, so \ldots
590 \let\install@mathalphabet\@gobbletwo
593 % Having set up the local definitions, execute the list for the normal
599 % So now the offsets are all entered into the table, separated by
601 % Finish off the definition by making this an |\ifcase|. Add a default
602 % value of zero, so that any symbol fonts declared later will also
603 % work, as long as a bold version is assigned to the bold math version.
605 \expandafter\xdef\csname bm@#1table\endcsname{%
606 \noexpand\ifcase\@tempcnta
607 \csname bm@#1table\endcsname
613 % Put things back as they were.
615 \expandafter\split@name\bm@general\@nil
616 \let\install@mathalphabet\bm@pmb
617 \let\getanddefine@fonts\bm@pmb@
624 % \begin{macro}{\bmmax}
625 % To save declaring too many symbol fonts, do not auto-declare
626 % any more than |\bmmax| bold symbol fonts into the normal math
627 % version. Any bold fonts not so allocated will be accessed via
628 % |\boldmath| which is slower and doesn't work for delimiters
629 % and accents. It may be set in the preamble with |\newcommand|
630 % but use |\chardef| here for a slight efficiency gain.
632 % If this is set to a higher value before this
633 % package is loaded, keep that value.
635 \ifx\bmmax\@undefined
640 % If there is no bold math version, It is very easy to set up
641 % the table, no need to use all the tricky code above.
642 % Also, at the end of the package redefine the internal macro
643 % that |\bm| uses to call |\boldmath|, to use poor man's bold
646 \ifx\mv@bold\@undefined
647 \def\bm@boldtable{\m@ne}
653 % Otherwise use the definition of |\bm| above to set up |\bm@boldtable|
654 % by comparing the fonts available in the normal and bold math versions.
659 % \begin{macro}{\mathbf}
660 % As the bold font has been defined as a symbol font, make |\mathbf|
661 % access that rather than have it allocate a new math group for the
662 % same font. (Just in case there were no free slots wrap this
665 \@ifundefined{symboldoperators}
667 {\DeclareSymbolFontAlphabet\mathbf{boldoperators}}
676 % \begin{macro}{\hmmax}
678 % Same for heavy (but default to three this time (enough for mathtime
679 % plus, as no heavy operators font).
681 \ifx\hmmax\@undefined
686 % Similarly if there is a heavy math version, set up |\bm@heavytable|.
687 % (If there is no heavy math version, do nothing here, as |\hm| will be
688 % set to |\bm| later, once that is defined.)
690 \ifx\mv@heavy\@undefined
698 % \begin{macro}{\bm@general}
699 % \changes{v1.0d}{1997/11/15}
700 % {extra code to support prime lookahead and breqn}
701 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
703 % |\bm| is pretty much |\bmdefine\bm@command| followed by executing
704 % |\bm@command|. It would in principle be possible to execute the
705 % emboldened tokens directly, rather than building up a macro first,
706 % but (as I learned the hard way) it's difficult to do this in the midst
707 % of all these nested |\if| constructs.
708 % First extract the central bit of code for |\hm| |\bm| |\hmdefine| and
709 % |\bmdefine|. Note that in the case of the inline versions they take
710 % an argument and brace it, rather than relying on |\bm@general| to pick
711 % up the argument. This makes the code robust with respect to premature
716 \@firstofone{\endgroup
717 \def\bm@general#1#2#3#4#5{%
720 % \changes{v1.0d}{1997/11/15}
721 % {make nested \cs{bm} vanish completely, not leave a brace group}
722 % First locally disable |\bm| and |\hm|, as they would mess things
723 % up terribly, and the original Spivak versions used the syntax
724 % |\bmdefine\balpha{\bm\alpha}|.
729 % Now initialise the commands used to save the tokens constructed.
731 \global\let\bm@command\@empty
732 \let\@let@token\@empty
734 % As we want to expand the macros to look at their definition
735 % turn off protection. Otherwise the |\protect| will be carried over
736 % and apply to the wrong token, eg |{|.
739 \let\@typeset@protect\@empty
741 % Set up either bold or heavy
743 \def\bm@mathchoice{\bm@m@thchoice#1}%
744 \def\bm@group{\bm@gr@up#1}%
747 % Make sure |\left| and |\right| are really non expandable,
748 % and not |\ifx| equal to anything else.
749 % \changes{v1.0d}{1997/11/15}
750 % {make sure \cs{left} is primitive}
752 \let\left\holdinginserts
754 % These three save on the number of |\ifx| tests below.
755 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
761 % Definition of |'| locally modified so as not to use |\futurelet|
762 % in the look ahead, but to make the |\prime| available at the top level
763 % to be made bold, or heavy or whatever.
764 % |'| is locally active for this definition.
765 % \changes{v1.0d}{1997/11/15}
769 \def'{\bm@prime\prime\relax}%
771 % For optional argument commands. This expandable version of
772 % |\@ifnextchar| is not 100\% safe, but works for |\sqrt| unless
773 % you put something really strange in the arguments.
774 % \changes{v0.11}{1997/01/06}
775 % {\cs{@ifnextchar} made safe.}
777 \def\@ifnextchar##1##2##3##4{%
779 \expandafter\@firstoftwo
781 \expandafter\@secondoftwo
785 % For Vladimir Volovich\ldots
786 % \changes{v1.0f}{1998/12/10}
787 % {Errors and warnings made safe. tools/2917}
789 \def\GenericWarning##1##2{%
790 \unvcopy{\GenericWarning{##1}{##2}}}%
791 \def\GenericError##1##2##3##4{%
792 \unvcopy{\GenericError{##1}{##2}{##3}{##4}}}%
794 % For AMS definitions.
799 \global\let\bm@first\@empty
801 % For AMS version of |\sqrt|: don't expand just wrap in brace group
802 % so that it can be made bold in a safe but slow way. Do the same for
803 % internal accent command
804 % \changes{v1.1b}{2003/10/05}{AMS \cs{sqrt} not working}
806 % \changes{v1.1c}{2004/02/26}{\cs{accentV} made safe (pr/3625)}
807 % Code for AMS accent allows bm to be used (just) with accent
808 % but stops the nested accents stacking correctly, this can be
809 % corrected by using an extra brace group as usual.
810 % |\bm{{\hat{\hat{F}}}}|
812 \ifx\uproot@\undefined\else
813 \def\root##1\of##2{{\root##1\of{##2}}}%
815 \def\mathaccentV##1{\mathaccent"\accentclass@}%
817 % For breqn definitions.
819 \let\@ifnext\@ifnextchar
820 \let\measure@lhs\copy
823 \let \after@open\copy
824 \let \after@close\copy
826 % Make sure things like |\pounds| take the `math branch' even
827 % in |\bmdefine| (which is not executed in math mode).
831 % We have to ensure that the math alphabets have definitions that
832 % correspond the the ``bold'' math version we are going to switch
833 % to. As these definitions are globally assigned when a math
834 % version is changed it is likely that right now we have those of
835 % the normal math version active. Argument |#3| holds either
836 % |\mv@bold| or |\mv@heavy| and we execute that after redefining
837 % |\install@mathalphabet| and |\getanddefine@fonts| suitably.
838 % The definitions are reverted back to their original the moment
839 % the scanning is done
840 % \changes{v1.0h}{2002/11/22}{Get math alphabets right (pr/3476)}
842 \let\install@mathalphabet\def
843 \let\getanddefine@fonts\@gobbletwo
846 % The last redefinition just makes |\mathit| type commands re-insert
847 % themselves (more or less) as if they are allowed to expand
848 % they die horribly if the expansions are put into |\mathchoice|
849 % and so executed more than once.
851 \def\select@group##1##2##3##4{{%
853 \def\use@mathgroup##1##2##3{{%
854 \protect\use@mathgroup##1{##2}{##3}}}%
857 % So now start looking at the argument.
858 % \changes{v0.10}{1997/01/04}
865 % Finally outside the group either execute |\bm@command| (for |\bm|)
866 % or save its definition (for |\bmdefine|).
870 % End of the |\@firstofone| above, and the scope of the active |'|.
877 % \changes{v1.0d}{1997/11/15}
878 % {Make \cs{bm} grab its argument even when protected}
879 % Set up the bold (rather than heavy) version, and run |\bm@command|
880 % right at the end, to execute the emboldened argument.
881 % The argument is grabbed by the top level function, and explicitly
882 % braced, so that |\bm| works even if the braces are omitted round
883 % its argument in a `moving argument'.
884 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
886 \DeclareRobustCommand\bm{%
887 \bm@general\boldmath\bm@boldtable\mv@bold\bm@command}
888 \protected@edef\bm#1{\bm{#1}}
892 % \begin{macro}{\DeclareBoldMathCommand}
893 % \changes{v0.07}{1996/12/14}
895 % \begin{macro}{\bm@declare}
896 % \changes{v0.07}{1996/12/14}
898 % |DeclareBoldMathCommand|%^^A
899 % \oarg{mathversion}\marg{command}\marg{math expression}\\
900 % looks like |\bm| except at the end the specified command is
901 % globally defined to be |\bm@command|.
902 % The \meta{mathversion} defaults to `bold'.
904 \def\DeclareBoldMathCommand{\@testopt\bm@declare{bold}}
907 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
909 \def\bm@declare[#1]#2{%
910 \expandafter\bm@general
911 \csname #1math\expandafter\endcsname
912 \csname bm@#1table\expandafter\endcsname
913 \csname mv@#1\endcsname
919 % \begin{macro}{\bmdefine}
920 % |\bmdefine| Shorthand for |\DeclareBoldMathCommand[bold]|.
922 % |\bm| is empty within the definition, so that either\\
923 % |\bmdefine\balpha{\bm\alpha}| or |\bmdefine\balpha{\alpha}| \\
924 % may be used. (The former just for compatibility with the original
925 % version for plain \TeX).
927 \def\bmdefine{\DeclareBoldMathCommand[bold]}
932 % \changes{v1.0d}{1997/11/15}
933 % {Make \cs{hm} grab its argument even when protected}
934 % \begin{macro}{\hmdefine}
935 % Same again for |\hm|.
937 \ifx\mv@heavy\@undefined
940 % If there is no heavy math version defined, let |\hm| be defined
941 % as |\bm|. Currently there is no warning given, perhaps there should
942 % be, or even an error?
945 \let\heavymath\boldmath
946 \let\bm@heavytable\bm@boldtable
953 % Otherwise define |\hm| and |\hmdefine| in direct analogy with the
955 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
957 \DeclareRobustCommand\hm{%
958 \bm@general\heavymath\bm@heavytable\mv@heavy\bm@command}
959 \protected@edef\hm#1{\hm{#1}}
963 \def\hmdefine{\DeclareBoldMathCommand[heavy]}
972 % \begin{macro}{\bm@end}
973 % \changes{v0.10}{1997/01/04}
975 % Normally speaking |\outer| declarations should be avoided at all
976 % costs. (\LaTeX\ redefines all of plain \TeX's allocation macros
977 % to be non-outer.) However this is one place where it seems like a
978 % good idea. If a command taking an argument is put in |\bm| without
979 % its argument, then the |\@@end| terminating token would be taken as
980 % the argument, and so the rest of the paragraph would be gobbled up
981 % and the \LaTeX\ would die horribly. So make the internal terminating
982 % token |\outer|. (The actual test for termination is made against
983 % |\@@end| not |\bm@end| as this macro will be expanded by the look-ahead
986 \outer\def\bm@end{\@@end}
990 % \begin{macro}{\bm@expand}
991 % \changes{v0.11}{1997/01/06}
993 % \begin{macro}{\bm@exp@nd}
994 % \changes{v0.11}{1997/01/06}
996 % |\afterassignment| trick to fully expand the following tokens until
997 % the first non-expandable token is revealed. This may discard a space
998 % token (which is what \TeX\ is looking for) but that doesn't matter in
999 % math mode. The expansion lookahead is done twice in case any stray
1000 % space tokens have crept in.\footnote{The need for this was noticed
1001 % while testing \cs{sqrt}. The definition of \cs{root} inherited from
1002 % plain \TeX\ has an anomalous space token, that is normally harmless
1003 % (just wastes memory), but which killed earlier versions of this
1006 \def\bm@expand{\afterassignment\bm@exp@nd\count@`\a}
1010 \def\bm@exp@nd{\afterassignment\bm@test\count@`\a}
1015 % \begin{macro}{\bm@test}
1016 % Normally we will grab the non-expandable token as a macro argument
1017 % but better check it is not |{| first. Save the previous token
1018 % so we can check later if it was |\left|, in which case use the delcode
1019 % rather than the mathcode if the current token is a character.
1022 \let\bm@previous\@let@token
1023 \futurelet\@let@token\bm@test@}
1027 % \begin{macro}{\bm@test@}
1028 % If looking at a single token, switch to |\bm@test@token|, else if
1029 % looking at a |{ }| group, grab the whole group with |\bm@group|.
1030 % A |\bgroup| token will take the wrong branch here (currently not
1034 \ifx\@let@token\bgroup
1035 \expandafter\bm@group
1037 \expandafter\bm@test@token
1042 % \begin{macro}{\bm@gr@up}
1043 % \changes{v1.0c}{1997/10/09}
1044 % {Extra brace around argument for \cs{over}}
1045 % If faced with a group,
1046 % If we are in math mode, stick it in a |\boldsymbol| like construct
1047 % and then recurse on |\bm@expand|.
1048 % Otherwise just use |\bfseries\boldmath|.
1049 % The actual test is deferred till `run time'.
1050 % Here and elsewhere could deal with the inner list with an inner call
1051 % to |\bm|, but that doesn't seem to gain very much, and complicates the
1054 % |#1| is either |\boldmath| or |\heavymath|.
1055 % Need to add an extra set of explicit braces around |#2| as otherwise
1056 % the math style commands applied in |\mathchoice| might only apply
1057 % to the first half of an |\over| construction.
1060 \bm@add{{\bm@gr@@p#1{{#2}}}}}
1064 % \begin{macro}{\bm@gr@@p}
1065 % |#1| is either |\boldmath| or |\heavymath|.
1069 \bm@mchoice#1{#2}{#2}{#2}{#2}%
1076 % \begin{macro}{\bm@test@token}
1077 % If not facing a |{ }| group then test to see what we have.
1078 % Basic idea: Trap |\mathchardef| tokens, character tokens, and calls to
1079 % |\mathchar|, |\mathaccent|, etc, and change the \emph{math-group}
1080 % (fam) to point at the bold version.
1081 % Other things just copy straight over to the command being built.
1082 % (Anything inside a |\mathop| or similar will end up being made bold
1083 % as the |\mathop| will be copied over, but its argument will be made
1084 % bold by the group code above.
1086 \def\bm@test@token#1{%
1090 % Stop here. Note that it is vital that the terminating token
1091 % is non-expandable and defined, rather than the usual \LaTeX\
1092 % terminators |\@nil| or |\@@|. (Worse still would be a `quark'
1093 % like |docstrip|'s |\qStop|.)
1098 % |\bm@mathchoice| uses macro arguments, so need to make the tail
1099 % recursion explicit here. All the other cases recurse by way of
1100 % |\afterassignment| which means all the trailing |\fi| are eaten
1101 % while making the assignment.
1103 \else\ifx#1\mathchoice
1104 \let\bm@next\bm@mathchoice
1107 % The main point: Find these expressions, and change the mathgroup.
1109 \else\ifx#1\mathchar
1110 \afterassignment\bm@mathchar\count@
1111 \else\ifx#1\mathaccent
1112 \afterassignment\bm@mathaccent\count@
1113 \else\ifx#1\delimiter
1114 \afterassignment\bm@delimiter\count@
1116 \afterassignment\bm@radical\count@
1119 % Need to trap spaces otherwise digits will get turned to bold
1121 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
1124 \bm@register#1{\muskip\z@}%
1126 \bm@register#1\skip@
1128 \bm@register#1\count@
1131 % \changes{v1.0f}{1998/12/10}
1132 % {Add possibility to copy brace group unmodified. tools/2917}
1133 % |\vcopy| is a flag to copy the next group unchanged to the
1141 \else\ifcat\noexpand#1\relax
1143 % Other command, look if it's a mathchardef token (otherwise just add
1145 % \changes{v1.2a}{2016/02/27}
1146 % {Additional quotes for testing \cs{Umathchar}}
1148 \xdef\meaning@{\meaning#1}%
1149 \expandafter\bm@mchar@test\meaning@""""\@nil#1%
1151 % \changes{v1.0d}{1997/11/15}
1152 % {New active \cs{mathcode} code.}
1154 % If it is of catcode 11 or 12, get its mathcode.
1155 % If that is |"8000| replace the token by its active version, and then
1156 % let bm expansion look again at the character. Being really active
1157 % this time, it will expand away (probably).
1159 % If the previous token was |\left| or |\right|, get the delcode
1160 % instead of the mathcode.
1162 \else\ifcat.\ifcat a#1.\else#1\fi
1163 \count@\mathcode`#1\relax
1164 \ifnum\count@=\mathcode`\'%
1165 \begingroup\uccode`\~`#1\uppercase{\endgroup
1166 \def\bm@next{\bm@expand~}}%
1168 \ifx\bm@previous\left
1169 \count@\delcode`#1\relax
1173 % \changes{v1.2b}{2016/07/07}
1174 % {Check for mathchar values being reported as if via \cs{Umathchar}}
1175 % Here we need to check for LuaTeX merging mathchar values with Umathchar.
1178 \Umathcharnumdef\@tempa\count@
1179 \xdef\meaning@{\meaning\@tempa}%
1180 \expandafter\bm@mchar@test\meaning@""""\@nil\@tempa
1191 % And final possibility:
1192 % a character token of catcode other than 11 or 12.
1195 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1201 % \begin{macro}{\bm@define}
1202 % \changes{v0.08}{1996/12/18}
1203 % {Defined commands now always robust}
1204 % End code for |\bmdefine|. Define the given command name to the
1205 % robust form of the accumulated code.
1207 % If |\bm@command| is equal to |\@gtempa| then it is a macro whose
1208 % expansion is a single call to |\mathchar|, so that can be optimised
1209 % with a |\mathchardef|.
1213 \ifx\bm@command\@gtempa
1214 \def\mathchar{\global\mathchardef#1}%
1218 % Rather than simply |\let#1\bm@command|, make the defined command
1219 % robust. |\bm@first| is normally empty, but might be something like
1220 % |\DOTSI| which needs to be lifted to the top level, in front
1221 % of any |\protect| because of the lookahead mechanism used
1222 % in the \textsf{amsmath} package.
1224 \toks@\expandafter{\bm@command}%
1225 \xdef#1{\bm@first\noexpand\bm@protect\noexpand#1{\the\toks@}}%
1232 % \begin{macro}{\bm@protect}
1233 % \changes{v0.08}{1996/12/18}
1235 % Commands defined by |\bmdefine| re-insert themselves
1236 % if protection is enabled.
1239 \ifx\protect\@typeset@protect
1240 \expandafter\@firstofone
1242 \protect#1\expandafter\@gobble
1247 % \begin{macro}{\bm@mchoice}
1248 % |\boldsymbol|, more or less.
1249 % |#1| is either |\boldmath| or |\heavymath|.
1251 \def\bm@mchoice#1#2#3#4#5{%
1252 \mathchoice{\hbox{#1$\displaystyle\m@th#2$}}%
1253 {\hbox{#1$\textstyle\m@th#3$}}%
1254 {\hbox{#1$\scriptstyle\m@th#4$}}%
1255 {\hbox{#1$\scriptscriptstyle\m@th#5$}}}
1259 % \begin{macro}{\bm@m@thchoice}
1260 % Action if you find a |\mathchoice|. Add the bold version to
1261 % |\bm@command| then recurse.
1263 % |#1| is either |\boldmath| or |\heavymath|.
1265 \def\bm@m@thchoice#1#2#3#4#5{%
1266 \bm@add{\bm@mchoice#1{#2}{#3}{#4}{#5}}}
1270 % \begin{macro}{\bm@register}
1271 % \changes{v0.07}{1996/12/14}
1273 % Combined code for setting up |\bm@r@gister| with the correct
1276 \def\bm@register#1#2{%
1277 \def\@tempa{#1\the#2}%
1278 \afterassignment\bm@r@gister#2}
1282 % \begin{macro}{\bm@r@gister}
1283 % \changes{v0.06}{1996/12/12}
1284 % {Support \cs{mskip}}
1285 % \changes{v0.07}{1996/12/14}
1286 % {Combine all register macros}
1287 % |\mkern| itself would transfer to |\bm@command| without any special
1288 % test, but any explicit dimension following would be converted to
1289 % |\mathchar|. So trap this and grab the muskip as a muskip.
1290 % This is used in |\iiint|. |\penalty| was needed for the
1291 % AMS version of |\colon|, and so do most of the others as well.
1294 \bm@xadd{\@tempa\space}}
1299 % \begin{macro}{\bm@mathchar}
1300 % \changes{v0.10}{1997/01/04}
1301 % {Modify to use \cs{boldmath} or \cs{pmb} if needed.}
1302 % Change the family (math group) of a mathcode and then
1303 % use the modified code with |\mathchar|. If there is no
1304 % suitable bold font in the current math version, use the original
1305 % unmodified mathcode, but switch to |\boldmath| (if there is a bold
1306 % font there) or use `poor man's bold'. Note that these other
1307 % possibilities are only possible here, not for the otherwise similar
1308 % code for |\delimiter| or |\mathaccent|, as those commands
1309 % must work with fonts from the same math version.
1311 % Finally recurse down the list.
1318 \let\@tempa\bm@group
1321 % |\bm@changefam| will isolate the math group from the mathcode
1322 % and look up the offset in the current table.
1327 % If the mathcode has changed, then just add the new |\mathchar|
1328 % (saving |\@gtempa| allows |\bmdefine| to optimise this to a
1329 % mathchardef if it turns out to be the only symbol in the argument).
1331 \ifnum\count@>\@tempcntb
1335 \ifx\bm@command\@empty
1336 \xdef\@gtempa{\mathchar\the\count@\space}%
1338 \bm@xadd{\mathchar\the\count@\space}%
1342 % Otherwise grab the math class from the math code
1343 % and add that (locally zapping |\bm@expand| as we don't want
1344 % to recurse at this point).
1348 \let\bm@expand\relax
1352 % |\@tempa| will be |\bm@group| (which applies |\boldmath| and
1353 % |\mathchoice|) unless it was changed by |\bm@changefam| to |\bm@pmb|
1354 % (which applies a `poor man's bold' construction in a |\mathchoice|).
1357 \noexpand\@tempa{\mathchar\the\count@\space}}%
1363 % \begin{macro}{\bm@umathchar}
1364 % \changes{v1.2a}{2016/02/27}
1366 % \changes{v1.2a}{2017/01/16}
1367 % {Test for zero table entry (\cs{boldmath}) added}
1368 % Version of \verb|\bm@mathchar| for \verb|\Umathchar|, this is easier
1369 % as no need to take apart the number, the match class and fam are provided
1370 % as distinct arguments.
1372 \def\bm@umathchar#1#2#3{%
1376 \bm@gr@up\boldmath{\Umathchar#1 #2 #3 }%
1380 \advance\@tempcnta\count@
1382 \bm@xadd{\Umathchar#1\space
1383 \the\@tempcnta\space\space
1389 % \begin{macro}{\bm@pmb}
1390 % \changes{v0.10}{1997/01/04}
1392 % Add a poor man's bold construction to the list being built.
1395 \bm@add{\bm@pmb@{#1}}}
1399 % \begin{macro}{\bm@pmb@}
1400 % \changes{v0.10}{1997/01/04}
1402 % |\pmb| variant. (See \TeX{}Book, or AMS \textsf{amsbsy} package).
1403 % This one takes a bit more care to use smaller offsets in subscripts.
1406 \setbox\tw@\hbox{$\m@th\mkern.4mu$}%
1408 \bm@pmb@@\displaystyle\@empty{#1}%
1409 \bm@pmb@@\textstyle\@empty{#1}%
1410 \bm@pmb@@\scriptstyle\defaultscriptratio{#1}%
1411 \bm@pmb@@\scriptscriptstyle\defaultscriptscriptratio{#1}}}
1415 % \begin{macro}{\bm@pmb@@}
1416 % \changes{v0.10}{1997/01/04}
1418 % Helper macro. Box |#3| and set it three times in the style |#1|,
1419 % offset by an amount reduced by the ratio specified in |#2|.
1421 \def\bm@pmb@@#1#2#3{{%
1422 \setbox\z@\hbox{$\m@th#1#3$}%
1426 \raise1.5\dimen@\rlap{\copy\z@}%
1432 % \begin{macro}{\bm@class}
1433 % \changes{v0.10}{1997/01/04}
1435 % Convert a numeric math class back to a math class command.
1436 % |\mathord| is omitted in class $0$ and $7$ to save space and so
1437 % things work out right in constructions such as |x^a| where
1438 % |x^\mathord{a}| would not work.
1453 % \begin{macro}{\bm@add}
1454 % \changes{v0.07}{1996/12/14}
1456 % A version of |\g@addto@macro| that internally uses a |\begingroup|
1457 % rather than a brace group\footnote{This bug is fixed in the \LaTeX\
1458 % kernel of 1996/12/01}, to save creating a mathord.
1460 % As need to redefine it anyway, save some tokens by making
1461 % it specific to |\bm@command|, and to execute |\bm@expand|
1462 % to continue the loop.
1466 \toks@\expandafter{\bm@command#1}%
1467 \xdef\bm@command{\the\toks@}%
1473 % \begin{macro}{\bm@xadd}
1474 % An |\xdef| version of |\bm@add|.
1478 \toks@\expandafter{\bm@command}%
1479 \xdef\bm@command{\the\toks@#1}%
1485 % \begin{macro}{\bm@mathaccent}
1486 % \changes{v1.0e}{1997/11/21}
1487 % {Use bm on argument group, as spotted on c.t.t.}
1488 % |\mathaccent| version of |\bm@mathchar|.
1490 \def\bm@mathaccent{%
1493 % The next four lines were added a v1.0e. Without them |\bm{\hat{A}}|
1494 % makes the accent bold using |\bm| but the group |{A}| is made bold
1495 % via a |\mathchoice| construction as for any other group, as |\bm|
1496 % does not attempt to parse inside brace groups. While that produces
1497 % something acceptable for lower case letters, it produces
1498 % $\bm{\hat{{A}}}$ which is not too good. The braces may simply be
1500 % |\bm{\hat A}| would work, producing $\bm{\hat A}$, however I did not
1501 % want to document such a restriction, so now modify bm so that such
1502 % brace groups are handled gracefully.
1504 % It would be possible to locally make mathaccents take an argument
1505 % during the bm look-ahead, so the brace groups would then vanish
1506 % during expansion, however I would then need to explicitly skip past
1507 % \meta{filler} and also make sure that the end of parse token
1508 % was not gobbled in marginal cases like |$\bm\hat$|.
1510 % So instead do the following which gets rid of \meta{filler}
1511 % with a redefinition of |\relax|, and just locally changes
1512 % |\bm@group| so that instead of doing a |\mathchoice| it simply adds
1513 % |\bgroup| and |\egroup| around the tokens, and lets bm modify the
1514 % tokens of the `argument'. This means that |\bm{\hat{A}}| now produces
1516 % \mathaccent 29790 \bgroup \mathchar 30017 \egroup
1518 % The inner math list is a single mathchar, and so \TeX\ will not box
1519 % it, and the math accent will correctly position, taking into account
1520 % the skewchar information.
1522 % As the normal bm lookahead is used, it is automatic that the parse
1523 % will end without trying to go past |\bm@end|.
1525 % One disadvantage is that the group will mean that |\bm@previous|
1526 % will not be correctly updated. However that is only used for
1527 % delimiter checking, so can not matter here.
1530 \def\bm@group##1{\endgroup\bm@xadd{\bgroup}##1\egroup}%
1531 \def\bm@test@token{\endgroup\bm@test@token}%
1536 \bm@xadd{\mathaccent\the\count@\space}}
1540 % \begin{macro}{\bm@delimiter}
1541 % \changes{v1.0d}{1997/11/15}
1542 % {Support \cs{left}. null delimiter.}
1543 % Change both families (math groups) of a delcode and then
1544 % use the modified code with |\delimiter|. Don't change code `0'
1545 % as that denotes a null delimiter.
1552 \bm@xadd{\delimiter\the\count@\space}}%
1556 % \begin{macro}{\bm@radical}
1557 % Same for |\radical|.
1562 \bm@xadd{\radical\the\count@\space}}%
1566 % \begin{macro}{\bm@mchar@}
1567 % Catcode 12 |\mathchar|, for |\ifx| tests.
1569 \edef\bm@mchar@{\meaning\mathchar}
1573 % \begin{macro}{\bm@umchar@}
1574 % \changes{v1.2a}{2016/02/27}
1576 % Catcode 12 |\Umathchar|, for |\ifx| tests.
1578 \edef\bm@umchar@{\string\U\expandafter\@gobble\meaning\mathchar}
1582 % \begin{macro}{\bm@mchar@test}
1583 % Test if the |\meaning| starts with |\mathchar|. If it does, grab the
1584 % value into |\count@| and call |\bm@mathchar|, else just copy the
1585 % command into the accumulated tokens.
1586 % |#1|, |#2|, |#3| are all |\meaning| produced tokens, or `dummy tokens'
1587 % added at the time this is called. |#4| is the original token, in case
1588 % decide not to use the |\meaning|.
1589 % \changes{v1.2a}{2016/02/27}
1590 % {Additional arguments added}
1592 \def\bm@mchar@test#1"#2"#3"#4"#5\@nil#6{%
1594 \ifx\meaning@\bm@mchar@
1599 % Test for \verb|\Umathchar|.
1601 \ifx\meaning@\bm@umchar@
1602 \bm@umathchar{"#2}{"#3}{"#4}%
1605 % Some other command: copy it straight over. If it is the first thing
1606 % added, and it is a |\relax| token, save it in |\bm@first| for use
1609 \ifx\bm@previous\@empty
1620 % \begin{macro}{\bm@changefam}
1621 % \changes{v0.10}{1997/01/04}
1622 % {Rewrite for new \cs{bm@table} system}
1623 % Pull out one specified hex digit and passes
1624 % it to |\bm@modify| to change. argument is empty normally but |000| to
1625 % access the second math group in a delimiter code.
1627 \def\bm@changefam#1{%
1629 \divide\@tempcnta"1000#1 %
1630 \multiply\@tempcnta"1000#1 %
1631 \advance\@tempcnta-\count@
1632 \divide\@tempcnta-"100#1 %
1634 % Having isolated the required math group (fam), look up
1635 % the offset in the current table.
1639 % If the offset is $-1$, keep |\count@| unchanged, but set |\@tempa|
1640 % to use poor man's bold. Otherwise increment |\count@| to change the
1641 % math group specified.
1643 \ifnum\@tempcnta=\m@ne
1646 \multiply\@tempcnta"100#1 %
1647 \advance\count@\@tempcnta
1652 % \begin{macro}{\bm@prime}
1653 % \changes{v1.0d}{1997/11/15}
1655 % Support |'|. Earlier versions did not make the prime bold in a'.
1657 % |\bm{a''}| will now produce (with the normal encodings)
1660 % \bm@prime \mathchar 1584 \relax
1661 % \bm@prime \mathchar 1584 \relax
1663 % So |\bm@prime| does essentially the same as the active definition of
1664 % |'|, which is to start a superscript group then keep adding |\prime|
1665 % for each |'| (or |\bm@prime|) following. Here modified to grab a
1666 % |\relax| delimited argument and use that instead of |\prime|.
1667 % |\bm@prime| is locally |\let| to |'| so the |\ifx| tests in |\pr@m@s|
1668 % don't need changing.
1670 \def\bm@prime{^\bgroup
1672 \def\prim@s##1\relax{##1\futurelet\@let@token\pr@m@s}%
1677 % \begin{macro}{\boldsymbol}
1678 % \changes{v1.0b}{1997/04/14}
1680 % \begin{macro}{\heavysymbol}
1681 % Finally, to ease conversion of documents between this package and
1682 % the \textsf{amsbsy} package: