nbsphinx: Centered equations not rendering properly

When trying to reproduce the centered equation from your documentation (using the latest version of nbsphinx from pypi):


eqn0


I find that the centered equation does not render properly:


eqn


I used the exact content of your notebook cell:

## Equations

Equations can be formatted really nicely, either inline, like $\text{e}^{i\pi} = -1$, or on a separate line, like

\begin{equation}
\int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
\end{equation}

*Note:* Avoid leading and trailing spaces around math expressions, otherwise errors like the following will occur when Sphinx is running:

    ERROR: Unknown interpreted text role "raw-latex".

See also the [pandoc docs](http://pandoc.org/MANUAL.html#math):

> Anything between two `$` characters will be treated as TeX math. The opening `$` must have a non-space character immediately to its right, while the closing `$` must have a non-space character immediately to its left, and must not be followed immediately by a digit.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 34 (17 by maintainers)

Commits related to this issue

Most upvoted comments

This did the trick! Verified on Windows with pandoc 2.1

The \begin statement has to have a blank line before it for the math to be rendered correctly.

Thanks @meowklaski, that sounds promising! Looks like this option was added in version 2.0.

I’ve created #161, but I have no idea if that actually works.

Can somebody please test it with pandoc >= 2.0 on Windows (and also on other OSs)? With pandoc < 2.0 it will still fail on Windows.

BTW, there isn’t really a Python API for pandoc. It’s just started as a sub-process and arbitrary command line arguments can be passed.

I set up a conda environment in Windows Subsystem for Linux and was able to get the centered equations to run properly. It is most definitely the Windows issue.

I do suspect that /n/r characters are occurring via pandoc in the intermediate rst form.

(Unfortunately, I cannot get parallel building to work on WSL; this along with WSL’s hindered disk IO makes the sphinx build slow… An eventual fix to this would be awesome 😄)

Edit: googling “WSL waiting for workers” brings up a bunch of Marxist info pages haha 😃

the never ending story .-)

https://docs.python.org/3/glossary.html#term-universal-newlines

This is caused by Windows using CRLF, but I’m not sure if the ‘\r’ characters are introduced by Python or by pandoc.

I think it is pandoc - back home i will test that. I have a running WIN and Linux env.

Hmmm, one strange thing is that you seem to have additional blank lines between each line … Is this the case in the whole intermediate RST file?

Can you please check with a hex-editor if the “newlines” are CRLF or LF or alternating or something else? See https://en.wikipedia.org/wiki/Newline.

Which OS and which Python version are you using?

Or maybe this has something to do with pandoc? Which version are you using and where did you get it?

Finally, can you please try to insert this line right before the last return statement in the function markdown2rst() in the file src/nbsphinx.py:

    print(repr(rststring))

… and run Sphinx again (probably using the -E option to re-build the whole environment)? How does the output for the math directive look in this case?