
「<id>-<name>」という命名規則に従うファイルのフォルダがあります。LaTeX ドキュメントからそれらを参照する必要がありますが、「<name>」は頻繁に変更されるため、「<id>」のみを使用して参照する必要があります。
shell-escape
私は、 を有効にしてを使用し\input{|"<command>"}
、ID から完全なファイル名を取得するシェル コマンドを実行することで、これを実現できました。shell-escape
うまくいきましたが、このシステムは、私が作成していないファイルや読み取っていないファイルをコンパイルすることが時々あるため、有効にすることに不安を感じています。
もっと良い解決策を思いつく人はいますか、それともshell-escape
安全に有効化できる方法があるのでしょうか?
答え1
ls
(またはWindows で)を使用してファイル リストを生成しdir
、それを tex に渡すことができますが、tex 内で実行する必要がある場合は、texosquery
デフォルトで実行が許可されるため、次のようになります。
現在のディレクトリのテストサブディレクトリに3つのファイルがある
$ ls testdir
a-b.txt a-c.txt z-a.txt
このドキュメント
\documentclass{article}
\usepackage{texosquery}
\begin{document}
\TeXOSQueryRegularFileList\zzz{,}{testdir}
\show\zzz
\end{document}
端末出力を生成する
$ 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
?
\zzz
ファイル名のコンマ区切りリストも同様です。\show
リストに対して実行する必要があるループに置き換えます。