parseMixed with existing packages

I would like to use CodeMirror’s markdown language as the main language of the editor, but implement parseMixed with TeXlyre’s LaTeX language, which has its own existing grammar. The goal (and assumption) is that LaTeX will pick up math in dollar signs and any LaTeX commands and environments with backslashes, and Markdown will cover the rest.

I have no idea how to use parseMixed to make this happen, though. Any suggestions?

If you’re talking about making the LaTeX mode pick up stuff that looks like LaTeX commands in the Markdown text itself, that’s not going to work. You’d have to start by writing an extension for the Markdown parser that recognizes the elements you want to parse as LaTeX, so that they have their own nodes. At that point, parseMixed can be used to parse those nodes with latexLanguage.parser.

I knew it wouldn’t simply work, it’s why I asked about parseMixed. Let me see if I understand correctly the way to proceed:

  • create a MarkdownExtension(aka MarkdownConfig)
  • create nodes with MarkdownConfig.defineNodes
  • use MarkdownConfig.parseBlock and MarkdownConfig.parseInline to define the nodes
  • finally, use MarkdownConfig.wrap with parseMixed to have any of the now-defined nodes handled by latexLanguage.parser