Skip to content

feat(core): make multiline env, newline breaks and bar rendering configurable - #22

Open
iasandcb wants to merge 2 commits into
widcardw:mainfrom
iasandcb:feat/render-options
Open

feat(core): make multiline env, newline breaks and bar rendering configurable#22
iasandcb wants to merge 2 commits into
widcardw:mainfrom
iasandcb:feat/render-options

Conversation

@iasandcb

@iasandcb iasandcb commented Aug 18, 2026

Copy link
Copy Markdown

Depends on #21. That commit is included here and will drop out once it merges.

Three rendering behaviours are hardcoded with no way to opt out:

Behaviour Location
multiline expressions wrapped in aligned codegen.ts
a blank line (two \n) required to emit \\ trie.ts
an unpaired | rendered as \mid parser.ts

Each is a reasonable default, but each is also a matter of house style. I
maintain an Obsidian plugin whose vault convention differs on all three, and
the only way to get there today is to patch the built bundle.

Change

Three new optional fields on AsciiMathConfig:

new AsciiMath({
  multilineEnv: 'gather*',   // default 'aligned'
  singleNewlineBreak: true,  // default false
  barAsMid: false,           // default true
})

All three default to the existing behaviour, so this is backwards compatible.

Implementation notes

  • codegen takes an options object as a second argument and threads it
    through its own recursion.
  • Trie gains a newline threshold (2 or 1) set from singleNewlineBreak.
  • barAsMid is read from a module-scoped variable that parser() sets on
    entry. walk recurses through roughly 30 call sites and threading an
    options object through all of them would be a large diff for a single
    boolean. parser is synchronous and non-reentrant so this is safe, but if
    you would rather see it threaded explicitly I am happy to redo it — it is
    mechanical, just noisy.

A fourth customisation I needed — norm without \left/\right
required no core change at all; the existing symbols extension point covers
it. That may be worth a line in the README, since it is not obvious that
built-in tokens can be overridden and not just extended.

Tests

test/render-options.test.ts, 11 cases covering defaults, each option
individually, and all four composed. One snapshot line changes.

@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

Deploy Preview for marvelous-muffin-35eb19 ready!

Name Link
🔨 Latest commit 260e9b5
🔍 Latest deploy log https://app.netlify.com/projects/marvelous-muffin-35eb19/deploys/6a841430a30bad00086d2fe0
😎 Deploy Preview https://deploy-preview-22--marvelous-muffin-35eb19.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

createTrie mutated the module-level SYMBOLMAP, so passing `symbols`
to one AsciiMath instance changed the output of every other instance
in the process - including instances constructed earlier, since the
tex lookup resolves against the shared map at tokenize time.

Copy the map in createTrie and hand it to the Trie instead.
…igurable

Three behaviours were hardcoded with no way to opt out:

- codegen wrapped multiline expressions in `aligned`
- the tokenizer required a blank line to emit a line break
- an unpaired `|` was always rendered as `\\mid`

Expose them as `multilineEnv`, `singleNewlineBreak` and `barAsMid`
on AsciiMathConfig. All three default to the current behaviour, so
this is backwards compatible.
@iasandcb
iasandcb force-pushed the feat/render-options branch from d889811 to 260e9b5 Compare August 18, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant