3

I am using the mhchem package with the Libertinus font family in my PhD thesis.

When typesetting with LuaTeX, there are some weird issues with arrows depicting reactions. Here is the MWE to reproduce my issue.

%! TEX program = lualatex
\documentclass[varwidth=true, border=10pt, convert={size=640x}]{standalone}
\usepackage[version=4]{mhchem}
\usepackage{unicode-math}
\setmainfont[Numbers={Proportional},Ligatures={TeX, Common%, Historic, Contextual, Rare, Discretionary
}]{Libertinus Serif}
\setmonofont[Scale=0.8]{Libertinus Mono}
\setsansfont{Libertinus Sans}
\setmathfont{Libertinus Math}
\begin{document}
\ce{A <=> B + C}
\vspace{5mm}
\ce{A <-->[long forward]B + C}
\vspace{5mm}
\ce{X <-->Y + Z}
\end{document}

This code produces the following PDF output

image of weird arrows in chemical equations

In the first equation, notice the weird break in the forward reaction. In the second equation, it is clear that the arrows do not remain straight. The forward reaction arrow is clearly bent upwards, whilst the reverse reaction also seems to be made of two separate arrows with an overlap error. The third equation also shows the same problem, but you will have to squint a little bit to see the issue.

I tried first with TL2017 and later on with Tl2018-pretest, but the same issue persists in both. What could be the source of the issues and how to fix them?

  • Second and third look like waht you would see due to the way the pdf viewer shows the document, if you print it an still see the problem then it's a different matter. The first one seems like a bug. – Manuel Apr 26 '18 at 13:04
  • @Manuel, thank you for the suggestion. I just printed it and all the issues persist for all equations on paper too. – Krishna Apr 26 '18 at 13:10
  • this looks to me at least partly like a font bug, with the precise positioning of the "extenders" not aligned with the arrow segments. the positioning of the right/upward harpoon may be a macro bug (if this is changed so that it uses the default cm fonts, the first reaction has the harpoons separated by the distance shown on the left). the example is also processable by xelatex -- try that and see if the results are the same. – barbara beeton Apr 26 '18 at 13:21
  • @barbarabeeton I get the same issues in the output with xelatex. – Krishna Apr 26 '18 at 14:46
3

The font is imho the main problem. The right harpoon is to high. But it would be also better if mhchem would (with lualatex) use the extensible versions of the arrows instead of trying to assemble them with the amsmath -- but adjusting mhchem wouldn't help here as the font has not all the needed arrows and the existing arrows are not all extensible.

So your best way out is to use pgf arrows:

\documentclass[varwidth=true, border=10pt, convert={size=640x}]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage[version=4]{mhchem}
\mhchemoptions{arrows=pgf}
\usepackage{unicode-math}
\setmainfont[Numbers={Proportional},Ligatures={TeX, Common%, Historic, Contextual, Rare, Discretionary
}]{Libertinus Serif}
\setmonofont[Scale=0.8]{Libertinus Mono}
\setsansfont{Libertinus Sans}
\setmathfont{Libertinus Math}
\begin{document}
\ce{A <=> B + C}
\vspace{5mm}
\ce{A <-->[long forward]B + C}
\vspace{5mm}
\ce{X <-->Y + Z}
\end{document}

enter image description here

  • Unfortunately this is not an option for me although it works in this minimum example. The pgf-arrows options has problems with TikzExternalize (which my document class uses), leading to a few errors and does not compile. – Krishna Apr 26 '18 at 14:21
  • Imho your choices are only to use pgf (and solve the problems with tikzexternalize) or to switch to another font. – Ulrike Fischer Apr 26 '18 at 14:50
  • Thank you. Maybe I can try to do \tikzexternaldisable in my document just before the reaction-equations, and turn it back on again with \tikzexternalenable after them. And repeat this procedure for every chemistry equation involving arrows. – Krishna Apr 26 '18 at 14:53
  • Hooray. the enable-disable switches for the tikz externalisation actually worked! – Krishna Apr 26 '18 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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