我对 emacs 有点陌生。我正在用 latex 编辑一个文档,我想用斜体显示一些单词。我想要一个简单的宏,如果我将光标放在单词上,然后按组合键,该单词就会用斜体包围,如下所示 \textit{word}
。
是否有插件或快速方法来实现此目的或 emacs-lisp 宏?
最佳答案
就个人而言,我在 emacs
中使用 AUCTeX
进行 TeX/LaTeX 编辑。有很多关于如何使用它的很好的教程,例如A simpleton's guide to (…)TeX workflow with emacs或Emacs as the Ultimate LaTeX Editor 。回答您的问题:是的,这是可能的,并且 AUCTeX
提供了工具:
手册中相关章节为Changing the Font ,摘自手册:
AUCTeX provides convenient keyboard shortcuts for inserting macros which specify the font to be used for typesetting certain parts of the text. They start with C-c C-f, and the last C- combination tells AUCTeX which font you want:
[...]
C-c C-f C-i
Insert italics ‘\textit{∗}’ text.
如果您使用事件区域执行该命令,它将将该区域放入格式化命令的参数中。如果没有区域,将插入格式化命令,然后您输入所需的内容。
通过将其与诸如 expand-region
之类的包结合起来或thing-cmds
您可以按步骤更改单词的格式
- 使用
expand-region
/mark-thing
标记单词 - 使用
AUCTeX
应用格式
人们可以将这两个步骤组合成一个即发即忘的函数(例如TeX-italicise-word
,但是,我强烈建议不要这样做,因为(在我的观点)emacs
的真正力量来自于组合函数/ Action 。
如果您确实坚持使用单键解决方案,我建议您阅读 Keyboard Macros它可用于以交互方式创建复合命令。
关于emacs - emacs 中的斜体字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29915483/