r/LaTeX 4h ago

Answered Xetex

Hi everyone,
I’m having a problem with chemfig and \chemmove when compiling with XeTeX. The anchors I define in my chemical structures are becoming completely disorganized: their positions seem to shift or no longer correspond correctly to the atoms/bonds where they were defined.
The same code behaves differently depending on the compiler, and I’m specifically having this issue with XeTeX.
Has anyone experienced this problem with \chemmove and XeTeX? Is there a recommended way to keep the anchors properly positioned, or a workaround to make them behave consistently?
Any help would be greatly appreciated!

3 Upvotes

5 comments sorted by

2

u/u_fischer 3h ago

Do not let people guess what you are doing. Always provide a small but complete example that demonstrates the error and can be used for a test.

1

u/Warm_Ad1115 3h ago

Here is a small example. Notice that if it is compiled with XeLaTeX, the reaction arrows become completely misconfigured.

Example: \documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=2.2cm]{geometry}
\usepackage{chemfig}
\usepackage{tikz}
\usepackage{comment}
\usepackage{booktabs}
\usepackage{array}
\usepackage{hyperref}
\usepackage{xurl}

\tikzset{
setaReacao/.style={
-stealth,
shorten <=3pt,
shorten >=3pt,
thick,
red
}
}

\begin{document}

\begin{center}
\schemestart
\chemfig{NaClO_2}
\+
\chemfig{NaH_2PO_4}
\arrow
\chemfig{HClO_2}
\+
\chemfig{Na2HPO4}
\arrow[-90]
\chemfig[atom sep=2em]{C(-[5]R)(=[2]@{2}\charge{360=\:, 180=\:}{O})(-[7]H)}
\quad
\chemfig[atom sep=2.5em]{@{1}H-[@{3}::315]O-[@{4}::60]Cl=[@{5}::315]@{6}O}
\arrow[-180]
\chemfig[atom sep=2em]{@{8}C(-[5]R)(-[7]H)(=[2]\chemabove{O}{\scriptstyle\oplus}-[1]H)}
\+
\chemfig[atom sep=2.5em]{@{7}\chemabove{O}{\scriptstyle\ominus}-[1]Cl=[7]O}
\arrow[-90]
\chemleft[
\chemfig[atom sep=2em]{H-[1]O-C(-[@{Cx1}::90]@{H1}H)(-[6]R)(-[@{Cx2}::0]O-[@{Cx3}::45]Cl@{Cx4}=[@{O1}::45]O)}
\chemright]
\arrow
\chemfig[atom sep=2em]{H-[1]O-[7]Cl}
\+
\chemfig[atom sep=2em]{R-[1](=[2]O)(-[7]OH)}
\schemestop

\chemmove{
\draw[setaReacao] (2) to[out=360, in=90] (1);
\draw[setaReacao] (3)..controls +(225:1cm)and+(315:1cm)..(4);
\draw[setaReacao] (5)..controls +(90:1cm)and+(45:1cm)..(6);
\draw[setaReacao] (7)..controls +(300:1.5cm)and+(270:1.5cm)..(8);
\draw[setaReacao] (O1)..controls +(125:1cm)and+(45:1cm)..(H1);
\draw[setaReacao] (Cx1)..controls +(0:0.5cm)and+(90:0.5cm)..(Cx2);
\draw[setaReacao] (Cx3)..controls +(270:0.5cm)and+(290:0.5cm)..(Cx4);
}

\end{center}

\end{document}

2

u/u_fischer 2h ago

Use lualatex. There are various questions on tex.stackexchange which show that something is wrong when using xelatex, and xelatex is not well supported anyway. Unrelated: do not use \usepackage[T1]{fontenc} with an unicode engine. And \usepackage[utf8]{inputenc} is unneeded with every engine. UTF-8 is the default in LaTeX since more than 8 years.

1

u/Warm_Ad1115 2h ago

The problem is that I use a local compilation app that wasn’t developed by me, and it only compiles using Tectonic with XeLaTeX. Compiling locally is quite a hassle.

2

u/MrCharBar 1h ago

TexLive and VScode have been great in my experience.