I am using Windows as OS and TeXstudio as editor.

My project has the following structure:


I am using the subfiles package in order to compile independently the various chapters of my document. I would like to use the minted package in each chapterN.tex file in order to list the codes present in the listings subdirectory of the chapterN directory.

I am not sure whether this is actually possible with minted, because it seems that it can only work with the root document directory according to what I have found here and here.

At the moment, compiling main.tex using chapter1/listing/pythonfile.py within \inputminted succeeds, however this generates an error when I compile chapter1.tex. The curious thing is that compiling chapter1.tex using ./listing/pythonfile.py has no effect on the output (the compilation seems to succeed bbut actually I do not notice any change in the .pdf output). Edit: I found out that for some reason the automatic update of the pdf output does not work anymore using minted, problem observed also here.

Is there a solution for this issue? If not, is there an alternative to minted that allows me to maintain the same project structure (and gives nice results with matlab and python codes possibly)? Edit: The issue remained is the fact that I have to use two different arguments for the inputminted command when compiling main.tex and chapter1.tex.

Below my MWE.





\def\biblio{\bibliographystyle{amsalpha}\bibliography{\main/bibgraf}}  % *Modification: added `\main/` to specify relative file location.


\usepackage[justification=centering]{caption} % Centred captions

% Typesetting code


Hallo main




%!TeX root = chapter1




%% my chapter 1 content
Hallo, this is a test:
\int dx =0 

This is a figure test:

\onlyinsubfile{this only appears if chapter1.tex is compiled (not when main.tex is compiled)}
\notinsubfile{this only appears if main.tex is compiled (not when chapter1.tex is compiled)}

This is a reference test: \cite{anderson}

This is a listing test:
    \caption{Source code of \texttt{pythonfile.py}, where the main classes are defined.}

\onlyinsubfile{Call reference}
  • 1
    Note that subfiles 2019/10/25 v1.4 is able to handle locally included files (like images). There should be no need anymore to modify input and graphics pathes. This probably does not solve your issues, but the code should become simpler.
    – gernot
    Oct 25, 2019 at 19:30

1 Answer 1


If you use a recent version of the subfiles package (v1.3 2019/09/28 or later) you can fix the problem by defining a command \subfix in the preamble, like that:


Then, if some error message indicates that a file is searched in the wrong directory, wrap the command around the name of the file. E.g., write


instead of just \inputminted{python}{./listings/pythonfile.py}.

Here is a complete example with the following file structure:


where the files have the following contents:

% main.tex

% sub/sub.tex

% sub/listings/prime.py
def prime(n):
    if n < 2:
        return False
    for i in range(2,n):
        if (n % i) == 0:
           return False
    return True

Running the command pdflatex -shell-escape main.tex in the main directory and pdflatex -shell-escape sub.tex in the subdirectory sub yields files main.pdf and sub/sub.pdf, respectively, both of which look like

enter image description here

You must log in to answer this question.

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