[Bug Report]: curly braces with recurring underscores conflict with MathJax #2479

Closed
opened 2026-02-05 04:17:37 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @onionyst on GitHub (Nov 9, 2021).

Describe the Bug

When using Markdown with MathJax, the following pattern cannot display normally:

$$
{v}_{a_{i,j}}
$$

image

Steps to Reproduce

  1. Set Page Editor as Markdown.
  2. Set Custom HTML Head Content with the following code:
<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
  1. Create a new note with the following content and save.
$$
{v}_{a_{i,j}}
$$
  1. Note equation not renderring correctly.

Expected Behaviour

Should render the equation.

A minimal demo works properly (you can check it here or locally):

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" id="MathJax-script" async
    src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
  <p>
  $${v}_{a_{i,j}}$$
  </p>
</body>
</html>

image

So I suppose BookStack has something with this pattern (maybe a higher priority on italics) and conflicts with MathJax.

Screenshots or Additional Context

No response

Exact BookStack Version

v21.10.3

PHP Version

No response

Hosting Environment

Latest Docker image provided by linuxserver.

Originally created by @onionyst on GitHub (Nov 9, 2021). ### Describe the Bug When using Markdown with MathJax, the following pattern cannot display normally: ```latex $$ {v}_{a_{i,j}} $$ ``` ![image](https://user-images.githubusercontent.com/14269397/140967749-39fd7e73-4a4a-4132-b3c8-04a65e5c3451.png) ### Steps to Reproduce 1. Set Page Editor as Markdown. 2. Set Custom HTML Head Content with the following code: ```html <script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"> </script> ``` 3. Create a new note with the following content and save. ``` $$ {v}_{a_{i,j}} $$ ``` 4. Note equation not renderring correctly. ### Expected Behaviour Should render the equation. A minimal demo works properly (you can check it [here](https://jsbin.com/sodumoreka/edit?html,output) or locally): ```html <!DOCTYPE html> <html> <head> <script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> </head> <body> <p> $${v}_{a_{i,j}}$$ </p> </body> </html> ``` ![image](https://user-images.githubusercontent.com/14269397/140967821-b9d110bc-c444-46ae-9759-74b78bac262c.png) So I suppose BookStack has something with this pattern (maybe a higher priority on italics) and conflicts with MathJax. ### Screenshots or Additional Context _No response_ ### Exact BookStack Version v21.10.3 ### PHP Version _No response_ ### Hosting Environment Latest Docker image provided by [linuxserver](https://hub.docker.com/r/linuxserver/bookstack).
OVERLORD added the 🐛 Bug label 2026-02-05 04:17:37 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Nov 9, 2021):

Hi @onionyst,

I wouldn't consider this to be a bug in BookStack, as reported, since this is related to a MathJax rendering/library which is not built in or officially supported.

This is occurring since the underscores in your MathJax content are assumed to be markdown italic syntax, so the actually resulting HTML is actually:

<p>$$
{v}<em>{a</em>{i,j}}
$$</p>

This therefore breaks the MathJax library parsing. You can get around this by wrapping the MathJax content in HTML tags to get the content to be parsed as HTML instead of MathJax. For example, pasting the below in the Markdown editor should get the result you desire:

<p>$$
{v}_{a_{i,j}}
$$<p>

Note, You may come across other oddities but having MathJax run globally across all page content like it looks to do by default.

@ssddanbrown commented on GitHub (Nov 9, 2021): Hi @onionyst, I wouldn't consider this to be a bug in BookStack, as reported, since this is related to a MathJax rendering/library which is not built in or officially supported. This is occurring since the underscores in your MathJax content are assumed to be markdown italic syntax, so the actually resulting HTML is actually: ```html <p>$$ {v}<em>{a</em>{i,j}} $$</p> ``` This therefore breaks the MathJax library parsing. You can get around this by wrapping the MathJax content in HTML tags to get the content to be parsed as HTML instead of MathJax. For example, pasting the below in the Markdown editor should get the result you desire: ```html <p>$$ {v}_{a_{i,j}} $$<p> ``` Note, You may come across other oddities but having MathJax run globally across all page content like it looks to do by default.
Author
Owner

@onionyst commented on GitHub (Nov 9, 2021):

Thanks, @ssddanbrown.

I understand that it is caused by the rendering sequence. Would it be possible to have pre-markdown-rendering hooks to have custom modifications?

Another question would be, is there any method to have custom header (e.g. MathJax) available also on the Markdown preview pane on the right?

@onionyst commented on GitHub (Nov 9, 2021): Thanks, @ssddanbrown. I understand that it is caused by the rendering sequence. Would it be possible to have pre-markdown-rendering hooks to have custom modifications? Another question would be, is there any method to have custom header (e.g. MathJax) available also on the Markdown preview pane on the right?
Author
Owner

@ssddanbrown commented on GitHub (Nov 10, 2021):

I understand that it is caused by the rendering sequence. Would it be possible to have pre-markdown-rendering hooks to have custom modifications?

We do provide editor hooks (BookStack Editor Events) although they might be rudundant soon as we change editor and I don't think this would help here. Markdown is rendered to HTML server-side so you won't be able to get in-front of the markdown parsing for page views. You could maybe tweak the back-end render using the logical theme system.

We current don't inject custom header scripts into the preview pane, as to avoid any issues, we only inject styles. You could use the linked editor hooks above to inject scripts in yourself if desired.

@ssddanbrown commented on GitHub (Nov 10, 2021): >> I understand that it is caused by the rendering sequence. Would it be possible to have pre-markdown-rendering hooks to have custom modifications? We [do provide editor hooks (BookStack Editor Events)](https://www.bookstackapp.com/docs/admin/hacking-bookstack/#bookstack-editor-events) although they might be rudundant soon as we change editor and I don't think this would help here. Markdown is rendered to HTML server-side so you won't be able to get in-front of the markdown parsing for page views. You could maybe tweak the back-end render using the [logical theme system](https://github.com/BookStackApp/BookStack/blob/master/dev/docs/logical-theme-system.md). We current don't inject custom header scripts into the preview pane, as to avoid any issues, we only inject styles. You could use the linked editor hooks above to inject scripts in yourself if desired.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2479