1

In the preamble of my tex document I can set graphicspath. Is it also possible to set a path to sub sections and tables, so I can do \input{relative-path/filename.tex} from any tex file and move that text file to any location?

I am not trying to import a package.

I want to be able to go from this directory structure:

images/image1.png
figures/figure1.tex
tables/table1.tex
section1/filename.tex
main.tex

To this directory structure (i.e. change the location of filename.tex to a sub directory or move it to the root directory):

chapter1/images/image1.png
chapter1/figures/figure1.tex
chapter1/tables/table1.tex
chapter1/section1/filename.tex
chapter1/main.tex

It will break, if main.tex contains \input{chapter1/filename.tex}. Can I avoid manually having to change that to \input{chapter1/section1/filename.tex} upon changing the directory structure?

  • you can do \input{relative-path/filename.txt} anyway without any preamble setup? – David Carlisle Oct 22 '15 at 19:50
  • As far as I know, you can. Did you try it? – darthbith Oct 22 '15 at 19:54
  • Have a look at this question: http://tex.stackexchange.com/questions/139401/how-to-use-graphicspath It seems as if graphicspath is intended for absolute paths? For relative paths, you can do something like \graphicspath{{subdir1/}{subdir2/}{subdir3/}...{subdirn/}} – Wamseln Oct 22 '15 at 19:55
  • the analogue of graphicspath for input would allow you to use \input{filename} having specified the path in the preamble, Actually latex has that facility for \input and \includegraphics just locally uses it, there is an existing answer somewhere I'll find it... – David Carlisle Oct 22 '15 at 19:55
  • Yes, but what happens, when I move the file to a subdirectory? Then it breaks. – tommy.carstensen Oct 22 '15 at 19:56
  • @tommy.carstensen why does it break? – David Carlisle Oct 22 '15 at 19:59
  • for both tex and images it is much better not to ue \graphicspath (\input@path) but simply use \input{file} or \includegraphics{file} and make sure that the file is in a directory in your TEXINPUTS then it works from anywhere just as \documentclass{article} always finds article.cls – David Carlisle Oct 22 '15 at 20:02
  • @Wamseln I don't understand your comment about absolute paths. – David Carlisle Oct 22 '15 at 20:03
  • @David Carlisle - Suppose you have the main .tex-file in a certain folder. And also in that folder you have several subdirectories, in which you have all the graphic files. You can then specify these subdirectories with \graphicspath{{subdir1/}{subdir2/}{subdir3/}} and all you have to do then is to use \includegraphics{graphic1.png} or \includegraphics{graphic2.png}. These files will be found no matter in which of the specified subdirectories the included graphics are, hence you are able to move them around, but: they have to be in one of the specified directories. – Wamseln Oct 22 '15 at 20:25
  • @Wamseln Exactly! But can this also be done for tex files? – tommy.carstensen Oct 22 '15 at 20:28
  • 2
    Ok, got your question wrong! Have a look at this question: http://tex.stackexchange.com/questions/128067/using-a-non-centralized-structure-for-tex-files-similar-to-graphicspath – Wamseln Oct 22 '15 at 20:31
  • @Wamseln I know how \graphicspath works (I wrote that command) but it doesn't have anything to do with "absolute paths". but anyway as i say above the underlying mechanism is implemented for \input, \includegraphics just locally redefines the path to use a different path for image files. – David Carlisle Oct 22 '15 at 20:35
  • @Wamseln ah well found, I was looking for that, I knew it was somewhere:-) so probably this question is a duplicate of that. – David Carlisle Oct 22 '15 at 20:36
  • @DavidCarlisle - sorry for that. (And thank you!) I guess, what I wrote is just nonsense then. What I meant to say was, for specifying subdirectories \includegraphics might be sufficient. But since one can also use absolute paths in \graphicspath, it might come in very handy if you want to do something like: \graphicspath{{/absolute/path/to/directory1/}{/absolute/path/to/a/completely/different/directory2/}{/absolute/path/to/yet/another/completely/different/directory3/}}. But of course, I must confess being guilty of not having understood the matter sufficiently before commenting. – Wamseln Oct 22 '15 at 20:49
  • 1
  • @Wamseln Thanks! I will try that thing TEXINPUTS=.//:. Not sure where to add it. I will try it before I begin the document. Maybe I should have stuck to Word+Endnote after all :) Oh dear... – tommy.carstensen Oct 23 '15 at 00:10

0 Answers0