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

So, I actually prefer all of the features of the LaTeX parser, so I’d rather modify that parser to read a minimal amount of Markdown and using parseMixed there.

My thought is using configure on the parser, but I’m not sure how to do this exactly. The extensions for the Markdown parser are a bit more obvious with parseInline and parseBlock properties on the config. But I’m trying to use LRParser.configure and I can’t figure out how to do the same thing. Would something that would go in parseInline be established as an ExternalTokenizer and passed to ParserConfig.tokenizers? Or is it somehow incorporated in NodeProp.add? I don’t feel the examples are explicit on this type of mixed parsing (but it could just be me).

The LaTeX parser uses an LR grammar, so it doesn’t support the type of extension that the Markdown parser supports. You cannot change how it behaves without forking it and building your own grammar, basically, and trying to incorporate Markdown parsing in an LR parser isn’t something I’d recommend.

Okay, so the best strategy would be to just fork it and modify the grammar directly. Thanks!

If I understand what you’re trying to do (integrate Markdown parsing into the LaTeX parser) then no, I don’t think that’s a workable strategy at all. Unless it’s a very small, simple subset of Markdown.