[Tex/LaTex] Using \DeclareMathVersion

fontsmath-mode

It is my understanding that \DeclareMathVersion can be used to switch between math font variants. I am wondering how this can be used in a document that leverages two fonts: Times Roman for body text and Garamond for captions and headings. (The style is certainly unconventional, but works quite nicely.)

Times, through \usepackage{txfonts} and Garamond through \usepackage[urw-garamond]{mathdesign} both provide math fonts. What is required for the following example to typeset?

While I believe \DeclareMathVersion is the solution, documentation is on it is sparse. However, I have seen several LaTeX typeset books which pull this switching off. May be related to Change math font only in some parts of a document?

\documentclass{article}

\usepackage[urw-garamond]{mathdesign}
\usepackage{txfonts}

% ...

\begin{document}
 % This will be in times
 \[ \int e^{ax}\sin(bx+c)dx \]
 % We want this in Garamond
 % ...
 \[ \int e^{ax}\sin(bx+c)dx \]
\end{document}

Best Answer

After defining new math versions with \DeclareMathVersion, you can use \DeclareMathAlphabet, \SetMathAlphabet, \DeclareSymbolFont and \SetSymbolFont to set all math families manually. You must rename the math family names. You must be sure there are no more than 16 math alphabet families (but symbol familis can be more). And there may be encoding problems.

Anyway, although it's quite complex, it is posible:

enter image description here

\documentclass{article}
%%% text fonts
\renewcommand\rmdefault{txr}
\newcommand\gmfamily{\fontfamily{mdugm}\selectfont}

%%% New math versions
\DeclareMathVersion{varnormal}
\DeclareMathVersion{varbold}
\newcommand\txmath{\mathversion{normal}}
\newcommand\txboldmath{\mathversion{bold}}
\newcommand\mdmath{\mathversion{varnormal}}
\newcommand\mdboldmath{\mathversion{varbold}}

%%% Math symbol fonts
%%% some examples only
% Math letters from txfonts and mdugm
\SetSymbolFont{letters}{normal}{OML}{txmi}{m}{it}
\SetSymbolFont{letters}{bold}{OML}{txmi}{bx}{it}
\SetSymbolFont{letters}{varnormal}{OML}{mdugm}{m}{it}
\SetSymbolFont{letters}{varbold}{OML}{mdugm}{b}{it}
% Math operators
\SetSymbolFont{operators}{normal}{OT1}{txr}{m}{n}
\SetSymbolFont{operators}{bold}{OT1}{txr}{bx}{n}
\SetSymbolFont{operators}{varnormal}{OT1}{mdugm}{m}{n}
\SetSymbolFont{operators}{varbold}{OT1}{mdugm}{b}{n}
% Math symbols
\SetSymbolFont{symbols}{normal}{OMS}{txsy}{m}{n}
\SetSymbolFont{symbols}{bold}{OMS}{txsy}{bx}{n}
\SetSymbolFont{symbols}{varnormal}{OMS}{mdugm}{m}{n}
\SetSymbolFont{symbols}{varbold}{OMS}{mdugm}{b}{n}
% Large symbols
\SetSymbolFont{largesymbols}{normal}{OMX}{txex}{m}{n}
\SetSymbolFont{largesymbols}{bold}{OMX}{txex}{bx}{n}
\SetSymbolFont{largesymbols}{varnormal}{OMX}{mdugm}{m}{n}
\SetSymbolFont{largesymbols}{varbold}{OMX}{mdugm}{b}{n}

%%% Math alphabets, at most 16 families
%%% some examples only
\SetMathAlphabet{\mathrm}{normal}{OT1}{txr}{m}{n}
\SetMathAlphabet{\mathrm}{bold}{OT1}{txr}{bx}{n}
\SetMathAlphabet{\mathrm}{varnormal}{OT1}{mdugm}{m}{n}
\SetMathAlphabet{\mathrm}{varbold}{OT1}{mdugm}{b}{n}

\SetMathAlphabet{\mathit}{normal}{OT1}{txr}{m}{it}
\SetMathAlphabet{\mathit}{bold}{OT1}{txr}{bx}{it}
\SetMathAlphabet{\mathit}{varnormal}{OT1}{mdugm}{m}{it}
\SetMathAlphabet{\mathit}{varbold}{OT1}{mdugm}{b}{it}

\begin{document}

This is Times font. $a^2 + b^2 = c^2$. Math font
\[
  \sum_i \int_a^b \left( \frac1{K+1} \oplus\alpha_i \right) \,\mathrm{d}x = 0
\]
and bold math font
{\txboldmath\[
  \sum_i \int_a^b \left( \frac1{K+1} \oplus\alpha_i \right) \,\mathrm{d}x = 0
\]}

\gmfamily\mdmath
This is Garamond font. $a^2 + b^2 = c^2$. Math font
\[
  \sum_i \int_a^b \left( \frac1{K+1} \oplus\alpha_i \right) \,\mathrm{d}x = 0
\]
and bold math font
{\mdboldmath\[
  \sum_i \int_a^b \left( \frac1{K+1} \oplus\alpha_i \right) \,\mathrm{d}x = 0
\]}

\end{document}