I want to automate the process of inputting tex files from subfolders. Previously I managed to automate the inclusion of images from "images" subfolder within the subfolder of each subfile. I would like to do the same for tex files. Please have a look at: Is it possible to use includegraphics with relative path with subfolder, inside subfiles?

Now I want to add a modifier, so that


would add subfolder1/fig1.tex in the file, while


would add subfolder2/fig1.tex to my file.

  • Why not just define e.g. \subinput{} to use in an analogous way?
    – cfr
    Commented Nov 18, 2015 at 2:27
  • I am currently doing \edef\CurrentFileDir{\currfiledir} and \renewcommand{\myimagedir}{\CurrentFileDir images/}. \input{\myimagedir fig_matlab_sinemodulation} seems to work. Is there any easier way to do it?
    – sajid
    Commented Nov 18, 2015 at 5:14
  • What I had in mind was a new input command so you could say e.g. \subinput{fig_matlab_sinemodulation} - a wrapper around \input{}, in other words.
    – cfr
    Commented Nov 18, 2015 at 14:28
  • can you give any examples related to that? I am really a newbee in LaTeX. Thank you so much for the help.
    – sajid
    Commented Nov 18, 2015 at 15:23
  • I've posted an example. Are you sure subfiles doesn't provide something like this already? I've never used it, but this seems like the kind of thing people might often want to do and is a bit different from the graphics case (where mostly, setting the search path in the preamble or configuring different inputs for TeX will work). I understand use of \graphicspath{} is not considered good practice, by the way. That said, bad practice works well for me since I use it all the time.
    – cfr
    Commented Nov 18, 2015 at 23:27

1 Answer 1


You might create a new command \subinput{} for handling this. Basically, this is a wrapper around \input{} which prefixes the relevant path.

File hierarchy for example is as follows:

<main filename>.tex


\documentclass[../<main filename>.tex]{subfiles}

  Sub file.

  Here's a tiger:




% sub/sub2.tex
That is some tiger!

<main filename>.tex:


  \filename@parse{#1}% LaTeX's file name parser
  \graphicspath\expandafter{\expandafter{\filename@area img/}}%
    \input\expandafter{\expandafter\filename@area ##1}%

  Main file


sub-tigers with sub-sub annotations

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .