Emacs 中 LaTeX 的代码折叠 [英] Code folding for LaTeX in Emacs

查看:25
本文介绍了Emacs 中 LaTeX 的代码折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 Emacs 次要模式(或一段 elisp 代码)可以让您在 LaTeX 模式下有选择地隐藏/显示环境?例如,我想移动到一个长 egin{figure} 块的开头,点击一个按键,然后隐藏图形环境的内容.与 egin{proof} 等类似,理想情况下甚至使用 subsections.

Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in LaTeX mode? For instance, I would like to move to the beginning of a long egin{figure} block, hit a keystroke, and have the contents of that figure environment hidden from view. Similarly with egin{proof} and so on, and ideally even with subsections.

这可能吗?我刚刚尝试了 hs-minor-modeallout-modeoutline-minor-mode,但大多数都无法识别 LaTeX环境,例如hs-minor-mode 失败并显示扫描错误:括号不平衡".我不想在 folding-mode 中输入明确的折叠标记,如 {{{.

Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize LaTeX's environments, e.g. hs-minor-mode fails with "scan error: unbalanced parentheses". I would prefer not to have to enter explicit folding marks like {{{ as in folding-mode.

[理想情况下,如果折叠是持久,那就太好了,但我看到了问题还没有被接受的答案.]

[Ideally it would be great if the folding were persistent, but I see that that question doesn't have an accepted answer yet.]

推荐答案

AUCTeX 进行折叠:http://www.gnu.org/software/auctex/manual/auctex.html#Folding

AUCTeX does folding: http://www.gnu.org/software/auctex/manual/auctex.html#Folding

对 TeX 和 LaTeX 等标记语言的普遍抱怨是,源文本过于混乱,无法很好地专注于内容.在某些宏中,您只对它们所包含的内容感兴趣,例如字体说明符,其中的内容可能已经通过字体锁定以特殊方式进行了字体化.或者宏,您只希望在实际编辑时查看其内容,例如脚注或引文.同样,当您试图将注意力集中在文档正文时,您可能会发现某些环境或评论会让人分心.

A popular complaint about markup languages like TeX and LaTeX is that there is too much clutter in the source text and that one cannot focus well on the content. There are macros where you are only interested in the content they are enclosing, like font specifiers where the content might already be fontified in a special way by font locking. Or macros the content of which you only want to see when actually editing it, like footnotes or citations. Similarly you might find certain environments or comments distracting when trying to concentrate on the body of your document.

使用 AUCTeX 的折叠功能,您可以折叠这些项目并将它们替换为固定字符串、其中一个参数的内容或两者的混合.如果您想让原始文本再次可见以进行查看或编辑,请将点从侧面移动到占位符(也称为显示字符串)上或用鼠标指针在其上单击左键.(后者目前仅在 Emacs 上受支持.)宏或环境将自动展开,只要点在其中就保持打开状态,一旦您将点移出它就会再次折叠.(请注意,折叠环境目前不适用于所有 AUCTeX 模式.)

With AUCTeX’s folding functionality you can collapse those items and replace them by a fixed string, the content of one of their arguments, or a mixture of both. If you want to make the original text visible again in order to view or edit it, move point sideways onto the placeholder (also called display string) or left-click with the mouse pointer on it. (The latter is currently only supported on Emacs.) The macro or environment will unfold automatically, stay open as long as point is inside of it and collapse again once you move point out of it. (Note that folding of environments currently does not work in every AUCTeX mode.)

为了使用这个功能,你必须激活 TeX-fold-mode 这将激活自动显示功能和必要的命令来隐藏和显示宏和环境.您可以通过键入命令 M-x TeX-fold-mode RET 或使用键盘快捷键 C-c C-o C-f 来激活特定缓冲区中的模式.如果你想每次编辑 LaTeX 文档时都使用它,把它加到一个钩子上:

In order to use this feature, you have to activate TeX-fold-mode which will activate the auto-reveal feature and the necessary commands to hide and show macros and environments. You can activate the mode in a certain buffer by typing the command M-x TeX-fold-mode RET or using the keyboard shortcut C-c C-o C-f. If you want to use it every time you edit a LaTeX document, add it to a hook:

(add-hook 'LaTeX-mode-hook (lambda ()
                             (TeX-fold-mode 1)))

如果它应该在所有 AUCTeX 模式下激活,请使用 TeX-mode-hook 而不是 LaTeX-mode-hook.

If it should be activated in all AUCTeX modes, use TeX-mode-hook instead of LaTeX-mode-hook.

一旦模式处于活动状态,有几个命令可用于隐藏和显示宏、环境和注释...

Once the mode is active there are several commands available to hide and show macros, environments and comments...

这篇关于Emacs 中 LaTeX 的代码折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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