# Open a file whose name start with a dot and other strangely named files?

The syntax of TeX's \openout command is rather simple:

\openoutN=ﬁlename

where N is a four-bit number, but what is filename? How do you open a file whose name stars with a dot? More generally, how do you deal with a filename passed as a parameter which may include strange characters?

To make my difficulty concrete, here is a sequence of commands that:

1. Will switch to a temporary directory
2. Remove any remaining files from previous runs
3. Create a demo tex file, named joseph.tex which tries to write to a file named wright, and then to a file named .joseph.
4. Examine the result via ls
5. Try to print out the resulting files

pushd /tmp; rm -f joseph* .joseph* wright*;cat<<EOF >joseph.tex
\newwrite\mywrite
\immediate\openout\mywrite=wright
\immediate\write\mywrite{Hello, World!}
\immediate\openout\mywrite=.joseph.tex
\immediate\write\mywrite{Hello, World!}
\bye
EOF
echo q | tex joseph.tex
ls -ls joseph* .joseph* wright*; cat wright.tex; popd


(copy/paste the above to your favorite command shell) My output is:

    This is TeX, Version 3.1415926 (TeX Live 2010)
(./joseph.tex
tex: Not writing to .joseph.tex (openout_any = p).

! I can't write on file .joseph.tex'.
l.4 \immediate\openout\mywrite=.joseph.tex

(Press Enter to retry, or Control-D to exit; default file extension is .tex')
Please type another output file name:  )
No pages of output.
Transcript written on joseph.log.
0 /tmp 12:12:05 $ls -ls joseph* .joseph* wright*; cat wright.tex; popd /bin/ls: cannot access .joseph*: No such file or directory 4 -rw-r--r-- 1 yogi yogi 449 2011-03-12 12:12 joseph.log 4 -rw-r--r-- 1 yogi yogi 176 2011-03-12 12:12 joseph.tex 4 -rw-r--r-- 1 yogi yogi 14 2011-03-12 12:12 wright.tex Hello, World! /tmp  which I interpret to be a failure to create file named .joseph, but success in creating the file named wright. I tried creating a file named ./joseph but this does not seem to work as well. I fear the worst when I will try to create a file in a directory, e.g., .joseph/wright.thanks - ## 2 Answers This is a security restriction which is enabled by default in TeX Live. Quoting the default texmf.cnf: % 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


Hence you need to set openout_any to a for your example to work. Note that you should refrain from changing this feature system-wide and instead use the openout_any environment variable:

> openout_any=a tex myfile.tex

-
@Yossi: See also this answer to How can I safely compile other people's LaTeX documents?. –  Martin Scharrer Mar 12 '11 at 10:49

For me, a simple test file

\newwrite\mywrite
\openout\mywrite=.test
\immediate\write\mywrite{Hello world}
\bye


works entirely as expected. Apart from the restrict that UTF-8 characters might not work as expected with pdfTeX, I don't think TeX is too worried about the file name. Of course, spaces are a different matter!

-
Thanks Joseph for taking interest in this. I tried adding more detail to my question to show where I experience the difficulty. –  Yossi Gil Mar 12 '11 at 10:23