Prologue

I want to write a document that I can output in both blackletter and latin typefaces just by commenting out a few commands and removing the comment signs from others. Because German blackletter typesetting rules require the use of latin typefaces for certain stuff (foreign language expressions, formulae etc) I have defined an \antiquafont with the help of fontspec (loaded by mathspec) and also \antiqua{} as shown in the MWE.

Everything I'm doing, I'm doing with XeLaTeX.

The problem

The mhchem package takes the surrounding font for its \ce{} command. The documentation only mentiones the possibility to enter sf and a few other similar in my case hardly helpful options. Since chemical formulae should be typeset in latin even in blackletter documents, and for the ease of writing and editing, I wanted to define a new command (or redefine the \ce{] command) so that all \ce is generally included in an \antiqua{} surrounding.

The non-working solutions and MWE

My attempts so far failed miserably. Instead of generating an output in latin typeface, I get an ouput in blackletter, consisting of a leading 0 followed by the formula as entered. The only one that worked consistently was enclosing the \ce{} in an \antiqua{} or {\antiquafont } environment but that's exactly the kind of solution I want to avoid.

\documentclass[12pt,a4paper,twoside]{scrreprt}
\usepackage[version=3]{mhchem}
\usepackage{mathspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmathsfont(Digits,Latin,Greek){LiberationSerif}
\setmathrm{LiberationSerif}
\setmathsf{LiberationSans}
\newfontfamily\antiquafont[Mapping=tex-text]{LiberationSerif}
\newcommand\antiqua[1]{{\antiquafont #1}}
\setmainfont[Mapping=tex-text,Mapping=slong-German]{UnifrakturMaguntia}
\setsansfont[Mapping=tex-text,Mapping=slong-German]{UnifrakturCook}

% Test commands incoming:
\newcommand{\Ace[1]}{{\antiquafont \ce{#1}}}
\newcommand{\Bce[1]}{{\antiquafont\relax \ce{#1}}}
\newcommand{\Cce[1]}{\antiqua{\ce{#1}}}

\begin{document}
\chapter{test chapter}
This is all about the nasty \ce{H2O} which just won't turn into \Ace{H2O}
although {\antiquafont \ce{H2O}} works as fine as \antiqua{\ce{H2O}} does.
The isotope-enriched \Bce{D2O} and \Cce{T2O} don't work as I want them to,
either

\end{document}


In the order of appearance, the first gives properly formatted H2O in blackletter, the second, fifth and sixth give 0H2O as seen here, and the two in the middle give properly formatted H2O in latin typefaces.

The questions

1. Why is this so?
2. What is the solution/workaround?
• @summer that looks like an answer to me:-) – David Carlisle Mar 17 '15 at 0:01

As the others mentioned, your approach would work if you wrote

\newcommand{\Ace}[1]{{\antiquafont \ce{#1}}}


However, you could just skip all that redefining and write

\usepackage[version=3,textfontname=antiquafont]{mhchem}


\documentclass{minimal}
\usepackage[version=3,textfontname=antiquafont]{mhchem}
\usepackage{mathspec}
\newfontfamily\antiquafont[Mapping=tex-text]{LiberationSerif}
\setmainfont[Mapping=tex-text,Mapping=slong-German]{UnifrakturMaguntia}
\begin{document}
This is all about the \ce{H2O}, which should not be in Fraktur.
\end{document}

• Oh, that's so much of a nicer option. Was it just me that I didn't find it in the documentation or is it too well hidden? Thanks a million anyways. =) – Jan Mar 17 '15 at 20:50
• It is in the manual. There, the example of textfontname=sffamily is explained. It seems, you thought, that's an option that is hard-coded. However, my intention was that the user can place any font-switching command there. – mhchem Mar 18 '15 at 7:18

The problem is simply that

\newcommand{\Ace[1]}


should be

\newcommand{\Ace}[1]


(and the same for the other 2 new commands). Note that if you write \newcommand{\Ace[1]} you are defining a command \Ace which is expecting an argument in brackets (and no argument in curly braces). Thus, in this case you could still achieve the desired result by writing \Ace[H2O] in the main document.

• Oh wow, that was absurdly stupid of me. Thanks ^^' – Jan Mar 17 '15 at 20:49