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

    AlephZero

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

    \def\mygraphics#1{\includegraphics{\mypath/#1}}
     
    and then in the first section
    Code (Text):

    \def\mypath{subdirectory1}
    \mygraphics{fig1.png}
    \mygraphics{fig2.png}
     
    and in the next section
    Code (Text):

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

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

    \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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Latex: include with path, not just filename
  1. MATLAB Runs Filename (Replies: 2)

Loading...