Tyler Clemons

Using nested \input with subdirectories in LaTeX

by on Jul.19, 2012, under LaTeX

I ran into this annoyance using LaTeX (more specifically TeXShop on OSX). Apparently you can’t use nested input commands with LaTeX without special instruction. We can use the import package.

Suppose you have a root directory with a root tex file called root.tex, and a subdirectory called chapter1. Further suppose chapter1 has files called intro.tex and and section1.tex. Inside root.tex, you may have something like this:


\input{chapter1/intro}

Inside intro.tex, you might have something like this:


\input{section1.tex}

When you try to compile root.tex, LaTeX will not find section1.tex. To fix this, return to root.tex. We are going to add the following line:


\usepackage{import}

and change:


\input{chapter1/intro}

to


\import{chapter1/}{intro}

\import allows relative \input commands, and graphic includes as well, to execute without any problems.


Leave a Reply

Looking for something?

Use the form below to search the site: