I am using the LaTeX markdown package to insert quick notes in my document. I would like Emacs to switch to markdown mode inside the markdown environment so it for example won't automatically re-indent markdown nested lists.

Here is an excerpt of the latex file:



Here's what'll be in this chapter:
* thing 1
* thing 2
    - aspect A
    - aspect B


In this chapter, we describe ...

Is there a way to change Emacs behavior without the need to invoking markdown mode manually each time I want to edit the inside of the environment?

1 Answer 1


You can use mmm-mode available at GNU Elpa.

There are examples how mmm-mode is to be configured.

In your case the following Elisp lines in your init file should work.

When you open a LaTeX file with markdown environments those are highlighted in grey. If you put point within those regions markdown-mode becomes active (e.g., indentation). When you write a new markdown environment per hand you should run Parse Block from the MMM menu. This is automagically done for you if you insert a markdown environment by C-c C-e (bound to LaTeX-environment).

(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
    :submode markdown-mode
    :face mmm-declaration-submode-face
    :front "\\\\begin{markdown}"
    :delimiter-mode nil
    :back "\\\\end{markdown}")))
(mmm-add-mode-ext-class 'latex-mode nil 'latex-markdown)

(defun my-LaTeX-parse-block-after-insert-environment (env _b _e)
  "Parse MMM block after inserting a markdown environment.
`mmm-parse-block' is only called when ENV is \"markdown\"."
  (when (string-equal env "markdown")
    (mmm-parse-block 3)))

(add-hook 'LaTeX-after-insert-env-hook #'my-LaTeX-parse-block-after-insert-environment)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.