Talk:Mathematics/Fonts/Bold Math

From Wiki
Jump to navigation Jump to search

I am moving the old definitions here. boldsymbol is now defined in core.

Wrapping in a \hbox

If the solution presented in that MyWay does not suit your needs, you can always use a \hbox wrapper, by defining something like this:

\definetypeface [boldmath] [mm] [boldmath] [latin-modern] [default]
\setupformulae[method=bold]
\unprotect
\def\boldsymbol@normal#1{\hbox{\formula[boldmath]{#1}}}
\def\boldsymbol@inline{\boldsymbol@normal}
\def\boldsymbol@script#1{\hbox{\formula[boldmath,script]{#1}}}
\def\boldsymbol@scriptscript#1{\hbox{\formula[boldmath,scriptscript]{#1}}}
\def\boldsymbol#1{%
  \mathchoice
    {\boldsymbol@normal{#1}}%
    {\boldsymbol@normal{#1}}%
    {\boldsymbol@script{#1}}%
    {\boldsymbol@scriptscript{#1}}}
\protect

Then you can get bold vectors:

\define\grad{\boldsymbol{\nabla}}
%\define\vec{\boldsymbol} % Raise a warning because \vec
\def\vec{\boldsymbol}     % is already defined in ConTeXt.
\define[1]\unitvec{{\hat{\vec{#1}}}}

and formulas like this typeset perfectly:

\formula{\grad \eta = e^{\vec k \cdot \vec x} \unitvec{n}}

An Alternate Definition

An alternate way to define \boldsymbol is

  • \definetypeface [boldmath] [mm] [boldmath] [latin-modern] [modern] [encoding=texnansi]
    
    
    \unprotect
    \def\boldsymbol#1%
      {\preparebinrel{#1}%
       \currentbinrel
        {\mathchoice
         {\hbox{\switchtoformulabodyfont             [boldmath]$\m@th#1$}}
         {\hbox{\switchtoformulabodyfont             [boldmath]$\m@th#1$}}
         {\hbox{\switchtoformulabodyfont      [boldmath,script]$\m@th#1$}}
         {\hbox{\switchtoformulabodyfont[boldmath,scriptscript]$\m@th#1$}}}}
    \protect
    
    % The previous example again
    \def\grad{\boldsymbol{\mathop{\nabla}}}
    % The correct way to define this is 
    % \def\grad{\mathop{\boldsymbol{\nabla}}}
    % The former is used just to show that \boldsymbol gives the correct
    % spacing for mathop
    \def\vec{\boldsymbol}
    \def\unitvec#1{{\hat{\vec{#1}}}}
    
    $\grad \eta = e^{\vec k \cdot \vec x} \unitvec{n}$
    

The \preparebinrel and \currentbinrel ensure that the correct spacing is used around the symbol. This is slightly more efficient than the first version.