Difference between revisions of "Bold Math"

From Wiki
Jump to navigation Jump to search
(→‎An Alternate Definition: An improved definition)
(boldsymbol is now in core)
Line 1: Line 1:
 
< [[Math]] | [[Bold Typewriter]] | [[Fonts]] >
 
< [[Math]] | [[Bold Typewriter]] | [[Fonts]] >
  
see [http://www.pragma-ade.com/general/magazines/mag-0005.pdf MyWay No.5 about "Mixed Normal and Bold Math"] by Pragma
+
Hans has descibed how to work with bold math in [http://www.pragma-ade.com/general/magazines/mag-0005.pdf MyWay No.5 about "Mixed Normal and Bold Math"].
 +
However, this method only seems to work with lucida fonts. For other fonts (currently only for latin modern and euler), one can also define
  
== 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:
 
 
<texcode>
 
<texcode>
 
\definetypeface [boldmath] [mm] [boldmath] [latin-modern] [default]
 
\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
 
</texcode>
 
 
Then you can get bold vectors:
 
<texcode>
 
\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}}}}
 
</texcode>
 
 
and formulas like this typeset perfectly:
 
 
<texcode>
 
\formula{\grad \eta = e^{\vec k \cdot \vec x} \unitvec{n}}
 
 
</texcode>
 
</texcode>
  
== An Alternate Definition ==
+
and then use <code>boldsymbol</code> around symbol that you want in bold.
An alternate way to define <cmd>boldsymbol</cmd> is
 
 
 
<context source="yes">
 
\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}$
 
</context>
 
 
 
The <cmd>preparebinrel</cmd> and <cmd>currentbinrel</cmd> ensure that the correct spacing is used around the symbol.  
 
This is slightly more efficient than the first version.
 
 
 
 
== Mixing Math Fonts ==
 
== Mixing Math Fonts ==
  

Revision as of 23:07, 5 January 2009

< Math | Bold Typewriter | Fonts >

Hans has descibed how to work with bold math in MyWay No.5 about "Mixed Normal and Bold Math". However, this method only seems to work with lucida fonts. For other fonts (currently only for latin modern and euler), one can also define

\definetypeface [boldmath] [mm] [boldmath] [latin-modern] [default]

and then use boldsymbol around symbol that you want in bold.

Mixing Math Fonts

This should be better documented and should go into a separate document, but until then I just leave it here before it gets lost. Perhaps the example above could be typeset in a similar way as well.


Someone thinks this entry needs some more explanation. (See: Needs Explanation?, To-Do List.)


Background: If you use

\setupbodyfont[ant] % Antykwa Torunska

the math will be typeset with Antykwa as well. (Perhaps this is a deprecated way of selecting fonts, I don't know. It works on my distribution, but not on the garden. Please use at your own risk.)

So far so good. You get pretty mathematical symbols mathcing the document style. The problem arises when you want to try something like

$\Longrightarrow$

Solution: Taco provided the following code and comments:

\starttypescript [math] [antykwa-torunska] [name]
  \definefontsynonym [MathRoman]        [ComputerModernMath-Roman]
  \definefontsynonym [MathExtension]    [ComputerModernMath-Extension]
  %definefontsynonym [MathItalic]       [ComputerModernMath-Italic]
  \definefontsynonym [MathSymbol]       [ComputerModernMath-Symbol]
\stoptypescript

Since there is more in the MathItalic fonts than just letters, it may produce un-even effects.

If you want more detailed control, you have to load extra math font families and redefine selected bits of the math collection (see also font-unk.tex, math-tex.tex and type-syn.tex)