Is there a way to tell minted to import the snippets from a certain directory? I'm looking for something similar to the way \graphicspath{{img/}} works for images.

Right now, all the files I need to import get mixed with my other .tex files.

2 Answers 2


The feature is not available in the current minted. Redefining \inputminted is out of the question, I'm afraid, because it has different definitions according to whether draft is on or off.

Anyhow, you can quite easily define a wrapper around \inputminted. The syntax of \pathinputminted is the same as \inputminted:


Full code


  \seq_gset_split:Nnn \g_paulie_mintedpath_seq { } { #1 }
  \seq_gput_left:Nn \g_paulie_mintedpath_seq { }

\seq_new:N \g_paulie_mintedpath_seq

  \seq_map_inline:Nn \g_paulie_mintedpath_seq
    \file_if_exist:nT { ##1 #3 }
      \inputminted[#1]{#2}{##1 #3}

\mintedpath{ {sub1/} {sub2/} }


\pathinputminted{latex}{test1.tex} % this is only in sub1

\pathinputminted{latex}{test2.tex} % this is both in sub1 and sub2

\pathinputminted{latex}{test3.tex} % this is only in sub2

\pathinputminted{latex}{test4.tex} % this is both in current directory and sub1


This is the directory structure I set up for the purpose of the example, after the document has been typeset once, so the Pygments files are already shown.

paulie > ls -R
_minted-paulie/ paulie.log  paulie.tex  sub2/
paulie.aux  paulie.pdf  sub1/       test4.tex


test1.tex   test2.tex

test2.tex   test3.tex   test4.tex

As you see from the output

enter image description here

only the first hit is input. I added an implicit ./ at the beginning of the search paths, so a file in the working directory is found first and, like in the other cases, further searching is not performed.

  • Is there a way to use your solution with the \newmintedfile command?
    – Piolie
    Commented Mar 10, 2019 at 21:39
  • 1
    @Paulie I'd say no.
    – egreg
    Commented Mar 10, 2019 at 22:00

You can do it with \inputminted[<options>]{<language>}{<filename>}.

In <filename> you can indicate the complete path (remember to use \ (not /) also for Windows paths.

If you want to set a fixed path, you can simple create a new command, for example:





  • Thank you, but I already know how to do that. I'm asking if there is a way to declare the folder (\mintedpath{my/dir/}, for example), so that I can just write \inputminted{<language>}{snippet.snip} to import the snippet.
    – Piolie
    Commented Mar 9, 2019 at 21:25
  • @Paulie Just create a new command, see my renewed answer.
    – CarLaTeX
    Commented Mar 9, 2019 at 21:31
  • I like your approach, but a new command would have to be defined for every minted language and set of options, right?
    – Piolie
    Commented Mar 10, 2019 at 21:20
  • @Paulie Alternatively, you can define a new command with more than one parameter: one for the file name, the others for the other opinions.
    – CarLaTeX
    Commented Mar 11, 2019 at 8:29

You must log in to answer this question.

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