Backslashes in markdown cells are sometimes incorrectly interpreted as inline TeX
Backslashes in markdown cells sometimes result in nbsphinx-math role tags making it into the HTML output. Here's an example:
| Markdown cell contents | Jupyter Lab editor | nbsphinx HTML output |
|---|---|---|
folder = r'C:\Users\User' |
I think this is because pandoc is (undesirably, in this case) interpreting the backslashes as inline TeX commands, despite the cell not using $ or \( to indicate TeX? When I add -raw_tex to the pandoc build command, the HTML rendering of the above test cell becomes as I expect (no nbsphinx-math literals).
I'd like to somehow achieve nice rendering of this example without manually modifying how nbsphinx calls pandoc. Is that possible? If not, would it make sense to add a configuration option to nbsphinx to add -raw_tex to the build command?
The raw_tex feature is needed to allow LaTeX environments, so it cannot be disabled.
despite the cell not using
$or\(to indicate TeX?
$ is used for in-line math, \( does nothing for math (because it's just an escaped parenthesis).
nbsphinx-mathrole tags making it into the HTML output
The reason why those spurious :nbsphinx-math: snippets are visible, is the fact that reST doesn't support nested markup.
On the long run, this should be solved by avoiding the intermediate reST representation (see #36), but this might not happen soon.
In the meantime, you should simply avoid nested markup.
Thanks @mgeier. The thing is, I'm not actually trying to nest markup; I want the text inside the asterisks to be interpreted literally, as it is in the jupyter lab interface. Is there a way to rewrite it so that it doesn't try to nest markup? Maybe I am missing something obvious...
I'm not actually trying to nest markup
I know. It's the intermediate reST representation that does that.
I want the text inside the asterisks to be interpreted literally, as it is in the jupyter lab interface.
AFAIK, that's currently not possible.
But if you simply write your code snippets as code (as in your fourth example), it works fine, doesn't it?
Is there a way to rewrite it so that it doesn't try to nest markup?
Not at the moment, but maybe in a future version.
But I don't really see a problem in your concrete examples, since code should be formatted as code anyway. Do you have other examples where there is an actual problem?
Do you have other examples where there is an actual problem?
I suppose there are probably cases where backslashes can exist legitimately in non-code contexts, but I concede that formatting as code is appropriate in my case here :)
Thanks for your help @mgeier, and happy American Thanksgiving!