1

I'm wondering if it's possible to modify the function of the \input command so that e.g.

\input{macros}

would work recursively.

Variant 1

  1. Check if macros.tex exists in the current directory. If yes, include it and exit the algorithm. Otherwise go to step 2.
  2. Go up to the parent directory and go back to step 1.

This will have the effect of using the macros.tex file in the current directory when it exists, and otherwise falling back to the next parent one that exists. This would already be great but even better for my purpose would be a slightly more complicated version:

Variant 2

  1. Check if macros.tex exists in the current directory. If yes, include it. In any case, go to step 2.
  2. Check whether we've already reached some pre-specified "root" directory (past which we don't want to search further). If not, go up to the parent directory and go back to step 1.

This is similar but keeps including all the macros files that exist until we get to some specified root directory.

  • 1
    why up not (as all file searching is set up to do), down? You can do this by setting TEXINPUTS to a suitable value. – David Carlisle Jun 4 at 7:02
  • @DavidCarlisle You're right, I did mean to go down instead of up (so that the current folder overrides the 'global' macros). – SollteSoSein Jun 4 at 10:11
  • but normally you have a local area say $HOME/tex where all your local files are so you just need $HOME/tex//: so anything under there is found before the standard search path, no need to go up the tree from the working directory – David Carlisle Jun 4 at 10:30
  • @DavidCarlisle Not sure I understand. Say I have $HOME/tex/project1/subproject7/notes1.tex, and a macros.tex in that directory and in all of the parent directories as well (tex/macros.tex, tex/project1/macros.tex, etc.). Then I want to import all of those macros.tex files automatically. Adding just $HOME/tex to the path won't do that as far as I understand. – SollteSoSein Jun 4 at 10:51
  • $HOME/tex//: will do that, // means recursive subdirectories and teh trailing : means add the standard path at the end(in fact ~/texmf is in the default search path, so if you use that naming you don't need to set anything at all) oh no. not with the same name in the same search path you only get one – David Carlisle Jun 4 at 11:03
3

If the current directory is

/users/SollteSoSein/something/latex/document

then

TEXINPUTS=.:/users/SollteSoSein/something/latex:/users/SollteSoSein/something:/users/SollteSoSein:  pdflatex myfile.tex

would do what you ask, not going higher than users/SollteSoSein

That is bash syntax, using : as the path separator, you could do the equivalent in windows setting the TEXINPUTS environment variable and using an appropriate syntax for the windows command shell (still using / but with ;)

  • I have hundreds of these subfolders so it's not practical to do it manually as you suggest. It does answer the question though so +1 (not actually though, since I don't have enough reputation yet). – SollteSoSein Jun 4 at 10:11
  • I guess I can write a simple script to automate typing this, that should work for me. A purely LaTeX solution would still be interesting though. Thanks! – SollteSoSein Jun 4 at 10:13
  • you could so something with \input@path but it is such a weird thing I don't see why you do not simply use TEXINPUTS=/users/SollteSoSein/something/latex//: and find all files below there. – David Carlisle Jun 4 at 11:05
  • It would be much faster if you just pre-indexed /users/SollteSoSein/something/latex// with mktexlsr and then kpathse would find files there without searching the disk at all, just as it does for the standard directories constructing alist of hundreds of directories to search by hand is going to make things terribly slow. @SollteSoSein – David Carlisle Jun 4 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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