LaTeX Latex: include with path, not just filename

  • Thread starter Thread starter gsal
  • Start date Start date
  • Tags Tags
    Latex Path
AI Thread Summary
The discussion revolves around the challenges of using LaTeX's \include command for managing multiple sections and figures in separate directories. The user aims to compile both individual section files and a main document while ensuring that figure paths are correctly resolved. Suggestions include defining a custom command to manage figure paths and using unique file names across subdirectories to avoid conflicts. The user also explores alternative solutions, such as organizing figures into separate folders within each subdirectory. Overall, the goal is to achieve a flexible document structure that allows for seamless compilation of both main and section files.
gsal
Messages
1,065
Reaction score
54
latex: "include" with path, not just filename

Say, a co-worker and I are writing two separate sections for the same document; each will get large and have many figures. Somewhere, I read that 'include' is more convenient than 'input' for large documents and for actual (sub)documents than just figures.

So, I am looking to structure my documents like:
Code:
|-main.tex
|-subdirectory1
|   SectionStress.tex
|-subdirectory2
    fig1.png
    fig2.png
    fig3.png
    SectionPressure.tex
What I am hoping for is for each Section*.tex file to be full, legal, self-contained, file that can be compiled in its own right and generate a *.pdf file. Additionally, for "main.tex" to be able to include the 2 sections, compile and generate a full *.pdf document...

In main.tex, I am using
Code:
%usepackage{standalone}
\includeonly{subdirectory/SectinoStress,subdirectory2/SectionPressure}
.
.
.
\include{subdirectory/SectinoStress}
\include{subdirectory2/SectionPressure}

The above works as far as text goes (references, section numbering, etc.), but not when using figures ( \includegraphics{} ). More clearly, the section files work when the includegrahpics commands do not include any path preceeding the figure file names (since they are in the same directory); but the "main.tex" complains about not finding the figures. On the flip side, if I include path to the figure file inside the section files so that they can be found by "main.tex", then, the section files themselves fail to find the figures.

...is there fix to this?

I would appreciate any hints.
 
Physics news on Phys.org


A cheap and cheerful way is do something like this at the start of the document
Code:
\def\mygraphics#1{\includegraphics{\mypath/#1}}
and then in the first section
Code:
\def\mypath{subdirectory1}
\mygraphics{fig1.png}
\mygraphics{fig2.png}
and in the next section
Code:
\def\mypath{subdirectory2}
\mygraphics{fig1.png}
\mygraphics{fig2.png}
Note you can have different files with the same names in each subdirectory if you want.

But if you want to use optional parameters in [ ] with the \includegraphics command, that could be "too simple." For some more ideas, try
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=graphicspath
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=docotherdir
 


AlephZero:

Thanks for the quick response; but I am afraid I don't quite understand where I am supposed to write what.

is it clear to you that I actually have 3 different tex files? A "main.tex" one that \includes other two and that I want to be able to compile the "main" one as well as the other two as full, legal self-contained latex files? (not just contents without preamble, etc).

In regards to your post:
Is the first piece of code meant to be included in the "main.tex" (see my previous post),
the second one into "SectionStress.tex", and
the third one into "SectionPressure.tex" ?

Here is a short version of my main.tex:
Code:
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{float}
%\floatstyle{boxed} 
%\restylefloat{figure}

\usepackage{standalone}
\includeonly{./sub1/SectionStress,./sub2/SectionPressure}

\begin{document}

\include{./sub1/SectionStress}
\include{./sub2/SectionPressure}

\end{document}

I want to be able to compile sub2/SectionPressure and be able to include the graphics in such directory.
AND
I want to be able to compile main.tex and make sure that the graphics being imported from within ./sub2/SectionPressure come thru, as well.

I am reviewing the first link you provided...it looks like that is one way to achieve what I want with the limitation that figure file names need to be unique across sub directories.

Another trick is to play around with file system...ugly but it worked...just put a folder for figures in each sub directory and point to them from "main" level with links of the same name. ; -)

As I continue to review first link and test it, I would appreciate if you could confirm my suspicion or further clarify your proposal.

Thanks,

gsal
 

Similar threads

Replies
8
Views
12K
Replies
5
Views
6K
Replies
4
Views
3K
Replies
4
Views
42K
Replies
1
Views
6K
Replies
9
Views
4K
Back
Top