Note that there are some explanatory texts on larger screens.

plurals
  1. POEmacs: How to switch mode after typing certain string?
    primarykey
    data
    text
    <p>I am writing R Markdown (.Rmd) file with a lot of LaTeX contents. The major mode is Markdown-mode. But what I want is that: when I try to type some LaTeX commands between <code>$$</code>, I want to automatically turn on the LaTeX major mode, and after I end the LaTeX chunk with <code>$$</code> or <code>$</code>, it can turn off LaTeX major mode and turn on Markdown-mode again. </p> <p>The inline format for LaTeX is </p> <pre><code>$\alpha$ </code></pre> <p>The equation(displaymath) format for LaTeX is </p> <pre><code>$$ \alpha + \beta $$ </code></pre> <p>A similar example is when I was writing a <code>.Rnw</code> file, the major mode is LaTeX, but when I edit the R code chunk:</p> <pre><code>&lt;&lt;&gt;&gt;= y &lt;- 1000 @ </code></pre> <p>between <code>&lt;&lt;&gt;&gt;=</code> and <code>@</code>, it turns on the ESS mode. </p> <p>So can anyone help me to do the similar stuff in Markdown-LaTeX case? Thanks!</p> <hr> <p>Updates after Inaimathi's answer:</p> <p>Following <a href="http://www.emacswiki.org/emacs/MultipleModes#toc6" rel="nofollow">http://www.emacswiki.org/emacs/MultipleModes#toc6</a>, I need to modify the two-mode-mode.el</p> <pre><code>- (if (string= to-mode mode-name) + (if (string= to-mode major-mode) </code></pre> <p>and for emacs 24</p> <pre><code>- (make-local-hook 'post-command-hook) </code></pre> <p>Then, by Inaimathi, I put the following in my <code>.emacs</code>:</p> <pre><code>(require 'two-mode-mode) (setq default-mode (list "Markdown" 'markdown-mode) second-modes (list (list "LaTeX" "\\\[" "\\\]" 'latex-mode))) </code></pre> <p>Then the major mode switches between <code>\[</code> and <code>\]</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload