代码之家  ›  专栏  ›  技术社区  ›  phimuemue

emacs/auctex:自动启用/禁用LaTex数学模式

  •  5
  • phimuemue  · 技术社区  · 15 年前

    我将emacs与auctex结合使用(如果这很重要的话,运行Ubuntu10.04)。

    如果该点在任何数学环境中(即 $...$ A $$...$$ , begin{equation}...\end{equation} 等等?

    我认为有一个相对简单的答案,因为语法突出显示使用相同的标准来为数学东西着色,但我找不到任何东西。

    2 回复  |  直到 15 年前
        1
  •  5
  •   Community Mohan Dere    9 年前

    如果 andre-r 你不满意的答案,这里有一些代码 ` 在文本模式下自我插入,在数学模式下充当数学模式前缀。 LaTeX-math-mode 必须是 远离的 .

    (defun LaTeX-maybe-math ()
      "If in math mode, act as a prefix key for `LaTeX-math-keymap'.
    Otherwise act as `self-insert-command'."
      (interactive)
      (if (texmathp)
          (let* ((events (let ((overriding-local-map LaTeX-math-keymap))
                           (read-key-sequence "math: ")))
                 (binding (lookup-key LaTeX-math-keymap events)))
            (call-interactively binding))
        (call-interactively 'self-insert-command)))
    (define-key LaTeX-mode-map "`" 'LaTeX-maybe-math)
    

    以下改进留作练习:

    • 使其成为次要模式。

    • 使它对意外的输入更加健壮(我只测试了基本操作)。

    • 如果用户按未绑定的键序列,则显示更好的错误消息。

    • 如果用户按 C-h f1 .

        2
  •  3
  •   andre-r    15 年前

    LaTeX-math-mode “用于输入带有许多数学符号的文本的特殊次要模式。” (对于那些不知道该怎么做的人,你按“A”键,然后全神贯注。)所以我想如果你不学数学的话,把它开着也没什么害处。

    因此,信息页面建议:

    (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
    

    imho唯一的缺点是你必须按两次前缀:“to get”,至少可以使用标准前缀“customized in” LaTeX-math-abbrev-prefix .

    推荐文章