Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslashes in markdown cells are sometimes incorrectly interpreted as inline TeX #771

Open
kandersolar opened this issue Nov 15, 2023 · 4 comments

Comments

@kandersolar
Copy link

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'

*folder = r'C:\Users\User'*

**folder = r'C:\Users\User'**

`folder = r'C:\Users\User'`

> folder = r'C:\Users\User'
image image

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?

@mgeier
Copy link
Member

mgeier commented Nov 17, 2023

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-math role 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.

@kandersolar
Copy link
Author

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...

@mgeier
Copy link
Member

mgeier commented Nov 18, 2023

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?

@kandersolar
Copy link
Author

kandersolar commented Nov 22, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants