I have a document which compiles fine. I am trying to refactor it into separate files but the input
command seems to be basing its paths relative to the build directory rather than the source directory.
My directory structure:
project/src/main.tex
project/build/
main.tex looks initially like this, simplified
\documentclass[a4paper,12pt]{book}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\begin{document}
...
\end{document}
If I do this
$> cd project/build
$> pdflatex ../src/main.tex
then I get the desired output in project/build/
with no junk added to project/src
, great.
Now move \renewcommand...
into project/src/commands.tex
and edit main.tex
\documentclass[a4paper,12pt]{book}
\input{commmands}
\begin{document}
...
\end{document}
Now when I run pdflatex
it halts on the second line:
! LaTeX Error: File `commands.tex' not found.
If I edit main.tex
thus:
\documentclass[a4paper,12pt]{book}
\input{../src/commands}
\begin{document}
...
\end{document}
then it compiles fine.
This is clearly idiotic. The source code should not care about the working directory of the compiler invocation.
How to I write main.tex
so that it includes all other files relative to its own path (and for this behaviour to apply to includes-of-includes and so on) so that I can compile the document out-of-source?
\input{C:/project/src/commands}
should do the trick, assuming thatproject/
is located in theC:
-directory of your windows-system. By using absolute pathes, your documents is no more portable, as with relative pathes. – Jan Jan 5 '17 at 14:22\usepackage{import}
comes to the rescue – vaettchen Jan 5 '17 at 15:01\input
is defined. It may not be what you expected but it is clearly not idiotic, people have worked with it that way for over 30 years. (I would not use absolute paths just use the TEXINPUTS search path, just as\documentclass{book}
(which is\input{book.cls}
) just requires the local filename not a path. – David Carlisle Jan 5 '17 at 15:09