# How can I use fontspec to set a sans heading font with mathdesign

I like the mathdesign package, but would like to use Myriad Pro section headings in LuaLaTeX. Is this possible, or do I have to convert an OTF font to T1? (My ignorance of font issues in *TeX is boundless.) The \setsansfont command and mathdesign packages seem not to work together, though there is no mention of fontspec within mathdesign. Here's a MWE that shows what doesn't work when running through LuaLaTeX.

 \documentclass{article}
\usepackage [english] {babel}
\usepackage {blindtext}
\usepackage {titlesec}
\usepackage {etoolbox}
\usepackage {ifluatex}
\titleformat{\section}{\Large\sffamily\bfseries}{\thesection}{1em}{}

\ifbool{luatex} {
\usepackage {fontspec}
\usepackage [charter] {mathdesign}
}{\usepackage [T1] {fontenc}
\usepackage [charter] {mathdesign}
}

\begin{document}
\section {A section}
\blindmathpaper
\end{document}


The beginning of that document looks as follows (note the lack of sans serif section heading)

If I load the mathdesign package before fontspec I get the correct section heading font, but the rmdefault font switches to CM.

Interestingly, the math font remains Charter in all cases.

-
It's not something fontspec can do. You need to redefine the heading commands and letting the redefined commands set the headings in sans serif with fontspec. To redefine the headers you can use a package but it may depend on which headers you want to redefine. –  Marc van Dongen Dec 11 '12 at 8:20
How about loading \usepackage [charter] {mathdesign} before fontspec in your preamble? I don't have myriad pro but it should work in other otf fonts. –  hpesoj626 Dec 11 '12 at 8:24
@MarcvanDongen, I am redefining the section heading with the \titleformat command (from the titlesec package) to set them in sans serif. At least that's what the intent is, and it works right up until (and unless) I use fontspec and mathdesign together. –  GTK Dec 11 '12 at 8:29
you can get the Charter ITC as TrueType from font-zone.com/download.php?fid=953. Then you can define the font with \setmainfont as usual –  Herbert Dec 11 '12 at 8:39
@GTK It's another example that shows that using different LaTeX engines may cause problems. This is exactly the reason why I always recommend to my students they should use one and only one engine. I always recommend they should use pdflatex (no offence to implementors of other engines). –  Marc van Dongen Dec 11 '12 at 8:48

You have to set also the correct font encoding in order to choose the correct font (for the LuaLaTeX version):

\titleformat{\section}
{\fontencoding{EU2}\Large\sffamily\bfseries}
{\thesection}
{1em}
{}


\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{titlesec}
\usepackage{ifluatex}

\ifluatex
\usepackage {fontspec}
\usepackage[T1]{fontenc}
\usepackage[charter]{mathdesign}
\titleformat{\section}
{\fontencoding{EU2}\Large\sffamily\bfseries}
{\thesection}
{1em}
{}
\else
\usepackage[T1]{fontenc}
\usepackage[charter]{mathdesign}
\titleformat{\section}
{\Large\sffamily\bfseries}
{\thesection}
{1em}
{}
\fi

\begin{document}

\section {A section}
\blindmathpaper
\end{document}


Just for completeness, here is a LuaTeX only version with the fonts Herbert pointed at in a comment:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{titlesec}

\usepackage[charter]{mathdesign}
\usepackage[no-math]{fontspec}
\setmainfont[Ligatures=TeX,
BoldFont={CharterITC Bold BT},
BoldItalicFont={CharterITC Bold Italic BT},
]{CharterITC BT}

\titleformat{\section}{\Large\sffamily\bfseries}{\thesection}{1em}{}

\begin{document}

\textbf{Abc}

\section {A section}
\blindmathpaper
\end{document}


Your way to specify the fonts may need to be different (here I put the fonts in the system fonts). Notice that one has to specify by hand the bold and bold italic versions, because the defaults are "Black", which fontspec doesn't understand. I added a boldface word just as an example.

-