2

Is it possible with TeX to write somewhere else than in the current folder?

The following does not work:

\documentclass{article}
\begin{document}

\newwrite\tempfile
\openout\tempfile=/Users/colas/Desktop/coucou.aux
\write\tempfile{Test}
\closeout\tempfile

Test

\end{document}

The error is

./bac_a_sable.tex:13: I can't write on file `/Users/colas/Desktop/coucou.aux'. \endgroup \set@typeset@protect l.13 \end{document}

4
  • 2
    You'll need to lower the security settings to allow it. Are you sure you want to do that? Apr 17, 2018 at 15:18
  • My goal is to store some info in a global file. See:tex.stackexchange.com/q/426972/8323
    – Colas
    Apr 17, 2018 at 15:20
  • 2
    if you lower your settings to allow that never run any code from someone you do not trust (eg any examples from this site) you would be allowing them to write new password files or ssh keys or .... Apr 17, 2018 at 17:33
  • 2
    it is far safer to keep the security setting but make a symbolic link in the current directory to your global file so you can write that file with a local path Apr 17, 2018 at 17:35

1 Answer 1

4

TeX Live (which I'm guessing you're using) normally doesn't allow file write operations outside of the current directory path because it's a security risk. This is governed by the openout_any setting, which may take one of three values (information copied from texmf.cnf):

  • a (any) : any file can be opened.
  • r (restricted) : disallow opening dot files
  • p (paranoid) : as r and disallow going to parent directories, and restrict absolute paths to be under $TEXMFOUTPUT.

Normally the setting is p, which doesn't allow going to parent directories. I really don't recommend changing this setting.

You might want to consider changing $TEXMFOUTPUT to the target directory (since you're using an absolute path), which should then be allowed write access under TeX (if the filing system permits it), but I think David's comment is better:

it is far safer to keep the security setting but make a symbolic link in the current directory to your global file so you can write that file with a local path

If you are absolutely sure that you want to lower the security settings, you can change your preferred setting in your texmf.cnf file. But I really don't recommend it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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