6

I am working on a project and i want to slim it down a litle so please help me with the following. I have a document structure like this:

/DocumentRoot
 |-main.tex
 |-title.tex
 |
 |-/chapter-1
 |  |-/images
 |  |-chapter-1.tex
 |
 |-/chapter-2
    |-/images
    |-chapter-2.tex

My document is like this:

\begin{document}
\include{./title}
\include{./chapter-1/chapter-1}
\include{./chapter-2/chapter-2}
\include{./chapter-3/chapter-3}
\end{document}

in my chapters i use both some images and some heavy tikz plots so i use externalize and draft options for quicker compilation. But i want the images to be placed in the respective chapter folders but for example in chapter 3 this works:

\includegraphics[width=\linewidth]{./chapter-3/images/img.jpg}

and this doesn't

\includegraphics[width=\linewidth]{./images/img.jpg}

for some reason xelatex has problems with the relative paths of included chapters. I also want to control the location output and the naming of the externalized tikz documents. Any help with that? I am working with miktex and texworks.

1

1 Answer 1

8

The idea is simple, just prepare directory paths (to import both chapter files and images files) whenever you include a new chapter.

Main.tex

\documentclass{book}
\usepackage{graphicx}

\def\Include#1{%
        \def\ChapterPath{#1/}%
        \def\GraphicsPath{\ChapterPath Images/}%
        \include{\ChapterPath#1}}

\newcommand\IncludeGraphics[2][width=\linewidth]{%
    \includegraphics[#1]{\GraphicsPath #2}}    

\begin{document}
    \Include{Chapter-1}
\end{document}

Chapter-1.tex

\chapter{Chapter One}


\IncludeGraphics[width=0.5\linewidth]{Tulips}

Remarks:

  1. Folder Chapter-1 is in Docoment-Root folder.

  2. Chapter-1.tex is in folder Chapter-1.

  3. Tulips.jpg is in folder Chapter-1/Images.

Tips

  1. If your TikZ code is not "linked" to the text with nodes, for example, then put such TikZ code into a separate, compilable input file. Use article document class plus preview to get a tight PDF output. You can also use standalone document class instead.

  2. If you table is not long enough to span across multiple pages, then put it into a separate, compilable input file to get a tight PDF output.

  3. It is better not to specify the image extension explicitly when invoking \includegraphics.

  4. Define macros for often-used materials and put them into a package such that you can change their definition later in one place and the changes effect the whole document.

2
  • See also my another answer here. Commented Nov 9, 2013 at 9:28
  • Will these macros work with import or subimport as well ?
    – Anusha
    Commented Aug 4, 2014 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .