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.
14 # Leave commented if you don't use a bibliography file.
16 #BIBS = references.bib
18 # A space-separated list of the mjotex files that you use. The path to
19 # mjotex must be contain in your $TEXINPUTS environment variable.
20 MJOTEX = mjo-algorithm.tex mjo-arrow.tex mjo-common.tex mjo-cone.tex
21 MJOTEX += mjo-convex.tex mjo-font.tex mjo-linear_algebra.tex mjo-listing.tex
22 MJOTEX += mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex
23 MJOTEX += mjo-theorem-star.tex mjo-topology.tex
25 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
26 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS
27 # variable should contain all (Bib)TeX source files for the document.
30 SRCS += $(shell kpsewhich $(BIBS))
33 SRCS += $(shell kpsewhich $(MJOTEX))
37 # The first target is the default, so put the PDF document first.
39 # This voodoo is all designed to find a "fixed point" of calling
40 # $(LATEX). When you build a LaTeX document, it requires an unknown
41 # number of compilation passes. How do you know when to stop? Easy,
42 # stop when the output file stops changing! But how to encode that
45 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
46 # If you ignore the "sed" for now, then the next step is to check for
47 # the existence of a "previous" file. If there isn't one, this is the
48 # first time that we've tried to build the PDF. In that case, take the
49 # PDF that we've just built and make *that* the previous file. Then
50 # start all over. If there is a previous file, then this is the second
51 # (or more) time that we've tried to build the PDF. We diff the PDF
52 # file that we've just built against the previous file; if they're the
53 # same, then we've succeeded and stop. Otherwise, we make the new PDF
54 # the previous file, and start all over. The end result is that we
55 # will loop until the newly-created PDF and the previous file are
58 # But what about the "sed" call? By default, pdflatex will compile the
59 # creation date, modification date, and a unique ID into the output
60 # PDF. That means that two otherwise-identical documents, created
61 # seconds apart, will look different. We only need to know when the
62 # *contents* of the document are the same -- we don't care about the
63 # metadata -- so sed is used to remove those three nondeterministic
64 # pieces of information.
66 # The creation and modification dates should become optional in pdftex
67 # v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that
68 # version of pdflatex makes it into TeX Live 2016, we can replace
69 # those two sed scripts with something smarter.
71 $(PN).pdf: $(SRCS) $(PN).bbl
75 -e '/^\/ID \[<.*>\]/d' \
76 -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \
77 -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \
80 if [ ! -f $@.previous ]; then \
85 if cmp -s $@ $@.previous; then \
97 # The pipe below indicates an "order-only dependency" on the aux file.
98 # Without it, every compilation of $(PN).tex would produce a new
99 # $(PN).aux, and thus $(PN).bbl would be rebuild. This in turn causes
100 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
101 # $(PN).tex... and so on. The order-only dependency means we won't
102 # rebuild $(PN).bbl if $(PN).aux changes.
104 # As a side effect, we now need to depend on $(SRCS) here, since we
105 # won't pick it up transitively from $(PN).aux.
107 # If the $BIBS variable is undefined, we presume that there are no
108 # references and create an empty bbl file. Otherwise, we risk trying
109 # to run biblatex on an aux file containing no citations.
111 $(PN).bbl: $(SRCS) | $(PN).aux
118 # Run chktex to find silly mistakes. There is some exit code weirdness
119 # (Savannah bug 45979), so we just look for empty output.
122 @[ -z "$(shell chktex --quiet mjotex.sty)" ]
124 # Clean up leftover junk.
127 rm -f *.{aux,bbl,bcf,bib,blg,listing,lof,log}
128 rm -f *.{nav,out,pdf,snm,spl,toc,xml}
131 # If this document will be published, the publisher isn't going to
132 # have your BibTeX database or your mjotex files. So, you need to
133 # package them up along with the code for your document. This target
134 # will create a "dist" directory and copy the necessary stuff there.
139 cp $(SRCS) $(PN).bbl dist/