5

I have a LaTeX-file (thesis.tex) which I edit daily. Some LaTeX-package I use requires me to compile the file with --shell-escape, so I added the file-local variable

%%% TeX-command-extra-options: "--shell-escape"

at the end of my file. This variable is considered risky, so every time I open my file, emacs asks me to confirm this variable is safe for this file. This is a bit annoying.

For arbitrary files I totally agree with the reasoning that --shell-escape is unsafe, so I do not want to mark this value as safe for arbitrary files by customizing safe-local-variable-values, as described in the documentation.

Is it possible to mark this local variable safe only for thesis.tex?

1 Answer 1

10

In the elisp manual at C-hig (elisp)File Local Variables we find:

You can specify safe values for a variable with a ‘safe-local-variable’ property. The property has to be a function of one argument; any value is safe if the function returns non-‘nil’ given that value. Many commonly-encountered file variables have ‘safe-local-variable’ properties; these include ‘fill-column’, ‘fill-prefix’, and ‘indent-tabs-mode’. For boolean-valued variables that are safe, use ‘booleanp’ as the property value.

Hence in your config you can set this to a function which approves your specific file.

(put 'TeX-command-extra-options 'safe-local-variable
     (lambda (value)
       (and (equal value "--shell-escape")
            (equal buffer-file-name "/path/to/thesis.tex"))))
1
  • Thanks, works perfectly! Commented Apr 11 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.