5

When trying to compile the given example in the chemfig manual "Esterification: Step 1" (p. 22, sec. 11.2) with xelatex, the output does not match the expected result given in the manual. When compiling the example with pdflatex, the output matches the expected result.

\setatomsep{7mm}
\schemestart
\chemfig{R-@{dnl}\lewis{26,O}-H}
\+
\chemfig{R-@{atoc}C([6]-OH)=[@{db}]O}
\arrow(.mid east--){<->[\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}]}
\schemestop
\chemmove[shorten <=2pt]{
    \draw(dnl)..controls +(90:1cm)and+(north:1cm)..(atoc);
    \draw[shorten >=6pt](db)..controls +(north:5mm)and+(100:1cm)..(atoh);}

Expected: enter image description here

Actual: enter image description here

Is there a way to fix this while still using XeTeX?

1 Answer 1

4

This is only a partial answer to OP's question.

First, How to fix chemfig's chemmove in XeTeX? I believe the answer here is that, in the majority of instances, chemmove works as expected when compiled with XeLaTeX, as illustrated by the following simple tests developed from examples in the ChemFig Manual.

\documentclass[10pt,a4paper]{article}

\usepackage{chemfig}
\usepackage{fontspec}
\usepackage{caption}
\usepackage{verbatim}
\setmainfont{Arial}
\fboxsep=0pt
\renewcommand\printatom[1]{\ensuremath{\mathsf{#1}}}
\setatomsep{5mm}

\begin{document}
\begin{figure}
    \caption{XeLaTeX can be used to compile reaction schemes that use the \texttt{chemmove} macro. Example from: \textit{ChemFig Manual} v1.2d section 11.1 and 11.2  p20, December 2015}
    \vspace{1cm}
    \begin{tikzpicture}
        %Example from: ChemFig Manual v1.2d section 11.1  p20, December 2015} 
        \schemestart
        \chemfig{@{a1}=_[@{db}::30]-[::-60]\lewis{2,X}}
        \arrow{<->}
        \chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60]
            \chemabove{X}{\scriptstyle\oplus}}
        \schemestop
        \chemmove{\draw(db).. controls +(100:5mm) and +(145:5mm).. (a1);}
    \end{tikzpicture}\hspace{6cm}%
    \begin{tikzpicture}
        %Example from: ChemFig Manual v1.2d section 11.2  p22, December 2015} 
        \chemfig{R-O-C(-[2]R)(-[6]OH)-@{dnl}\lewis{26,O}H}\hspace{1cm}
        \chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}
        \chemmove{
            \draw[shorten <=2pt, shorten >=7pt]
            (dnl).. controls +(south:1cm) and +(north:1.5cm).. (atoh);}
    \end{tikzpicture}
\end{figure}
\end{document}

Fig1

Nevertheless, the OP has clearly had a problem using the example from p22 of the ChemFig manual (see above) when the code is compiled with XeLaTeX. The problem does not occur when compiled with pdfLaTeX.

ChemFig is built on Tikz. Its macros permit drawing chemical molecules and reaction schemes, among other things.

By elimination, it can be shown that this problem is attributable to drawing a reaction mechanism using chemmove when it spans a chemical reaction drawn with the arrow macro.

Here I use a few hypothetical reaction schemes to provide examples of code and output to try to isolate the cause of the problem. Generally, reaction schemes can be written and compiled from simple code that uses ChemFig macros like this.

\documentclass[border=20pt,crop=true]{standalone}

\usepackage{chemfig}
%\usepackage{fontspec}
%\setmainfont{Comic Sans MS} %substitute with any font
%\defaultfontfeatures{Ligatures=TeX}
\setatomsep{5mm}

\begin{document}
    \schemestart
    \chemfig{@{x1}A}
    \arrow {<->} % this is the reaction
    \chemfig{@{x2}B}
    \schemestop
    \chemmove{\draw[shorten >=4pt](x1).. controls +(90:1cm) and +(90:1cm).. (x2);} % this may be relevant when something moves from A to B

\end{document}

It produces a reaction scheme like this:

Fig2

On the other hand, compiling the same code, suitably modified to invoke fontspec with XeLaTeX, gives the following. I cannot offer any explanation for the curious difference in result between the use of pdfLaTeX and XeLaTeX.

Fig3

Removing \arrow demonstrates that the root cause of the problem is the \arrow command.

Fig4

\documentclass[border=20pt,crop=true]{standalone}

\usepackage{chemfig}
\usepackage{fontspec}
\setmainfont{Comic Sans MS} %substitute with any font
\defaultfontfeatures{Ligatures=TeX}
\setatomsep{5mm}

\begin{document}
    \schemestart
        \chemfig{@{x1}A}
%        \arrow{<->}
        \chemfig{@{x2}B}
    \schemestop
    \chemmove{\draw[shorten >=4pt](x1).. controls +(90:1cm) and +(90:1cm).. (x2);}
\end{document}

A partial workaround may be to wrap the arrow command in a subscheme environment, which in this case, produces the desired reaction scheme.

Fig5

\documentclass[border=20pt,crop=true]{standalone}

\usepackage{chemfig}
\usepackage{fontspec}
\setmainfont{Comic Sans MS} %substitute with any font
\defaultfontfeatures{Ligatures=TeX}
\setatomsep{5mm}

\begin{document}
    \schemestart
    \chemfig{@{x1}A}
    \subscheme{\arrow(.mid east--) {<->}}
    \chemfig{@{x2}B}
    \schemestop
    \chemmove{\draw[shorten >=4pt](x1).. controls +(90:1cm) and +(90:1cm).. (x2);}
\end{document}

I don't claim that the use of subscheme represents a general solution since I was not able to construct a suitable subscheme for OP's problem. Someone more skilled in ChemFig's syntax may be able to do so.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .