LaTeX: Import & Subimport for Document Organization

Large LaTeX documents can be organized nicely by using the \input command. For more on that see this post. However, the \input 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 \import and \subimport 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 \import or \subimport 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}
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s