mitex icon indicating copy to clipboard operation
mitex copied to clipboard

Extract preamble

Open th1j5 opened this issue 8 months ago • 0 comments

Callisto uses mitex (and cmarker) to parse LaTeX commands in Jupyter Notebooks. Part of their capability is that some cell can define a \newcommand, and a few cells further down, this command can be used. Since those are different cells, this means those are two different calls to #mitex (or #mitex-convert). But the \newcommand defined in the first call, should be remembered, since the second call doesn't have this...

This issue is already discussed here, and we could do some crude workarounds (using regexes to extract \newcommand), but it would be really beneficial if mitex itself could extract these commands and either retain state (probably not wanted) or return these preambles (then the caller can combine these like shown in https://github.com/mitex-rs/mitex/pull/192). For example (see the referenced issue in callisto):

// But something equivalent for mitex, since cmarker actually only directly calls mitex
#let (out1, preamb) = cmarker.render(markdown1, extract-preamble: true)
#let (out2, preamb) = cmarker.render(markdown2, extract-preamble: true, preamble: preamb)
#let (out3, preamb) = cmarker.render(markdown3, extract-preamble: true, preamble: preamb)
// the preamble argument would be specified like shown in #192 

th1j5 avatar Jul 01 '25 21:07 th1j5