简体   繁体   English

带有'$'字符的AucTeX / emacs问题

[英]AucTeX/emacs problem with '$' character

AucTeX on emacs is pretty amazing tool, but when I write one single '$', all the coloring is broken. 关于emacs的AucTeX是非常了不起的工具,但是当我写一个单独的'$'时,所有的颜色都被打破了。

Normally one '$' is accompanied by another '$' to express math equations, but for source listing single '$' is frequently used. 通常一个'$'伴随着另一个'$'表示数学方程式,但对于源列表,经常使用单个'$'。

\begin{Verbatim}
(let ((buffer (url-retrieve-synchronously
...
    (re-search-forward "^$" nil 'move) <-- It breaks the coloring 
...
\end{Verbatim}

The easy solution is as follows to match the '$'. 简单的解决方案如下匹配'$'。

(re-search-forward "^$" nil 'move) ;; $

Is there any option in AucTeX to prevent this single '$' problem? AucTeX中有任何选项可以防止出现这个单一的'$'问题吗?

AUCTeX knows that $ is not special in verbatim environments, but you have to tell it that Verbatim is a verbatim environment by arranging for it to appear in LaTeX-verbatim-environments-local . AUCTeX知道$在逐字环境中不是特别的,但你必须告诉它Verbatim是一个逐字环境,安排它出现在LaTeX-verbatim-environments-local

If AUCTeX is installed optimally, it already knows, because AUCTeX loads a style hook for each file you load through \\usepackage and friends. 如果AUCTeX以最佳方式安装,它已经知道了,因为AUCTeX为你通过\\usepackage和friends加载的每个文件加载一个样式挂钩。 You may need to tell it to parse your header file with Cc Cn ( TeX-normal-mode ). 您可能需要告诉它使用Cc CnTeX-normal-mode )解析头文件。

If that's not enough, it means Verbatim was defined in a style file for which AUCTeX doesn't have enough information. 如果这还不够,则意味着在样式文件中定义了Verbatim ,而AUCTeX没有足够的信息。 You can tell AUCTeX to parse some or all the style files you have installed; 您可以告诉AUCTeX解析您安装的部分或全部样式文件; see the “Automatic” chapter in the AUCTeX manual. 请参阅AUCTeX手册中的“自动”章节。

Sometimes AUCTeX doesn't manage to parse the style file; 有时AUCTeX无法解析样式文件; then you can do this part by hand. 然后你可以手工完成这部分。 The code below assumes that you're getting the Verbatim environment from the fancyvrb package; 下面的代码假设您从fancyvrb包获得了Verbatim环境; adapt the name otherwise. 否则改编名称。 Create a file called fancyvrb.el in one of the directories mentioned in TeX-style-path with the following contents (there may be other things worth putting there, I've just adapted alltt.el ): TeX-style-path提到的一个目录中创建一个名为fancyvrb.el的文件,其中包含以下内容(可能还有其他值得投入的内容,我刚刚调整了alltt.el ):

(TeX-add-style-hook
 "fancyvrb"
 (lambda ()
   (LaTeX-add-environments "BVerbatim" "LVerbatim" "SaveVerbatim" "Verbatim")
   (make-local-variable 'LaTeX-indent-environment-list)
   (add-to-list 'LaTeX-indent-environment-list '("BVerbatim" current-indentation))
   (add-to-list 'LaTeX-indent-environment-list '("LVerbatim" current-indentation))
   (add-to-list 'LaTeX-indent-environment-list '("SaveVerbatim" current-indentation))
   (add-to-list 'LaTeX-indent-environment-list '("Verbatim" current-indentation))
   (make-local-variable 'LaTeX-verbatim-regexp)
   (setq LaTeX-verbatim-regexp (concat LaTeX-verbatim-regexp "\\|\\([BL]?\\|Save\\)Verbatim"))
   (add-to-list 'LaTeX-verbatim-environments-local "BVerbatim")
   (add-to-list 'LaTeX-verbatim-environments-local "LVerbatim")
   (add-to-list 'LaTeX-verbatim-environments-local "SaveVerbatim")
   (add-to-list 'LaTeX-verbatim-environments-local "Verbatim")
   (when (and (featurep 'font-latex)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-set-syntactic-keywords)
     (setq font-lock-set-defaults nil)
     (font-lock-set-defaults))))

(I thought you could also do it manually through file variables, but this turns out not to work, because the font-lock settings are built before the file local variables are initialized, and I don't see a workaround.) (我认为你也可以通过文件变量手动完成,但事实证明这不起作用,因为字体锁设置是在文件局部变量初始化之前构建的,我没有看到解决方法。)

Is there a reason to use Verbatim vs. verbatim? 是否有理由使用逐字与逐字? verbatim makes everything in the section the same color for me. 逐字会使该部分中的所有内容都适合我。 As an aside, I prefer to use the listings package. 顺便说一句,我更喜欢使用列表包。 for showing program code in latex. 用于显示乳胶中的程序代码。

Using the package listings you can add non-formatted text as you would do with \\begin{verbatim} but its main aim is to include the source code of any programming language within your document. 使用包列表,您可以像添加\\ begin {verbatim}一样添加非格式化文本,但其主要目的是在文档中包含任何编程语言的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM