# Custom typeface for sans serif in math mode

How to set custom typeface for sans serif in math mode for pdfLaTeX?

Background: I use \usepackage[bitstream-charter]{mathdesign} which does not provide sans serif font, CM-super is used instead for sans serif typeface. This font does not fit well with Charter (different scale,..) so I want to try alternatives (Bera, Biolinum, Luxi Sans, ..??).

Example..

\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}  %fix [noamsfonts] bug
\documentclass[noamsfonts]{amsart}

\usepackage[utf8x]{inputenx}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[T1]{fontenc}

\begin{document}
$\mathsf A$ % I want to change this typeface
\end{document}

• pdfLaTeX and XeLaTeX handle fonts very differently. Your question suggests you are mostly concerned with pdfLaTeX (or are not using the enhanced font facilities of XeLaTeX). Either way, please post a Minimal Working Example i.e. the code for a small, compilable document which demonstrates the issue. – cfr Apr 8 '14 at 16:09
• Yes, these are two different questions, I would like to know answers for both, but more interested in pdfLaTeX. – DCh Apr 8 '14 at 16:32
• The question for XeLaTeX depends a lot on the rest of your configuration. That's another reason a MWE is so important. Are you using mathunicode? fontspec? opentype versions of the fonts? – cfr Apr 8 '14 at 16:51
• OK, thanks for explaining. I will edit the question to ask only for pdfLaTeX. – DCh Apr 9 '14 at 18:46
• You probably want [utf8]{inputenc} rather than [utf8x]{inputenx}, by the way. – cfr Apr 9 '14 at 21:34

Do you just want something like this?

EDIT: The following code is edited to eliminate loading charter which turns out to be pointless. mathdesign wants to set \rmdefault to mdbch rather than bch - so let it.

\documentclass{article}
\usepackage[T1]{fontenc}
\renewcommand{\sfdefault}{fvs}
\renewcommand{\ttdefault}{fvm}
\usepackage[charter, sfscaled, ttscaled]{mathdesign}

\begin{document}
Oh sphinx of black quartz, hear my vow!

\textsf{Oh sphinx of black quartz, hear my vow!}

\texttt{Oh sphinx of black quartz, hear my vow!}

$E=m\mathrm{c}^2$
$\mathrm{roman\ maths}\ \mathsf{sans\ maths}\ \mathtt{typewriter\ maths}\ \mathbf{bold\ maths}$

\end{document}


# XCharter

Thanks to Manuel's comment, I discovered a relatively new extension of Charter provided by the XCharter package (yes, it is capitalised). Based on the package documentation, I tried this to adjust the sizing appropriately:

\documentclass{article}
\usepackage[T1]{fontenc}
\renewcommand{\sfdefault}{fvs}
\renewcommand{\ttdefault}{fvm}
\usepackage[charter, expert, sfscaled, ttscaled]{mathdesign}
\usepackage[scaled=.96,osf]{XCharter}% matches the size used in math

\begin{document}
Oh sphinx of black quartz, hear my vow! 0123456789

\textsf{Oh sphinx of black quartz, hear my vow! 0123456789}

\texttt{Oh sphinx of black quartz, hear my vow! 0123456789}

$E=m\mathrm{c}^2$
$0123456789$
$\mathrm{roman\ maths}\ \mathsf{sans\ maths}\ \mathtt{typewriter\ maths}\ \mathbf{bold\ maths}$

\textsc{\itshape Oh sphinx of black quartz, hear my vow! 0123456789}

\textsc{Oh sphinx of black quartz, hear my vow! 0123456789}

\textsc{\itshape\bfseries Oh sphinx of black quartz, hear my vow! 0123456789}

\textsc{\textbf{Oh sphinx of black quartz, hear my vow! 0123456789}}

\end{document}


It is worth noting that the manual doesn't really recommend using mathdesign. For an alternative, see example 2 on page 2 of XCharter's manual.

• With this setup, does the font for regular text come from the charter package or mathdesign? Switching the order of \usepackage{charter} and \usepackage[charter]{mathdesign} produces different outputs. Also, the latter setup complains about Font shape T1/bch/m/fsc undefined(Font) .. (small caps?) – DCh Apr 10 '14 at 17:16
• @DCh See my edit. Loading charter was wrong. It turns out that mathdesign wants to set \rmdefault to mdbch (rather than bch). So you got different output because loading charter first has no effect - mathdesign overwrites the setting - but loading it second means it clobbers mathdesign's setting. So not loading it at all is the solution. I can't reproduce the error you mention bu not loading charter should eliminate it. It happens because bch, unlike mdbch, doesn't have an fsc shape. I don't know what fsc is. The files define sc (as usual) for small-caps. – cfr Apr 10 '14 at 21:49
• I would personally load XCharter after the math package, so you get a fully enhaced text font. – Manuel Apr 10 '14 at 21:57
• @Manuel I wasn't aware of XCharter - thanks. Although it looks nice, I don't think it is a good solution here because I believe the OP is using Debian's TL which I'm guessing will not have this package. However, I should probably add it in for other users as an option for those with current installations... I do wish people would not use capitals in package names, though! – cfr Apr 10 '14 at 22:07
• @Manuel See my edit... – cfr Apr 10 '14 at 22:34