]> gitweb.michael.orlitzky.com - mjotex.git/blob - GNUmakefile
mjo-complex.tex: new file with a \compconj (complex conjugate) command.
[mjotex.git] / GNUmakefile
1 #
2 # Example makefile using mjotex and a BibTeX references database.
3 #
4
5 # The latex compiler.
6 LATEX = pdflatex -file-line-error -halt-on-error
7
8 # The name of this document.
9 PN = examples
10
11 # A space-separated list of bib files. These must all belong to paths
12 # contained in your $BIBINPUTS environment variable.
13 #
14 # Leave commented if you don't use a bibliography database.
15 #
16 #BIBS = references.bib
17
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-complex.tex
21 MJOTEX += mjo-cone.tex mjo-convex.tex mjo-font.tex mjo-linear_algebra.tex
22 MJOTEX += mjo-listing.tex mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex
23 MJOTEX += mjo-theorem-star.tex mjo-topology.tex mjo.bst
24
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.
28 SRCS = $(PN).tex
29 ifdef BIBS
30 BIBPATHS = $(shell kpsewhich $(BIBS))
31 SRCS += $(BIBPATHS)
32 endif
33 ifdef MJOTEX
34 MJOTEXPATHS = $(shell kpsewhich $(MJOTEX))
35 SRCS += $(MJOTEXPATHS)
36 endif
37
38
39 # The first target is the default, so put the PDF document first.
40 #
41 # This voodoo is all designed to find a "fixed point" of calling
42 # $(LATEX). When you build a LaTeX document, it requires an unknown
43 # number of compilation passes. How do you know when to stop? Easy,
44 # stop when the output file stops changing! But how to encode that
45 # in a makefile?
46 #
47 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
48 # If you ignore the "sed" for now, then the next step is to check for
49 # the existence of a "previous" file. If there isn't one, this is the
50 # first time that we've tried to build the PDF. In that case, take the
51 # PDF that we've just built and make *that* the previous file. Then
52 # start all over. If there is a previous file, then this is the second
53 # (or more) time that we've tried to build the PDF. We diff the PDF
54 # file that we've just built against the previous file; if they're the
55 # same, then we've succeeded and stop. Otherwise, we make the new PDF
56 # the previous file, and start all over. The end result is that we
57 # will loop until the newly-created PDF and the previous file are
58 # identical.
59 #
60 # But what about the "sed" call? By default, pdflatex will compile the
61 # creation date, modification date, and a unique ID into the output
62 # PDF. That means that two otherwise-identical documents, created
63 # seconds apart, will look different. We only need to know when the
64 # *contents* of the document are the same -- we don't care about the
65 # metadata -- so sed is used to remove those three nondeterministic
66 # pieces of information.
67 #
68 # The creation and modification dates should become optional in pdftex
69 # v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that
70 # version of pdflatex makes it into TeX Live 2016, we can replace
71 # those two sed scripts with something smarter.
72 #
73 $(PN).pdf: $(SRCS) $(PN).bbl
74 $(LATEX) $(PN).tex
75
76 sed --in-place \
77 -e '/^\/ID \[<.*>\]/d' \
78 -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \
79 -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \
80 $@
81
82 if [ ! -f $@.previous ]; then \
83 mv $@ $@.previous; \
84 $(MAKE) $@; \
85 fi;
86
87 if cmp -s $@ $@.previous; then \
88 rm $@.previous; \
89 else \
90 mv $@ $@.previous; \
91 $(MAKE) $@; \
92 fi;
93
94
95 $(PN).aux: $(SRCS)
96 $(LATEX) $(PN).tex
97
98
99 # The pipe below indicates an "order-only dependency" on the aux file.
100 # Without it, every compilation of $(PN).tex would produce a new
101 # $(PN).aux, and thus $(PN).bbl would be rebuilt. This in turn causes
102 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
103 # $(PN).tex... and so on. The order-only dependency means we won't
104 # rebuild $(PN).bbl if $(PN).aux changes.
105 #
106 # As a side effect, we now need to depend on $(SRCS) here, since we
107 # won't pick it up transitively from $(PN).aux.
108 #
109 # If the $BIBS variable is undefined, we presume that there are no
110 # references and create an empty bbl file. Otherwise, we risk trying
111 # to run biblatex on an aux file containing no citations. If you do
112 # define $BIBS but don't cite anything, you'll run into a similar
113 # problem. Don't do that.
114 #
115 $(PN).bbl: $(SRCS) | $(PN).aux
116 ifdef BIBS
117 bibtex $(PN).aux
118 else
119 echo -n '' > $@
120 endif
121
122 # If the output PDF exists but the log file does not, then an attempt
123 # to "build the log file" (i.e. build the PDF) would do nothing. Thus
124 # whenever the log file does not exist, we do a fresh build.
125 $(PN).log: $(SRCS)
126 $(MAKE) clean
127 $(MAKE)
128
129 # Ensure that there are no overfull or underfull boxes in the output
130 # document by parsing the log for said warnings.
131 .PHONY: check-boxes
132 check-boxes: $(PN).log
133 @! grep -i 'overfull\|underfull' $<
134
135 # Run chktex to find silly mistakes. There is some exit code weirdness
136 # (Savannah bug 45979), so we just look for empty output.
137 .PHONY: check-chktex
138 CHKTEX = chktex --localrc .chktexrc --quiet --inputfiles=0
139 check-chktex:
140 @[ -z "$(shell $(CHKTEX) mjotex.sty)" ]
141
142 # Ensure that there are no undefined references in the document by
143 # parsing the log file for said warnings.
144 .PHONY: check-undefined
145 check-undefined: $(PN).log
146 @! grep -i 'undefined' $<
147
148 # Run a suite of checks.
149 .PHONY: check
150 check: check-boxes check-chktex check-undefined
151
152 # Clean up leftover junk. This only looks overcomplicated because
153 # the *.{foo,bar} syntax supported by Bash is not POSIX, and Make
154 # will execute these commands using /bin/sh (which should be POSIX).
155 JUNK_EXTENSIONS = aux bbl bcf bib blg listing lof log nav out pdf
156 JUNK_EXTENSIONS += snm spl toc xml
157 .PHONY: clean
158 clean:
159 for ext in $(JUNK_EXTENSIONS); do rm -f *.$$ext; done;
160 rm -rf dist/
161
162 # If this document will be published, the publisher isn't going to
163 # have your BibTeX database or your mjotex files. So, you need to
164 # package them up along with the code for your document. This target
165 # will create a "dist" directory and copy the necessary stuff there.
166 #
167 .PHONY: dist
168 dist: $(PN).bbl
169 mkdir -p dist
170 cp $(SRCS) $(PN).bbl $(BIBPATHS) $(MJOTEXPATHS) dist/