# graphicspath per chapter with individual .tex files for each chapter

I have found a fix for what I want to do if I use subfiles, however I am either having an issue using subfiles with the custom class that I need to use, or am I having issues updating subfiles to a more recent version to fix this. Whilst it would be nice to be able to compile individual chapters on their own for the sake of speed, I am fine with compiling the whole thesis using the Master Document option in Texmaker. What I would like to do is have individual folders for the images of individual chapters, and define these folders at the start of the .tex file for that chapter. Currently, I can only seem to do this by not using graphicspath and instead define the full path from main.tex when calling the filename, but there has to be a nicer way to do this, surely?

My file structure is as follows:

• root/main.tex
• root/chapters/chapter1/chapter1.tex
• root/chapters/chapter1/figs/myfig1.jpg
• root/chapters/chapter2/chapter2.tex
• root/chapters/chapter2/figs/myfig2.jpg
• root/bib.bib

etc.

My main.tex file looks like this (I include all the packages in the template I was given in case someone knows of an obsolete package or any conflicts)

\documentclass{customclass}  % Define class
\usepackage[utf8]{inputenc} % Input encoding
\usepackage{amsmath}        % Maths symbols
\usepackage{amsfonts}       % Maths fonts
\usepackage{amssymb}        % More maths stuff
\usepackage{graphicx}       % Allows for embedded graphics
\usepackage{epstopdf}
\usepackage[compress]{cite} % Allows for the use of a bibliography, and automatically handles things like numbering
\usepackage{tabu}
\usepackage[hidelinks]{hyperref}    % Allows for embedded clickable links

\title{My thesis title}
\begin{document}
\titlePage % this syntax is used in my custom class

\chapter{Introduction}\label{chapter1}
\input{Chapters/chapter1/chapter1}

\chapter{Another chapter}\label{chapter2}
\input{Chapters/chapter2/chapter2}

% Bibliography style
\bibliographystyle{custombibstyle} % this is a custom bibliography style given to me
\bibliography{bib}

\end{document}


And here is an example of what chapter1.tex looks like currently (I won't include chapter2 but you should get the jist by now).

This is an example of a chapter, with my image

\begin{figure}
\centering
\includegraphics[width=\linewidth]{Chapters/chapter1/figs/myfig1}
\caption[Figure1]{Long description of figure1}
\label{fig_myfig1}
\end{figure}


In an ideal world, I would like to change chapter1.tex to

\graphicspath{./figs/}
This is an example of a chapter, with my image

\begin{figure}
\centering
\includegraphics[width=\linewidth]{myfig1}
\caption[Figure1]{Long description of figure1}
\label{fig_myfig1}
\end{figure}


and the same for chapter2.tex, etc. Is this possible?

• your graphicspath sytax is wrong \graphicspath{{chapters/chapter2/figs/}} missing a brace group and should be relative to the working directory from where you run latex – David Carlisle Jan 6 at 10:11
• unrelated but if you used \include not \input you could speed things up a lot by using \includeonly to process just the chapters you are working on. and you almost certainly don't need epstopdf package, and beware tabu is unmaintained and not fully functional. – David Carlisle Jan 6 at 10:13
• @DavidCarlisle I can't believe the fix was that simple, thank you! I tried changing \input to \include and it seemed to move the content of the file on a new line after the titles Chapter 1 and Introduction - should I include \chapter{Introduction} \label{chapter1} inside the chapter1.tex file instead of main.tex? I'm also a little unsure how to use \includeonly as I don't just replace \include with it. Should my preamble in main.tex be put inside \includeonly{}? – Steven Thomas Jan 6 at 11:17
• yes put the \chapter inside the included files, do one run of the whole document (to get references and page counts for the whole thing) then put \includeonly(Chapters/chapter2/chapter2} and it will just process chapter 2 but any \ref sections in other chapters will still work – David Carlisle Jan 6 at 11:38
• I don't use texmaker so I don't know the details of how its master document works, the similar feature in emacs doesn't make a new main each time, it simply tells the editor which document to run (well there is also a preview feature which does make a temp document) but yes for includeonly the idea is you edit the list (typically people comment/uncomment the command as required) – David Carlisle Jan 6 at 16:42

\graphicspath{{chapters/chapter2/figs/}}