Debian Codegraph @

texmf-dist/source/latex/tools/bm.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 %
5 % The LaTeX Project and any individual authors listed elsewhere
6 % in this file.
7 %
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
10 %
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 % https://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.
18 %
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
21 %
22 % \fi
23 %
24 % \iffalse
25 %% Copyright 1996 1997 1998 1999 2002 2003 2004 2016 2017 2019 2021 2022 2023 2025
26 %% David Carlisle Frank Mittelbach
27 %%
28 %% Development of this package was commissioned by Y&Y Inc.
29 %
30 %
31 %<*dtx>
32 \ProvidesFile{bm.dtx}
33 %</dtx>
34 %<package>\NeedsTeXFormat{LaTeX2e}
35 %<package>\ProvidesPackage{bm}
36 %<driver>\ProvidesFile{bm.drv}
37 % \fi
38 % \ProvidesFile{bm.dtx}
39 [2025/10/21 v1.2g Bold Symbol Support (DPC/FMi)]
40 %
41 % \iffalse
42 %<*driver>
43 \documentclass{ltxdoc}
44 \usepackage{bm}
45 \begin{document}
46 \DocInput{bm.dtx}
47 \end{document}
48 %</driver>
49 % \fi
50 %
51 %
52 % \GetFileInfo{bm.dtx}
53 %
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.}}
58 %
59 % \date{\filedate}
60 % \author{David Carlisle with support by Frank Mittelbach}
61 % \MaintainedByLaTeXTeam{tools}
62 % \maketitle
63 %
64 % \section{Introduction}
65 %
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.
69 %
70 % The syntax of |\bm| is:\\
71 % |\bm|\marg{math expression}\\
72 % So |$\alpha \not= \bm{\alpha}$| produces $\alpha \not= \bm{\alpha}$.
73 %
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
78 % provided.
79 %
80 % |\DeclareBoldMathCommand|%^^A
81 % \oarg{math version}\marg{cmd}\marg{math expression}
82 %
83 % Defines |\cmd| to be the bold form of the math expression.
84 % The \meta{math version} defaults to `bold' (i.e., |\boldmath|).
85 %
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|.
91 %
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]|.
97 %
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 accesses 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]|.
106 %
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.
112 %
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|).
126 %
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.
131 %
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.
136 %
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
140 % your font set.
141 %
142 % \section{Features}
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.
145 %
146 % \subsection{Interaction with Math Alphabet Commands}
147 %
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.
151 %\begin{verbatim}
152 % $1 g \bm{g}$
153 % $2 \mathrm{g \bm{g}}$
154 % $3 {g} \bm{{g}}$
155 % $4 \mathrm{{g} \bm{{g}}}$
156 % $5 \mathrm{g} \bm{\mathrm{g}}$
157 %\end{verbatim}
158 % produces the following:
159 % \begin{flushleft}
160 % $1 g \bm{g}$
161 % $2 \mathrm{g \bm{g}}$
162 % $3 {g} \bm{{g}}$
163 % $4 \mathrm{{g} \bm{{g}}}$
164 % $5 \mathrm{g} \bm{\mathrm{g}}$
165 % \end{flushleft}
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.
173 %
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).
180 %
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$
185 % is obtained.
186 %
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}.
190 %
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
198 % produces $<>$.
199 %
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.
206 %
207 % \subsection{Command Arguments}
208 %
209 % Normally if a command takes arguments the full command, including
210 % any arguments, should be included in |\bm|.
211 %
212 % So |\bm{\overbrace{abc}}| (producing \smash{$\bm{\overbrace{abc}}$}),
213 % not
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|
218 % \texttt{\ldots}
219 %
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,
225 % $\bm{\hat{a}}$.
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}}$
230 %
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$}}}
237 % \end{array}$
238 %
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
245 % allocations.
246 %
247 % If no bold font appears to be available for a particular symbol,
248 % |\bm| will use `poor man's bold', which will overprint the same
249 % character in slightly offset
250 % positions to give an appearance of boldness.
251 %
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
260 % available.
261 %
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
271 % declare:\\
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|.
277 %
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}}|.
291 %
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|.
297 %
298 % \section{Package Options}
299 %
300 % \subsection{Logging level}
301 % As described above, the \textsf{bm} package has to interrogate the font
302 % setup to try to find matching bold fonts for each font used in the |normal|
303 % math version. This can fail in various ways as there may be no bold font
304 % or a bold font may be found but no room is available to allocate it.
305 % The options |warn|, |info| and |silent| control whether messages that \textsf{bm}
306 % produces are sent to the terminal, or just to the log file (the default) or suppressed.
307 %
308 % \subsection{Poor Man's Bold}
309 % As discussed above, by default, if no real bold font is available, \textsf{bm} will use
310 % ``poor man's bold''. That is, over-printing the character with slight offsets.
311 % Since version 1.2e, the package now warns if a font is set up to use this over-printing and
312 % the package option |nopbm| is available which prevents its use in which case |\bm| will
313 % use the non-bold for characters from the affected font.
314 %
315 % \MaybeStop{}
316 %
317 % \section{Implementation}
318 %
319 % \changes{v0.01}{1996/12/01}
320 % {Initial DPC attempt,
321 % remove all assumptions about mathtime encoding}
322 % \changes{v0.02}{1996/12/02}
323 % {Add \cs{mathchoice} stuff}
324 % \changes{v0.03}{1996/12/12}
325 % {Completely reimplement (again). Add \cs{bmdefine}.}
326 % \changes{v0.04}{1996/12/12}
327 % {Add \cs{hm} and support for special active mathcode.}
328 % \changes{v0.05}{1996/12/12}
329 % {Assorted fixes}
330 % \changes{v0.99}{1997/01/16}
331 % {First public version}
332 % \changes{v1.0a}{1997/02/14}
333 % {First ctan version (same as 0.99b)}
334 % \changes{v1.0b}{1997/04/14}
335 % {Add to tools bundle.}
336 % \changes{v1.0g}{1999/07/05}
337 % {minor doc changes latex/3058}
338 %
339 %
340 % \changes{v1.2e}{2021/04/25}
341 % {Package options gh/71}
342 % Options to use or not use poor man's bold (over-printing)
343 % and level of warning messages.
344 % \begin{macrocode}
345 %<*package>
346 \DeclareOption{nopmb}{\let\bm@pmb@\@firstofone}
347 \DeclareOption{warn}{\def\bm@info{\PackageWarningNoLine{bm}}}
348 \DeclareOption{info}{\def\bm@info#1{\PackageInfo{bm}{#1\@gobble}}}
349 \DeclareOption{silent}{\let\bm@info\@gobble}
350 \ExecuteOptions{info}
351 \ProcessOptions\relax
352 %</package>
353 % \end{macrocode}
354 %
355 % The commands |\bm| and |\hm| work by defining a number of additional
356 % symbol fonts corresponding to the standard ones
357 % `operators', `letters', `symbols', and `largesymbols'.
358 % The names for these symbols fonts are produced by prefixing the usual
359 % name with `bold' or `heavy'.
360 %
361 % For maximum flexibility we get the font definitions by looking in the
362 % corresponding math versions, i.e., into |\mv@bold| and if defined into
363 % |\mv@heavy|.
364 %
365 % \begin{macrocode}
366 %<*package>
367 % \end{macrocode}
368 % \changes{v0.09}{1996/12/19}
369 % {Always define \cs{bm} even if no bold math}
370 %
371 % \begin{macro}{\bm@table}
372 % \changes{v0.10}{1997/01/04}
373 % {Macro added}
374 % \changes{v0.12}{1997/01/10}
375 % {Ensure do not allocate too many math group slots.}
376 % \changes{v0.99a}{1997/01/17}
377 % {Let \cs{hm} use font allocated for \cs{bm}}
378 % \changes{v0.99b}{1997/01/19}
379 % {Restore NFSS internals}
380 % \begin{macro}{\bm@boldtable}
381 % \begin{macro}{\bm@heavytable}
382 % The table, |\bm@table|, (which is locally |\let| to either the bold
383 % or heavy version) defines, for each \meta{math group} (\meta{fam}),
384 % the `offset' to the bold version of the specified symbol font.
385 % If there is no bold symbol font defined, the offset will be
386 % set to zero if there is a bold font assigned to this slot in the
387 % bold math version, or $-1$ if the font in the bold math version
388 % is the same as the one in the normal math version. In this case
389 % a `poor man's bold' system of overprinting is used to achieve
390 % boldness where this is possible.
391 %
392 % The settings are made at the time this package is read, and so
393 % it is best to load this package late, after any font loading packages
394 % have been loaded. Symbol fonts loaded after this package will get the
395 % offset of zero, so they will still be made bold by |\bm| as long as an
396 % appropriate font is declared for the bold math version.
397 %
398 % |\bm@boldtable| and |\bm@heavytable| are set up using very similar
399 % code, which is temporarily defined to |\bm|, to save wasting a csname.
400 % Similarly |\bm@pmb|\ldots\ (which will be defined later) are used
401 % as scratch macros.
402 % (This csname saving no longer used, setup command is |\bm@setup|, not |\bm|.)
403 %
404 % The general plan. Run through the fonts allocated to the normal math
405 % version. Ignore \meta{math alphabet} allocations\footnote{For now?}
406 % but for each math symbol font, look in the math version specified by
407 % |#1| (bold or heavy). If the font there is different, then allocate
408 % a new symbol font in the normal math version to access that bold font
409 % and place the numerical difference between the allocations of the bold
410 % and normal font into the table being built (|\bm@boldtable|, if |#1|
411 % is bold). If the symbol allocation is already greater than |\bmmax|
412 % do not allocate a new symbol font, but rather set the offset in the
413 % table to zero. |\bm| will detect this, and use |\boldmath| on its
414 % argument in this case, so the bold font will be accessed but more
415 % slowly than using a direct access to a bold font allocated into the
416 % normal math version. If the font allocated in the bold math version is
417 % the same as the font in the normal math version, set the offset to
418 % $-1$, which is a flag value that causes |\bm| to use `poor man's bold'
419 % overprinting three copies of the symbol, offset slightly to give an
420 % appearance of boldness.
421 %
422 % Fonts containing delimiters and math accents \emph{must} be allocated
423 % into the normal math version if they are to be used with |\bm|. (In
424 % these cases |\bm| will produce the normal weight symbol, rather than
425 % using |\boldmath| or poor man's bold.)
426 %
427 % \begin{macrocode}
428 \def\bm@setup#1#2{%
429 % \end{macrocode}
430 % This code can not work inside a group, as that would affect any symbol
431 % font allocations, so instead use some scratch macros to save and
432 % restore the definitions of commands we need to change locally.
433 % \begin{macrocode}
434 \let\bm@install@mathalphabet\install@mathalphabet
435 \let\bm@getanddefine@fonts\getanddefine@fonts
436 \let\bm@or\or
437 \edef\bm@general{\f@encoding/\f@family/\f@series/\f@shape/\f@size}%
438 % \end{macrocode}
439 %
440 % |#2| specifies the maximum number of fonts to allocate
441 % (either |\bmmax| or |\hmmax|). First check against |\count18|
442 % that there are that many slots left, and if not reduce accordingly.
443 % Put the resulting value in |\@tempcnta|.
444 % \begin{macrocode}
445 \@tempcnta#2%
446 \count@-\count18%
447 \advance\count@-\@tempcnta
448 \advance\count@15\relax
449 \ifnum\count@<\z@
450 \advance\@tempcnta\count@
451 \fi
452 % \end{macrocode}
453 % Make |\or| non-expandable, so we can build an |\ifcase| bit-by-bit
454 % in a sequence of |\edef|s.
455 % \begin{macrocode}
456 \let\or\relax
457 % \end{macrocode}
458 %
459 % Initialise the table (to |\@gobble| to remove the first |\or|).
460 % \begin{macrocode}
461 \expandafter\let\csname bm@#1table\endcsname\@gobble
462 % \end{macrocode}
463 %
464 % Helper macro that adds the next entry to the table being built.
465 % \begin{macrocode}
466 \def\bm@define##1{%
467 \expandafter\xdef\csname bm@#1table\endcsname{%
468 \csname bm@#1table\endcsname\or##1}}%
469 % \end{macrocode}
470 %
471 % Each symbol font is recorded in the math version list by a sequence
472 % such as:\\
473 % | \getanddefine@fonts \symsymbols \OMS/cmsy/m/n|\\
474 % Where the first argument is a chardef token carrying the number
475 % allocated (to symbols, in this example), and the second argument is a
476 % csname whose \emph{name} denotes the font used.
477 % So locally redefine |\getanddefine@fonts| to compare |#2| with
478 % the name in the appropriate slot in the bold math version.
479 % \begin{macrocode}
480 \def\getanddefine@fonts##1##2{%
481 \def\@tempa{##2}%
482 % \end{macrocode}
483 %
484 % \begin{macrocode}
485 \def\@tempb####1##1####2####3\@nil{\def\@tempb{####2}}%
486 % \end{macrocode}
487 %
488 % \begin{macrocode}
489 \expandafter\expandafter\expandafter
490 \@tempb\csname mv@#1\endcsname\@nil
491 % \end{macrocode}
492 %
493 % Now |\@tempa| and |\@tempb| contain the names of the fonts allocated
494 % to this slot in the two math versions.
495 % \begin{macrocode}
496 \ifx\@tempa\@tempb
497 % \end{macrocode}
498 % If they are the same, set this offset to $-1$, as a flag to use
499 % poor man's bold.
500 % \changes{v1.2e}{2021/04/25}
501 % {make use of pmb optional and warn about it gh/71}
502 % \begin{macrocode}
503 \bm@define\m@ne
504 \bm@info{No #1 for \string##2%
505 \ifx\bm@pmb@\@firstofone\else, using \string\pmb\fi}%
506 \else
507 % \end{macrocode}
508 % Else make a new name by adjoining |#1| to the name of the symbol font,
509 % eg, |\symboldsymbols| to match |\symsymbols|. If that font has already
510 % been allocated, or if |\@tempcnta| is positive so we can allocate a
511 % new slot for this font, then the table will be
512 % set with the offset between the two fonts. Otherwise set the offset to
513 % zero (so |\boldmath| will be used to access the font).
514 % \begin{macrocode}
515 \edef\@tempa{sym#1\expandafter\@gobblefour\string##1}%
516 \ifnum\@tempcnta<%
517 \expandafter\ifx\csname\@tempa\endcsname\relax
518 \@ne
519 \else
520 \m@ne
521 \fi
522 % \end{macrocode}
523 %
524 % \begin{macrocode}
525 \bm@define\z@
526 \else
527 % \end{macrocode}
528 %
529 % If the font is not yet allocated, allocate it now, using
530 % an internal hack into |\DeclareMathSymbolFont|.
531 %
532 % However before allocating it look in the bold math version
533 % to see if it is the same, and if so use that. For example
534 % with Mathtime the `operators' font in the `heavy' math version
535 % is different from that in `normal', but it is the same as
536 % the font in `bold' (Times bold). So rather than allocate
537 % |\symheavyoperators| just set it equal to |\symboldoperators|.
538 % \begin{macrocode}
539 \expandafter\ifx\csname\@tempa\endcsname\relax
540 \begingroup
541 \escapechar\m@ne
542 \edef\@tempb{\endgroup
543 \noexpand\split@name
544 \expandafter\string\@tempb}%
545 \@tempb/\@nil
546 % \end{macrocode}
547 %
548 % \begin{macrocode}
549 \expandafter\ifx
550 \csname symbold\expandafter\@gobblefour\string##1\endcsname
551 \relax
552 % \end{macrocode}
553 % If no font has been allocated for |\bm| yet, then allocate it now.
554 % \begin{macrocode}
555 \expandafter\new@mathgroup\csname\@tempa\endcsname
556 \expandafter\new@symbolfont\csname\@tempa\endcsname
557 \f@encoding\f@family\f@series\f@shape
558 % \end{macrocode}
559 % Reduce by one the number of fonts we can still allocate.
560 % \begin{macrocode}
561 \advance\@tempcnta\m@ne
562 % \end{macrocode}
563 %
564 % \begin{macrocode}
565 \else
566 % \end{macrocode}
567 % Else do a similar look into the bold mathgroup.
568 % Use |\bm@expand| as a scratch macro to save on string space.
569 % \begin{macrocode}
570 \def\bm@expand####1##1####2####3\@nil{\def\bm@expand{####2}}%
571 \expandafter\expandafter\expandafter
572 \bm@expand\csname mv@bold\endcsname\@nil
573 % \end{macrocode}
574 %
575 % \begin{macrocode}
576 \ifx\bm@expand\@tempb
577 % \end{macrocode}
578 % If the font just found (in heavy) is the same as the font in bold
579 % use the slot (in normal) previously allocated for the bold font.
580 % (That clear?)
581 % \begin{macrocode}
582 \expandafter\let\csname\@tempa\expandafter\endcsname
583 \csname symbold\expandafter
584 \@gobblefour\string##1\endcsname
585 % \end{macrocode}
586 %
587 % \begin{macrocode}
588 \else
589 % \end{macrocode}
590 % Otherwise allocate a new slot for it.
591 % \begin{macrocode}
592 \expandafter\new@mathgroup\csname\@tempa\endcsname
593 \expandafter\new@symbolfont\csname\@tempa\endcsname
594 \f@encoding\f@family\f@series\f@shape
595 \advance\@tempcnta\m@ne
596 % \end{macrocode}
597 %
598 % \begin{macrocode}
599 \fi
600 \fi
601 % \end{macrocode}
602 %
603 % \begin{macrocode}
604 \else
605 % \end{macrocode}
606 % If the font has been allocated already, use the existing allocation.
607 % \begin{macrocode}
608 \bm@info
609 {Symbol font \@tempa\space already defined.\MessageBreak
610 Not overwriting it}%
611 \fi
612 % \end{macrocode}
613 % Whether the font has just been allocated, or whether it was previously
614 % allocated, compute the offset and add it to the table.
615 % \begin{macrocode}
616 \count@\csname\@tempa\endcsname
617 \advance\count@-##1%
618 \bm@define{\the\count@\relax}%
619 \fi
620 \fi}%
621 % \end{macrocode}
622 %
623 % The math version list also contains information about math alphabet
624 % commands, but we want to ignore those here, so \ldots
625 % \begin{macrocode}
626 \let\install@mathalphabet\@gobbletwo
627 % \end{macrocode}
628 %
629 % Having set up the local definitions, execute the list for the normal
630 % math version.
631 % \begin{macrocode}
632 \mv@normal
633 % \end{macrocode}
634 %
635 % So now the offsets are all entered into the table, separated by
636 % |\or|.
637 % Finish off the definition by making this an |\ifcase|. Add a default
638 % value of zero, so that any symbol fonts declared later will also
639 % work, as long as a bold version is assigned to the bold math version.
640 % \begin{macrocode}
641 \expandafter\xdef\csname bm@#1table\endcsname{%
642 \noexpand\ifcase\@tempcnta
643 \csname bm@#1table\endcsname
644 \noexpand\else
645 \z@
646 \noexpand\fi}%
647 % \end{macrocode}
648 %
649 % Put things back as they were.
650 % \begin{macrocode}
651 \expandafter\split@name\bm@general\@nil
652 \let\install@mathalphabet\bm@install@mathalphabet
653 \let\getanddefine@fonts\bm@getanddefine@fonts
654 \let\or\bm@or}
655 % \end{macrocode}
656 % \end{macro}
657 % \end{macro}
658 % \end{macro}
659 %
660 % \begin{macro}{\bmmax}
661 % To save declaring too many symbol fonts, do not auto-declare
662 % any more than |\bmmax| bold symbol fonts into the normal math
663 % version. Any bold fonts not so allocated will be accessed via
664 % |\boldmath| which is slower and doesn't work for delimiters
665 % and accents. It may be set in the preamble with |\newcommand|
666 % but use |\chardef| here for a slight efficiency gain.
667 %
668 % If this is set to a higher value before this
669 % package is loaded, keep that value.
670 % \begin{macrocode}
671 \ifx\bmmax\@undefined
672 \chardef\bmmax=4
673 \fi
674 % \end{macrocode}
675 %
676 % If there is no bold math version, it is very easy to set up
677 % the table since there is no need to use all the tricky code above.
678 % Also, at the end of the package redefine the internal macro
679 % that |\bm| uses to call |\boldmath|, to use poor man's bold
680 % instead.
681 % \begin{macrocode}
682 \ifx\mv@bold\@undefined
683 \def\bm@boldtable{\m@ne}
684 \AtEndOfPackage{%
685 \def\bm@gr@up#1#2{%
686 \bm@install@mathalphabet{#2}}}
687 \else
688 % \end{macrocode}
689 % Otherwise use the definition of |\bm| above to set up |\bm@boldtable|
690 % by comparing the fonts available in the normal and bold math versions.
691 % \begin{macrocode}
692 \bm@setup{bold}\bmmax
693 % \end{macrocode}
694 %
695 % \begin{macro}{\mathbf}
696 % As the bold font has been defined as a symbol font, make |\mathbf|
697 % access that rather than have it allocate a new math group for the
698 % same font. (Just in case there were no free slots wrap this
699 % in an extra test.)
700 % \begin{macrocode}
701 \@ifundefined{symboldoperators}
702 {}
703 {\DeclareSymbolFontAlphabet\mathbf{boldoperators}}
704 % \end{macrocode}
705 % \end{macro}
706 %
707 % \begin{macrocode}
708 \fi
709 % \end{macrocode}
710 % \end{macro}
711 %
712 % \begin{macro}{\hmmax}
713 %
714 % Same for heavy, but default to three this time (enough for mathtime
715 % plus, as no heavy operators font).
716 % \begin{macrocode}
717 \ifx\hmmax\@undefined
718 \chardef\hmmax=3
719 \fi
720 % \end{macrocode}
721 %
722 % Similarly if there is a heavy math version, set up |\bm@heavytable|.
723 % (If there is no heavy math version, do nothing here, as |\hm| will be
724 % set to |\bm| later, once that is defined.)
725 % \begin{macrocode}
726 \ifx\mv@heavy\@undefined
727 \else
728 \bm@setup{heavy}\hmmax
729 \fi
730 % \end{macrocode}
731 % \end{macro}
732 %
733 %
734 % \begin{macro}{\bm@general}
735 % \changes{v1.0d}{1997/11/15}
736 % {extra code to support prime lookahead and breqn}
737 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
738 % \changes{v1.2d}{2019/07/24}
739 % {guard against active underscore}
740 %
741 % |\bm| is pretty much |\bmdefine\bm@command| followed by executing
742 % |\bm@command|. It would in principle be possible to execute the
743 % emboldened tokens directly, rather than building up a macro first,
744 % but (as I learned the hard way) it's difficult to do this in the midst
745 % of all these nested |\if| constructs.
746 % First extract the central bit of code for |\hm| |\bm| |\hmdefine| and
747 % |\bmdefine|. Note that in the case of the inline versions they take
748 % an argument and brace it, rather than relying on |\bm@general| to pick
749 % up the argument. This makes the code robust with respect to premature
750 % expansion.
751 % \begin{macrocode}
752 \begingroup
753 \catcode`\'=\active
754 \catcode`\_=\active
755 \@firstofone{\endgroup
756 \def\bm@general#1#2#3#4#5{%
757 \begingroup
758 % \end{macrocode}
759 % \changes{v1.0d}{1997/11/15}
760 % {make nested \cs{bm} vanish completely, not leave a brace group}
761 % First locally disable |\bm| and |\hm|, as they would mess things
762 % up terribly, and the original Spivak versions used the syntax
763 % |\bmdefine\balpha{\bm\alpha}|.
764 % \begin{macrocode}
765 \let\bm\@firstofone
766 \let\hm\@firstofone
767 % \end{macrocode}
768 % Now initialise the commands used to save the tokens constructed.
769 % \begin{macrocode}
770 \global\let\bm@command\@empty
771 \let\@let@token\@empty
772 % \end{macrocode}
773 % As we want to expand the macros to look at their definition
774 % turn off protection. Otherwise the |\protect| will be carried over
775 % and apply to the wrong token, eg |{|.
776 % \begin{macrocode}
777 \let\protect\@empty
778 \let\@typeset@protect\@empty
779 % \end{macrocode}
780 % Set up either bold or heavy.
781 % \begin{macrocode}
782 \def\bm@mathchoice{\bm@m@thchoice#1}%
783 \def\bm@group{\bm@gr@up#1}%
784 \let\bm@table#2%
785 % \end{macrocode}
786 % Make sure |\left| and |\right| are really non expandable,
787 % and not |\ifx| equal to anything else.
788 % \changes{v1.0d}{1997/11/15}
789 % {make sure \cs{left} is primitive}
790 % \begin{macrocode}
791 \let\left\holdinginserts
792 % \end{macrocode}
793 % These three save on the number of |\ifx| tests below.
794 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
795 % \begin{macrocode}
796 \let\right\left
797 \let\mskip\mkern
798 \let\hskip\kern
799 % \end{macrocode}
800 % Definition of |'| locally modified so as not to use |\futurelet|
801 % in the look ahead, but to make the |\prime| available at the top level
802 % to be made bold, or heavy or whatever.
803 % |'| is locally active for this definition.
804 % \changes{v1.0d}{1997/11/15}
805 % {prime code added}
806 % \changes{v1.0d}{1997/11/15}
807 % {prime code added}
808 % \changes{v1.2d}{2019/07/24}
809 % {guard against active underscore}
810 % \begin{macrocode}
811 \let\bm@prime\copy
812 \let_\relax
813 \def'{\bm@prime\prime\relax}%
814 % \end{macrocode}
815 % For optional argument commands. This expandable version of
816 % |\@ifnextchar| is not 100\% safe, but works for |\sqrt| unless
817 % you put something really strange in the arguments.
818 % \changes{v0.11}{1997/01/06}
819 % {\cs{@ifnextchar} made safe.}
820 % \changes{v1.2e}{2021/04/25}
821 % {treat \cs{kernel@ifnextchar} like \cs{@ifnextchar}}
822 % \begin{macrocode}
823 \def\@ifnextchar##1##2##3##4{%
824 \if##1##4%
825 \expandafter\@firstoftwo
826 \else
827 \expandafter\@secondoftwo
828 \fi
829 {##2##4}{##3{##4}}}%
830 \let\kernel@ifnextchar\@ifnextchar
831 % \end{macrocode}
832 % For Vladimir Volovich\ldots
833 % \changes{v1.0f}{1998/12/10}
834 % {Errors and warnings made safe. tools/2917}
835 % \begin{macrocode}
836 \def\GenericWarning##1##2{%
837 \unvcopy{\GenericWarning{##1}{##2}}}%
838 \def\GenericError##1##2##3##4{%
839 \unvcopy{\GenericError{##1}{##2}{##3}{##4}}}%
840 % \end{macrocode}
841 % For AMS definitions.
842 % \changes{v1.2f}{2022/01/05}
843 % {Guard \cs{nolimits@}, gh/744}
844 % \begin{macrocode}
845 \let\DN@\copy
846 \let\FN@\copy
847 \let\nolimits@\copy
848 \let\next@\copy
849 \global\let\bm@first\@empty
850 % \end{macrocode}
851 % For AMS version of |\sqrt|: don't expand, just wrap it in a brace
852 % group so that it can be made bold in a safe but slow way. Do the same
853 % for internal accent command.
854 % \changes{v1.1b}{2003/10/05}{AMS \cs{sqrt} not working}
855 %
856 % \changes{v1.1c}{2004/02/26}{\cs{accentV} made safe (pr/3625)}
857 % Code for AMS accent allows bm to be used (just) with accent
858 % but stops the nested accents stacking correctly, this can be
859 % corrected by using an extra brace group as usual.
860 % |\bm{{\hat{\hat{F}}}}|
861 % \begin{macrocode}
862 \ifx\uproot@\undefined\else
863 \def\root##1\of##2{{\root##1\of{##2}}}%
864 \fi
865 \def\mathaccentV##1{\mathaccent"\accentclass@}%
866 % \end{macrocode}
867 % For breqn definitions.
868 % \begin{macrocode}
869 \let\@ifnext\@ifnextchar
870 \let\measure@lhs\copy
871 \let \rel@break\copy
872 \let \bin@break\copy
873 \let \after@open\copy
874 \let \after@close\copy
875 % \end{macrocode}
876 % Make sure things like |\pounds| take the `math branch' even
877 % in |\bmdefine| (which is not executed in math mode).
878 % \begin{macrocode}
879 \let\ifmmode\iftrue
880 % \end{macrocode}
881 % We have to ensure that the math alphabets have definitions that
882 % correspond the ``bold'' math version we are going to switch
883 % to. As these definitions are globally assigned when a math
884 % version is changed it is likely that right now we have those of
885 % the normal math version active. Argument |#3| holds either
886 % |\mv@bold| or |\mv@heavy| and we execute that after redefining
887 % |\install@mathalphabet| and |\getanddefine@fonts| suitably.
888 % The definitions are reverted back to their original the moment
889 % the scanning is done.
890 % \changes{v1.0h}{2002/11/22}{Get math alphabets right (pr/3476)}
891 % \begin{macrocode}
892 \let\install@mathalphabet\def
893 \let\getanddefine@fonts\@gobbletwo
894 #3%
895 % \end{macrocode}
896 % The last redefinition just makes |\mathit| type commands re-insert
897 % themselves (more or less) as if they are allowed to expand
898 % they die horribly if the expansions are put into |\mathchoice|
899 % and so executed more than once.
900 % \begin{macrocode}
901 \def\select@group##1##2##3##4{{%
902 \protect##1{##4}}}%
903 \def\use@mathgroup##1##2##3{{%
904 \protect\use@mathgroup##1{##2}{##3}}}%
905 % \end{macrocode}
906 %
907 % So now start looking at the argument.
908 % \changes{v0.10}{1997/01/04}
909 % {Use \cs{bm@end}}
910 % \begin{macrocode}
911 \bm@expand#5\bm@end
912 \endgroup
913 % \end{macrocode}
914 %
915 % Finally outside the group either execute |\bm@command| (for |\bm|)
916 % or save its definition (for |\bmdefine|).
917 % \begin{macrocode}
918 #4}
919 % \end{macrocode}
920 % End of the |\@firstofone| above, and the scope of the active |'|.
921 % \begin{macrocode}
922 }
923 % \end{macrocode}
924 % \end{macro}
925 %
926 % \begin{macro}{\bm}
927 % \changes{v1.0d}{1997/11/15}
928 % {Make \cs{bm} grab its argument even when protected}
929 % Set up the bold (rather than heavy) version, and run |\bm@command|
930 % right at the end, to execute the emboldened argument.
931 % The argument is grabbed by the top level function, and explicitly
932 % braced, so that |\bm| works even if the braces are omitted round
933 % its argument in a `moving argument'.
934 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
935 % \begin{macrocode}
936 \DeclareRobustCommand\bm{%
937 \bm@general\boldmath\bm@boldtable\mv@bold\bm@command}
938 \protected@edef\bm#1{\bm{#1}}
939 % \end{macrocode}
940 % \end{macro}
941 %
942 % \begin{macro}{\DeclareBoldMathCommand}
943 % \changes{v0.07}{1996/12/14}
944 % {Macro added}
945 % \begin{macro}{\bm@declare}
946 % \changes{v0.07}{1996/12/14}
947 % {Macro added}
948 % |DeclareBoldMathCommand|%^^A
949 % \oarg{mathversion}\marg{command}\marg{math expression}\\
950 % looks like |\bm| except at the end the specified command is
951 % globally defined to be |\bm@command|.
952 % The \meta{mathversion} defaults to `bold'.
953 % \begin{macrocode}
954 \def\DeclareBoldMathCommand{\@testopt\bm@declare{bold}}
955 % \end{macrocode}
956 %
957 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
958 % \begin{macrocode}
959 \def\bm@declare[#1]#2{%
960 \expandafter\bm@general
961 \csname #1math\expandafter\endcsname
962 \csname bm@#1table\expandafter\endcsname
963 \csname mv@#1\endcsname
964 {\bm@define#2}}
965 % \end{macrocode}
966 % \end{macro}
967 % \end{macro}
968 %
969 % \begin{macro}{\bmdefine}
970 % |\bmdefine| Shorthand for |\DeclareBoldMathCommand[bold]|.
971 %
972 % |\bm| is empty within the definition, so that either\\
973 % |\bmdefine\balpha{\bm\alpha}| or |\bmdefine\balpha{\alpha}| \\
974 % may be used. (The former just for compatibility with the original
975 % version for plain \TeX.)
976 % \begin{macrocode}
977 \def\bmdefine{\DeclareBoldMathCommand[bold]}
978 % \end{macrocode}
979 % \end{macro}
980 %
981 % \begin{macro}{\hm}
982 % \changes{v1.0d}{1997/11/15}
983 % {Make \cs{hm} grab its argument even when protected}
984 % \begin{macro}{\hmdefine}
985 % Same again for |\hm|.
986 % \begin{macrocode}
987 \ifx\mv@heavy\@undefined
988 % \end{macrocode}
989 %
990 % If there is no heavy math version defined, let |\hm| be defined
991 % as |\bm|. Currently there is no warning given, perhaps there should
992 % be, or even an error?
993 % \begin{macrocode}
994 \let\hm\bm
995 \let\heavymath\boldmath
996 \let\bm@heavytable\bm@boldtable
997 % \end{macrocode}
998 %
999 % \begin{macrocode}
1000 \else
1001 % \end{macrocode}
1002 %
1003 % Otherwise define |\hm| and |\hmdefine| in direct analogy with the
1004 % above.
1005 % \changes{v1.0h}{2002/11/22}{Pass math version as third (new) argument}
1006 % \begin{macrocode}
1007 \DeclareRobustCommand\hm{%
1008 \bm@general\heavymath\bm@heavytable\mv@heavy\bm@command}
1009 \protected@edef\hm#1{\hm{#1}}
1010 % \end{macrocode}
1011 %
1012 % \begin{macrocode}
1013 \def\hmdefine{\DeclareBoldMathCommand[heavy]}
1014 % \end{macrocode}
1015 %
1016 % \begin{macrocode}
1017 \fi
1018 % \end{macrocode}
1019 % \end{macro}
1020 % \end{macro}
1021 %
1022 % \begin{macro}[outer]{\bm@end}
1023 % \changes{v0.10}{1997/01/04}
1024 % {Macro added}
1025 % Normally speaking |\outer| declarations should be avoided at all
1026 % costs. (\LaTeX\ redefines all of plain \TeX's allocation macros
1027 % to be non-outer.) However this is one place where it seems like a
1028 % good idea. If a command taking an argument is put in |\bm| without
1029 % its argument, then the |\@@end| terminating token would be taken as
1030 % the argument, and so the rest of the paragraph would be gobbled up
1031 % and the \LaTeX\ would die horribly. So make the internal terminating
1032 % token |\outer|. (The actual test for termination is made against
1033 % |\@@end| not |\bm@end| as this macro will be expanded by the look-ahead
1034 % system.)
1035 % \begin{macrocode}
1036 \outer\def\bm@end{\@@end}
1037 % \end{macrocode}
1038 % \end{macro}
1039 %
1040 % \begin{macro}{\bm@expand}
1041 % \changes{v0.11}{1997/01/06}
1042 % {Double up.}
1043 % \begin{macro}{\bm@exp@nd}
1044 % \changes{v0.11}{1997/01/06}
1045 % {Macro added}
1046 % |\afterassignment| trick to fully expand the following tokens until
1047 % the first non-expandable token is revealed. This may discard a space
1048 % token (which is what \TeX\ is looking for) but that doesn't matter in
1049 % math mode. The expansion lookahead is done twice in case any stray
1050 % space tokens have crept in.\footnote{The need for this was noticed
1051 % while testing \cs{sqrt}. The definition of \cs{root} inherited from
1052 % plain \TeX\ has an anomalous space token, that is normally harmless
1053 % (just wastes memory), but which killed earlier versions of this
1054 % package.}
1055 % \begin{macrocode}
1056 \def\bm@expand{\afterassignment\bm@exp@nd\count@`\a}
1057 % \end{macrocode}
1058 %
1059 % \begin{macrocode}
1060 \def\bm@exp@nd{\afterassignment\bm@test\count@`\a}
1061 % \end{macrocode}
1062 % \end{macro}
1063 % \end{macro}
1064 %
1065 % \begin{macro}{\bm@test}
1066 % Normally we will grab the non-expandable token as a macro argument
1067 % but better check it is not |{| first. Save the previous token
1068 % so we can check later if it was |\left|, in which case use the delcode
1069 % rather than the mathcode if the current token is a character.
1070 % \begin{macrocode}
1071 \def\bm@test{%
1072 \let\bm@previous\@let@token
1073 \futurelet\@let@token\bm@test@}
1074 % \end{macrocode}
1075 % \end{macro}
1076 %
1077 % \begin{macro}{\bm@test@}
1078 % If looking at a single token, switch to |\bm@test@token|, else if
1079 % looking at a |{ }| group, grab the whole group with |\bm@group|.
1080 % A |\bgroup| token will take the wrong branch here (currently not
1081 % trapped).
1082 % \begin{macrocode}
1083 \def\bm@test@{%
1084 \ifx\@let@token\bgroup
1085 \expandafter\bm@group
1086 \else
1087 \expandafter\bm@test@token
1088 \fi}
1089 % \end{macrocode}
1090 % \end{macro}
1091 %
1092 % \begin{macro}{\bm@gr@up}
1093 % \changes{v1.0c}{1997/10/09}
1094 % {Extra brace around argument for \cs{over}}
1095 % If faced with a group
1096 % when we are in math mode, put it in a |\boldsymbol|-like construct
1097 % and then recurse on |\bm@expand|.
1098 % Otherwise just use |\bfseries\boldmath|.
1099 % The actual test is deferred till `run time'.
1100 % Here and elsewhere could deal with the inner list with an inner call
1101 % to |\bm|, but that doesn't seem to gain very much, and complicates the
1102 % code quite a bit.
1103 %
1104 % |#1| is either |\boldmath| or |\heavymath|.
1105 % Need to add an extra set of explicit braces around |#2| as otherwise
1106 % the math style commands applied in |\mathchoice| might only apply
1107 % to the first half of an |\over| construction.
1108 % \begin{macrocode}
1109 \def\bm@gr@up#1#2{%
1110 \bm@add{{\bm@gr@@p#1{{#2}}}}}
1111 % \end{macrocode}
1112 % \end{macro}
1113 %
1114 % \begin{macro}{\bm@gr@@p}
1115 % |#1| is either |\boldmath| or |\heavymath|.
1116 % \begin{macrocode}
1117 \def\bm@gr@@p#1#2{%
1118 \ifmmode
1119 \bm@mchoice#1{#2}{#2}{#2}{#2}%
1120 \else
1121 \bfseries#1#2%
1122 \fi}
1123 % \end{macrocode}
1124 % \end{macro}
1125 %
1126 % \begin{macro}{\bm@test@token}
1127 % If not facing a |{ }| group then test to see what we have.
1128 % Basic idea: Trap |\mathchardef| tokens, character tokens, and calls to
1129 % |\mathchar|, |\mathaccent|, etc, and change the \emph{math-group}
1130 % (fam) to point at the bold version.
1131 % Other things just copy straight over to the command being built.
1132 % (Anything inside a |\mathop| or similar will end up being made bold
1133 % as the |\mathop| will be copied over, but its argument will be made
1134 % bold by the group code above.)
1135 % \begin{macrocode}
1136 \def\bm@test@token#1{%
1137 \let\bm@next\@empty
1138 % \end{macrocode}
1139 %
1140 % Stop here. Note that it is vital that the terminating token
1141 % is non-expandable and defined, rather than the usual \LaTeX\
1142 % terminators |\@nil| and |\@@|. (Worse still would be a `quark'
1143 % like |docstrip|'s |\qStop|.)
1144 % \begin{macrocode}
1145 \ifx#1\@@end
1146 % \end{macrocode}
1147 %
1148 % |\bm@mathchoice| uses macro arguments, so need to make the tail
1149 % recursion explicit here. All the other cases recurse by way of
1150 % |\afterassignment| which means all the trailing |\fi| are eaten
1151 % while making the assignment.
1152 % \begin{macrocode}
1153 \else\ifx#1\mathchoice
1154 \let\bm@next\bm@mathchoice
1155 % \end{macrocode}
1156 %
1157 % The main point: Find these expressions, and change the mathgroup.
1158 % \begin{macrocode}
1159 \else\ifx#1\mathchar
1160 \afterassignment\bm@mathchar\count@
1161 \else\ifx#1\mathaccent
1162 \afterassignment\bm@mathaccent\count@
1163 \else\ifx#1\delimiter
1164 \afterassignment\bm@delimiter\count@
1165 \else\ifx#1\radical
1166 \afterassignment\bm@radical\count@
1167 % \end{macrocode}
1168 %
1169 % Need to trap spaces, otherwise digits will get turned to bold
1170 % mathchars.
1171 % \changes{v1.1a}{2003/09/01}{Forgotten to check for \cs{hskip} (pr/3572)}
1172 % \begin{macrocode}
1173 \else\ifx#1\mkern
1174 \bm@register#1{\muskip\z@}%
1175 \else\ifx#1\kern
1176 \bm@register#1\skip@
1177 \else\ifx#1\penalty
1178 \bm@register#1\count@
1179 % \end{macrocode}
1180 %
1181 % \changes{v1.0f}{1998/12/10}
1182 % {Add possibility to copy brace group unmodified. tools/2917}
1183 % |\vcopy| is a flag to copy the next group unchanged to the
1184 % result command.
1185 % \begin{macrocode}
1186 \else\ifx#1\unvcopy
1187 \let\bm@next\bm@add
1188 % \end{macrocode}
1189 %
1190 % \begin{macrocode}
1191 \else\ifcat\noexpand#1\relax
1192 % \end{macrocode}
1193 % Other command, look if it's a mathchardef token (otherwise just add
1194 % it).
1195 % \changes{v1.2a}{2016/02/27}
1196 % {Additional quotes for testing \cs{Umathchar}}
1197 % \begin{macrocode}
1198 \xdef\meaning@{\meaning#1}%
1199 \expandafter\bm@mchar@test\meaning@""""\@nil#1%
1200 % \end{macrocode}
1201 % \changes{v1.0d}{1997/11/15}
1202 % {New active \cs{mathcode} code.}
1203 % Character token.
1204 % If it is of catcode 11 or 12, get its mathcode.
1205 % If that is |"8000| replace the token by its active version, and then
1206 % let bm expansion look again at the character. Being really active
1207 % this time, it will expand away (probably).
1208 %
1209 % If the previous token was |\left| or |\right|, get the delcode
1210 % instead of the mathcode.
1211 % \begin{macrocode}
1212 \else\ifcat.\ifcat a#1.\else#1\fi
1213 \count@\mathcode`#1\relax
1214 \ifnum\count@=\mathcode`\'%
1215 \begingroup\uccode`\~`#1\uppercase{\endgroup
1216 \def\bm@next{\bm@expand~}}%
1217 \else
1218 \ifx\bm@previous\left
1219 \count@\delcode`#1\relax
1220 \bm@delimiter
1221 \else
1222 % \end{macrocode}
1223 % \changes{v1.2b}{2016/07/07}
1224 % {Check for mathchar values being reported as if via \cs{Umathchar}}
1225 % Here we need to check for LuaTeX merging mathchar values with Umathchar.
1226 % \begin{macrocode}
1227 \ifnum\count@>"8000
1228 \Umathcharnumdef\@tempa\count@
1229 \xdef\meaning@{\meaning\@tempa}%
1230 \expandafter\bm@mchar@test\meaning@""""\@nil\@tempa
1231 \else
1232 \bm@mathchar
1233 \fi
1234 % \end{macrocode}
1235 %
1236 % \begin{macrocode}
1237 \fi
1238 \fi
1239 \else
1240 % \end{macrocode}
1241 % And final possibility:
1242 % a character token of catcode other than 11 or 12.
1243 % \begin{macrocode}
1244 \bm@add{#1}%
1245 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1246 \bm@next}
1247 % \end{macrocode}
1248 % \end{macro}
1249 %
1250 %
1251 % \begin{macro}{\bm@define}
1252 % \changes{v0.08}{1996/12/18}
1253 % {Defined commands now always robust}
1254 % End code for |\bmdefine|. Define the given command name to the
1255 % robust form of the accumulated code.
1256 %
1257 % If |\bm@command| is equal to |\@gtempa| then it is a macro whose
1258 % expansion is a single call to |\mathchar|, so that can be optimised
1259 % with a |\mathchardef|.
1260 % \begin{macrocode}
1261 \def\bm@define#1{%
1262 \begingroup
1263 \ifx\bm@command\@gtempa
1264 \def\mathchar{\global\mathchardef#1}%
1265 \bm@command
1266 \else
1267 % \end{macrocode}
1268 % Rather than simply |\let#1\bm@command|, make the defined command
1269 % robust. |\bm@first| is normally empty, but might be something like
1270 % |\DOTSI| which needs to be lifted to the top level, in front
1271 % of any |\protect| because of the lookahead mechanism used
1272 % in the \textsf{amsmath} package.
1273 % \begin{macrocode}
1274 \toks@\expandafter{\bm@command}%
1275 \xdef#1{\bm@first\noexpand\bm@protect\noexpand#1{\the\toks@}}%
1276 \fi
1277 \endgroup}
1278 % \end{macrocode}
1279 % \end{macro}
1280 %
1281 %
1282 % \begin{macro}{\bm@protect}
1283 % \changes{v0.08}{1996/12/18}
1284 % {macro added}
1285 % Commands defined by |\bmdefine| re-insert themselves
1286 % if protection is enabled.
1287 % \begin{macrocode}
1288 \def\bm@protect#1{%
1289 \ifx\protect\@typeset@protect
1290 \expandafter\@firstofone
1291 \else
1292 \protect#1\expandafter\@gobble
1293 \fi}
1294 % \end{macrocode}
1295 % \end{macro}
1296 %
1297 % \begin{macro}{\bm@mchoice}
1298 % |\boldsymbol|, more or less.
1299 % |#1| is either |\boldmath| or |\heavymath|.
1300 % \begin{macrocode}
1301 \def\bm@mchoice#1#2#3#4#5{%
1302 \mathchoice{\hbox{#1$\displaystyle\m@th#2$}}%
1303 {\hbox{#1$\textstyle\m@th#3$}}%
1304 {\hbox{#1$\scriptstyle\m@th#4$}}%
1305 {\hbox{#1$\scriptscriptstyle\m@th#5$}}}
1306 % \end{macrocode}
1307 % \end{macro}
1308 %
1309 % \begin{macro}{\bm@m@thchoice}
1310 % Action if you find a |\mathchoice|. Add the bold version to
1311 % |\bm@command| then recurse.
1312 %
1313 % |#1| is either |\boldmath| or |\heavymath|.
1314 % \begin{macrocode}
1315 \def\bm@m@thchoice#1#2#3#4#5{%
1316 \bm@add{\bm@mchoice#1{#2}{#3}{#4}{#5}}}
1317 % \end{macrocode}
1318 % \end{macro}
1319 %
1320 % \begin{macro}{\bm@register}
1321 % \changes{v0.07}{1996/12/14}
1322 % {Macro added}
1323 % Combined code for setting up |\bm@r@gister| with the correct
1324 % register type.
1325 % \begin{macrocode}
1326 \def\bm@register#1#2{%
1327 \def\@tempa{#1\the#2}%
1328 \afterassignment\bm@r@gister#2}
1329 % \end{macrocode}
1330 % \end{macro}
1331 %
1332 % \begin{macro}{\bm@r@gister}
1333 % \changes{v0.06}{1996/12/12}
1334 % {Support \cs{mskip}}
1335 % \changes{v0.07}{1996/12/14}
1336 % {Combine all register macros}
1337 % |\mkern| itself would transfer to |\bm@command| without any special
1338 % test, but any explicit dimension following would be converted to
1339 % |\mathchar|. So trap this and grab the muskip as a muskip.
1340 % This is used in |\iiint|. |\penalty| was needed for the
1341 % AMS version of |\colon|, and so do most of the others as well.
1342 % \begin{macrocode}
1343 \def\bm@r@gister{%
1344 \bm@xadd{\@tempa\space}}
1345 % \end{macrocode}
1346 % \end{macro}
1347 %
1348 %
1349 % \begin{macro}{\bm@mathchar}
1350 % \changes{v0.10}{1997/01/04}
1351 % {Modify to use \cs{boldmath} or \cs{pmb} if needed.}
1352 % Change the family (math group) of a mathcode and then
1353 % use the modified code with |\mathchar|. If there is no
1354 % suitable bold font in the current math version, use the original
1355 % unmodified mathcode, but switch to |\boldmath| (if there is a bold
1356 % font there) or use `poor man's bold'. Note that these other
1357 % possibilities are only possible here, not for the otherwise similar
1358 % code for |\delimiter| or |\mathaccent|, as those commands
1359 % must work with fonts from the same math version.
1360 %
1361 % Finally recurse down the list.
1362 % \begin{macrocode}
1363 \def\bm@mathchar{%
1364 % \end{macrocode}
1365 %
1366 % \begin{macrocode}
1367 \@tempcntb\count@
1368 \let\@tempa\bm@group
1369 % \end{macrocode}
1370 %
1371 % |\bm@changefam| will isolate the math group from the mathcode
1372 % and look up the offset in the current table.
1373 % \begin{macrocode}
1374 \bm@changefam{}%
1375 % \end{macrocode}
1376 %
1377 % If the mathcode has changed, then just add the new |\mathchar|
1378 % (saving |\@gtempa| allows |\bmdefine| to optimise this to a
1379 % mathchardef if it turns out to be the only symbol in the argument).
1380 % \begin{macrocode}
1381 \ifnum\count@>\@tempcntb
1382 % \end{macrocode}
1383 %
1384 % \begin{macrocode}
1385 \ifx\bm@command\@empty
1386 \xdef\@gtempa{\mathchar\the\count@\space}%
1387 \fi
1388 \bm@xadd{\mathchar\the\count@\space}%
1389 \else
1390 % \end{macrocode}
1391 %
1392 % Otherwise grab the math class from the math code
1393 % and add that (locally zapping |\bm@expand| as we don't want
1394 % to recurse at this point).
1395 % \begin{macrocode}
1396 \begingroup
1397 \divide\count@"1000
1398 \let\bm@expand\relax
1399 \bm@xadd\bm@class
1400 \endgroup
1401 % \end{macrocode}
1402 % |\@tempa| will be |\bm@group| (which applies |\boldmath| and
1403 % |\mathchoice|) unless it was changed by |\bm@changefam| to |\bm@pmb|
1404 % (which applies a `poor man's bold' construction in a |\mathchoice|).
1405 % \begin{macrocode}
1406 \edef\@tempb{%
1407 \noexpand\@tempa{\mathchar\the\count@\space}}%
1408 \@tempb
1409 \fi}
1410 % \end{macrocode}
1411 % \end{macro}
1412 %
1413 % \begin{macro}{\bm@umathchar}
1414 % \changes{v1.2a}{2016/02/27}
1415 % {Macro added}
1416 % \changes{v1.2a}{2017/01/16}
1417 % {Test for zero table entry (\cs{boldmath}) added}
1418 % Version of \verb|\bm@mathchar| for \verb|\Umathchar|, this is easier
1419 % as no need to take apart the number, the match class and fam are provided
1420 % as distinct arguments.
1421 % \begin{macrocode}
1422 \def\bm@umathchar#1#2#3{%
1423 \@tempcnta#2\relax
1424 \count@\bm@table
1425 \ifnum\count@=\z@
1426 \bm@gr@up\boldmath{\Umathchar#1 #2 #3 }%
1427 \else
1428 \ifnum\count@=\m@ne
1429 \else
1430 \advance\@tempcnta\count@
1431 \fi
1432 \bm@xadd{\Umathchar#1\space
1433 \the\@tempcnta\space\space
1434 #3\space}%
1435 \fi}
1436 % \end{macrocode}
1437 % \end{macro}
1438 %
1439 % \begin{macro}{\bm@pmb}
1440 % \changes{v0.10}{1997/01/04}
1441 % {Macro added}
1442 % \changes{v1.2e}{2021/04/25}
1443 % {option to make pmb a no-op}
1444 % Add a poor man's bold construction to the list being built.
1445 % \begin{macrocode}
1446 \def\bm@pmb#1{%
1447 \bm@add{\bm@pmb@{#1}}}
1448 % \end{macrocode}
1449 % \end{macro}
1450 %
1451 % \begin{macro}{\bm@pmb@}
1452 % \changes{v0.10}{1997/01/04}
1453 % {Macro added}
1454 % |\pmb| variant. (See \TeX{}book, or AMS \textsf{amsbsy} package.)
1455 % This one takes a bit more care to use smaller offsets in subscripts.
1456 % \begin{macrocode}
1457 \ifx\bm@pmb@\@firstofone\else
1458 \def\bm@pmb@#1{{%
1459 \setbox\tw@\hbox{$\m@th\mkern.4mu$}%
1460 \mathchoice
1461 \bm@pmb@@\displaystyle\@empty{#1}%
1462 \bm@pmb@@\textstyle\@empty{#1}%
1463 \bm@pmb@@\scriptstyle\defaultscriptratio{#1}%
1464 \bm@pmb@@\scriptscriptstyle\defaultscriptscriptratio{#1}}}
1465 % \end{macrocode}
1466 % \end{macro}
1467 %
1468 % \begin{macro}{\bm@pmb@@}
1469 % \changes{v0.10}{1997/01/04}
1470 % {Macro added}
1471 % Helper macro. Box |#3| and set it three times in the style |#1|,
1472 % offset by an amount reduced by the ratio specified in |#2|.
1473 % \begin{macrocode}
1474 \def\bm@pmb@@#1#2#3{{%
1475 \setbox\z@\hbox{$\m@th#1#3$}%
1476 \dimen@#2\wd\tw@
1477 \rlap{\copy\z@}%
1478 \kern\dimen@
1479 \raise1.5\dimen@\rlap{\copy\z@}%
1480 \kern\dimen@
1481 \box\z@}}%
1482 \fi
1483 % \end{macrocode}
1484 % \end{macro}
1485 %
1486 % \begin{macro}{\bm@class}
1487 % \changes{v0.10}{1997/01/04}
1488 % {Macro added}
1489 % Convert a numeric math class back to a math class command.
1490 % |\mathord| is omitted in class $0$ and $7$ to save space and so
1491 % things work out right in constructions such as |x^a| where
1492 % |x^\mathord{a}| would not work.
1493 % \begin{macrocode}
1494 \def\bm@class{%
1495 \ifcase\count@
1496 \or
1497 \mathop\or
1498 \mathbin\or
1499 \mathrel\or
1500 \mathopen\or
1501 \mathclose\or
1502 \mathpunct\or
1503 \fi}
1504 % \end{macrocode}
1505 % \end{macro}
1506 %
1507 % \begin{macro}{\bm@add}
1508 % \changes{v0.07}{1996/12/14}
1509 % {macro added}
1510 % A version of |\g@addto@macro| that internally uses a |\begingroup|
1511 % rather than a brace group\footnote{This bug is fixed in the \LaTeX\
1512 % kernel of 1996/12/01}, to save creating a mathord.
1513 %
1514 % As need to redefine it anyway, save some tokens by making
1515 % it specific to |\bm@command|, and to execute |\bm@expand|
1516 % to continue the loop.
1517 % \begin{macrocode}
1518 \def\bm@add#1{%
1519 \begingroup
1520 \toks@\expandafter{\bm@command#1}%
1521 \xdef\bm@command{\the\toks@}%
1522 \endgroup
1523 \bm@expand}
1524 % \end{macrocode}
1525 % \end{macro}
1526 %
1527 % \begin{macro}{\bm@xadd}
1528 % An |\xdef| version of |\bm@add|.
1529 % \begin{macrocode}
1530 \def\bm@xadd#1{%
1531 \begingroup
1532 \toks@\expandafter{\bm@command}%
1533 \xdef\bm@command{\the\toks@#1}%
1534 \endgroup
1535 \bm@expand}
1536 % \end{macrocode}
1537 % \end{macro}
1538 %
1539 % \begin{macro}{\bm@mathaccent}
1540 % \changes{v1.0e}{1997/11/21}
1541 % {Use bm on argument group, as spotted on c.t.t.}
1542 % |\mathaccent| version of |\bm@mathchar|.
1543 % \begin{macrocode}
1544 \def\bm@mathaccent{%
1545 \bm@changefam{}%
1546 % \end{macrocode}
1547 % The next four lines were added in v1.0e. Without them |\bm{\hat{A}}|
1548 % makes the accent bold using |\bm| but the group |{A}| is made bold
1549 % via a |\mathchoice| construction as for any other group, as |\bm|
1550 % does not attempt to parse inside brace groups. While that produces
1551 % something acceptable for lower case letters, it produces
1552 % $\bm{\hat{{A}}}$ which is not too good. The braces may simply be
1553 % omitted:
1554 % |\bm{\hat A}| would work, producing $\bm{\hat A}$, however I did not
1555 % want to document such a restriction, so now modify bm so that such
1556 % brace groups are handled gracefully.
1557 %
1558 % It would be possible to locally make mathaccents take an argument
1559 % during the bm look-ahead, so the brace groups would then vanish
1560 % during expansion, however I would then need to explicitly skip past
1561 % \meta{filler} and also make sure that the end of parse token
1562 % was not gobbled in marginal cases like |$\bm\hat$|.
1563 %
1564 % So instead do the following which gets rid of \meta{filler}
1565 % with a redefinition of |\relax|, and just locally changes
1566 % |\bm@group| so that instead of doing a |\mathchoice| it simply adds
1567 % |\bgroup| and |\egroup| around the tokens, and lets bm modify the
1568 % tokens of the `argument'. This means that |\bm{\hat{A}}| now produces
1569 %\begin{verbatim}
1570 % \mathaccent 29790 \bgroup \mathchar 30017 \egroup
1571 %\end{verbatim}
1572 % The inner math list is a single mathchar, and so \TeX\ will not box
1573 % it, and the math accent will correctly position, taking into account
1574 % the skewchar information.
1575 %
1576 % As the normal bm lookahead is used, it is automatic that the parse
1577 % will end without trying to go past |\bm@end|.
1578 %
1579 % One disadvantage is that the group will mean that |\bm@previous|
1580 % will not be correctly updated. However that is only used for
1581 % delimiter checking, so can not matter here.
1582 % \begin{macrocode}
1583 \begingroup
1584 \def\bm@group##1{\endgroup\bm@xadd{\bgroup}##1\egroup}%
1585 \def\bm@test@token{\endgroup\bm@test@token}%
1586 \let\relax\@empty
1587 % \end{macrocode}
1588 %
1589 % \begin{macrocode}
1590 \bm@xadd{\mathaccent\the\count@\space}}
1591 % \end{macrocode}
1592 % \end{macro}
1593 %
1594 % \begin{macro}{\bm@delimiter}
1595 % \changes{v1.0d}{1997/11/15}
1596 % {Support \cs{left}. null delimiter.}
1597 % Change both families (math groups) of a delcode and then
1598 % use the modified code with |\delimiter|. Don't change code `0'
1599 % as that denotes a null delimiter.
1600 % \begin{macrocode}
1601 \def\bm@delimiter{%
1602 \ifnum\count@>\z@
1603 \bm@changefam{}%
1604 \bm@changefam{000}%
1605 \fi
1606 \bm@xadd{\delimiter\the\count@\space}}%
1607 % \end{macrocode}
1608 % \end{macro}
1609 %
1610 % \begin{macro}{\bm@radical}
1611 % Same for |\radical|.
1612 % \begin{macrocode}
1613 \def\bm@radical{%
1614 \bm@changefam{}%
1615 \bm@changefam{000}%
1616 \bm@xadd{\radical\the\count@\space}}%
1617 % \end{macrocode}
1618 % \end{macro}
1619 %
1620 % \begin{macro}{\bm@mchar@}
1621 % Catcode 12 |\mathchar|, for |\ifx| tests.
1622 % \begin{macrocode}
1623 \edef\bm@mchar@{\meaning\mathchar}
1624 % \end{macrocode}
1625 % \end{macro}
1626 %
1627 % \begin{macro}{\bm@char@}
1628 % \changes{v1.2g}{2025/10/21}
1629 % {Macro added}
1630 % Catcode 12 |\char|, for |\ifx| tests.
1631 % \begin{macrocode}
1632 \edef\bm@char@{\meaning\char}
1633 % \end{macrocode}
1634 % \end{macro}
1635 %
1636 % \begin{macro}{\bm@umchar@}
1637 % \changes{v1.2a}{2016/02/27}
1638 % {Macro added}
1639 % Catcode 12 |\Umathchar|, for |\ifx| tests.
1640 % \begin{macrocode}
1641 \edef\bm@umchar@{\string\U\expandafter\@gobble\meaning\mathchar}
1642 % \end{macrocode}
1643 % \end{macro}
1644 %
1645 % \begin{macro}{\bm@mchar@test}
1646 % Test if the |\meaning| starts with |\mathchar|. If it does, grab the
1647 % value into |\count@| and call |\bm@mathchar|, else just copy the
1648 % command into the accumulated tokens.
1649 % |#1|, |#2|, |#3| are all |\meaning| produced tokens, or `dummy tokens'
1650 % added at the time this is called. |#4| is the original token, in case
1651 % decide not to use the |\meaning|.
1652 % \changes{v1.2a}{2016/02/27}
1653 % {Additional arguments added}
1654 % \changes{v1.2g}{2025/10/21}
1655 % {add test for \cs{char}}
1656 % \begin{macrocode}
1657 \def\bm@mchar@test#1"#2"#3"#4"#5\@nil#6{%
1658 \xdef\meaning@{#1}%
1659 \ifx\meaning@\bm@mchar@
1660 \count@"#2\relax
1661 \bm@mathchar
1662 \else
1663 % \end{macrocode}
1664 % Test for \verb|\Umathchar|.
1665 % \begin{macrocode}
1666 \ifx\meaning@\bm@umchar@
1667 \bm@umathchar{"#2}{"#3}{"#4}%
1668 \else
1669 % \end{macrocode}
1670 % Treat a |\chardef| token like a |\mathchardef| token based on the |mathcode|
1671 % of the character.
1672 % \begin{macrocode}
1673 \ifx\meaning@\bm@char@
1674 \count@\mathcode"#2\relax
1675 \bm@mathchar
1676 \else
1677 % \end{macrocode}
1678 % Some other command: copy it straight over. If it is the first thing
1679 % added, and it is a |\relax| token, save it in |\bm@first| for use
1680 % in |\bm@define|.
1681 % \begin{macrocode}
1682 \ifx\bm@previous\@empty
1683 \ifx\relax#6%
1684 \gdef\bm@first{#6}%
1685 \fi
1686 \fi
1687 \bm@add{#6}%
1688 \fi
1689 \fi
1690 \fi}
1691 % \end{macrocode}
1692 % \end{macro}
1693 %
1694 % \begin{macro}{\bm@changefam}
1695 % \changes{v0.10}{1997/01/04}
1696 % {Rewrite for new \cs{bm@table} system}
1697 % Pull out one specified hex digit and pass
1698 % it to |\bm@modify| to change. Its one argument is normally empty,
1699 % but it will be |000| when necessary to access the second math group
1700 % in a delimiter code.
1701 % \begin{macrocode}
1702 \def\bm@changefam#1{%
1703 \@tempcnta\count@
1704 \divide\@tempcnta"1000#1 %
1705 \multiply\@tempcnta"1000#1 %
1706 \advance\@tempcnta-\count@
1707 \divide\@tempcnta-"100#1 %
1708 % \end{macrocode}
1709 % Having isolated the required math group (fam), look up
1710 % the offset in the current table.
1711 % \begin{macrocode}
1712 \@tempcnta\bm@table
1713 % \end{macrocode}
1714 % If the offset is $-1$, keep |\count@| unchanged, but set |\@tempa|
1715 % to use poor man's bold. Otherwise increment |\count@| to change the
1716 % math group specified.
1717 % \begin{macrocode}
1718 \ifnum\@tempcnta=\m@ne
1719 \let\@tempa\bm@pmb
1720 \else
1721 \multiply\@tempcnta"100#1 %
1722 \advance\count@\@tempcnta
1723 \fi}
1724 % \end{macrocode}
1725 % \end{macro}
1726 %
1727 % \begin{macro}{\bm@prime}
1728 % \changes{v1.0d}{1997/11/15}
1729 % {Macro added}
1730 % Support |'|. Earlier versions did not make the prime bold in a'.
1731 %
1732 % |\bm{a''}| will now produce (with the normal encodings)
1733 %\begin{verbatim}
1734 % \mathchar 30049
1735 % \bm@prime \mathchar 1584 \relax
1736 % \bm@prime \mathchar 1584 \relax
1737 %\end{verbatim}
1738 % So |\bm@prime| does essentially the same as the active definition of
1739 % |'|, which is to start a superscript group then keep adding |\prime|
1740 % for each |'| (or |\bm@prime|) following. Here modified to grab a
1741 % |\relax| delimited argument and use that instead of |\prime|.
1742 % |\bm@prime| is locally |\let| to |'| so the |\ifx| tests in |\pr@m@s|
1743 % don't need changing.
1744 % \begin{macrocode}
1745 \def\bm@prime{^\bgroup
1746 \let\bm@prime'%
1747 \def\prim@s##1\relax{##1\futurelet\@let@token\pr@m@s}%
1748 \prim@s}
1749 % \end{macrocode}
1750 % \end{macro}
1751 %
1752 % \begin{macro}{\boldsymbol}
1753 % \changes{v1.0b}{1997/04/14}
1754 % {Macro added}
1755 % \begin{macro}{\heavysymbol}
1756 % Finally, to ease conversion of documents between this package and
1757 % the \textsf{amsbsy} package:
1758 % \begin{macrocode}
1759 \let\boldsymbol\bm
1760 % \end{macrocode}
1761 %
1762 % \begin{macrocode}
1763 \let\heavysymbol\hm
1764 % \end{macrocode}
1765 % \end{macro}
1766 % \end{macro}
1767 % \begin{macrocode}
1768 %</package>
1769 % \end{macrocode}
1770 %
1771 % \Finale
1772 %