将 minted(源代码 LaTeX 包)与 emacs/auctex 一起使用
正如此处所述,我发现 minted 包对于源代码列表来说非常酷。
我的问题是如何将 minted 包与 AucTeX/emacs 一起使用? 对于命令行,我可以使用pdflatex -shell-escape SOURCE
,但是
- 问题1:如何修改AucTeX以插入
-shell-escape
?我的意思是,如何更改 C-c+C-c 的操作? - Q2 :
-shell 是否需要 C-c+C-c 以外的特殊密钥-escape选项?或者说,使用起来没有任何问题就可以了吗?
- Q3:
-shell-escape
是做什么用的?
As is explained in here, I find minted package is pretty cool for source code listing.
My question is how to use minted package with AucTeX/emacs?
For command line I can use pdflatex -shell-escape SOURCE
, but
- Q1 : How can I modify the AucTeX to insert the
-shell-escape
? I mean, how to change the action for C-c+C-c? - Q2 : Do I need special key other than C-c+C-c for
-shell-escape
option? Or, is it just OK to use it without any problem? - Q3 : What is the
-shell-escape
for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Q1:您需要编辑AucTeX调用LaTeX的方式。一种方法是将以下内容添加到您的 .emacs 文件中:
Q2:进行更改后,所有通过 Cc Cc 对 LaTeX 的调用都将使用
-shell-escape
选项。Q3:参见康拉德的回答。请注意,此方法将为在 AucTeX 中编辑的所有文件启用
-shell-escape
,因此如果使用其他人的包或文件,可能会存在潜在的安全风险。Q1: You need to edit the way LaTeX is called by AucTeX. One way of doing this is to add the following to your .emacs file:
Q2: Once you have made the changes, all calls to LaTeX with C-c C-c will use the
-shell-escape
option.Q3: See Konrad's answer. Note that this method will enable
-shell-escape
for all files edited in AucTeX, so can be a potential security risk if using other peoples packages or files.在 auctex 的最新版本中,看起来设置 TeX-command-extra-options 会更可靠,它就是为此目的而设计的,并且不会让您覆盖各种表单
TeX 命令
。据我了解(可能是错误的),这不能全局设置,但必须为每个文件设置。您可以使用钩子来完成此操作。例如,在.emacs
中,您可以添加以下内容:并且由于您没有完全覆盖 Latex 命令调用,因此其他功能仍然有效 - 例如打开
synctex
支持与(setq TeX-source-correlate-mode t)
[这可能发生在钩子之外]。In recent versions of auctex, it looks like it'll be more reliable to set
TeX-command-extra-options
, which is designed for just this purpose, and doesn't make you override the various forms ofTeX-command
. As I understand it (might be wrong), this can't be set globally, but must be set for each file. You can do this with a hook. For example, in.emacs
you might add this:And since you don't fully overwrite the latex command call, other features will still work -- like turning on
synctex
support with(setq TeX-source-correlate-mode t)
[which can happen outside the hook].我只能回答问题3:
minted 使用第三方应用程序 pygmentize 来处理源代码。出于安全原因,LaTeX 通常不允许调用其他应用程序(恶意包可能会调用任意代码)。要显式启用调用外部应用程序,您需要启用这种所谓的 shell 转义 - 在大多数 LaTeX 安装中,这是通过
-shell-escape
开关完成的。I can only answer question 3:
minted uses a third-party application,
pygmentize
, to process the source code. LaTeX usually doesn’t allow calling other applications for security reasons (a rogue package could otherwise call aribtrary code). To explicitly enable calling external applications, you need to enable this so-called escape to the shell – which, on most LaTeX installations, is done via the-shell-escape
switch.使用这个
.dir-locals.el
文件讨论
将上面的 .dir-locals.el 文件放在与使用 minted 的 Latex 文件相同的目录中。
这会导致 Ctrlc Ctrlc 使用
-shell-escape
选项。第一行将其设置为 AUCTeX,第二行将其设置为 emacs 的内置乳胶模式(当未安装 AUCTeX 时)。文件的其余部分向 emacs 提示“minted”环境的样式应类似于逐字环境。通常,emacs 的 Latex 模式将下划线后面的字符显示为下标,例如 _this_for_example。
为什么不是
.emacs
文件?使用 .emacs 很方便,但有风险。全局启用
-shell-escape
被认为是危险的——默认情况下它没有启用是有原因的——应该谨慎使用。相反,使用 .dir-locals.el 文件可以选择仅对实际需要的文档启用-shell-escape
。Use this
.dir-locals.el
fileDiscussion
Put the above .dir-locals.el file in the same directory as the latex files which use minted.
This causes Ctrlc Ctrlc to use the
-shell-escape
option. The first line sets it up for AUCTeX and the second sets it for emacs's builtin latex-mode, when AUCTeX is not installed.The remainder of the file hints to emacs that the "minted" environment should be styled like a verbatim environment. Normally emacs's latex-mode displays the character after an underscore as a subscript, like_this_for_example.
Why not the
.emacs
file?Using .emacs is convenient, but risky. Enabling
-shell-escape
globally is considered dangerous — there's a reason it is not on by default — and it should be used sparingly. Using a .dir-locals.el file instead allows one to choose to enable-shell-escape
only for the documents that actually need it.