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

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

问题描述

是否有一个Emacs小模式(或一些精灵代码),可以让您在LaTeX模式下有选择地隐藏/显示环境?例如,我想移动到一个长的 \begin {figure} 块的开头,点击击键,并使该图形环境的内容从视图中隐藏。同样地, \begin {proof} 等等,理想情况下即使是 \subsection

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 \begin{figure} block, hit a keystroke, and have the contents of that figure environment hidden from view. Similarly with \begin{proof} and so on, and ideally even with \subsections.

这可能吗?我刚尝试过 hs-minor-mode allout-mode outline-minor-模式,但大多数人不认识LaTeX的环境,例如hs-minor-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-折叠模式,这将激活自动显示功能和必要的命令来隐藏和显示宏和环境。您可以通过键入命令 Mx TeX-fold-mode RET 或使用键盘快捷键 Cc Co Cf 。如果要在每次编辑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天全站免登陆