This is a rewrite of my first answer. There are two options:
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!).
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
\showboxbreadth\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
beamer
class overwrites the work ofmathastext
: it assigns letters and digits to some other fonts, aftermathastext
. I will investigate. But the simplest would be to get upright math from beamer itself, and forget aboutmathastext
.mathastext
to use Biolinum as sans-serif (and math) font and Linux Libertine as serif font. I don't know how to achieve this withoutmathastext
.mathastext
withbeamer
one needs either to useprofessionalfont
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 formathastext
in future releases ofbeamer
to be among the packages for whichbeamer
automatically activates its class optionprofessionalfont
.mathastext
(via the use of math active characters) are annihilated bybeamer
in certain environments such asalign
,gather
etc.. as an indirect result of a certain "Math mode color hackery
". This explains why you observed that things went awry inalign
although they looked ok in standard display math (letters were math active and thus used the mathastext definitions). I have posted a proposal on thebeamer
site for an alternativemath mode hackery
which would not amputatemathastext
of some of its functionalities.