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.

Im trying to link from my preamble to some pictures used in the header. My problem is i use the same preamble in multiple documents.

lets say the preamble and the needed picture is in the top folder, and i have two different main files for two different reports, each in its own subfolder.

when i call the preamble i get an error telling me the path to the picture is not correct. as far as i have gotten it seems that i need to have two preambles with the path from the include folder to the preamble picture. (which sort of takes the idea of a preamble away)

folder structure:

work
  preamble
    pics
  project1
    main.tex
  project2
    main.tex

i would expect that in my preamble i could do this

\includegraphics[scale=0.5]{pics/image.png}

the i have tried with setting this command ind the main.tex

\newcommand{\folder}{/path/to/pic}
\includegraphics[scale=0.5]{\folder/pics/image.png}

but that doesnt work either.

does any one know how to solve this problem? (i Hope i made the problem clear)

share|improve this question
add comment

3 Answers

If you add \RequirePackage{currfile} to each of your main.tex files, how about using something like \let\preamblepath\currfiledir in the preamble, and then you can do \includegraphics{\preamblepath/pics/image.png}?

Or, without currfile, in each main.tex, do

\def\preamblepath{../preamble}
\input{\preamblepath/preamble.tex}

and then you can still refer to \preamblepath in the same way.

share|improve this answer
add comment

You could define the search path using \graphicspath

I suppose that you could write someting like that in your preamble:

\graphicspath{{./}{/path/to/pic/}}

\includegraphics will search first in the current directory (./), then in /path/to/pic

So that your picture could be used as:

\includegraphics[scale=.5]{pics/image}

The image.png will be first searched as ./pics/image.png, and if not found as /path/to/pic/pics/image.png

Hints: you should not add the '.png': write image instead image.png


Other possibility:

You have to transform your "preamble" into a TeX package by moving all your preamble folder in your personal TEXMF tree (or make symbolic link, if you are working on linux) or make your TeX distribution search in your preamble folder.


Third option:

On smart OS, you could make symbolic links to point to the preamble folder, and use relative path to access to your pictures. If you move your main folder, you just have to adapt this links.

On linux, a symbolic link named "folder" is created like this:

ln -s /path/to/target/folder folder
share|improve this answer
    
that gives me the same problem. that the grphicspath is dependend on where i include the preamble. so if i decide to have an extra folder lvl for one report then i need two different preambles... what i want is some way to give the path to picture based on the preamble location and not the main.tex file –  Rasmus Dec 20 '12 at 15:14
    
or if that is not possible, then be able to do a new command from the main.tex \newcommand{\path}{path/to/pics/} and then call \path in the preamble, but i cant make it work –  Rasmus Dec 20 '12 at 15:20
    
No, \graphicspath is not dependend on where you include the preamble if /path/to/pic is an absolute path (like /home/userX/pictures/), it will search in the pointed directory. {./} means the current directory (and it's a relative path) –  Lionel MANSUY Dec 20 '12 at 15:27
    
What i mean is pics is a subfolder in my preamble folder. but it does not work to do \graphicspath{{./}{pics/}} i have to put the path from my main.tex file so what works is \graphicspath{{./}{../../../../Preambles/pics/}} but this doesnt help if i decide to move my main.tex... –  Rasmus Dec 20 '12 at 15:56
    
{pics/} is a relative path, not an absolute one! An absolute path have to begin with / on unix and perhaps C:/ on windows. You have to put the absolute path to your preamble in \graphicspath –  Lionel MANSUY Dec 20 '12 at 16:08
show 3 more comments

I actually found the solution, the answer from CyberSingularity pionted me in the correct way.

It is actually quite easy.

if i define the newcommand \folder before the documentclass it works. :)

share|improve this answer
add comment

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.