# parseMixed with existing packages

**URL:** https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797
**Category:** Lezer
**Created:** [June 10, 2026, 3:43pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797 "2026-06-10T15:43:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![slashinfty](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/slashinfty/32/5489_2.png) [@slashinfty](https://discuss.codemirror.net/u/slashinfty)
#### Post date: [June 10, 2026, 3:43pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/1 "2026-06-10T15:43:41Z")

</div>

I would like to use [CodeMirror’s markdown language](https://code.haverbeke.berlin/codemirror/lang-markdown) as the main language of the editor, but implement parseMixed with [TeXlyre’s LaTeX language](https://github.com/texlyre/codemirror-lang-latex), 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?

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [June 10, 2026, 4:50pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/2 "2026-06-10T16:50:12Z")

</div>

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](https://code.haverbeke.berlin/lezer/markdown) 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`.

---

<div class="post-metadata">

### Author: ![slashinfty](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/slashinfty/32/5489_2.png) [@slashinfty](https://discuss.codemirror.net/u/slashinfty)
#### Post date: [June 11, 2026, 2:35pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/3 "2026-06-11T14:35:38Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![slashinfty](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/slashinfty/32/5489_2.png) [@slashinfty](https://discuss.codemirror.net/u/slashinfty)
#### Post date: [June 16, 2026, 12:31pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/4 "2026-06-16T12:31:27Z")

</div>

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](https://lezer.codemirror.net/docs/ref/#lr.ParserConfig) 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).

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [June 16, 2026, 12:47pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/5 "2026-06-16T12:47:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![slashinfty](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/slashinfty/32/5489_2.png) [@slashinfty](https://discuss.codemirror.net/u/slashinfty)
#### Post date: [June 16, 2026, 12:49pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/6 "2026-06-16T12:49:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [June 16, 2026, 1:01pm UTC](https://discuss.codemirror.net/t/parsemixed-with-existing-packages/9797/7 "2026-06-16T13:01:35Z")

</div>

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.
