Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am a dedicated user of Donald Arsenau's dchem package, which has been distributed privately for a long time but which he has never felt was sufficiently developed to be released publicly (or, if that is no longer true, a public release has apparently not floated high enough on his priority list to get done.)

I am now trying to switch to xelatex/mathspec. Unfortunately I find that this change has broken the main \ch command of the dchem package. I wrote to D. Arsenau privately, and have asked on c.t.t., but I also thought I might try here to find advice.

I have tried to reduce the problem to an absolute minimum. I therefore extracted a single line of dchem.sty, and renamed it gchem.sty:

\newcommand\ch{\fam\z@\everymath{\fam\z@}}
% like \rm but don't have to repeat 

This command is typically used like $\ch H_2O$ to produce chemical formulas set in roman (more accurately, mathrm) type.

This line falls within some complex conditionals in dchem.sty that try to determine something about the current latex environment and its \everymath, and the implementation is somewhat different depending on the conditional branches, but I believe that this single line is the essence of all versions of the \ch command.

Now, I write a simple test file using the Fourier package:

\documentclass{article}
\usepackage{fourier}
\usepackage{gchem}
\begin{document}
$\rm CH_2O$, $\ch CH_2O$
\end{document}

When I process this package with pdflatex, both the formula produced with \rm and the formula produced with \ch come out in Utopia as expected.

I then modify the test file to use xelatex/mathspec:

\documentclass{article}
\usepackage{mathspec}
\setmainfont{Minion Pro}
\setmathsfont(Digits,Latin,Greek){Minion Pro}
\setmathrm{Minion Pro}
\usepackage{gchem}
\begin{document}
$\rm CH_2O$, $\ch CH_2O$
\end{document}

When I process this file with xelatex (This is XeTeX, Version 3.1415926-2.3-0.9997.5 (MiKTeX 2.9), the \rm formula comes out in Minion Pro as expected but the \ch version comes out in Computer Modern except for the subscript 2 which is Minion Pro.

I have log files, including ones with tracing turned on, that show distinct differences between the behavior of \rm and \ch, and I can post or forward them if needed.

But I think these examples get the point across: it seems that the short \fam\z@ command used by dchem does effect a switch to \mathrm in pdflatex but does not do so in xelatex. Is this expected? If not, where is the problem? If so, how should the \ch command be modified to be compatible with xetex?

share|improve this question
    
Welcome to TeX.SX! :) usually we neither sign questions nor greet fellow users. This is not rude, we just try to focus on the essence of the questions. If you are happy with the answer and wish to thank for it, upvote and/or accept good answers. Another thing: code can be highlighted (by adding 4 spaces before a code line or use the 'curly braces' icon on top of the editor field or use backticks if the code is part of a line), making your question much more readable. Happy TeXing! :) –  Count Zero Feb 5 '12 at 7:40
    
I suspect you are in trouble as dchem does not seem to be using the NFSS properly. Newer font packages, particularly those for XeLaTeX/LuaLaTeX, do, and so if you don't through the official interface you are in trouble. –  Joseph Wright Feb 5 '12 at 9:36

1 Answer 1

mathspec doesn't change the basic math group 0, but assigns new math alphabets or math symbol fonts. One that should correspond to upright characters is the one used for digits, so

\makeatletter
\newcommand\ch{\fam\csname sym\eu@DigitsArabic@symfont\endcsname
  \everymath{\fam\csname sym\eu@DigitsArabic@symfont\endcsname }}
\makeatother

might be what you need.

Let's see what happens. At a certain point, mathspec declares

\DeclareSymbolFont{Digits:m:n}{EU1}{\eu@Digitsmathsfont}{m}{n}

and \eu@Digitsmathsfont is translated into the correct family name. This defines a new math group (called a family in the TeXbook), that LaTeX accesses by adding the string sym to Digits:m:n. But it's safer, in my opinion, to use \eu@DigitsArabic@symfont, that will be the right string in any case, independently of the options given at package loading.

So what we do is

\fam\csname sym\eu@DigitsArabic@symfont\endcsname

Since \fam expects a number after it, it will expand \csname...\endcsname; this causes the expansion of \eu@DigitsArabic@symfont (in your case to Digits:m:n) and the formation of the token

\symDigits:m:n

that is equivalent to the number assigned by \DeclareSymbolFont to the desired math group.

share|improve this answer
    
This works as advertised. But I don't understand how it works. eu@DigitsArabic@symfont is the symbol font declared in mathspec for digits, and assigned the value Digits:m:n. \csname is a TeX primitive that generates commands, but there's no code following \endcsname in your snippet that would become the body of the new command. Does \csname have a return value that gets passed to \fam? Or does the \csname call, declaring an empty command \symDigits:m:n, have the side effect of switching to that symbol font? Or is something else happening? –  George McBane Feb 5 '12 at 23:44
    
@GeorgeMcBane See the explanation –  egreg Feb 5 '12 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.