⚠️ Inline KaTeX/MathJax $...$ inside [grid] can leak BBCode when used with [details]

Ethsim2
Thu, 03 Jul 2025 16:22:25 +0000
Support

BBCode and LaTeX Rendering in [grid] and [details]: Unexpected Behavior Explained

I’ve been experimenting with how Discourse handles LaTeX inside [grid] and [details] and wanted to document the behavior and workaround here for others using math-heavy formatting.

Problem

When using [grid] to lay out multiple LaTeX expressions side-by-side, inserting even one whitespace between two $...$ inline math blocks inside the grid breaks the rendering:

[grid] shows side-by-side content with \text{whitespace} = 1

But BBCode tags like [grid] and [/grid] become visible

See this screenshot, where the layout looks correct but [grid] appears as text:

Screenshot 1: [grid] showing visibly despite rendering correctly

Diagnosis

Discourse’s markdown parser interprets:

$...$ with no whitespace between blocks as inline math

This causes layout confusion inside [grid]

[grid] expects block-level content, not inline

Solution

Use $$...$$ (block LaTeX) instead of inline $...$ inside [grid] to ensure correct rendering. Example:

[grid]
$$
\nabla \times \mathbf{A} = \left| \begin{matrix}
\hat{i} & \hat{j} & \hat{k} \\
\partial_x & \partial_y & \partial_z \\
A_x & A_y & A_z
\end{matrix} \right|
$$
$$
\nabla \times \mathbf{A} = \left| \begin{matrix}
\hat{i} & \hat{j} & \hat{k} \\
\partial_x & \partial_y & \partial_z \\
A_x & A_y & A_z
\end{matrix} \right|
$$
[/grid]

4 messaggi - 2 partecipanti