Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I include a file from a subdirectory with \include{subdir/sub} and compile the file with pdflatex -output-directory .tex_test/ main.tex, pdflatex complains, that it can't write to .tex_test/subdir/sub.aux. (Same happens with xelatex)

Is there a way to automatically create the necessary file structure in the output-directory? Of course it would also be ok, if sub.aux would be written directly to .tex_test/, but I guess that is not possible...

Full MWE: ./main.tex contains:

Main Document


and ./subdir/sub.tex contains just anything. More importantly the directory .tex_test/ exists.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Just recreate in the invisible directory the same tree as your "visible" one: I tried and creating a subdir directory inside .tex_test worked.

Actually I changed the names, but it's just the same. Here's the log

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, 
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
 polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, 
welsh, loaded.
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(.canaout/canasub.aux (.canaout/canasub/sub.aux)) [1{/usr/local/texlive/2012/te
xmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./canasub/sub.tex) [2]
(.canaout/canasub.aux (.canaout/canasub/sub.aux)) )</usr/local/texlive/2012/tex
Output written on .canaout/canasub.pdf (2 pages, 13249 bytes).
Transcript written on .canaout/canasub.log.

As you see, the sub.aux file is read in from .canasub/canasub

With shell escape enabled, you can create the directory:


  \def\@mkdir#1{\immediate\write18{mkdir -p .tex_test/#1}}
  \def\@mkdir{\typeout{Expect errors}}

Main Document


Here I assume a Unix system (I don't know how to create a directory on Windows) and that all \include commands have the same structure


It should be quite easy to cope with different patterns. Of course you have to add -shell-escape to the call of pdflatex.

However the .tex_test part must be hard encoded, as TeX has no internal knowledge of the output directory.

share|improve this answer
That's why I wrote "Is there a way to automatically create the necessary file structure in the output-directory?"... –  canaaerus Jul 22 '12 at 20:34
@canaaerus No: TeX doesn't create directories. You might use shell-escape for this, but I wouldn't recommend it. –  egreg Jul 22 '12 at 20:35
Shell help is acceptable. But then TeX would have to output the directory structure somehow. –  canaaerus Jul 22 '12 at 20:38
add comment

WinEdt 7 is able to do what you need automatically.

Simply create a subfolder named TeXAux in your main folder and WinEdt takes care of creating subfolders automatically.

You don't even need to pass -output-directory to the command-line.

share|improve this answer
add comment

I use a Makefile for my LaTeX document. This command creates the directory structure of the root directory in the output-directory:

for DIR in $(shell find . -maxdepth 1 -mindepth 1 -type d -exec basename '{}' \;) ; do \
    mkdir -p ${OUTPUTDIRECTORY}/$$DIR ; \

-maxdepthdefines how deep findgoes to look for directories. I got this command from here.

Using a Rakefile or Python script would probably make this even easier. There doesn't seem to be a way for pdflatexto automatically create the necessary directories.

share|improve this answer
Welcome to TeX.SX! –  mafp Jun 20 '13 at 15:09
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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