Closed ferntheplant closed 1 month ago
I tested a little more and found that I could get the matrix to span multiple lines by replacing the \\
with \\\\
in the math block. The following math block renders as such
$$
A_G = \begin{pmatrix} 1 & 2 & 3 \\\\ a & b & c \end{pmatrix}
$$
I didn't dig deep into mistune or beautiful soup but my theory is that either one of these packages are replacing the ampersands and double backslashes with their escaped versions. Since the math block rendering occurs last in the rendering chain (see custom_tags.py:117
) the provided content no longer has the correct backslash and ampersand characters due to mistune or beautiful soup escaping them.
Finally had some time to look into mistune. Fairly certain all that's needed to fix this is to register the custom math renderer (see render_latex()
) as a mistune HTML renderer (similar to this example here).
I understand bear isn't open to contributions right now but I wouldn't mind taking a crack at this. @HermanMartinus let me know if you'd be open to a PR if you don't have the capacity to fix this right now
@ferntheplant Thanks for reporting this. I have some free time today so can give it a go :)
I didn't expect to rewrite the entire markdown renderer today, but it was well needed. Your examples are working now, and I managed to remove Beautiful Soup and leverage Mistune's custom renderer. Let me know if you have any other issues with LaTeX :)
One note, mistune uses $
for inline and $$
for block. Because Bear has previously supported $$
for both and determines whether it is inline by the context, I've written a basic pre-parser that turns inline $$
into single $
for backward compatibility.
I've updated the docs to use mistune's way going forward.
Awesome thanks a ton!
I'm trying to include matrices in my blog content but can't get them working right. I've tried a few different LaTeX style syntaxes for rendering matrices but it seems like bear always renders it on a single line and parses the ampersands
&
weirdly. So far I've tried the following:I think there might be a bug in the parser converting the strings between
$$
into MathML. This was tested on Firefox 125.0.3 on macOS. The matrices render on a single line like so: