Harry Rose

Home » Other » TexMake

TexMake

I'm afraid this is rather hacked. Its basically written just for me but I decided to upload it so I can show off and prove that I can write Makefiles.

######################################################
# A general .tex building makefile for coursework    #
#                                                    #
# Written by Harry Rose in 2007                      #
#	 	htr106@ecs.soton.ac.uk		     #
######################################################

#Command to compile latex
LATEX= latex

#Type of document
DOCTYPE= article

#Arguments to pass to the document, must be at least 1
DOCARGS= a4paper

#The title of the document
TITLE= Info2009 Coursework 2

#The author of the document
AUTHOR= Harry Rose \\\url{htr106@ecs.soton.ac.uk}

#Packages the document should include.
# If you need to provide options, do so in the format [options]package
PACKAGES= url [pdftex]hyperref graphicx natbib

#Files which should be included into this document.  Do not write directly into the output file
#as it is likely to get overwritten.
INCLUDES= MedicalEthics.tex MisuseOfResources.tex WebsiteCopyright.tex 

#Should we build the wordcount into the end of the document?
BUILDWC= y

#Should we put a contents page at the start?
BUILDCONTENTS= n

#Where is the bibliography database for this document? (blank for none)
BIBLIOGRAPHY= bibliography.bib

#What style of bibliography referencing should we use? (blank for default)
BIBLIOGRAPHYSTYLE= ieeetrh

#The filename of the file that contains the abstract. (blank for none)
ABSTRACT= 

#Any other header commands you want to include.
OTHERHEADER=\bibpunct{[}{]}{,}{n}{}{;}

#Paths to images that your document will be using. (include trailing /, can be blank)
IMAGEDIR= 

#What file should we create and view by default? (dvi or pdf)
DEFAULTVIEW= pdf

#What program should we use to view dvi files?
DVIVIEWER= xdvi

#What program should we use to view pdf files?
PDFVIEWER= evince

#WORDS and ABSTRACT_WORDS may have to be edited in order to use the right program to
#count the amount of words in the latex files in ${INCLUDES}
WORDS=	`twc ${INCLUDES} | gawk -F ":" "/Words in text:/{ if (totalseen == 1) {print $2}} /TotalSUM/{totalseen=1}" | sed "s/.*: //"`
ifneq (${ABSTRACT},)
ABSTRACT_WORDS= `twc ${ABSTRACT} | gawk -F ":" "/Words in text:/{print $2}" | sed "s/.*: //"`
endif
###############################################
# Don't edit below this line
###############################################



all:	coursework.pdf

wc.tex:	${INCLUDES}
	@echo Word count: ${WORDS}
	@echo Abstract:	${ABSTRACT_WORDS}
	@echo "\section{Word Count}Word count: ${WORDS}" > wc.tex

ifneq (${ABSTRACT},)
	@echo "\\\\Abstract: ${ABSTRACT_WORDS}">>wc.tex
endif

view:	${DEFAULTVIEW}_view

pdf_view:	coursework.pdf
	${PDFVIEWER} coursework.pdf &

dvi_view:	coursework.dvi
	${DVIVIEWER} coursework.dvi &

coursework.pdf:	coursework.dvi
	#dvipdfm coursework.dvi

coursework.rtf: coursework.tex ${INCLUDES} ${BIBLIOGRAPHY} wc.tex
	latex2rtf coursework.tex

coursework.dvi:	coursework.tex ${INCLUDES} ${BIBLIOGRAPHY} wc.tex
	${LATEX} coursework.tex
ifneq ($(BIBLIOGRAPHY),)
	bibtex coursework
endif
	${LATEX} coursework.tex
	${LATEX} coursework.tex

coursework.tex: Makefile
	echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' > coursework.tex
	echo '% This file was generated by a Makefile written by Harry Rose. %' >> coursework.tex
	echo '%                                                              %' >> coursework.tex
	echo '% DO NOT EDIT THIS DOCUMENT DIRECTLY AS IT IS LIKELY TO BE     %' >> coursework.tex
	echo '% OVERWRITTEN.  Instead you should make a new .tex file and    %' >> coursework.tex
	echo '% add it to the INCLUDES variable in the Makefile.             %' >> coursework.tex
	echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' >> coursework.tex
	echo '' >> coursework.tex
	echo '\documentclass[${DOCARGS}]{${DOCTYPE}}' >> coursework.tex
	echo $(foreach var,${PACKAGES},`echo ${var}| sed "s/\(\[.*\]\)\?\(.*\)/\\\\\usepackage\1{\2}/"` ) >>coursework.tex
ifneq (${IMAGEDIR},)
	echo '\graphicspath{$(foreach var,${IMAGEDIR},{${var}})}' >> coursework.tex
endif
	echo '${OTHERHEADER}' >> coursework.tex
	echo '\title{${TITLE}}' >> coursework.tex
	echo '\author{${AUTHOR}}' >> coursework.tex
	echo '\begin{document}' >> coursework.tex
	echo '	\maketitle' >> coursework.tex
ifneq (${ABSTRACT},)
	echo '	\begin{abstract}' >> coursework.tex
	echo '		\input{${ABSTRACT}}' >> coursework.tex
	echo '	\end{abstract}' >> coursework.tex
endif
ifeq (${BUILDCONTENTS},y)
	echo '	\tableofcontents' >> coursework.tex
endif
	echo '	$(foreach var,${INCLUDES},\input{${var}})' >> coursework.tex
ifeq (${BUILDWC},y)
	echo '	\input{wc}' >> coursework.tex
endif

ifneq (${BIBLIOGRAPHY},)
ifneq (${BIBLIOGRAPHYSTYLE},)
	echo '	\bibliographystyle{${BIBLIOGRAPHYSTYLE}}' >> coursework.tex
endif
	echo '	\bibliography{${BIBLIOGRAPHY}}' >> coursework.tex
endif
	echo '\end{document}' >> coursework.tex

clean:
	- rm *.aux *.bbl *.blg *.dvi *.log *.pdf *.toc coursework.tex