The syntax of TeX's \openout
command is rather simple:
\openout
N=
filename
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:
- Will switch to a temporary directory
- Remove any remaining files from previous runs
- Create a demo tex file, named
joseph.tex
which tries to write to a file named wright, and then to a file named .joseph. - Examine the result via
ls
- 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