1

It's very convenient to use mhchem to typeset chemical formulas. It works very good in English writing, but when using Chinese (ctex), every chemical formula is followed by a space, which makes the text ugly. How to solve this small (but seemingly not so trivial) problem? Thanks.

Here is what I mean.

\usepackage[version=4]{mhchem}
There is no space after \ce{HNO3} in English environment. 
如果是在中文的环境中\ce{HNO3}会有一个空格。

Which gives the result:

enter image description here

6
  • Probably \ch{HNO3} in combination with \usepackage{chemformula} is an alternative?
    – leandriis
    Commented Mar 24, 2020 at 16:07
  • you can probably use \unskip after \ce{HNO3} to remove the space, but please supply complete small document not just a fragment so answers can be tested Commented Mar 24, 2020 at 16:12
  • Weird. Could be a bug in my package. I cannot test right now, so could you try (\ce{HNO3}) in English? There should be no space between 3 and ).
    – mhchem
    Commented Mar 24, 2020 at 17:19
  • 1
    That space is added by xetex-only package xeCJK, which tries to automatically add a space between CJK characters and non-CJK ones. This works well for plain input, for example abc<auto space>中文<auto space>abc. However, in the case of abc \cmd{...} abcxeCJK may make mistakes. When compiled with xetex, ctex auto loads xeCJK. Commented Mar 24, 2020 at 19:59
  • 1
    @mhchem \ce is not the only one which may cause problems with xeCJK. So don't worry. I have opened an issue on the repository of xeCJK, to ask for a general solution. Commented Mar 24, 2020 at 20:02

1 Answer 1

2

enter image description here

The space appears to be added by the ctex code when switching from Latin script to Chinese. The above is generated with xelatex. Note the space is also added after !! placing an empty \mbox{} seems to suppress it, as shown in the last line.

\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage[version=4]{mhchem}
\begin{document}

\showoutput
(\ce{HNO3})


AA \ce{HNO3} BB

中\ce{HNO3}会

中\ce{HNO3}!!会

中\ce{HNO3}\mbox{}会

\end{document}

with xetex the space seems to be added in the \XeTeXinterchartoks code, and for luatex the output is different, with no space after !! but still space after the Chemical formula.

enter image description here

2
  • Does anybody know why "The space appears to be added by the ctex code when switching from Latin script to Chinese"?
    – mhchem
    Commented Mar 24, 2020 at 19:15
  • @mhchem I tried texdoc ctex but it's not the easiest read. Commented Mar 24, 2020 at 19:24

You must log in to answer this question.

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