- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人知道一些用于清理 LaTeX 代码的好 elisp 宏吗?
我对其他人的资源进行了很多 LaTeX 编辑,并且我想扩展我的清理工具集,因为不是每个人都以我喜欢的方式组织他们的代码 ;-)
特别有趣的是,在缓冲区上运行函数 X 并让所有 LaTeX 环境(\begin{...} 和\end{...} 对)位于它们自己的行上,这有助于代码。
我可以自己尝试一下,但想听听有关编写此类功能的最佳实践的建议,例如它当然不应该引入自己的空行。
建议?
编辑:对于文件,这是我根据给出的答案的当前版本(假设使用 auctex)。它或多或少适合我目前的需求。我添加了 y-or-n 测试只是为了能够检测到我没有想到的极端情况。
(defun enviro-split ()
"Find begin and end macros, and put them on their own line."
(interactive)
(save-excursion
(beginning-of-buffer)
;; loop over document looking for begin and end macros
(while (re-search-forward "\\\\\\(begin\\|end\\)" nil t)
(catch 'continue
; if the line is a pure comment, then goto next
(if (TeX-in-commented-line)
(throw 'continue nil)
)
;; when you find one, back up to the beginning of the macro
(search-backward "\\")
;; If it's not at the beginning of the line, add a newline
(when (not (looking-back "^[ \t]*"))
(if (y-or-n-p "newline?")
(insert "\n")
)
)
;; move over the arguments, one or two pairs of matching braces
(search-forward "{") ; start of the argument
(forward-char -1)
(forward-sexp) ; move over the argument
(if (looking-at "[ \t]*{") ; is there a second argument?
(forward-sexp)
) ; move over it if so
(if (looking-at "[ \t]*\\[") ; is there a second argument?
(forward-sexp)
) ; move over it if so
(when (looking-at (concat "[ \t]*" (regexp-quote TeX-esc) "label"))
(goto-char (match-end 0))
(forward-sexp)
)
(if (looking-at (concat "[ \t]*%" ))
(throw 'continue nil)
)
;; If there is anything other than whitespace following the macro,
;; insert a newline
(if (not (looking-at "\\s *$"))
;;(insert "\n")
(if (y-or-n-p "newline (a)?")
(insert "\n")
)
)
) ; end catch 'continue
)
(LaTeX-fill-buffer 'left)
)
)
最佳答案
您可能可以编写一个正则表达式并为此进行正则表达式替换。但是,我发现这些操作的逻辑变得非常复杂,尤其是当您想要考虑各种边缘情况时。在您的示例中,您需要处理一些环境采用一个参数,而其他环境采用两个参数。我认为将一系列简单的正则表达式与基本的文本编辑命令结合起来更容易:
(defun enviro-split ()
"Find begin and end macros, and put them on their own line."
(interactive)
(save-excursion
(beginning-of-buffer)
;; loop over document looking for begin and end macros
(while (re-search-forward "\\\\\\(begin\\|end\\)" nil t)
;; when you find one, back up to the beginning of the macro
(search-backward "\\")
;; If it's not at the beginning of the line, add a newline
(when (not (looking-at "^"))
(insert "\n"))
;; move over the arguments, one or two pairs of matching braces
(search-forward "{") ; start of the argument
(forward-char -1)
(forward-sexp) ; move over the argument
(if (looking-at "\\s *{") ; is there a second argument?
(forward-sexp)) ; move over it if so
;; If there is anything other than whitespace following the macro,
;; insert a newline
(if (not (looking-at "\\s *$"))
(insert "\n")))))
关于emacs - 用于清理 LaTeX 代码的 Elisp 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538167/
有没有办法让某些文本仅在 [draft] 选项处于事件状态时显示。 例如,当草稿选项处于事件状态时,我希望在我的标题和摘要之间出现一些文字:“草稿:未经许可不得引用”或诸如此类。 最佳答案 通常这是用
我有一个小问题,我想将 LaTeX 文档的 svn diff 插入到 另一个 LaTeX 文档,目标是显示自修订版 XXX 以来发生的变化。 但是,由于差异包含大量 LaTeX 命令,我无法将其直接包
如何用它们的定义替换所有出现的用户定义的 latex 宏? 例如,给定这个文件 旧的.tex \newcommand{\blah}[2]{#1 \to #2} ... foo \blah{egg}{s
是否可以在 LaTeX 的一个环境 block 中使用多个命令?我试过类似的东西,但没有用...... \begin{sffamily,emph} I'm sans serif and ita
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 8 年前。 Improve
我想将每个项目彼此更靠近,即减少行距,但我没有找到任何有用的东西。 \begin{itemize} \item Processor: Intel Core \textsuperscr
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我试图在 LaTeX 文档中插入四个数字,但如果我使用 subfigure 命令,我的两个数字保留在第一行,另外两个转到第二行。像这样: 我尝试的另一个解决方案是使用 minipage 命令,但 mi
我将做大量的讲义,然后将它们编译成 LaTeX,这样我就可以拥有出色的文档供将来查看。我正在尝试组织事物,以便我可以拥有一堆包含讲座笔记的小文档,然后在学期结束时将它们编译成包含所有内容的大文档。我过
我有几个引理,其中指定了常量 $C_1$、$C_2$ 等以供以后引用。当然,当我稍后在中间插入一个新的常量定义时,这很烦人。我想要的是一个宏,它可以让我为常量分配标签并为我处理编号。我在想一些事情 %
我想制作一个包含两个目录的 LaTeX 文档,例如: Contents overview 1 - Introduction 2 - Solution Detailed contents 1 - Int
我正在使用 Latex 输入一堆数字 \begin{figure}[h] \centering \subfloat 等等。 如何让 subfloat 数字转到下一页?我的意思是,我输入了大
我在 \documentclass{article}在 latex 。我如何将顾问的名字放在第一页上?我在 latex 中看到过类似 \principaladvisor{} 的例子。但这似乎是通过论文
我目前卡住了,有两个单独的词汇表:main & acronyms . Acronyms词汇表在文本中首次使用时打印脚注,但 main词汇表没有。除了 acronyms 之外,还有什么方法可以制作任何其
如何在 Latex 中定义标签和对自定义环境的相应引用? 例子: \newcounter{fpcounter} \newenvironment{fp}[2] { \stepcounter{fpcoun
我希望doxygen文档生成器根本不生成任何LaTeX文件。 HTML对我来说足够了。是否可以配置doxygen.ini来这样做? 最佳答案 如果使用doxygen.ini是doxygen的配置文件,
我有一个关于 Latex 表的简单对齐问题。在 它看起来如下: \begin{center} \begin{tabular}{| c | l | l | } \hline \tt {
我对 LaTeX 中的定理编号有疑问。我可以按小节编号,例如 Theorem 1.2.1 对于第一节第二小节中的第一个定理。但我需要它给我看 只有小节和定理的编号,而不是节编号,如下所示: Theor
在标题部分中,我引用了文档的各个部分: \section {标题\cite {abc},\cite {def}} 文本 我也在使用目录功能,但是Latex必须首先查看标题(针对目录)中的引文,并为它们
我正在写一个程序(用C语言编写,但我想那不太重要),它与LaTeX中的一些记录 Material 有关。我希望纪录片 Material 包含原始代码中的代码片段。 为了包括源代码并使其保持最新,我在文
我是一名优秀的程序员,十分优秀!