Emacs 中 LaTeX 的代码折叠

发布于 2024-08-28 13:19:19 字数 628 浏览 8 评论 0原文

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

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

[理想情况下,如果折叠是持久的,那就太好了,但我发现这个问题没有还没有一个被接受的答案。]

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.

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.]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2024-09-04 13:19:19

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

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

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

为了使用此功能,您必须激活 TeX-fold-mode ,这将激活自动显示功能以及隐藏和显示宏和环境的必要命令。您可以通过键入命令 Mx TeX-fold-mode RET 或使用键盘快捷键 Cc Co Cf 来激活特定缓冲区中的模式。如果您想在每次编辑 LaTeX 文档时使用它,请将其添加到挂钩中:

(add-hook 'LaTeX-mode-hook (lambda ()
                             (TeX-折叠模式 1)))

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

模式激活后,有几个命令可用于隐藏和显示宏、环境和注释...

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

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.

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.)

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)))

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文