In my document, I'm currently using chemformula
for chemical formulae. To draw reaction mechanisms I'm trying to use chemfig
, but it's proving very difficult to get chemfig to use the same sans-serif font that chemformula
does.
I'm using XeLaTeX as my engine so I'm using fontspec
and unicode-math
with it.
My document's main font is a serif font (Palatino); the math font is Cambria Math, and finally the sans-serif font is Source Sans Pro. By default chemfig
uses math mode to typeset atoms so they will appear in my math font.
How do I get it to use my sans-serif font?
I have tried:
Redefining \printatom
to use \ch
Does not work. This would be the best solution (I think), but I can't figure out how to get \ch
from chemformula to accept chemfig
's input.
\documentclass[a4paper,11pt]{report}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{fontspec}
\setmainfont{Palatino Linotype}
\setmathfont[version=cm]{Cambria Math}
\setsansfont{Source Sans Pro}
\setmathfont[version=ssp]{Source Sans Pro}
\usepackage{chemformula}
\usepackage{chemfig}
\setchemformula{format=\sffamily}
\def\printatom#1{\ch{#1}}
\begin{document}
\chemfig{C=Cl}
\end{document}
I get this:
! Undefined control sequence.
<argument> \atom 1 \CF
nodestrut
l.19 \chemfig{C=Cl}
^^M
Redefining \printatom
to use \mathsf
\def\printatom#1{\ensuremath{\mathsf{#1}}}
It builds, but \mathsf
doesn't use Source Sans Pro but the Unicode mathematical sans-serif characters instead (because of unicode-math
) and I'm not sure how to get it to actually use Source Sans Pro.
Redefining \printatom
to use \mathversion
\def\printatom#1{\mathversion{ssp}\ensuremath{#1}\mathversion{cm}}
Does not work. TikZ doesn't like \mathversion
outside of the math block it seems, and \mathversion
cannot be used inside math mode.
! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.18 \chemfig{C=Cl}
^^M
Other attempts
I also tried using \DeclareMathAlphabet
to define Source Sans Pro as a math font, but I couldn't figure out how to get it to work.