Last active
April 22, 2024 17:21
-
-
Save abzrg/2ecb41a71534877047292a84ddced67c to your computer and use it in GitHub Desktop.
A Makefile for Latex projects
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
#------------------------------------------------------------------------------ | |
# Author: | |
# Ali Bozorgzadeh | |
# Copyright: | |
# Copyright (c) 2024 Ali Bozorgzadeh | |
# License: | |
# The MIT License (see https://opensource.org/license/mit) | |
#------------------------------------------------------------------------------ | |
# Project structure: | |
# | |
# . | |
# ├── Makefile | |
# ├── include | |
# │ ├── chapter1.tex | |
# │ ├── chapter2.tex | |
# │ └── chapter3.tex | |
# └── main.tex | |
#------------------------------------------------------------------------------ | |
INCDIR := include # Name of the folder in which files are included/input in main.tex | |
BUILDDIR := build | |
SRC := main.tex # Name of top level code at the root of the project | |
INCLUDES := $(wildcard $(INCDIR)/*.tex) | |
PDF := document.pdf # Name of final document | |
TEXFLAGS = -pdf | |
TEXFLAGS += -dvi- | |
TEXFLAGS += -output-directory=${BUILDDIR} | |
TEXFLAGS += -file-line-error | |
TEXFLAGS += -interaction=nonstopmode | |
all: $(PDF) | |
$(BUILDDIR): | |
mkdir -p $@ | |
$(INCDIR): | |
mkdir -p $@ | |
$(PDF): $(SRC) $(INCLUDES) | $(BUILDDIR) $(INCDIR) | |
latexmk $(TEXFLAGS) $< | |
-ln -fs $(BUILDDIR)/$(<:.tex=.pdf) $@ | |
# Convert to text (text width = 80) (assuming pandoc is installed) | |
text: | |
pandoc $(SRC) --wrap=auto --columns=70 --to=plain -o $(SRC:.tex=.txt) | |
# Word count (assuming texcount is installed) | |
wc: | |
@texcount -inc $(SRC) \ | |
| awk -v RS='' '/Sum of files/' \ | |
| grep 'Words in text' \ | |
| awk '{print $$4}' | |
clean: | |
@-latexmk -C -output-directory=$(BUILDDIR) | |
.PHONY: all text wc clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment