The following script searches files with the suffix .tex
in a directory (i.e. TeX files), for the string \RequireLuaTeX
, i.e. LuaTeX files in that directory, and creates a Bash array from the results.
It then runs the command latexmk
on the files in that array.
I'd like to exclude a list of user defined files from this array, possibly declared as an array thus:
excludedfiles=(foo.tex bar.tex baz.tex)
I'm writing to solicit suggestions for clean ways to do this.
I quite like the approach of putting everything in an array. For one thing, it makes it easy to list the files before running commands on them. But I'm willing to consider other approaches.
#!/bin/bash
## Get LuaTeX filenames
mapfile -t -d "" filenames < <(grep -Z -rL "\RequireLuaTeX" *.tex)
Run latexmk
on PDFTeX files.
for filename in "${filenames[@]}"
do
base="${filename%.*}"
rm -f "$base".pdf
latexmk -pdf -shell-escape -interaction=nonstopmode "$base".tex
done
BACKGROUND AND COMMENTS:
TeX users may be confused by my question. So I'm explaining here what I was trying to do, and how I miswrote the question. I'm not changing it, because the change would invalidate the existing answers and create confusion.
I have a collection of LaTeX files. The older ones use PDFLaTeX. The newer ones mostly use PDFLaTeX. This question is about the PDFLaTeX ones. What I'm trying to do in my script is
a) Create a list of PDFLaTeX files. My LuaLaTeX files contain the string "\RequireLuaTeX" in them. Therefore, files which do not contain that string are PDFLaTeX files.
So, I am trying to create a list of LaTeX files which do not contain the string "\RequireLuaTeX" in them.
b) Run PDFLaTeX on them using latexmk
.
My question has the following error. I wrote:
The following script searches files with the suffix
.tex
in a directory (i.e. TeX files), for the string\RequireLuaTeX
, i.e. LuaTeX files in that directory, and creates a Bash array from the results.
In fact I want files which do not contain that string, because as explained above, those correspond to my PDFLaTeX files.
latexmk
override the.pdf
files by itself? Is there some special reason for therm
? – Quasímodo Dec 13 '20 at 12:16latexmk
won't do a rebuild if the PDF file is newer than all the source file. It acts likemake
in that respect. – Faheem Mitha Dec 13 '20 at 16:11