% content=tex
%
% copyright=pragma-ade readme=readme.pdf licence=cc-by-nc-sa

\usemodule[mag-01,abr-02]

\setvariables
  [magazine]
  [title={Mixed Normal and Bold Math},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   date=November 2003,
   number=5]

\startbuffer[abstract]
  This time we discuss how to deal with bold formula components.
  Depending on the field, whole formulas can be bold, or only parts
  of formulas, most noticably symbols.
\stopbuffer

\starttext \setups [titlepage] \setups [title]

Internally \TEX\ uses a concept of families. Each family has three
members: text, script and scriptscript. Fonts are bound to families.
Each math symbol comes from a family and can have additional
characteristics. While typesetting a formula \TEX\ sometimes
overloads the predefined characteristics. Let's see what happens
when we switch fonts.

\startbuffer
\startformula
e = m c^2
\stopformula

\startformula
\bf e = m c^2
\stopformula

\startformula
e = {\bf m} c^2
\stopformula
\stopbuffer

\typebuffer

Because \TEX\ sees text and numbers, it will apply the bold font
to each component inside the scope of the font switch.

\getbuffer

Special symbols behave differently as we will see in the next
example.

\startbuffer
\startformula
\alpha = \Gamma - 3
\stopformula

\startformula
\bf \alpha = \Gamma + x - 3
\stopformula

\startformula
\alpha = {\bf \Gamma + x} - 3
\stopformula

\startformula
\alpha = {\bf\mr \Gamma + x} - 3
\stopformula
\stopbuffer

\typebuffer

In the third case \TEX\ will automatically change the family of the
$\Gamma$ into the current family (being bold) which means that we
depend on the bold font having such a symbol. This is true for the
Computer Modern Roman, but not for the Palatino used in this
document. An escape is using \type {\mr} which sets the family to
zero which in this case results in a symbol being typeset, but only
when the normal math text font has such a symbol, which is not
always true.

\getbuffer

It may be clear that for typesetting bold math, we cannot rely on
the \type {\bf} font switch. In case you wonder why we use families
for text bold: by using families such text can adapt itself to
situations where script fonts are needed.

For demonstrating the handling of bold math, we use a typeface that
provides them: Lucida Bright. First we define a main typeface.

\startbuffer
\definetypeface [mainface] [rm] [serif] [lucida] [default]
\definetypeface [mainface] [tt] [mono]  [lucida] [default]
\definetypeface [mainface] [ss] [sans]  [lucida] [default]
\definetypeface [mainface] [mm] [math]  [lucida] [default]
\stopbuffer

\typebuffer \getbuffer

We enable this typeface with:

\startbuffer
\switchtobodyfont[mainface]
\stopbuffer

\typebuffer

A simple nonsense formula now looks like:

\startbuffer
\startformula
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula
\stopbuffer

\start \switchtobodyfont[mainface] \getbuffer \stop

This is keyed in as:

\typebuffer

Next we define an extra typeface, one that has bold math:

\startbuffer
\definetypeface [boldmath] [rm] [serif]    [lucida] [default]
\definetypeface [boldmath] [tt] [mono]     [lucida] [default]
\definetypeface [boldmath] [ss] [sans]     [lucida] [default]
\definetypeface [boldmath] [mm] [boldmath] [lucida] [default]
\stopbuffer

\typebuffer \getbuffer

Watch the difference between those two typefaces:

\startbuffer
$\mainface x=10 \Gamma \Delta \alpha \delta \zeta$
$\boldmath x=10 \Gamma \Delta \alpha \delta \zeta$
\stopbuffer

\typebuffer

\startlines
\switchtobodyfont[mainface] \getbuffer
\stoplines

There is a more convenient way to switch between normal and bold,
as is demonstrated in the following examples:

\startbuffer
\startformula
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[mainface]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,8pt]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,12pt,small]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,small]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,10pt]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,11pt,small]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula

\startformula[boldmath,9pt]
  x = \Gamma + \Delta + \alpha + \delta + \zeta
\stopformula
\stopbuffer

\typebuffer

Changing the bodyfont size nearly alway leads to suboptimal spacing
between paragraphs (and formulas).

\start \switchtobodyfont[mainface] \getbuffer \stop

So we have normal math and completely bold math, but how about a
mixed case? For that we need to add an extra typeface definition,
one that extends the existing normal math one:

\startbuffer
\definetypeface [mainface] [mm] [bfmath] [lucida] [default]
\definetypeface [boldmath] [mm] [bfmath] [lucida] [default]
\stopbuffer

\typebuffer \getbuffer

Next we have to enable bold math. Beware: if you turn this feature on
without defining fonts, you will get \TEX\ error messages with
regards to missing characters

\startbuffer
\setupformulas
  [method=bold]

\setupbodyfont
  [mainface]
\stopbuffer

\typebuffer

We will demonstrate this with another strange math example. Watch the
effects of grouping.

\startbuffer
\formula          {1 \beta \Gamma =  \bfm 1 \beta \Gamma x'  z}
\formula[mainface]{1 \beta \Gamma =  \bfm 1 \beta \Gamma x'  z}
\formula[boldmath]{1 \beta \Gamma =  \bfm 1 \beta \Gamma x'  z}
\formula[mainface]{1 \beta \Gamma = {\bfm 1 \beta \Gamma x'} z}
\formula[boldmath]{1 \beta \Gamma = {\bfm 1 \beta \Gamma x'} z}
\stopbuffer

\typebuffer

This results in:

\startlines
\setupformulas[method=bold] \switchtobodyfont[mainface] \getbuffer
\stoplines

For Lucida lovers, we prepared some typescripts that provide (mixed)
bold math. Given that you have Lucida installed, you can try:

\startbuffer
\starttext

\usetypescript[lucida]        [texnansi]
\usetypescript[lucidabfm]     [texnansi]
\usetypescript[lucidaboldmath][texnansi]

\setupformulas[method=bold]

\startformula[lucida]         1 \Gamma       \alpha x  \stopformula
\startformula[lucida]         1 \Gamma {\bfm \alpha x} \stopformula
\startformula[lucidaboldmath] 1 \Gamma       \alpha x  \stopformula
\startformula[lucidaboldmath] 1 \Gamma {\bfm \alpha x} \stopformula

\stoptext
\stopbuffer

\typebuffer

This effectively defined two typefaces:

\getbuffer

\setups [listing] \setups [lastpage] \stoptext
