Skip to content
Snippets Groups Projects
Commit a449160e authored by James Vasile's avatar James Vasile
Browse files

Move draft to plugin, simplify makefile

 * Make -rXXXX versions for all builds, not just drafts
 * Add draft plugin
 * In template, set draft to trigger on both True and 'True'
 * Move path into PIPELINE definition
 * Silence some echo
 * Use .tex instead of intermediate_ltx
 * Simplify some bash
 * Let the plugin handle draft instead of passing it as an option
 * Cleanup .tex files

We can now do redacted and draft at the same time.
parent 542bb71d
No related branches found
No related tags found
No related merge requests found
......@@ -13,9 +13,10 @@ LTX=$(wildcard *.ltx)
PDFLATEX="pdflatex"
# This is a script that takes yaml-fronted latex and runs it through
# our pipeline. See the ots-doctools pipeline directory for more.
PIPELINE=${OTS_DOCTOOLS_DIR}/pipeline/pipeline.py
# PIPELINE is a script that takes yaml-fronted latex and runs it
# through our pipeline. See the ots-doctools pipeline directory for
# more.
PIPELINE=venv/bin/python3 ${OTS_DOCTOOLS_DIR}/pipeline/pipeline.py
default: build-or-help
......@@ -78,19 +79,17 @@ all-redacted:
# it'll wake up, issue its cheery version-header greeting, realize
# that nothing actually needs to be done, and exit.)
%.pdf: %.ltx Makefile venv
@venv/bin/python3 ${PIPELINE} $< --output $(<:.ltx=.tex)
@latexmk -pdf -pdflatex=$(PDFLATEX) -halt-on-error $(<:.ltx=.tex)
# This builds the draft. This only works if you're using the a jinja
# template that extends down to base.ltx. If you're just compiling
# straight latex, building a draft version is unsupported and leads to
# undefined behavior.
%.draft.pdf: %.ltx Makefile venv
@if [ -L $(shell basename $< .ltx).draft.pdf ]; then rm $(shell basename $< .ltx).draft.pdf; fi
venv/bin/python3 ${PIPELINE} -o draft True $< --output $(<:.ltx=.intermediate_ltx)
latexmk -pdf -pdflatex=$(PDFLATEX) -halt-on-error --shell-escape $(<:.ltx=.intermediate_ltx)
mv $(shell basename $< .ltx).pdf $(shell basename $< .ltx)-$(REVBIN).pdf
ln -sf $(shell basename $< .ltx)-$(REVBIN).pdf $(shell basename $< .ltx).draft.pdf
@${PIPELINE} $< --output $(<:.ltx=.tex)
@latexmk -pdf -pdflatex=$(PDFLATEX) -halt-on-error --shell-escape $(<:.ltx=.tex)
@mv $@ $(@:.pdf=-$(REVBIN).pdf)
@ln -sf $(@:.pdf=-$(REVBIN).pdf) $@
# This builds a draft. This only works if you're using the jinja
# template that extends down to base.ltx. Without that, draft
# versions are unsupported and this should have no effect.
%.draft.ltx: %.ltx Makefile venv
@rm -f $@
@ln -s $< $@
# This builds a redacted version. It tells jinjify to look for a
# redacted field in the YAML pre-matter. That field should specify a
......@@ -136,7 +135,9 @@ clean: clean_latex
)
@if [ -s "latex2docx" ]; then rm -f latex2docx; fi
@if [ -s "latex2odt" ]; then rm -f latex2odt; fi
@rm -f $(patsubst %.ltx,%.intermediate_ltx,$(wildcard *.ltx))
@rm -f $(patsubst %.ltx,%.tex,$(wildcard *.ltx))
@rm -f $(patsubst %.ltx,%.draft.ltx,$(wildcard *.ltx))
@rm -f $(patsubst %.ltx,%.redacted.ltx,$(wildcard *.ltx))
@rm -f *.redacted.ltx
# Don't delete intermediate files
......
......@@ -2,7 +2,7 @@
\usepackage{ots}
\BLOCK{if draft is defined and draft=='True'}
\BLOCK{if draft is defined and (draft=='True' or draft==True)}
\usepackage{draftwatermark}
\SetWatermarkText{DRAFT}
\SetWatermarkScale{6}
......
#!/usr/bin/env python3
"""If we're making a file with 'draft' in the name, enable draft mode"""
def run_p(text, meta):
return 'draft' in meta['output_filename']
def run(text, meta):
meta['draft']=True
return text, meta
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment