4

I am using Sphinx 1.1.3 to document a reaction rate with an underscore.

\ce{A + $h$\nu ->[k_A] B}

It works perfectly when I make html documentation, using MathJax and a template file containing the following:

{% extends "!layout.html" %}

{% block extrahead %} 
 <script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    TeX: {
        extensions: ["mhchem.js"]
    }
  });
</script>
{% endblock %}

and including the _templates folder in the templates_path of the conf.py file.

You can see my mchem_example here.

But when I try to build a latexpdf using MiKTeX, with the preamble \usepackage[version=3]{mhchem} as stated in the mhchem documentation in the latex_elements dictionary of the conf.py, I don't get the reaction rate or the arrow. The other examples in the mhchem documentation all work, such as using +H20 or \alpha. I have made it work for both MathJax and MiKTeX by enclosing the \nu in curly braces.

\ce{A + $h${\nu} ->[k_A] B}

So now my question is why? Why does the \nu have to be in curly braces?

1 Answers1

3

This is TeX's 'skipping spaces after control sequences' behaviour coming into play. TeX ignorres spaces after control sequences, so here after \nu. That means that mhchem 'sees'

A + $h$\nu->[k_A] B

However, mhchem uses spaces to determine exactly things like arrows are. As a result, the space between \nu and - is needed to get things to parse correctly. Your solution works as it stops the space skipping: an alternative would be $h$\nu{}. I'd actually go for

A + $h\nu$ ->[k_A] B

as the h\nu really forms one mathematical entity (rather than a compound symbol).

I guess MathJax doesn't quite respect TeX's usual parsing rules here, so doesn't do the space skipping.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036