Using minted (source code LaTeX package) with emacs/auctex

耗尽温柔 提交于 2019-12-03 05:57:06

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:

(eval-after-load "tex" 
  '(setcdr (assoc "LaTeX" TeX-command-list)
          '("%`%l%(mode) -shell-escape%' %t"
          TeX-run-TeX nil (latex-mode doctex-mode) :help "Run LaTeX")
    )
  )

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.

I can only answer question 3:

What is the '-shell-escape' for?

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.

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 of TeX-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:

(add-hook 'TeX-mode-hook
  (lambda ()
    (setq TeX-command-extra-options "-shell-escape")
  )
)

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!