具有以下 MWE:
\documentclass{article}
\usepackage{filecontents,hyperref,listings}
\begin{filecontents*}{script.bat}
@echo off
echo "Hello, World!"
pause
\end{filecontents*}
\begin{document}
\lstinputlisting[language=csh,float,caption={A Windows batch file}]{script.bat}
Click \href{run:script.bat}{here} to run the script.
\end{document}
我总是收到错误
ERROR: I can't write on file `script.bat'. --- TeX said --- <to be read again> \relax l.4 \begin{filecontents*}{script.bat}
在交互模式 ( pdflatex test
) 下,此错误会持续存在,直到给出不带“bat”扩展名的文件名。这是怎么回事?
答案1
在 Windows 中,由于安全原因,您通常会遇到此错误。要消除此类错误,您需要执行以下操作:
openout_any = r
在 中设置值texmf.cnf
。这里有三个选项,任何(a)、限制(r)和偏执狂(p)。
% Allow TeX \openin, \openout, or \input on filenames starting with `.'
% (e.g., .rhosts) or outside the current tree (e.g., /etc/passwd)?
% a (any) : any file can be opened.
% r (restricted) : disallow opening "dotfiles".
% p (paranoid) : as `r' and disallow going to parent directories, and
% restrict absolute paths to be under $TEXMFOUTPUT.
openout_any = p
openin_any = a
笔记:根据@egreg,我改变了选项openout_any = a到openout_any = r,在 Windows 中也能成功运行。