如何在emacs中的文本块上插入LaTeX环境? [英] How to insert a LaTeX environment around a block of text in emacs?

查看:246
本文介绍了如何在emacs中的文本块上插入LaTeX环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有cdlatex模式的emacs来编辑LaTeX文件。我想知道如何在已经写入的文本块中插入LaTeX环境,以便 c \\ c> c \\ c> c \\ c在所选文本之前, \end {} 在所选文本之后。我试图使用cdlatex环境函数,但这样做会擦除所选文本。

I'm using emacs with cdlatex-mode to edit LaTeX files. I would like to know how to insert a LaTeX environment around a block of text that is already written so that the \begin{} goes before the selected text and the \end{} goes after the selected text. I've tried to use cdlatex-environment function but doing so erases the selected text.

推荐答案

AUCTeX



如果您使用 auctex


  1. 标记要在环境中包围的文本块。

  2. 按输入您选择的环境类型(您只能输入一些字符并使用选项卡完成),然后按输入

请参阅手册的详细信息。

请注意,在宏中包含标记文本的方法类似。执行1-3,而是按 C-c C-e C-c输入。有关详细信息,请参阅手册

Note that there is a similar method to enclose marked text in macros. Do as 1–3 but instead press C-c C-e or C-c Enter instead. See the manual for details.

如果您使用 YASnippet ,您可以创建与上述类似行为的代码段。例如,您可以使用以下内容(您使用正确的键盘代替keybinding):

If you use YASnippet you can create a snippet with similar behavior as above. For example you can use the following (you have replace "keybinding" with a proper keybinding):

# -*- mode: snippet -*-
# name: LaTeX environment
# key: "keybinding"
# --
\begin{$1}
  `yas/selected-text`$0
\end{$1}

如果你想要一个代码片段的宏,可以使用以下内容:

If you want a snippet for macros too you can use something like the following:

# -*- mode: snippet -*-
# name: LaTeX macro
# key: "keybinding"
# --
\$1{`yas/selected-text`$0}



Elisp



即使我推荐上述方法,可能会出现一些情况,而不是使用一些简单的elisp函数。以下只是一些粗略的东西,其功能远远低于上述方法:

Elisp

Even if I recommend the above approaches there might be situations where you want instead to use some simple elisp function. The following is just something rough which has far less functionality than the above approaches:

(defun ltx-environment (start end env)
  "Insert LaTeX environment."
  (interactive "r\nsEnvironment type: ")
  (save-excursion
    (if (region-active-p)
    (progn
      (goto-char end)
      (newline)
      (insert "\\end{" env "}")
      (goto-char start)
      (insert "\\begin{" env "}") (newline))
      (insert "\\begin{" env "}") (newline) (newline)
      (insert "\\end{" env "} "))))

对于宏,如果你也想这样做:

And for macros if you want that too:

(defun ltx-macro (start end env)
  "Insert LaTeX macro."
  (interactive "r\nsMacro: ")
  (save-excursion
    (if (region-active-p)
    (progn
      (goto-char end) (insert "}")
      (goto-char start) (insert "\\" env "{"))
      (insert "\\" env "{}"))))

要使用它们将它们放在.emacs中,然后执行 Mx ltx-environment ltx-macro

To use them put them in your .emacs and do M-x ltx-environment or ltx-macro respectively.

这篇关于如何在emacs中的文本块上插入LaTeX环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆