Last active
May 20, 2020 21:12
-
-
Save nzjrs/503886 to your computer and use it in GitHub Desktop.
LaTeX Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This uses a neat trick from the Sed & Awk Book from O'Reilly: | |
# Ensure that the last line looks like the end of a paragraph; if it isn't | |
# blank, hold it and blank it out. | |
${ | |
/^$/!{ | |
H | |
s/.*// | |
} | |
} | |
# Non-blank lines get held in the hold buffer | |
/^$/!{ | |
H | |
d | |
} | |
# Blank lines signify the end of a paragraph. | |
# Swap blank into hold buffer (bringing paragraph into pattern buffer). | |
# Move newline prefix to end of paragraph. | |
/^$/{ | |
x | |
s/^\(\n\)\(.*\)/\2\1/ | |
} | |
# Each P inside of :: represents a paragraph that we need to acquire. When we | |
# see two or more P, we reduce the number by one, append the recently acquired | |
# paragraph to the pattern space, then hold the whole thing and delete the | |
# pattern space. This puts the most recent paragraph into the hold buffer and | |
# starts the process over with paragraph accumulation. | |
# When discovering that we need, e.g., three more paragraphs, we can do the | |
# following: | |
# | |
# s/^/::PPP::/ | |
# G | |
# h | |
# d | |
# | |
# This prefixes the current paragraph with the number of paragraphs needed, | |
# appends the contents of the hold space (a single newline after paragraph | |
# processing), puts everything back into the hold space, and deletes the | |
# pattern space (looping back to the beginning of the script, where paragraph | |
# processing begins). See "needonemore" for a convenience label that you can | |
# branch to for adding one paragraph. | |
/^::P\(P\{1,\}\)::/{ | |
s//::\1::/ | |
G | |
h | |
d | |
} | |
# If we have exactly one P, then we swap it out for a zero and let processing | |
# continue (after :start). | |
/^::P::/{ | |
s//::0::/ | |
G | |
} | |
b start | |
# Convenience subroutines | |
:needonemore | |
s/^/::P::/ | |
G | |
h | |
d | |
:needtwomore | |
s/^/::PP::/ | |
G | |
h | |
d | |
:needthreemore | |
s/^/::PPP::/ | |
G | |
h | |
d | |
# Start regular processing (this file is intended to be a preamble) | |
:start | |
# File not found errors (e.g., for class and package files) require two more | |
# paragraphs to process properly And they don't start with a line number - that | |
# comes later by the "Emergency stop" output. | |
/^! LaTeX Error: File /{ | |
# Get rid of newlines, since splits on the first paragraph happen in | |
# interesting places. | |
s/\n//g | |
b needtwomore | |
} | |
# With -file-line-error specified in latex options, we get things like | |
# ./blah.tex:2: LaTeX Error | |
# (among other things). We find all lines that look like they might contain a | |
# filename and line number and add an easy-to-find prefix to them. That way we | |
# can easily find most errors, stuff that isn't called out here explicitly. | |
s/^[^[:cntrl:]:]*:[[:digit:]]\{1,\}:/!!! &/ | |
# Note that we preserve all of the stuff before the !!! because it might | |
# contain useful errors that we have to find below. Of particular interest is | |
# the File `something.cls' not found case. | |
# Note that any time we need to negate \n, we use [^[:cntrl:]] instead, since | |
# [^\n] doesn't work in POSIX sed. | |
s/^\(.*\n\)\([^[:cntrl:]:]*:[[:digit:]]\{1,\}: .*\)/\1!!! \2/ | |
# Graphics files that go missing need only two paragraphs, and the | |
# filename:line: is at the beginning of the error message. | |
/^!!! .* LaTeX Error: File /{ | |
# Get rid of newlines first, since latex error output is split on column | |
# boundaries regardless of context. | |
s/\n//g | |
b needonemore | |
} | |
# Parse things that look like this (triple paragraphs) | |
# ! LaTeX Error: File `missing.cls' not found. | |
# | |
# Type X to quit or <RETURN> to proceed, | |
# or enter new name. (Default extension: cls) | |
# | |
# Enter file name: | |
# ./test-missing-cls.tex:2: Emergency stop. | |
# <read *> | |
# | |
# l.2 ^^M | |
# | |
# *** (cannot \read from terminal in nonstop modes) | |
/^::0::! LaTeX Error: File .*/{ | |
# Request another paragraph if we run into the weird case where an error line | |
# is split just before its newline. | |
/\n\n$/{ | |
s/^::0::// | |
b needonemore | |
} | |
# Remove paragraph prefix | |
s/^::0::! // | |
s/^\(.*not found.\).*Enter file name:.*\n\(.*[[:digit:]]\{1,\}\): Emergency stop.*/\2: \1/ | |
b error | |
} | |
# Parse regular old file missing errors (not the special kind like classes and | |
# packages, but more mundane ones like missing graphics). | |
/^::0::!!! .*LaTeX Error: File .*/{ | |
# Request another paragraph if we run into the weird case where an error line | |
# is split just before its newline. | |
/\n\n$/{ | |
s/^::0::// | |
b needonemore | |
} | |
# Remove the paragraph prefix | |
s/::0::!!! // | |
# Handle file missing errors where we are looking for a particular extension | |
/could not locate.*any of these extensions:/{ | |
# We don't do anything with these - they are missing graphics. | |
d | |
# NOTE: this is here just in case we need it later. In general, we don't | |
# treat missing graphics as an error because they end up as dependencies, | |
# which causes other errors in other ways. If we colorize this, it ends up | |
# as a fatal error to be missing a graphic. We'd rather see it just add the | |
# dependency and move on. | |
#s/\(not found\.\).*extensions:.\([^[:cntrl:]]*\).*/\1 Extensions tried: \2/ | |
#s/,/, /g | |
#b error | |
} | |
# Handle everything else | |
s/\(not found\.\).*/\1/ | |
b error | |
} | |
# This one is simple: find a single line that says we're missing | |
# begin{document} and colorize it. Because this commonly happens when trying | |
# to build an include file (e.g., when typing "make" without a target in a | |
# directory that has a bunch of .tex files that are included in another), we | |
# handle it specially here. | |
/^\(.* LaTeX Error: Missing .begin.document.\.\).*/{ | |
s//\1 --- Are you trying to build an include file?/ | |
b error | |
} | |
# We deal with this one specially because it tends to be buried at the end of | |
# long paragraphs of other stuff, so it requires interesting processing. | |
# With the addition of the handy error prefix, though, we just need to delete | |
# the stuff before it and make the rest pretty. | |
# E.g., we want to parse this: | |
# LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 5. | |
# LaTeX Font Info: ... okay on input line 5. | |
# ./test.tex:6: Undefined control sequence. | |
# l.6 \halp | |
# | |
# The control sequence at the end of the top line | |
# of your error message was never \def'ed. If you have | |
# misspelled it (e.g., `\hobx'), type `I' and the correct | |
# spelling (e.g., `I\hbox'). Otherwise just continue, | |
# and I'll forget about whatever was undefined. | |
/.*\(!!! .*Undefined control sequence\)[^[:cntrl:]]*\(.*\)/{ | |
s//\1: \2/ | |
s/\nl\.[[:digit:]][^[:cntrl:]]*\(\\[^\\[:cntrl:]]*\).*/\1/ | |
b error | |
} | |
# Handle some fatal error cases | |
/^\(!pdfTeX error:.*\)s*/{ | |
b error | |
} | |
# Finally, we handle anything that looks remotely like an error that we | |
# haven't already caught. | |
/.*\(!!! .*\)/{ | |
s//\1/ | |
s/[[:cntrl:]]// | |
s/[[:cntrl:]]$// | |
b error | |
} | |
# Anything not dealt with above gets dumped into the trash. | |
d | |
# If we have an error (starts with !!! and we get this far), then strip the | |
# prefix, colorize, and output. | |
:error | |
s/^!\(!! \)\{0,1\}\(.*\)/\2/ | |
p | |
d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%----------------------------------------------------------- | |
% Instructions | |
% * original figures should be placed in ./figures/foo.bar | |
% and included using includegraphics[]{figures/foo} | |
%----------------------------------------------------------- | |
\usepackage{ifpdf} | |
\ifpdf | |
\usepackage{graphicx} | |
\DeclareGraphicsExtensions{.pdf,.png,.jpg} | |
\graphicspath{{./generated/}} | |
\else | |
\usepackage{graphicx} | |
\usepackage{epsf} | |
\usepackage{epsfig} | |
\DeclareGraphicsExtensions{.pdf,.png,.jpg} | |
\DeclareGraphicsExtensions{.eps,.ps} | |
\graphicspath{{./generated/}} | |
\fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile for LaTeX files | |
# Original file from http://www.acoustics.hut.fi/u/mairas/UltimateLatexMakefile | |
# please check http://www.takeonthecity.nl/roels-latex-makefile/ (Roel) | |
# current version http://gist.github.com/503886 (John) | |
# Copyright (c) 2009,2010 (in order of appearance): | |
# Roel Meeuws <r.j.meeuws@gmail.com> | |
# John Stowers <john.stowers@gmail.com> | |
# ChangeLog: | |
# 2011 - UNRELEASED | |
# - support latex/xetex selection from including makefiles | |
# 2010-07-01 - version 1.2.2 | |
# - don't loop forever if there is undefined references | |
# - add forgotten gif->pdf rule | |
# - make naming of VIEW* executable shell variables consistent | |
# - add default target and help | |
# - add wordcount target for gettin a very approximate wordcount... | |
# 2010-07-01 - version 1.2.1 | |
# - fixed bug in viewing code thanks to John Stowers | |
# - fixed bug in using bash shell thanks to John Stowers | |
# 2009-10-07 - version 1.2 | |
# - Added support for vector format .svg files | |
# - Added support for PGF/TikZ .tikz files which is basically a latex | |
# tikzpicture environment block in a separate file (begin and end | |
# tag should be in file too!) | |
# - font embedding using 'make embedpdf' although, this should not happen | |
# using this makefile and xetex... | |
# - Fix of font embedding when converting .fig files. | |
# - OpenDocument Drawing file (*.odg) format supported (requires unoconv | |
# and OpenOffice.org) | |
# - Remove all beamer temporary files when cleaning up | |
# - Add rule for installing prerequisites 'make get-requirements' | |
# 2009-07-02 - version 1.1 | |
# - Added support for gnuplot .gpi files | |
# - Added support for graphviz .dot files | |
# - Added support for xfig .fig files | |
# - Fixed the handling of metapost pictures. We now support multiple figures | |
# per metapost file | |
# - Added Google latex makefile error detection and coloring. | |
# - Replaced manual coloring with colored print routines for better | |
# readability and modularization | |
# - fixed rules for backup directory | |
# - use XeTex instead of PDFLaTeX for generating pdfs for better font support | |
# 2009-06-11 - version 1.0 | |
# - First version published. | |
# Copyright notice from original file: | |
# Copyright (c) 2005,2006 (in order of appearance): | |
# Matti Airas <Matti.Airas@hut.fi> | |
# Rainer Jung | |
# Antoine Chambert-Loir | |
# Timo Kiravuo | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#Viewers | |
VIEWPS = evince | |
VIEWPDF = evince | |
VIEWDJVU= evince | |
VIEWDVI = xdvi -gamma 4 | |
#Default targets for make and view (pdf,dvi,ps,djvu) | |
default : pdf | |
view : showpdf | |
#The following variables may be set prior to including this makefile | |
# - set these to the appropriate value if using XeTeX | |
LATEX ?= pdflatex -synctex=1 -interaction=batchmode -file-line-error-style | |
LTITLE ?= PDFLaTeX | |
# - set this to a single file if the directory contains multiple main tex documents | |
SRC ?= $(shell egrep -l '^[^%]*\\begin\{document\}' *.tex) | |
################################################################################ | |
# NO NEED TO EDIT BELOW HERE | |
################################################################################ | |
BIBTEX = bibtex | |
MAKEINDEX = makeindex | |
MAKEGLOSSARIES = makeglossaries | |
DVIPS = dvips | |
DVIPDF = dvipdft | |
MAKEDJVU= pdf2djvu -q | |
L2H = mk4ht xhmlatex | |
CONVERT= convert | |
GZIP = gzip --best | |
SED = sed | |
SHELL = /bin/bash | |
# Calculate the name of this makefile (use immediate expansion to stop include *.d from being | |
# returned, as it would be last in MAKEFILE_LIST | |
where-am-i = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) | |
THIS_MAKEFILE := $(call where-am-i) | |
ERROR_SEDSCRIPT := $(shell dirname $(shell realpath $(THIS_MAKEFILE)))/colorize-latex-errors.sed | |
RERUN = "(Rerun to get (cross-references|the bars) right)" | |
RERUNBIB = "No file.*\.bbl|Citation.*undefined" | |
USEMAKEIDX = "^[^%]*\\makeindex" | |
USEMAKEGLOSSARIES = "^[^%]*\\makeglossaries" | |
FIGDIR = generated | |
DATE=$(shell date +%Y-%m-%d) | |
COPY = if test -r $(<:%.tex=%.toc); then cp $(<:%.tex=%.toc) $(<:%.tex=%.toc.bak); fi > /dev/null | |
RM = rm -f | |
QUIET= &>/dev/null | |
DISPLAYERROR= || ($(call echo-error,Errors encountered:) && $(call colorize-latex-errors, $(<:%.tex=%.log))) | |
DVI := $(SRC:%.tex=%.dvi) | |
PSF := $(SRC:%.tex=%.ps) | |
PSZ := $(SRC:%.tex=%.ps.gz) | |
PDF := $(SRC:%.tex=%.pdf) | |
DJVU:= $(SRC:%.tex=%.djvu) | |
# Terminal color definitions | |
tput = | |
ifneq ($(TERM),) | |
ifndef NO_COLOR | |
tput = $(shell tput $1) | |
endif | |
endif | |
black := $(call tput,setaf 0) | |
red := $(call tput,setaf 1) | |
green := $(call tput,setaf 2) | |
yellow := $(call tput,setaf 3) | |
blue := $(call tput,setaf 4) | |
magenta := $(call tput,setaf 5) | |
cyan := $(call tput,setaf 6) | |
white := $(call tput,setaf 7) | |
bold := $(call tput,bold) | |
uline := $(call tput,smul) | |
reset := $(call tput,sgr0) | |
# | |
# | |
# User-settable definitions | |
# | |
LATEX_COLOR_WARNING ?= magenta | |
LATEX_COLOR_ERROR ?= red | |
LATEX_COLOR_INFO ?= green | |
LATEX_COLOR_UNDERFULL ?= magenta | |
LATEX_COLOR_OVERFULL ?= red bold | |
LATEX_COLOR_PAGES ?= bold | |
LATEX_COLOR_BUILD ?= blue | |
LATEX_COLOR_GRAPHIC ?= yellow | |
LATEX_COLOR_DEP ?= green | |
LATEX_COLOR_SUCCESS ?= green bold | |
LATEX_COLOR_FAILURE ?= red bold | |
LATEX_COLOR_FILENAME?= black bold | |
LATEX_COLOR_PROGNAME?= black bold | |
# Gets the real color from a simple textual definition like those above | |
# $(call get-color,ALL_CAPS_COLOR_NAME) | |
# e.g., $(call get-color,WARNING) | |
get-color = $(subst $(space),,$(foreach c,$(LATEX_COLOR_$1),$($c))) | |
# | |
# STANDARD COLORS | |
# | |
C_WARNING := $(call get-color,WARNING) | |
C_ERROR := $(call get-color,ERROR) | |
C_INFO := $(call get-color,INFO) | |
C_UNDERFULL := $(call get-color,UNDERFULL) | |
C_OVERFULL := $(call get-color,OVERFULL) | |
C_PAGES := $(call get-color,PAGES) | |
C_BUILD := $(call get-color,BUILD) | |
C_GRAPHIC := $(call get-color,GRAPHIC) | |
C_DEP := $(call get-color,DEP) | |
C_SUCCESS := $(call get-color,SUCCESS) | |
C_FAILURE := $(call get-color,FAILURE) | |
C_FILENAME := $(call get-color,FILENAME) | |
C_PROGNAME := $(call get-color,PROGNAME) | |
C_RESET := $(reset) | |
echo-img = echo -e "$(C_BUILD)====> $(C_INFO)Generating figure $(C_FILENAME)$1$(C_RESET)$(if $2, | $(red)Step $2$(C_RESET),)" | |
echo-cpy = echo -e "$(C_BUILD)====> $(C_INFO)Copying figure $(C_FILENAME)$1$(C_RESET)$(if $2, | $(red)Step $2$(C_RESET),)" | |
echo-tex-step = echo -e "$(C_BUILD)====> $(C_INFO)$1 $(C_PROGNAME)$2 $(C_RESET)| $(red)$3$(C_RESET)" | |
echo-gen = echo -e "$(C_BUILD)====> $(C_INFO)Generating $1 $(C_RESET)" | |
echo-do = echo -e "$(C_BUILD)====> $(C_INFO)$1 $(C_FILENAME)$(if $2,$2,)$(C_RESET)" | |
echo-error = echo -e "$(C_BUILD)====> $(C_ERROR)$1 $(C_FILENAME)$(if $2,$2,)$(C_RESET)" | |
echo-warning = echo -e "$(C_BUILD)====> $(C_WARNING)$1 $(C_FILENAME)$(if $2,$2,)$(C_RESET)" | |
echo-finish = echo -e "$(C_BUILD)====> $(blue)Finished $(C_RESET)$1$(C_INFO)$(if $2, in $(red)$2$(blue) runs,)$(C_RESET)" | |
echo-debug = echo -e "$(C_BUILD)====> $(C_INFO)DEBUG $1 $(C_RESET)" | |
# Colorizes real, honest-to-goodness LaTeX errors that can't be overcome with | |
# recompilation. | |
# | |
# Note that we only ignore file not found errors for things that we know how to | |
# build, like graphics files. | |
# | |
# $(call colorize-latex-errors,<log file>) | |
define colorize-latex-errors | |
$(SED) -f $(ERROR_SEDSCRIPT) $1 | |
endef | |
define run-latex | |
$(COPY) $(QUIET);\ | |
$(call echo-tex-step,Running,$(LTITLE),First Run);\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR) ; runs=1; \ | |
if egrep $(USEMAKEIDX) $< $(QUIET);\ | |
then\ | |
$(call echo-gen,index);\ | |
$(MAKEINDEX) $(<:%.tex=%) $(QUIET);\ | |
$(COPY) $(QUIET);\ | |
$(call echo-tex-step,Running,$(LTITLE),Including Index);\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR); let "runs=runs+1"; \ | |
fi;\ | |
if egrep $(USEMAKEGLOSSARIES) $< $(QUIET);\ | |
then\ | |
$(call echo-gen,glossaries);\ | |
$(MAKEGLOSSARIES) $(<:%.tex=%) $(QUIET);\ | |
$(call echo-tex-step,Running,$(LTITLE),Including Glossary);\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR); let "runs=runs+1"; \ | |
fi;\ | |
bibrun=1;\ | |
while egrep -c $(RERUNBIB) $(<:%.tex=%.log) $(QUIET);\ | |
do\ | |
test "$$bibrun" -eq "5" && break;\ | |
if [ "$$bibrun" -eq "1" ];\ | |
then\ | |
$(call echo-do,Parsing Bibliography);\ | |
$(BIBTEX) $(<:%.tex=%) $(QUIET);\ | |
fi;\ | |
$(call echo-tex-step,Running,$(LTITLE),Applying bibliography (run $$bibrun));\ | |
$(COPY) $(QUIET);\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR);\ | |
let "bibrun=bibrun+1";\ | |
done;\ | |
try=1;\ | |
while egrep -c $(RERUN) $(<:%.tex=%.log) $(QUIET);\ | |
do\ | |
test "$$try" -eq "5" && break;\ | |
$(call echo-tex-step,Running,$(LTITLE),Solving References (run $$try));\ | |
$(COPY) $(QUIET);\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR);\ | |
let "try=try+1"; \ | |
done;\ | |
let "runs=runs + bibrun + try - 2";\ | |
if cmp -s $(<:%.tex=%.toc) $(<:%.tex=%.toc.bak) $(QUIET);\ | |
then\ | |
true;\ | |
else \ | |
if test -r $(<:%.tex=%.toc.bak); \ | |
then \ | |
$(call echo-tex-step,Running,$(LTITLE),Solving References (run $$try));\ | |
$(LATEX) $< $(QUIET) $(DISPLAYERROR);\ | |
let "runs=runs+1";\ | |
fi;\ | |
fi;\ | |
$(RM) $(<:%.tex=%.toc.bak) $(QUIET);\ | |
$(call echo-finish,$(LTITLE),$$runs);\ | |
$(call echo-warning,Undefined references and citations:);\ | |
echo -n "$(C_WARNING)" && egrep -i "(Reference|Citation).*undefined" $(<:%.tex=%.log) && echo -n -e "$(C_RESET)" || echo -e "$(C_INFO)None.$(C_RESET)";\ | |
true; | |
endef | |
define get_dependencies | |
deps=`perl -ne '($$_)=/^[^%]*\\\(?:include|input)\{(.*?)\}/;@_=split /,/;foreach $$t (@_) {print "$$t.tex "}' $<` | |
endef | |
define get_dependent_dirs | |
depdirs=`echo -n ". "; for dir in $$(for file in $$(perl -ne '($$_)=/^[^%]*\\\(?:include|input)\{(.*?)\}/;@_=split /,/;foreach $$t (@_) {print "$$t.tex "}' $<);do echo $$(dirname $$file); done | sort -u); do echo -n $$dir; echo -n " "; done` | |
endef | |
define getbibs | |
bibs=`perl -ne '($$_)=/^[^%]*\\\bibliography\{(.*?)\}/;@_=split /,/;foreach $$b (@_) {print "$$b.bib "}' $< $$deps` | |
endef | |
define getepss | |
epss=`perl -ne '@foo=/^[^%]*\\\(includegraphics|begin\{overpic\}|psfig|[a-zA-Z]+WallPaper\{[0-9]*\.?[0-9]*\})(\[.*?\])?\{(.*?)\}/g;if (defined($$foo[2])) { if ($$foo[2] =~ /.eps$$/) { print "$(FIGDIR)/$$foo[2]\n"; } else { print "$(FIGDIR)/$$foo[2].eps\n"; }}' $< $$deps | sort -u | sed ':begin;N;s/\n/ /;t begin'` | |
endef | |
define getpdfs | |
pdfs=`perl -ne '@foo=/^[^%]*\\\(includegraphics|begin\{overpic\}|[a-zA-Z]+WallPaper\{[0-9]*\.?[0-9]*\})(\[.*?\])?\{(.*?)\}/g;if (defined($$foo[2])) { if ($$foo[2] =~ /.pdf$$/) { print "$(FIGDIR)/$$foo[2]\n"; } else { print "$(FIGDIR)/$$foo[2].pdf\n"; }}' $< $$deps | sort -u | sed ':begin;N;s/\n/ /;t begin'` | |
endef | |
define getfigdirs | |
dirs="";\ | |
for file in $$epss $$pdfs;\ | |
do\ | |
dir=`dirname $$file`;\ | |
if (echo -e $$dirs | egrep -c $$dir) > /dev/null;\ | |
then\ | |
true;\ | |
else\ | |
dirs="$$dirs $$dir ";\ | |
fi\ | |
done | |
endef | |
define manconf | |
mandeps=`if test -r $(basename $@).cnf ; then cat $(basename $@).cnf |tr -d '\n\r' ; fi` | |
endef | |
mpfignum = $(shell echo $1 | sed 's/.*-\([0-9]\+\)\.\(eps\|pdf\)/\1/') | |
$(DVI) : %.dvi : %.tex %.d | |
@$(run-latex) | |
$(PSF) : %.ps : %.dvi %.d | |
@$(call echo-do,Generating,$@) | |
@$(DVIPS) $< -o $@ $(QUIET) | |
$(PSZ) : %.ps.gz : %.ps | |
@$(call echo-do,Compressing,$@) | |
@$(GZIP) -c $< > $@ | |
$(PDF) : %.pdf : %.tex %.d | |
@$(run-latex) | |
$(PDF:.pdf=.embedded.pdf): $(PDF) | |
@$(call echo-do,Embedding fonts,$*) | |
@$(call echo-warning,This operation removes any hyperlinks in,$@) | |
@$(call echo-warning,This operation may increase file size of,$@) | |
@(pdftops $< $<.ps) | |
@(ps2pdf -dPDFSETTINGS=/prepress $<.ps $@) | |
@-rm $<.ps | |
$(DJVU): %.djvu : %.pdf | |
@$(call echo-gen,$@) | |
@($(MAKEDJVU) -o $@ $< ) $(QUIET) | |
# image conversion rules | |
generated/%.eps : %.png | |
@$(call echo-img,$@) | |
@$(CONVERT) -compress zip $< eps3:$@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.tiff | |
@$(call echo-img,$@) | |
@$(CONVERT) -compress zip $< eps3:$@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.jpg | |
@$(call echo-img,$@) | |
@$(CONVERT) -compress zip $< eps3:$@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.bmp | |
@$(call echo-img,$@) | |
@$(CONVERT) -compress zip $< eps3:$@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.gif | |
@$(call echo-img,$@) | |
@$(CONVERT) -compress zip $< eps3:$@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.pdf | |
@$(call echo-img,$@) | |
@pdftops -eps -level3 $< $@ 2> /dev/null 1> /dev/null | |
generated/%.eps : %.ps | |
@$(call echo-img,$@) | |
@ps2eps -l -q $< | |
@mv $*.eps $@ | |
generated/%.eps : %.eps | |
@$(call echo-cpy,$@) | |
@cp $< $@ | |
generated/%.eps : %.fig | |
@$(call echo-img,$@) | |
@fig2dev -L eps $< > $@ 2> /dev/null | |
generated/%.eps : %.dia | |
@$(call echo-img,$@) | |
@dia --export=$@ --filter=eps $< 2> /dev/null 1> /dev/null | |
generated/%.eps : %.gpi | |
@$(call echo-img,$@) | |
@(echo set terminal postscript eps enhanced color; cat $<) | gnuplot > $@ | |
generated/%.eps : %.dot | |
@$(call echo-img,$@) | |
@dot -Teps $< > $@ | |
generated/%.eps : %.svg | |
@$(call echo-img,$@) | |
@inkscape -z --file=$< --export-eps=$@ $(QUIET) | |
generated/%.eps: %.tikz | |
@$(call echo-img,$@) | |
@tikz2pdf -o $< $(QUIET) | |
@mv tikz2pdf_temp.pdf $*.pdf | |
@pdftops -eps -level3 $*.pdf $@ 2> /dev/null 1> /dev/null | |
@-rm $*.pdf | |
generated/%.eps: %.odg | |
@$(call echo-img,$@) | |
@unoconv -T 5 -d graphics -f eps --stdout $< > $@ | |
generated/%.pdf : %.pdf | |
@$(call echo-cpy,$@) | |
@cp $< $@ | |
generated/%.pdf : %.eps | |
@$(call echo-img,$@) | |
@epstopdf --outfile=$@ $< 2> /dev/null 1> /dev/null | |
generated/%.pdf : %.fig | |
@$(call echo-img,$@) | |
@cd $(dir $<);fig2mpdf $(notdir $<) 2> /dev/null 1> /dev/null | |
@pdftops $*.pdf $*.ps | |
@ps2pdf -dPDFSETTINGS=/prepress $*.ps $*.pdf | |
@-rm -rf $*.ps | |
@mv $*.pdf $@ | |
generated/%.pdf : %.dia | |
@$(call echo-img,$@,1) | |
@dia --export=$(<:.dia=.eps) --filter=eps $< 2> /dev/null 1> /dev/null | |
@$(call echo-img,$@,2) | |
@epstopdf --outfile=$@ $(<:.dia=.eps) 2> /dev/null 1> /dev/null | |
@-rm -rf $(<:.dia=.eps) &> /dev/null | |
generated/%.pdf : %.ps | |
@$(call echo-img,$@) | |
@ps2pdf14 -dPDFSETTINGS=/prepress $< $@ 2> /dev/null 1> /dev/null | |
generated/%.pdf : %.bmp | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.gif | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.png | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.jpg | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.tif | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.tiff | |
@$(call echo-img,$@) | |
@$(CONVERT) $< $@ | |
generated/%.pdf : %.gpi | |
@$(call echo-img,$@,1) | |
@(echo set terminal mp color; cat $<) | gnuplot > $(<:.gpi=.mp) | |
@$(call echo-img,$@,2) | |
@cd $(dir $<);mptopdf $(notdir $(<:.gpi=.mp)) &> /dev/null | |
@mv $*-0.pdf $@ | |
@-rm -rf $(<:.gpi=.mp)* $*-* $*.0 $*.log &> /dev/null | |
generated/%.pdf : %.dot | |
@$(call echo-img,$@) | |
@dot -Tpdf $< > $@ | |
generated/%.pdf : %.svg | |
@$(call echo-img,$@) | |
@inkscape -z --file=$< --export-pdf=$@ $(QUIET) | |
generated/%.pdf : %.tikz | |
@$(call echo-img,$@) | |
@tikz2pdf -o $< $(QUIET) | |
@mv tikz2pdf_temp.pdf $@ | |
generated/%.pdf: %.odg | |
@$(call echo-img,$@) | |
@unoconv -T 5 -d graphics -f pdf --stdout $< > $@ | |
# This is a rule to generate a file of prerequisites for a given .tex file | |
%.d : %.tex | |
@$(call echo-do,Determining dependencies);\ | |
$(get_dependencies) ; \ | |
$(getbibs) ; \ | |
$(getepss) ; \ | |
$(getpdfs) ; \ | |
$(getfigdirs) ;\ | |
$(get_dependent_dirs) ;\ | |
$(manconf) ;\ | |
echo -e "$*.dvi $*.pdf $@ : $< $$deps $$bibs $$mandeps $(EXTRAS)" > $@ ; echo "" >> $@ ; \ | |
echo -e "$*.dvi : $$dirs $$epss" >> $@ ; echo "" >> $@ ; \ | |
echo -e "$*.pdf : $$dirs $$pdfs" >> $@ ; echo "" >> $@ ; \ | |
for file in $$epss $$pdfs; \ | |
do \ | |
mpsrc=$$(echo $$file | sed 's/^generated\/\(.*\)-[0-9]\+.\(pdf\|eps\)/\1.mp/g'); \ | |
mpsrc=$$(echo $$mpsrc | grep [.]mp); \ | |
if [ $$mpsrc=="" ]; then continue; fi; \ | |
if [ -f $$mpsrc ]; \ | |
then \ | |
echo -e "$$file: $$mpsrc" >> $@; \ | |
echo -e "\t@\$$(call echo-img,\$$@)" >> $@; \ | |
if [ $${file##*.} != "pdf" ]; \ | |
then \ | |
echo -e "\t@cd \$$(dir \$$<);mpost \$$(notdir \$$<) \$$(QUIET)" >> $@; \ | |
echo -e "\t@mv \$$(basename \$$<).\$$(call mpfignum,\$$@) \$$@" >> $@; \ | |
else \ | |
echo -e "\t@cd \$$(dir \$$<);mptopdf \$$(notdir \$$<) &> /dev/null" >> $@; \ | |
echo -e "\t@mv \$$(basename \$$<)-\$$(call mpfignum,\$$@).pdf \$$@" >> $@; \ | |
echo -e "\t@rm -f \$$(basename \$$<).\$$(call mpfignum,\$$@) \$$<?* \$$(basename \$$<)-* \$$(basename \$$<).log mpgraph.mp" >> $@; \ | |
fi; \ | |
fi; \ | |
done; \ | |
echo "" >> $@; \ | |
echo -e "DEPDIRS=$$depdirs" >> $@ ; echo "" >> $@ ; \ | |
if [[ $$dirs != "" ]]; then\ | |
echo -e "$$dirs :" >> $@ ;\ | |
echo -e "\t@\$$(call echo-do,Creating directory,\$$@)" >> $@ ;\ | |
echo -e " @mkdir -p \$$@" >> $@ ;\ | |
fi | |
.PHONY : all show clean ps pdf embedpdf showps showpdf tidy clean-images wordcount archive | |
all : default | |
show : view | |
viewdjvu: showdjvu | |
showdjvu: djvu | |
@for i in $(DJVU) ; do \ | |
$(call echo-do,Viewing,$<: $$i); \ | |
$(VIEWDJVU) $$i; \ | |
done | |
viewdvi : showdvi | |
showdvi : $(DVI) | |
@for i in $(DVI) ; do \ | |
$(call echo-do,Viewing,$<: $$i); \ | |
$(VIEWDVI) $$i; \ | |
done | |
viewps : showps | |
showps : ps | |
@for i in $(PSF) ; do \ | |
$(call echo-do,Viewing,$<: $$i); \ | |
$(VIEWPS) $$i; \ | |
done | |
viewpdf : showpdf | |
showpdf : pdf | |
@for i in $(PDF) ; do \ | |
$(call echo-do,Viewing,$<: $$i); \ | |
$(VIEWPDF) $$i; \ | |
done | |
psgz: $(PSZ) | |
postscript: ps | |
ps : $(PSF) | |
pdf : $(PDF) | |
embedpdf: $(PDF:.pdf=.embedded.pdf) | |
djvu: pdf $(DJVU) | |
dvi : $(DVI) | |
refresh: | |
rm -rf *.d | |
help: | |
@echo -n "Make [" | |
@echo -n {view,}{pdf,dvi,ps,djvu}, | |
@echo -n " clean, tidy, archive, wordcount, pagecount" | |
@echo "]" | |
tidy:: | |
@$(call echo-do,Cleaning up temporary files) | |
@-rm -f $(DVI:%.dvi=%.acn) $(DVI:%.dvi=%.acr) $(DVI:%.dvi=%.alg) $(DVI:%.dvi=%.bbl) $(DVI:%.dvi=%.blg) $(DVI:%.dvi=%.glg) $(DVI:%.dvi=%.glo) $(DVI:%.dvi=%.gls) $(DVI:%.dvi=%.log) $(DVI:%.dvi=%.out) $(DVI:%.dvi=%.idx) $(DVI:%.dvi=%.ilg) $(DVI:%.dvi=%.ind) $(DVI:%.dvi=%.ist) $(DVI:%.dvi=%.toc) $(DVI:%.dvi=%.d) $(DVI:%.dvi=%.nav) $(DVI:%.dvi=%.snm) | |
@$(call echo-do,Cleaning up intermediate files) | |
@for dir in $(DEPDIRS); do cd $$dir && rm -f *.lox *.log *.aux *.dvi *.bbl *.blg *.ilg *.toc *.lof *.lot *.lol *.idx *.ind *.ps *~ && cd - > /dev/null; done | |
@-rm -f *.synctex.gz | |
clean-images: | |
@$(call echo-do,Cleaning up generated images) | |
@-rm -rf $(FIGDIR) | |
clean: tidy clean-images | |
@$(call echo-do,Cleaning up output files) | |
@-rm -f $(DVI) $(PSF) $(PSZ) $(PDF) $(DJVU) archive.tar.gz | |
archive: default tidy | |
@$(call echo-do,Creating archive of sources) | |
@rm -f archive.tar archive.tar.gz | |
@tar -chf archive.tar *.tex | |
@test -d generated && tar -uhf archive.tar generated | |
@test -f references.bib && tar -uhf archive.tar references.bib | |
@test -f Makefile && tar -uhf archive.tar Makefile | |
@test -f $(ERROR_SEDSCRIPT) && tar -uhf archive.tar --xform s:^.*/:: $(ERROR_SEDSCRIPT) &>/dev/null | |
@gzip archive.tar | |
get-requirements: | |
@$(call echo-do,Fetching required packages using apt-get) | |
@sudo apt-get install realpath imagemagick gnuplot unoconv pdf2djvu $(VIEWDJVU) $(VIEWPDF) $(VIEWPS) bash dia xfig graphviz inkscape perl gzip ps2eps psutils pdfjam pdftk ghostscript ttf-lyx lmodern | |
@$(call echo-do,Fetching required packages and LaTeX distribution using apt-get) | |
@sudo apt-get install texlive-base texlive-xetex texlive-science texlive-publishers texlive-pstricks texlive-metapost texlive-math-extra texlive-latex-extra texlive-latex-recommended texlive-generic-recommended | |
wordcount: $(SRC) | |
@detex $< | wc -w | |
pagecount: $(PDF) | |
@pdfinfo $< | grep 'Pages' | |
-include $(SRC:.tex=.d) | |
-include Makefile.extra | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment