Marked 3.1.26 — three defects in the MathJax / custom-processor subsystem

Viewed 11

Marked 3.1.26 — three defects in the MathJax / custom-processor subsystem

Environment

  • Marked 3.1.26 (build 1211), direct (non-MAS) build
  • macOS 26.6.2 (25G83), Apple silicon (arm64)
  • MathJax source: Local (bundled), processor: MultiMarkdown
  • hasMigratedToMKConductor = 1

All three were verified on a clean install state, by observing the rendered preview
rather than by reading code alone.


1. additionalMathJaxConfig is never passed to the preview — the entire feature is inert

Severity: high. The documented "Advanced MathJax configuration" field has no effect
whatsoever, and fails silently.

Repro

  1. Settings → Style → Advanced Configuration, enter valid JSON with an unmistakable
    visual effect:
    { "chtml": { "scale": 2.5 } }
    
  2. Open a new document containing any math.

Expected: math rendered at 2.5× scale.
Actual: no change at all. Same for tex.macros, tex.packages, delimiters — nothing
in the object is applied.

Cause. The preview JS in marked.min.js is fully written to consume this setting:

// config constructor
this.additionalMathJaxConfig = null,
!this.includeKatex && this.includeMathJax && t.additionalMathJaxConfig
  && i(t.additionalMathJaxConfig.trim()).length > 0)
try {
  var s = i(t.additionalMathJaxConfig.trim());
  ...
  var l = JSON.parse(s);
  Marked.config.additionalMathJaxConfig = l
} catch(e) { ... tipText("mathJaxConfigError", "Error parsing additional MathJax configuration") }

// merge, immediately before the MathJax script tag is appended
return Marked.config.additionalMathJaxConfig
  && Object.keys(Marked.config.additionalMathJaxConfig).length > 0
  && $.extend(!0, e, Marked.config.additionalMathJaxConfig), e

…but the native side never supplies the value. The settings dictionary injected into the
preview WebView contains mathJaxSource, mathJaxCDNBase, mathJaxComponent,
mathJaxEnablePhysics, mathJaxEnableMhchem, mathJaxEnableBraket,
mathJaxEnableBoldsymbol — but not additionalMathJaxConfig. So
t.additionalMathJaxConfig is undefined, the guard is false, the parse block never
runs, and $.extend is a no-op.

Confusing side effect. The Settings pane validates the JSON on its own, so a
malformed value does raise "Error parsing additional MathJax configuration". Users
correct the JSON, the error disappears, and they reasonably conclude the config is now
active — when in fact the renderer has never read it. The absence of the error is
indistinguishable from success.


2. The "Additional Packages" checkboxes name packages that are never loaded

Severity: high. All four checkboxes appear to do nothing.

Repro

  1. Settings → Style → Additional Packages… → check Bold symbols.
  2. Quit and relaunch Marked (verified with a full restart, not just a preview refresh).
  3. Preview a document containing $\boldsymbol{\alpha} + \boldsymbol{\beta}$.

Expected: bold α + β.
Actual: Undefined control sequence \boldsymbol.

Cause. The preview hardcodes the TeX package list:

var e = {
  options: { renderActions: { addMenu: [] } },
  startup: { typeset: !1 },
  tex: {
    inlineMath: [["$","$"],["\\(","\\)"]],
    displayMath: [["$$","$$"],["\\[","\\]"]],
    packages: ["base","ams"].slice(0)
  }
};

and the checkboxes only append names to that list:

if (Marked.config.mathJaxExtraPackages) {
  var t = e.tex.packages || [];
  var n = Marked.config.mathJaxExtraPackages;
  e.tex.packages = t.concat(n)      // -> ["base","ams","boldsymbol"]
}

packages controls which already-loaded extensions are enabled; it does not fetch
them. Normally autoload handles that — in the bundled tex-chtml.js, boldsymbol
appears only in the autoload map:

boldsymbol:["boldsymbol"], braket:["bra","ket",...], ...
"[tex]/boldsymbol":["input/tex-base"]

But autoload is not in the hardcoded ["base","ams"] list, and Marked never emits a
loader: { load: [...] } entry. So the extension file is never fetched and the package
name refers to nothing.

Suggested fix. For each enabled package, also add
loader.load = ['[tex]/boldsymbol', '[tex]/physics', …]; or include autoload (and
require) in the base package list and let MathJax resolve them.

Verified for boldsymbol. physics, mhchem, and braket are not individually tested, but
they have the identical structure — autoload-only reference, standalone extension file
present in the bundle, absent from the package list — so they are very likely affected
the same way.

Knock-on effects of the same hardcoded list

  • \newcommand and \def are unavailable (the newcommand package is not loaded), so
    users cannot define macros in the document either.
  • configmacros is not loaded, which means tex.macros would be inert even if defect
    #1 were fixed
    . This matters because the bundled help page for Advanced Configuration
    documents a macros block as its primary example — a feature that currently cannot
    work by two independent mechanisms.

3. customPreprocessorDefault = 1 crashes Marked on document open

Severity: high — reproducible hard crash.

Repro (on an install with hasMigratedToMKConductor = 1)

  1. Quit Marked.
  2. defaults write com.brettterpstra.marked useCustomPreprocessor -int 1
    defaults write com.brettterpstra.marked customPreprocessor -string /path/to/script.sh
    defaults write com.brettterpstra.marked customPreprocessorDefault -int 1
    
    (script is any executable reading stdin and writing stdout)
  3. Launch Marked and open any .md file.

Actual: immediate crash. Setting customPreprocessorDefault back to 0 and leaving
the other two set is stable, which isolates that key as the trigger. Confirmed by
alternating: crash with 1, stable with 0, crash again with 1 — 3 crash reports.

Crash signatureEXC_CRASH (SIGABRT), unrecognized selector forwarded from a block
on the main queue:

-[NSObject doesNotRecognizeSelector:]
___forwarding___
_CF_forwarding_prep_0
Marked                        (unsymbolicated)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__

These legacy customPreprocessor* keys look like leftovers from the pre-Conductor
system. The equivalent Conductor rule (a Preprocessor rule with a Search and Replace
action) works correctly and does not crash — so the practical impact is on users with
migrated settings, or anyone who sets these keys directly.


4. Minor: the bundled help page's JSON example is not copy-pasteable

Marked Help.help/MathJax.html has systematically doubled backslashes. The Advanced
Configuration example reads:

"macros": { "tr": "{\\\\scriptscriptstyle\\\\mathrm{T}}" }

which parses to {\\scriptscriptstyle\\mathrm{T}} — a TeX line break, not a control
sequence. It should be "{\\scriptscriptstyle\\mathrm{T}}". The same doubling affects
the inline-math examples on that page (\\\\(x^2\\\\) where MMD wants \\(x^2\\)), so it
looks like an escaping pass applied to the whole document rather than a single typo.

0 Answers