How do I define a variable (pathname) that can be recognized by various commands, such as \input{} and \includegraphics{} ?

I tried the following

\def \pathb {./folderB}

It did not work.

I am working with a few collaborators on a book. Each chapter is expected to have its own folder with images in a subfolder.

However, we changed the folder names or path name several times, for various reasons. Each time, we will have to also change the pathname in the tex files. This takes a lot of time.

It will be great if we can define a variable, say chapter1, and assign a pathname to it. In the tex file, we can then use the variable wherever needed. This way, when the folder name or path name is changed, we only need to update the variable. This will save us a lot of time.

Any input would be greatly appreciated!

  • 6
    \newcommand{\patha}{folderA} should work (the [] in your example is a syntax error) (or \def as you have it also should work) Jan 6 '14 at 1:17
  • 2
    That is strange, in my computer it works when you correct the syntax error of extra [] from the first definition. Why do you use \newcommand and then \def to define two path variables? Why not either \newcommand or \def for both? Just curious.
    – Masroor
    Jan 6 '14 at 1:21
  • 1
    I was guessing this was to demonstrate 2 things that had been tried?
    – cfr
    Jan 6 '14 at 1:31
  • 1
    Have you seen \graphicspath? (Consult the graphicx manual for its usage.)
    – yo'
    Feb 8 '15 at 12:34
  • 1
    Even though this question is closed it comes up as the top google result for "latex file path variable" so it would be good to link it to a possible duplicate
    – qdread
    Jan 8 '19 at 14:51

Browse other questions tagged or ask your own question.