Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a \graphicspath command at the beginning of a document (the main document):

\graphicspath{{images/}{extras/images/}}

I have sub-documents into which I insert images (actually SVG files from Inkscape):

\def\svgwidth{\linewidth}
\input{/another/path/images/ppn522-graphs.pdf_tex}

These sub-documents may be inserted into different main documents.

But they need some information about images to be included so I need to do this:

\def\svgwidth{\linewidth}
\graphicspath{{/another/path/images/}}
\input{/another/path/images/ppn522-graphs.pdf_tex}

Problem: this overrides my first \graphicspath declaration: my logo images (and extras/images) are not found anymore (generating errors) after I insert the \graphicspath{{/another/path/images/}}

My question: how could I append an entry to the \graphicspath ?

Or is there a variable that contains the \graphicspath value so I can re-use it ?

    \graphicspath{\thegraphicspathvalue{/another/path/images/}}

EDIT: I already tried this, but it does not work :

\graphicspath{\typeout{\Ginput@path}{../images/}}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

The variable containing the paths is \Ginput@path, so you can define

\makeatletter
\newcommand\appendtographicspath[1]{%
  \g@addto@macro\Ginput@path{#1}%
}
\makeatother

and \appendtographicspath{{../images/}} should do. Remember the braces around the path; you can add several paths.

This addition is global. You might want to extend the macro for “prepending”; in this case, use etoolbox:

\usepackage{etoolbox}
\makeatletter
\newcommand\appendtographicspath[1]{%
  \gappto\Ginput@path{#1}%
}
\newcommand\prependtographicspath[1]{%
  \gpreto\Ginput@path{#1}%
}
\makeatother

With \appto and \preto the additions would be local, but I don't think it's good.

share|improve this answer
    
I works perfectly. A question: the order is important only if I have several images with the same name, isn't it ? –  lauhub Apr 15 at 8:43
1  
@lauhub Yes. Note that using \graphicspath slows down the searching process, so more often visited directories should go first. –  egreg Apr 15 at 9:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.