# Upright maths in display mode, but italics in align environment in beamer class

I use mathastext like this

\renewcommand{\familydefault}{\sfdefault}
\usepackage[defaultmathsizes]{mathastext}
\renewcommand{\familydefault}{\rmdefault}


This gives me upright math throughout my document in an article class document, but in a beamer class document I end up with upright math in display math mode $...$, but in the align environment \begin{align} ... \end{align} the math is italic.

How do I get upright math in an align environment as well?

\documentclass[professionalfonts]{beamer}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[defaultmathsizes]{mathastext}
\renewcommand{\familydefault}{\rmdefault}

\begin{document}
\begin{frame}

Math in display
$abc$

Text...

Math in align
\begin{align}
abc
\end{align}

\end{frame}
\end{document}

• the beamer class overwrites the work of mathastext: it assigns letters and digits to some other fonts, after mathastext. I will investigate. But the simplest would be to get upright math from beamer itself, and forget about mathastext. – user4686 May 13 '14 at 14:10
• @jfbu Thank you for your input. I'm using mathastext to use Biolinum as sans-serif (and math) font and Linux Libertine as serif font. I don't know how to achieve this without mathastext. – Earthliŋ May 13 '14 at 14:16
• To use mathastext with beamer one needs either to use professionalfont as class option, or to use \usefonttheme{professionalfonts}. Notice the two distinct spellings. See my answer. I have posted an issue on the beamer development site to ask for mathastext in future releases of beamer to be among the packages for which beamer automatically activates its class option professionalfont. – user4686 May 14 '14 at 16:34
• Some of the advanced functionalities of mathastext (via the use of math active characters) are annihilated by beamer in certain environments such as align, gather etc.. as an indirect result of a certain "Math mode color hackery". This explains why you observed that things went awry in align although they looked ok in standard display math (letters were math active and thus used the mathastext definitions). I have posted a proposal on the beamer site for an alternative math mode hackery which would not amputate mathastext of some of its functionalities. – user4686 May 14 '14 at 22:06

This is a rewrite of my first answer. There are two options:

1. Use the professionalfont beamer class option and mathastext exactly as in your code, but notice the spelling without a final s. Alternatively, and as is recommended by a warning in the log file, issue rather in the preamble \usefonttheme{professionalfonts} (with a final s!).

2. Do not use the professionalfont class option nor \usefonttheme{professionalfonts}, do not load package mathastext, and exploit the fact that then the beamer class by itself already reassigns letters and digits to the document sans text font. There is perhaps an option somewhere in beamer to tell it to get the letters upright. But, not knowing it I provide a hack which has the desired effect.

The difference between the two options is in the treatment of characters such as =, ? and ;. In option 1, they will be from Biolinum (this is done by mathastext package), in option 2 they will be from the default math (usually Computer Modern) fonts.

## Option 1 (professionalfont+mathastext)

Code for option 1:

%\documentclass[professionalfont]{beamer}
%  or better (according to a warning in log file if the above):
\documentclass {beamer}
\usefonttheme {professionalfonts}

\usepackage[T1]{fontenc}
\usepackage{libertine}

\renewcommand{\familydefault}{\sfdefault}
\usepackage[defaultmathsizes]{mathastext}
\renewcommand{\familydefault}{\rmdefault}
\begin{document}
\begin{frame}

This is serif text, $sans math:E=mc^2$ (we see it is upright and sans), and
then display math which is also upright and sans:
$E=mc^2=abc;XYZ=tuv=TUV<123?$

Some serif text and then display math (with align)
\begin{align}
E=mc^2=abc;XYZ=tuv=TUV<123?
\end{align}

\end{frame}
\end{document}


## Option 2: hack, but no mathastext

Code for option 2:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usefonttheme[stillsansserifmath]{serif}

\makeatletter
\AtBeginDocument{\begingroup
\count0 \sympureletters
\count2 \symnumbers
\@tfor\x:=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\do
{\global\expandafter\mathcode\expandafter\x=\numexpr\expandafter\mathcode\expandafter\x-\count0*256+\count2*256\relax}\endgroup}
\makeatother

\begin{document}
\begin{frame}

This is serif text, $sans math:E=mc^2$ (we see it is upright and sans), and
then display math which is also upright and sans:
$E=mc^2=abc;XYZ=tuv=TUV<123?$

Some serif text and then display math (with align)
\begin{align}
E=mc^2=abc;XYZ=tuv=TUV<123?
\end{align}

\end{frame}
\end{document}


As an aside, not directly related to the OP question, I have noticed differences between pdflatex, and lualatex/xelatex with the following code.

\documentclass{beamer}
\usepackage{libertine}
\begin{document}
\begin{frame}
\showboxdepth\maxdimen
\setbox0\hbox{$=$}\showbox0\box0
\end{frame}
\end{document}


The font is cmss with pdflatex but cmr with lualatex/xetex.

pdftex:
> \box0=
\hbox(4.05148+0.0)x8.5167
.\mathon
.\OT1/cmss/m/n/10.95 =
.\mathoff

lualatex:
> \box0=
\hbox(4.01727+0.0)x8.5167, direction TLT
.\mathon
.\OT1/cmr/m/n/10.95 =
.\mathoff

xetex:
> \box0=
\hbox(4.01727+0.0)x8.5167
.\mathon
.\OT1/cmr/m/n/10.95 =
.\mathoff

• since beamer v3.34, no need for professionalfonts to use mathastext in beamer class. – user4686 Oct 29 '15 at 22:42