Latex: include with path, not just filename

  • LaTeX
  • Thread starter gsal
  • Start date
  • Tags
    Latex Path
In summary, latex: "include" with path, not just filename. 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: |-main.tex|-subdirectory1|-subdirectory2 fig1.png fig2.png
  • #1
gsal
1,065
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
  • #2


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
 
  • #3


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
 

Related to Latex: include with path, not just filename

1. What is Latex and how is it used in scientific research?

Latex is a typesetting language commonly used in scientific and mathematical research. It allows for the creation of professional-looking documents with complex equations and symbols. It is often used to write research papers, reports, and presentations.

2. How do I include a file path in Latex?

To include a file path in Latex, you can use the "\includegraphics" command. This command allows you to insert an image or file into your document by specifying the file path. For example: \includegraphics{C:/Users/Username/Documents/image.jpg}

3. Is it possible to include multiple files with different file paths in Latex?

Yes, it is possible to include multiple files with different file paths in Latex. You can use the "\include" command, which allows you to insert multiple files into your document. You can also specify the path for each file using the "\includeonly" command.

4. Can I include a file with a relative path in Latex?

Yes, you can include a file with a relative path in Latex. This means that the file path will be relative to the current working directory of your Latex document. For example, if your document is in a folder called "Research", and your file is in a subfolder called "Images", the path would be "\includegraphics{Images/image.jpg}".

5. What should I do if my Latex document cannot find the file path?

If Latex cannot find the specified file path, it will usually produce an error message. To solve this issue, make sure that the file is saved in the correct location and that the file path is correctly specified in your Latex document. You can also check if there are any typos or missing characters in the file path.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
41K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top