i need to load unknown number of "files.tex" in a folder and run LaTeX with \input command. i am trying the code below:

find . -type f | wc -l

and run \input{file.tex} unknown number of times.

  • 2
    In random order? In a real life it is not indifferent, when you put on pants and underwear. Sep 12 '16 at 4:49

A pipe can be used with the shell escape feature (Option -shell-escape in TeX Live or --enable-pipes/--enable-write18 in MiKTeX):


% Open a pipe and read the files line by line.
% Line ends are disabled by \endlinechar=-1
  \openin\mypipe="|find . -name \string\*.tex"
    \read\mypipe to \x
% The file list is now in macro `\FileList`, each file name
% as argument to `\do`.

  % \input{#1}%

Here is a \globinput macro that takes as optional argument a path (default . representing the working directory) and as mandatory argument a string to be passed onto find for searching files.


  \alexandre_globinput:fn { \tl_to_str:n { #2 } } { #1 }

\ior_new:N \g_alexandre_globinput_stream

\cs_new_protected:Nn \alexandre_globinput:nn
  \ior_open:Nn \g_alexandre_globinput_stream
   {% the pipe
  \ior_map_inline:Nn \g_alexandre_globinput_stream
\cs_generate_variant:Nn \alexandre_globinput:nn { f }




Here is the output of ls -R in order to show the setup:

> ls -R
alexandre.aux   alexandre.log   alexandre.pdf   alexandre.tex   tmp/

a.tex   b.tex   c.txt   d.tex

Running LaTeX on the document with -shell-escape enabled will input a.tex, b.tex and d.tex. Indeed, this is what is shown in the console.

> pdflatex -shell-escape alexandre.tex 
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
 \write18 enabled.
entering extended mode
LaTeX2e <2016/03/31> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
No file alexandre.aux.
(./tmp/a.tex) (./tmp/b.tex) (./tmp/d.tex) [1{/usr/local/texlive/2016/texmf-var/
fonts/map/pdftex/updmap/pdftex.map}] (./alexandre.aux) )</usr/local/texlive/201
Output written on alexandre.pdf (1 page, 10280 bytes).
Transcript written on alexandre.log.

Note that if you run on the current directory (no path argument), you'll also input the main file, which is not really desirable. A test might be added in the map to exclude \jobname.tex.


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.