Skip to content

Adding matching patterns for leaf nodes #3

Open

Description

@Ants-Aare

It may be that there already is a way to do this without adding a pre-walk, so please let me know.
I am trying to detect $Delta E$ as one single leaf node instead of two. It's not possible to combine leaf nodes and ideally I would just like to be able to add a a pattern which has higher priority over others (such as multiply), which forces specific combinations of symbols to be treated as a single leaf node. I didn't find anything in the docs about this and I kind of don’t want to process the entire tree just to find and merge these edge cases, but ideally do it at the parsing stage. I tried using $#box($Delta E$)$ and this works somewhat well, but I find it clumsy to write. I ended up using this pre-walk, but I think it should be possible to do as a parsing step.

#let pre(it) = {
  for i in range(it.args.len()).rev() {
    let arg = it.args.at(i)
    if type(arg) == dictionary and arg.head == "mul" and (arg.args.at(0).at("text", default: none) == "Δ") {
      it.args.remove(i)
      it.args.push(arg.args.join([ ]))
    }
  }
  it
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions