# different font family in math mode [duplicate]

I would use two different fonts in math mode. My personal aim is to reach the results showed in the following picture (I took it from an italian website). In this picture, computer modern sans serif is used (in math mode, only in "Definizione" and "Esempi" environment), instead the text font, that is serif computer modern.

So, I would create a new environment, e.g. "examples", in which computer modern sans serif is used (in math and text mode). P.S. I already know how to change the main font in text and math mode using

\DeclareSymbolFont


etc., but I don't know how to use two different font families together.

Can you help me?

Thanks.

-
This is much the same as tex.stackexchange.com/q/14570/15925 Also have a look at the documentation of unicode-math and the concept of Math Versions. –  Andrew Swann Mar 4 '13 at 13:42
@AndrewSwann: Is there a way to get these results only on latex? I would use the instructions described in latex font selection. For example, I would create a new alphabet that turns letters and numbers of specific math environment (e.g. "Esempi" of the picture below) into sans serif ones. –  Lorenzo Mar 5 '13 at 20:57

## marked as duplicate by mafp, Thorsten, Claudio Fiandrino, Paul Gaborit, lockstepMar 6 '13 at 10:23

LaTeX has a concept of math versions, see fntguide.pdf.

Normally the only two math versions provided are normal and bold. However you can set up a new one with \DeclareMathVersion. One then introduces new symbol fonts with \DeclareSymbolFont and sets them for use via \SetSymbolFont whose second argument specifies the math version. Similar commands do the same for math alphabets. You then have the command \mathversion available to switch to the new version.

Note that initially it inherits the current default fonts, so you can just specify those that need to be changed.

The example below borrows some code from mathpazo.sty to change a couple of fonts in \mathversion{mymath}, and then sets up an example environment which contains the math version switch.

\documentclass{article}

\DeclareMathVersion{mymath}
\DeclareSymbolFont{myletters}{OML}{zplm}{m}{it}
\SetSymbolFont{letters}{mymath}{OML}{zplm}{m}{it}
\DeclareSymbolFont{myoperators}{OT1}{pplx}{m}{n}
\SetSymbolFont{operators}{mymath}{OT1}{pplx}{m}{n}

\newenvironment{Exx}{\mathversion{mymath}\bigbreak\noindent\textbf{Example}\par}{\par\noindent\textit{End Example}\par\bigbreak}

\begin{document}

Test $$x + y = \int_0^3 f(t)\,dt$$.

\begin{Exx}
Test $$x + y = \int_0^3 f(t)\,dt$$.
\end{Exx}

Test $$x + y = \int_0^3 f(t)\,dt$$.

\end{document}


Similarly a version with sans serif fonts can be provided with:

\documentclass{article}

\DeclareMathVersion{sfmath}
\DeclareSymbolFont{sfletters}{OT1}{cmss}{m}{sl}
\SetSymbolFont{letters}{sfmath}{OT1}{cmss}{m}{sl}
\DeclareSymbolFont{sfoperators}{OT1}{cmss}{m}{n}
\SetSymbolFont{operators}{sfmath}{OT1}{cmss}{m}{n}
\SetMathAlphabet\mathit{sfmath}{OT1}{cmss}{m}{sl}
\SetMathAlphabet\mathrm{sfmath}{OT1}{cmss}{m}{n}

\newenvironment{Exx}{\sffamily\mathversion{sfmath}\bigbreak\noindent\textbf{Example}\par}{\par\noindent\textsl{End Example}\par\bigbreak}

\begin{document}

Test $$x + y = \int_0^3 f(t)\,dt$$ and $$\tan t = \frac{\sin t}{\cos t}$$.

\begin{Exx}
Test $$x + y = \int_0^3 f(t)\,dt$$ and $$\tan t = \frac{\sin t}{\cos t}$$.
\end{Exx}

Test $$x + y = \int_0^3 f(t)\,dt$$ and $$\tan t = \frac{\sin t}{\cos t}$$.

\end{document}


Note however that there will be problems with greek symbols as these are not in the required positions in cmss.

-
The OP asked how to use the sans serif font also in text mode. –  mafp Mar 6 '13 at 8:36
@mafp Sans serif example added. –  Andrew Swann Mar 6 '13 at 9:08
@AndrewSwann: Thank you for the answer. I have almost solved the problem (where I can post my instructions as answer to my own question? May I have to edit the question below?). –  Lorenzo Mar 6 '13 at 15:46
One possibility is to add your method as a solution to the duplicate question. If that is too much of a change, you can instead edit your question here, putting the details in at the end. –  Andrew Swann Mar 6 '13 at 16:09