Question

My emacs version is 24.3.1, and I need to input many latex code (e.g. math formula) in the markdown mode. So I want to use the autocompleting function provided by auctex. But markdown and latex are two major modes, and I can't use them in a same buffer. There is package named mmm-mode which supports multiple major modes in one buffer. The problem is that I don't know how to configure it in my .emacs files, please give me some suggestion about it. If you have other methods which can do such things, it is also welcome.

Was it helpful?

Solution

If you must do this in markdown-mode, I don't recommend using mmm, which is quite difficult to configure and somewhat buggy.

Instead, consider using indirect buffers. This process is analogous to a feature that org-mode has called org-edit-special, where you can edit source blocks in separate buffers using the source language's major mode.

  1. Visit your Markdown file, e.g. file.md, using markdown-mode.
  2. When you want to edit a LaTeX snippet, use M-x clone-indirect-buffer. Of course, you can bind this to some convenient key if you use it a lot.
  3. You will now have two buffers visiting file.md. By default they will be something like file.md (the original buffer in markdown-mode) and file.md<2> (the indirect buffer).
  4. This step is optional, but I strongly recommend narrowing your file.md<2> buffer to the relevant LaTeX snippet.
  5. In the file.md<2> buffer, change your major mode to AUCTeX.

The two buffers will be modifying the same file. Changes in one will be reflected in the other, and saving from either one will save the file. The difference is that one will use markdown-mode and the other will use AUCTeX.

You can either kill file.md<2> when you are done with it, or keep it around for the next snippet. Simply un-narrow it, find the new snippet, and narrow it again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top