2 # Example makefile using mjotex and a BibTeX references database.
6 LATEX = pdflatex -file-line-error -halt-on-error
8 # The name of this document.
11 # A space-separated list of bib files. These must all belong to paths
12 # contained in your $BIBINPUTS environment variable.
15 # A space-separated list of the mjotex files that you use. The path to
16 # mjotex must be contain in your $TEXINPUTS environment variable.
17 MJOTEX = mjo-algorithm.tex mjo-arrow.tex mjo-common.tex mjo-cone.tex
18 MJOTEX += mjo-convex.tex mjo-font.tex mjo-linear_algebra.tex mjo-listing.tex
19 MJOTEX += mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex
20 MJOTEX += mjo-theorem-star.tex mjo-topology.tex
22 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
23 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS
24 # variable should contain all (Bib)TeX source files for the document.
25 SRCS = $(PN).tex $(shell kpsewhich $(BIBS)) $(shell kpsewhich $(MJOTEX))
28 # The first target is the default, so put the PDF document first.
30 # This voodoo is all designed to find a "fixed point" of calling
31 # $(LATEX). When you build a LaTeX document, it requires an unknown
32 # number of compilation passes. How do you know when to stop? Easy,
33 # stop when the output file stops changing! But how to encode that
36 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
37 # If you ignore the "sed" for now, then the next step is to check for
38 # the existence of a "previous" file. If there isn't one, this is the
39 # first time that we've tried to build the PDF. In that case, take the
40 # PDF that we've just built and make *that* the previous file. Then
41 # start all over. If there is a previous file, then this is the second
42 # (or more) time that we've tried to build the PDF. We diff the PDF
43 # file that we've just built against the previous file; if they're the
44 # same, then we've succeeded and stop. Otherwise, we make the new PDF
45 # the previous file, and start all over. The end result is that we
46 # will loop until the newly-created PDF and the previous file are
49 # But what about the "sed" call? By default, pdflatex will compile the
50 # creation date, modification date, and a unique ID into the output
51 # PDF. That means that two otherwise-identical documents, created
52 # seconds apart, will look different. We only need to know when the
53 # *contents* of the document are the same -- we don't care about the
54 # metadata -- so sed is used to remove those three nondeterministic
55 # pieces of information.
57 # The creation and modification dates should become optional in pdftex
58 # v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that
59 # version of pdflatex makes it into TeX Live 2016, we can replace
60 # those two sed scripts with something smarter.
62 $(PN).pdf: $(SRCS) $(PN).bbl
66 -e '/^\/ID \[<.*>\]/d' \
67 -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \
68 -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \
71 if [ ! -f $@.previous ]; then \
76 if cmp -s $@ $@.previous; then \
88 # The pipe below indicates an "order-only dependency" on the aux file.
89 # Without it, every compilation of $(PN).tex would produce a new
90 # $(PN).aux, and thus $(PN).bbl would be rebuild. This in turn causes
91 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
92 # $(PN).tex... and so on. The order-only dependency means we won't
93 # rebuild $(PN).bbl if $(PN).aux changes.
95 # As a side effect, we now need to depend on $(SRCS) here, since we
96 # won't pick it up transitively from $(PN).aux.
98 $(PN).bbl: $(SRCS) | $(PN).aux
102 # Clean up leftover junk.
105 rm -f *.{aux,bbl,bcf,bib,blg,lof,log,nav,out,pdf,snm,toc,xml}
110 # If this document will be published, the publisher isn't going to
111 # have your BibTeX database or your mjotex files. So, you need to
112 # package them up along with the code for your document. This target
113 # will create a "dist" directory and copy the necessary stuff there.
118 cp $(SRCS) $(PN).bbl dist/