# How can I change the math font inside a document?

I need a solution for the following problem: I usually use newtxmath with libertine option to typeset all mathematical expressions. This time I need to typeset one special formula using eulervm, all other formulas should be displayed using newtxmath.

The following MWE shows what I'm trying to do.

\documentclass[a4paper,12pt]{article}

\usepackage{amssymb}
\usepackage{amsmath}

%\usepackage{eulervm}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{libertine}
\usepackage[libertine]{newtxmath}

\begin{document}

newtxmath:
\begin{displaymath}
E = mc^2
\end{displaymath}

eulervm:
\begin{displaymath} % use eulervm font here. exactly this one is needed.
4(\Phi^2x^2-y^2)(\Phi^2y^2-z^2)(\Phi^2z^2-x^2)-(1
\end{displaymath}

newtxmath again:
\begin{displaymath}
\int_{-\infty}^\infty \frac{e^{itx}}{x^2 + 1} \, dx
\end{displaymath}

\end{document}


Is this possible and does anyone know how to do that?

• Is the formula to be typeset with Euler exactly that one? Knowing the precise one is needed. – egreg Dec 15 '16 at 22:07
• @egreg I'm sorry, I thought that maybe there was a general solution to this problem. I replaced the dummy formula with the exact needed one. I know that this formula makes no sense, it is just part of a logo ... – philipp2357 Dec 15 '16 at 22:34

With the knowledge of the precise formula, we can set up what's needed for typesetting it with the Euler fonts.

\documentclass[a4paper,12pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{libertine}
\usepackage[libertine]{newtxmath}

\DeclareSymbolFont{eulerletters}{U}{zeur}{m}{n}
\DeclareSymbolFont{eulersymbols}{U}{zeus}{m}{n}
\DeclareMathSymbol{\eulerlparen}{\mathopen}{eulersymbols}{168}
\DeclareMathSymbol{\eulerrparen}{\mathclose}{eulersymbols}{169}
\DeclareMathSymbol{\eulerminus}{\mathbin}{eulerletters}{129}
\newcommand{\setupeuler}{%
\mathgroup\symeulerletters
\mathcode(=\eulerlparen
\mathcode)=\eulerrparen
\mathcode-=\eulerminus
}

\begin{document}

newtxmath:
\begin{displaymath}
E = mc^2
\end{displaymath}

eulervm:
\begin{displaymath} % use eulervm font here
\setupeuler
4(\Phi^2x^2-y^2)(\Phi^2y^2-z^2)(\Phi^2z^2-x^2)-1
\end{displaymath}

newtxmath again:
\begin{displaymath}
\int_{-\infty}^\infty \frac{e^{itx}}{x^2 + 1} \, dx
\end{displaymath}

\end{document}


Just for checking, here's the same formula with \usepackage[euler-digits]{eulervm}`: