This is the first time that I use GNU make to try to do something a bit less basic. I'd like the default target of a Makefile to look for any one of a number of matching filenames, a naming scheme for what I consider to be root tex files, expressed like this:
#!/usr/bin/env bash
# this is just a sketch, I know this is inaccurate
# and simplified by make's standard...
# mainfiles := main letter report course
mainfiles=(main letter report course)
_readable(){
if ([ -f "$1" ] && [ -r "$1" ]); then
return 0
fi
return 1
}
# how to make all of these existing targets using GNU make?
# all: $(patsubst %, %.tex, $$(mainfiles))
all() {
for base in $mainfiles[@]; do
if _readable "${base}.tex"; then
latexmk -pdfxe "${base}.tex"
fi
done
}
# clean:
# latexmk -c
clean(){
latexmk -c
}
I'm unsure how to turn this into a makefile.
edit:
@G-Man pointed out that my question was unclear at best. Indeed I was in a hurry, and I don't exactly know what I want. I guess want to be lazy, and use :make
instead of the fancy autocompile plugins from vim.
The point is that I used to edit a JOBNAME
variable in a generic Makefile that relies on latexmk for all of my (la|xe|lua)tex projects. When I open either of the non-existing files main.tex letter.tex course.tex etc in vim, I have it trigger an autocommand to read in a corresponding skeleton file, copy over my generic Makefile and run git init
if there's no .git
folder. Usually I only have one of those .tex
files in a folder, but there could be more of them.
I want a makefile because of a precompilation step (using mylatexformat), some more granular cleaning commands and something like a FILTER = 2>&1 | sed -n '/^\(Running\|Package\|Beginning\|Underfull\)/p;/^! /,$$p'
that I can prepend to the compiler commands. The precompilation step, for example, checks @if ((
grep -c endofdump $(TMP)/$(JOBNAME).tex== 1 )); then ...
.
My question is to be understood in a lazy attempt to avoid having to specify JOBNAME
, so that any of the files main.tex letter.tex course.tex etc are treated with the same dependencies, possibly an rsync and a precompilation step that perform checks, and a compilation step that requires $JOBNAME.pdf
to be made.
I use curly braces in ${mainfiles[@]}
for what I think is good practice. I included the -f
and -r
test because I assume that make checks this, too.
Anyway, @meuh's answer was helpful, but I revisited my use of make, in that I think it remains a better choice to just edit JOBNAME
because of flexibility and future use. I now change it with the power of vim (see my vim repo on github)
make
rule which applies to all existing files out of a list of file names, correct? – nohillside Sep 20 '18 at 18:43bash
, notmake
. Can you explain what you want to do? Just creating something form TeX files should be straight forward. – RalfFriedl Sep 20 '18 at 18:44main.pdf
,letter.pdf
,report.pdf
, andcourse.pdf
from the corresponding.tex
files? Are you talking about usingmake
because you don’t want to runlatexmk
over and over again on a.tex
file that hasn’t changed? What do you want to do about files that don’t exist? We can’t read your mind, and people who are highly knowledgeable aboutmake
might know little or nothing aboutlatexmk
. Please explain (in English sentences) what you are trying to accomplish in your question. … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 24 '18 at 23:26if [ -f "$1" ] && [ -r "$1" ]
(you don’t need the parentheses), (2b)if [ -r "$1" ]
is probably good enough (unless you’re concerned that you might someday have a directory or a dangling symbolic link calledmain.tex
), (2c) you can say"$base.tex"
(you don’t need the curly braces here), and (2d) you need curly braces in${mainfiles[@]}
. – G-Man Says 'Reinstate Monica' Sep 24 '18 at 23:26