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

Markdown emphasis captures before math does #639

Open
andyabateagility opened this issue Nov 20, 2023 · 2 comments
Open

Markdown emphasis captures before math does #639

andyabateagility opened this issue Nov 20, 2023 · 2 comments

Comments

@andyabateagility
Copy link
Contributor

andyabateagility commented Nov 20, 2023

Problem Description

Pdoc appears to keep looking for markdown emphasis tokens * within both inline $...$ and display $$...$$ math. This make starred environments break Pdoc's math rendering, and leads to unrendered math if matched stars do not have surrounding whitespace.

Steps to reproduce the behavior:

For example, this fails to render, and instead produces bare text, missing the stars *, and with emphasized text between the stars. Removing the stars allows this to render correctly as displaymath. VSCode's markdown preview renders both correctly.

$$
\begin{align*}
f(x) &= x^2\\
     &= x \cdot x
\end{align*}
$$

Underscores don't seem to have the same issue, and math renders correctly if there is whitespace around the stars (but that creates other errors in the math renderer, so it can't fix the above issue).

Possibly related, but newlines within displaymath break math rendering, and math newlines \\ are ignored.

System Information

pdoc: 14.1.0
Python: 3.10.12
Platform: Linux-6.2.0-36-generic-x86_64-with-glibc2.35

@mhils
Copy link
Member

mhils commented Dec 1, 2023

Thanks for the report! The issue here is that we do Markdown processing first, and only then our math renderer (MathJax) kicks in. Eventually we should solve this with a custom markdown2 extra that exempts $$/$ areas from processing. For now, as a workaround, you can escape the * to with \* get the desired behavior:

r"""
$$
\begin{align\*}
f(x) &= x^2\\
     &= x \cdot x
\end{align\*}
$$
"""

That workaround may break unfortunately when we get it fixed properly, but let's see. :)

@andyabateagility
Copy link
Contributor Author

Thanks for the tip on escaping! Newlines with four backslashes appear to work as well

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

No branches or pull requests

2 participants