Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In reStructuredText greek alpha needs "\\", other greek letters only "\" when target is pdf

I recently discovered reST/Sphinx and tried to use it to document a python class I had written some time before.

After some experimentation I found out I needed to write :math:`K_\\alpha` to get the greek letter in the subscript while using the make latexpdf target. With a single \ there were errors. Strangely enough every other greek letter only needed a single \ to produce the desired output.

What is happening?

like image 725
BandGap Avatar asked Dec 26 '22 09:12

BandGap


2 Answers

Thank you so much for asking this. It finally helped me solve my related problem.

For me, \alpha and \beta both fail. They both fail even without the subscript part coming into play. But if I use the curly braces it works:

:math:`\alpha` 

does not compile

:math:`{\alpha}` 

gives me the symbol I want

:math:`{\\alpha}` 

gives me the word 'alpha' written as adjacent math variables a, l, p, h, a.

like image 83
L. Amber O'Hearn Avatar answered Dec 31 '22 13:12

L. Amber O'Hearn


To get a K followed by a subscripted α in inline text, use

:math:`K_{\alpha}` 

Note curly braces and backticks. It works fine and is what you would expect based on these references:

  • http://www.emerson.emory.edu/services/latex/latex_117.html
  • http://sphinx-doc.org/ext/math.html#role-math

In math markup used in Python docstrings, you need two backslashes (or use "raw" strings):

:math:`K_{\\alpha}`

Edit: I was wrong about the curly braces. It turns out that these two samples give the same result in the PDF output:

:math:`K_{\alpha}`

and

:math:`K_\alpha`
like image 30
mzjn Avatar answered Dec 31 '22 15:12

mzjn