Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

LaTeX: Import & Subimport for Document Organization

📅 2010-May-27 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ import, latex ⬩ 📚 Archive

Large LaTeX documents can be organized nicely by using the * command. For more on that see this post. However, the * command is not intelligent, it blindly includes the content of its files.

For example, a Report.tex includes a 01-IntroDir/01-Intro.tex file that uses lots of images stored in 01-IntroDir. All of the \includegraphics commands in 01-IntroDir/01-Intro.tex would have to include the 01-IntroDir/ prefix:

% 01-IntroDir/01-Intro.tex
\includegraphics{01-IntroDir/Image0.png}
\includegraphics{01-IntroDir/Image1.png}
\includegraphics{01-IntroDir/Image2.png}

To intelligently include the content in other directories such that all their content paths are also relative, the * and * commands from the import package can be used.

For example, Report.tex can be changed to:

% Report.tex
\usepackage{import}
\subimport{01-IntroDir/}{01-Intro.tex}

When * or * are used, the imported files can refer to their images/files relative to themselves. So, the above 01-IntroDir/01-Intro.tex can be simplified to:

% 01-IntroDir/01-Intro.tex
\includegraphics{Image0.png}
\includegraphics{Image1.png}
\includegraphics{Image2.png}