Underscores in certain LaTeX equations, intended to be rendered by MathJax, are interpreted as <em>

Michael Liebling's Avatar

Michael Liebling

12 Apr, 2025 07:23 AM

Description of the issue:

Most of the time, Marked2's processor + MathJax seem to do the right thing with underscores in math environments: the processor does not interpret them as emphasis but and MathJax typesets subscripts. Nevertheless, I have several equations (one given below) where, unless I escape the underscores (replacing _ with \_), the equation is not rendered but, instead, the code is displayed verbatim with the part in between underscores in italics.

Looking for ways to fix things so I don't need to manually escape underscores, I came across a note in the docs which mentions that "Marked performs a bit of magic when either MathJax or KaTeX are enabled, converting math syntax to ensure its as compatible as possible with the current processor (MultiMarkdown or Discount). This should be great in all circumstances, but if you find it causing issues, contact support!", could my issue have something to do with this magic?

list of steps required to reproduce the issue

Equations like this one are rendered correctly by marked2 via Mathjax:

$$y_t = x_t$$

But the following is simply shown verbatim with whatever is within the _ rendered in italics

$$ \nabla_{\vec{x}^{(2)}} \ell = 2(\vec{x}^{(2)}-\vec{y}_{true}) $$

If I escape the underscores the equation renders fine:

$$ \nabla_{\vec{x}^{(2)}} \ell = 2(\vec{x}^{(2)}-\vec{y}_{true}) $$

If applicable please attach a sample document that causes the issue for you.

attached an example + screenshot of Marked2's rendering

// Configuration (do not edit)

Marked 2 1071 (Mac App Store)

macOS Version: 15.4

additionalMathJaxConfig: {
"HTML-CSS": { messageStyle: "normal", linebreaks: { automatic: false } }, tex2jax: { inlineMath: [["$","$"],["\(","\)"]], displayMath: [["$$","$$"],["\[","\]"]], processEscapes: true }, TeX: { Macros: { tr: "{\scriptscriptstyle\mathrm{T}}", } } } allowPageBreakInCode: YES
bookTxtIsLeanpub: NO
summaryMdIsGitBook: NO
codeIsPoetry: NO
codeCanWrap: YES
collapsibleHeadlines: YES
convertGithubCheckboxes: YES
convertGithubEmoji: YES
convertYAMLToMMD: YES
defaultMathJaxConfig: TeX-MML-AM_HTMLorMML
defaultPreviewStyle: 3
defaultProcessor: Discount (GFM)
enableMiniMap: YES
excludeBlockQuotesFromCounts: NO
excludeFootnotesFromCounts: NO
excludeVerbatimFromCounts: NO
excludeCaptionsFromCounts: NO
folderPreviewExtensionsArray: md, markdown, txt, mdown, html, opml
githubNewlines: YES
h1IsPageBreak: NO
h2IsPageBreak: NO
hrIsPageBreak: NO
includeMathJax: YES
includeKatex: NO
limitTextWidth: NO
mathNumberEquations: NO
mathNumberEquationsSide: 0
mathNumberEquationsAMSOnly: NO
minimalJavaScript: NO
outlineModeExtensions:
permissionGranted: YES
printHeaderBottomLeft:
printHeaderBottomRight:
printHeaderFirstPage: NO
printFooterFirstPage: NO
printHeaderTopLeft:
printHeaderTopRight:
processHTMLFiles: NO
removeMetadataForPreview: NO
removeYAMLHeaders: NO
scrollToEdit: YES
shouldDetectCritic: YES
shouldHighlightMarkupErrors: YES
shouldLoadCritic: NO
syntaxHighlight: YES
syntaxHighlightOnlyLang: NO
useCustomMarkdownProcessor: NO
customMarkdownProcessor:
useCustomPreprocessor: NO
customPreprocessor:
useFirstH1AsPrintTitle: NO

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • mathjax_underscore_equs.md 280 Bytes
  • mathjax_underscore_equs.jpeg 43 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac