24

I know that it is possible to include somedir/subdir/anotherfile.tex in somedir/file.tex by using \include{subdir/file}. Is it possible to do it the other way around?

A Linux workaround that I'm aware of is a symbolic link of somedir/file.tex to somedir/subdir/file.tex.

2 Answers 2

19

Use \include{../file}.

.. is UNIX for the parent directory, which Tex uses. See Kpathsea: Path searching.

Postscript

Lev Bishop notes that this won't allow you to write to the parent directory, and that \include typically wants to write to a *.aux file in the parent directory. You can workaround the absence of write permission by setting TEXMFOUTPUT: on a Unix system, env TEXMFOUTPUT=.. latex mydoc will allow Latex to write (and overwrite) any file in the parent directory or any of its subdirectories when it compiles mydoc.tex.

This is somewhat safer than allowing overwriting everywhere the Tex binary has permission, and should work with Pdftex on both Texlive and Miktex (I'm not sure if TEXMFOUT is supported by Xetex).

42

With modern distributions, you can't, for security reasons: the idea is that tex input files should only allow files to be written at the same level or lower in the directory hierarchy, because tex will happily overrwrite preexisting files. Reading is ok, as with \input{../xyz} but the trouble is that \include{../xyz} causes writing of a file ../xyz.aux, which is not permitted.

One workaround is, as you said, to use symbolic links. Another (not recommended) is to deactivate the security feature:

  • in miktex: set environment variable MIKTEX_ALLOWUNSAFEOUTPUTFILES=1
  • in most other tex distributions, set openout_any=a

The best thing is to avoid needing to include files from parent directories. This is good anyway because then the structure of your files can mirror the logical structure of the document.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .