Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Latex: include with path, not just filename

  1. Jan 8, 2013 #1
    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 (Text):
    |   SectionStress.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 (Text):
    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.
  2. jcsd
  3. Jan 8, 2013 #2


    User Avatar
    Science Advisor
    Homework Helper

    Re: latex: "include" with path, not just filename

    A cheap and cheerful way is do something like this at the start of the document
    Code (Text):

    and then in the first section
    Code (Text):

    and in the next section
    Code (Text):

    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
  4. Jan 8, 2013 #3
    Re: latex: "include" with path, not just filename


    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 (Text):





    I want to be able to compile sub2/SectionPressure and be able to include the graphics in such directory.
    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.


Share this great discussion with others via Reddit, Google+, Twitter, or Facebook