1

I have a folder of files which follows this naming convention: "<id>-<name>". I need to refer to them from a latex document, but "<name>" often changes, so i need to do so using only "<id>.

I have managed to do this by enabling shell-escape and using \input{|"<command>"}, to run a shell command which gets the full filename from an id. It works, but enabling shell-escape concerns me, because this system does, from time to time, compile files that i have not made, and have not read.

Can anyone think of a better solution, or is it somehow possible to make enabling shell-escape safe?

1
  • It is much safer to do ls > filelist.txt first and then read that from tex (or dir if you are on windows). or you can use texosquery to get a file list without using (full) shell escape Aug 23, 2020 at 17:07

1 Answer 1

0

You can generate a file list using ls (or dir in windows) and pass it to tex, but if you need to do it within tex then texosquery is allowed to run by default so:

With a test subdirectory of the current directory with three files

$ ls testdir
a-b.txt  a-c.txt  z-a.txt

this document

\documentclass{article}
\usepackage{texosquery}
\begin{document}

\TeXOSQueryRegularFileList\zzz{,}{testdir}
\show\zzz

\end{document}

produces terminal output of

$ pdflatex dd124
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./dd124.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-08-07>
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2020/texmf-dist/tex/latex/texosquery/texosquery.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/texosquery/texosquery.tex
(/usr/local/texlive/2020/texmf-dist/tex/latex/texosquery/texosquery.cfg)))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
(./dd124.aux) (|texosquery-jre8 -ir , testdir )
> \zzz=macro:
->a-b.txt,a-c.txt,z-a.txt.
l.6 \show\zzz
             
? 

so \zzz is the comma separated list of filenames, replace \show by whatever loop over that list you need to do.

2
  • I tried installing it, and it's working. I will have to build a solution around it, but i doubt that that will be a problem. Do you know how it works? Does it access a tex interface or something safe or whats going on?
    – aaaaaaaaaa
    Aug 23, 2020 at 19:06
  • @aaaaaaaaaa it's a java program that has been tested to be safe and obey the tex security settings such as as paranoid etc from texmf.cnf so it is allowed (like makeindex) in the default "restricted shell escape" list so it can be run without using --shell-escape although called via \write18 see texdoc texosquery Aug 23, 2020 at 19:29

You must log in to answer this question.

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