<commit_before># mstamat's Uber-Makefile boilerplate for LaTeX and Markdown
# Get the latest here: https://raw.githubusercontent.com/m000/cliutils/master/latex/latex.mak
#
# How to use:
# 	a. Copy in your working dir as "Makefile" and edit to match your needs.
# 	   You should only need to edit whatever is marked with "EDIT".
# 	b. Include from your Makefile. Set your own defaults before and add your
# 	   own rules after the include directive.


### Programs ######################################################
LATEX   	?= xelatex
BIBTEX     	?= bibtex
LATEXPAND  	?= latexpand
PANDOC		?= pandoc
ZIP        	?= zip
MKDIR      	?= mkdir -p
CP         	?= cp
RM         	?= rm -f
RSYNC      	?= rsync
SPONGE		?= sponge
GIT			?= git


### Input/Output files ############################################
# Locations (to be used e.g. in zip name):
MAKEFILE_PATH	= $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_DIR	= $(notdir $(realpath $(dir $(MAKEFILE_PATH))))
GIT_DIR			= $(notdir $(shell $(GIT) rev-parse --show-toplevel))

# Markdown:
MD_SRC		?= $(wildcard *.md)						# EDIT: default for markdown files to process
MD_html		= $(patsubst %.md,%.html,$(MD_SRC))
MD_txt		= $(patsubst %.md,%.txt,$(MD_SRC))
MD_pdf		= $(patsubst %.md,%.pdf,$(MD_SRC))

# LaTeX:
TEX_SRC		?= $(wildcard paper*.tex)				# EDIT: default for top-level tex files ti process
ifneq ($(wildcard *-cr.tex),)						# CR files present
TEX_SRC 	= $(wildcard *-cr.tex)
else
TEX_SRC_CR	= $(patsubst %.tex,%-cr.tex,$(TEX_SRC)) # CR files
endif
TEX_SRC_ALL	?= $(wildcard *.tex)
BIB_SRC		?= $(wildcard *.bib)
TEX_AUX		?= $(wildcard *.aux)
TEX_BBL		?= $(patsubst %.aux,%.bbl,$(TEX_AUX))
TEX_SUP		?= $(wildcard *.cls *.bst *.sty)
TEX_FIG		?= $(wildcard figs/*.pdf figs/*.eps figs/*.png)
TEX_PLOT	?= $(wildcard plots/*.pdf plots/*.eps plots/*.png)
TEX_CLEAN	?= $(wildcard *.log *.aux *.blg *.bbl *.out *.nav *.snm *.toc *.vrb)
TEX_pdf		= $(patsubst %.tex,%.pdf,$(TEX_SRC))

# Zip:
ZIPTARGET	?= $(notdir $(CURDIR)).zip				# EDIT: default name for zip file to be created
ZIPTARGET	:= $(strip $(ZIPTARGET))
ZIPDIR		= $(basename $(ZIPTARGET))				# temp directory for holding zipfile contents
ZIPDIR		:= $(strip $(ZIPDIR))
ZIP_CR_SRC	?= Makefile $(TEX_pdf) $(TEX_SRC_CR) $(TEX_FIG) $(TEX_PLOT) $(BIB_SRC) $(TEX_SUP)	# EDIT: files in the CR zip
ZIP_CR_CP	= $(addprefix $(ZIPDIR)/,$(ZIP_CR_SRC))


### Settings ######################################################
LATEX_FINAL_SETTINGS	?= -dPDFSETTINGS=/prepress
LATEXPAND_SETTINGS		?= --verbose --explain
ZIPEXCLUDE				?=							# EDIT: e.g. "-x v.pdf trip.pdf"


### Recipes #################################################
%.html: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t html5 --self-contained -o $(@) $(<)

%.txt: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t plain -o $(@) $(<)

%.tex %.pdf: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t latex -o $(@) $(<)

%.pdf: %.tex $(TEX_SRC_ALL) $(BIB_SRC) $(TEX_FIG) $(TEX_PLOT) $(TEX_SUP)
	$(LATEX) $(patsubst %.tex,%,$<)
	$(MAKE) $(TEX_BBL)
	$(LATEX) $(patsubst %.tex,%,$<)
	$(LATEX) $(LATEX_FINAL_SETTINGS) $(patsubst %.tex,%,$<)

%.bbl: %.aux
	- $(BIBTEX) $(patsubst %.aux,%,$*)

$(ZIPDIR)/%-cr.tex: %.tex
ifneq ($(TEX_SRC_CR),)
	@$(MKDIR) $(dir $(@))
	$(LATEXPAND) $(<) -o $(@) $(LATEXPAND_SETTINGS)
else
	$(error CR files already present)
endif

$(ZIPDIR)/%: %
ifneq ($(TEX_SRC_CR),)
	@$(MKDIR) $(dir $(@))
	$(CP) $(<) $(@)
else
	$(error CR files already present)
endif


### Rules ###################################################
DST			?= $(MD_pdf) $(TEX_pdf)					# EDIT: destination files

.PHONY: all zip zip-cr clean distclean

all: $(DST)
	@echo Done

zip: $(DST)
	$(ZIP) $(ZIPTARGET) $(ZIPEXCLUDE) -9 $^

zip-cr: $(ZIP_CR_CP)
	$(ZIP) $(ZIPTARGET) $(ZIPEXCLUDE) -9 $^

clean:
	$(RM) $(TEX_CLEAN)
	$(RM) -r $(ZIPDIR) $(ZIPTARGET)

distclean: clean
	$(RM) $(DST)<commit_msg>Update to latex.mak.<commit_after># mstamat's Uber-Makefile boilerplate for LaTeX and Markdown
# Get the latest here: https://raw.githubusercontent.com/m000/cliutils/master/latex/latex.mak
#
# How to use:
# 	a. Copy in your working dir as "Makefile" and edit to match your needs.
# 	   You should only need to edit whatever is marked with "EDIT".
# 	b. Include from your Makefile. Set your own defaults before and add your
# 	   own rules after the include directive.


### Programs ######################################################
LATEX   	?= xelatex
BIBTEX     	?= bibtex
LATEXPAND  	?= latexpand
PANDOC		?= pandoc
ZIP        	?= zip
MKDIR      	?= mkdir -p
CP         	?= cp
RM         	?= rm -f
RSYNC      	?= rsync
SPONGE		?= sponge
GIT			?= git


### Input/Output files ############################################
# Locations (to be used e.g. in zip name):
MAKEFILE_PATH	= $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_DIR	= $(notdir $(realpath $(dir $(MAKEFILE_PATH))))
GIT_DIR			= $(notdir $(shell $(GIT) rev-parse --show-toplevel))

# Markdown:
MD_SRC		?= $(wildcard *.md)						# EDIT: default for markdown files to process
MD_html		= $(patsubst %.md,%.html,$(MD_SRC))
MD_txt		= $(patsubst %.md,%.txt,$(MD_SRC))
MD_pdf		= $(patsubst %.md,%.pdf,$(MD_SRC))

# LaTeX:
TEX_SRC		?= $(wildcard paper*.tex)				# EDIT: default for top-level tex files ti process
ifneq ($(wildcard *-cr.tex),)						# CR files present
TEX_SRC 	= $(wildcard *-cr.tex)
else
TEX_SRC_CR	= $(patsubst %.tex,%-cr.tex,$(TEX_SRC)) # CR files
endif
TEX_SRC_ALL	?= $(wildcard *.tex)
BIB_SRC		?= $(wildcard *.bib)
TEX_AUX		= $(patsubst %.tex,%.aux,$(TEX_SRC))
TEX_BBL		= $(patsubst %.aux,%.bbl,$(TEX_AUX))
TEX_SUP		?= $(wildcard *.cls *.bst *.sty)
TEX_FIG		?= $(wildcard figs/*.pdf figs/*.eps figs/*.png)
TEX_PLOT	?= $(wildcard plots/*.pdf plots/*.eps plots/*.png)
TEX_CLEAN	?= $(wildcard *.log *.aux *.blg *.bbl *.out *.nav *.snm *.toc *.vrb)
TEX_pdf		= $(patsubst %.tex,%.pdf,$(TEX_SRC))

# Zip:
ZIPTARGET	?= $(notdir $(CURDIR)).zip				# EDIT: default name for zip file to be created
ZIPTARGET	:= $(strip $(ZIPTARGET))
ZIPDIR		= $(basename $(ZIPTARGET))				# temp directory for holding zipfile contents
ZIPDIR		:= $(strip $(ZIPDIR))
ZIP_CR_SRC	?= Makefile latex.mak $(TEX_pdf) $(TEX_SRC_CR) $(TEX_FIG) $(TEX_PLOT) $(BIB_SRC) $(TEX_SUP) $(ZIP_CR_SRC_EXTRA)	# EDIT: files in the CR zip
ZIP_CR_CP	= $(addprefix $(ZIPDIR)/,$(ZIP_CR_SRC))


### Settings ######################################################
LATEX_FINAL_SETTINGS	?= -dPDFSETTINGS=/prepress
LATEXPAND_SETTINGS		?= --verbose --explain
ZIPEXCLUDE				?=							# EDIT: e.g. "-x v.pdf trip.pdf"


### Recipes #################################################
%.html: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t html5 --self-contained -o $(@) $(<)

%.txt: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t plain -o $(@) $(<)

%.tex %.pdf: %.md
	$(PANDOC) --standalone --normalize -f markdown-hard_line_breaks -t latex -o $(@) $(<)

%.pdf: %.tex $(TEX_SRC_ALL) $(BIB_SRC) $(TEX_FIG) $(TEX_PLOT) $(TEX_SUP)
	$(LATEX) $(patsubst %.tex,%,$<)
	$(MAKE) $(TEX_BBL)
	$(LATEX) $(patsubst %.tex,%,$<)
	$(LATEX) $(LATEX_FINAL_SETTINGS) $(patsubst %.tex,%,$<)

%.bbl: %.aux
	- $(BIBTEX) $(patsubst %.aux,%,$*)

$(ZIPDIR)/%-cr.tex: %.tex
ifneq ($(TEX_SRC_CR),)
	@$(MKDIR) $(dir $(@))
	$(LATEXPAND) $(<) -o $(@) $(LATEXPAND_SETTINGS)
else
	$(error CR files already present)
endif

$(ZIPDIR)/%: %
ifneq ($(TEX_SRC_CR),)
	@$(MKDIR) $(dir $(@))
	$(CP) $(<) $(@)
else
	$(error CR files already present)
endif


### Rules ###################################################
DST			?= $(MD_pdf) $(TEX_pdf)					# EDIT: destination files

.PHONY: all zip zip-cr clean distclean

all: $(DST)
	@echo Done

zip: $(DST)
	$(ZIP) $(ZIPTARGET) $(ZIPEXCLUDE) -9 $^

zip-cr: $(ZIP_CR_CP)
	$(ZIP) $(ZIPTARGET) $(ZIPEXCLUDE) -9 $^

clean:
	$(RM) $(TEX_CLEAN)
	$(RM) -r $(ZIPDIR) $(ZIPTARGET)

distclean: clean
	$(RM) $(DST)

gitclean:
	$(GIT) clean -fdx
{'fraction_non_alphanumeric': 0.25219353221358737, 'fraction_numerical': 0.0015041363750313362, 'mean_word_length': 4.147741935483871, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294264', 'n_tokens_mistral': 3497, 'n_tokens_neox': 3271, 'n_words': 771}