"pdftools.mk" makeover

This commit is contained in:
Jörn-Michael Miehe 2025-10-08 22:53:38 +00:00
parent b1df8ef305
commit fcce86cbed

View file

@ -1,46 +1,94 @@
############# # use pandoc to process markdown
# FUNCTIONS # #
############# # params:
# 1. input file
# 2. pandoc template
# 3. output format (e.g. pdf, latex, ...)
# 4. output file
#
# vars:
# - PANDOCVARS: template variables given as "name:value", separated by space
# - PANDOCFLAGS: additional flags for `pandoc` commands
pdftools_pdmd = pandoc \
$(1) \
--standalone \
--from markdown \
--to $(3) \
--template $(2) \
$(addprefix --variable ,$(PANDOCVARS) csquotes:true hyperrefoptions:pdfa) \
--output $(4) \
$(PANDOCFLAGS)
PDFTOOLS_GSFLAGS := \ # common flags for `gs` invocations (internal)
__PDFTOOLS_GSFLAGS := \
-sDEVICE=pdfwrite \ -sDEVICE=pdfwrite \
-dNOOUTERSAVE \ -dSAFER \
-dNOPAUSE \ -dNOPAUSE \
-dQUIET \ -dQUIET \
-dBATCH -dBATCH
# use ghostscript to concatenate and/or adjust PDF file(s)
#
# params:
# 1. input file(s)
# 2. output file
#
# vars:
# - GS_CompatibilityLevel (default: 1.7): Refer to gs "dCompatibilityLevel"
# - GSNOFORCE: Set to anything to avoid forcing the paper size
# - GS_PAPERSIZE (if GSNOFORCE is unset, default: a4): Refer to gs "sPAPERSIZE"
# - GSNOCOMPRESS: Set to anything to avoid "distilling" the PDF
# - GS_PDFSETTINGS (if GSNOCOMPRESS is unset, default: /ebook): Refer to gs "dPDFSETTINGS"
# - GSFLAGS: additional flags for `gs` commands
pdftools_pdfcat = gs \ pdftools_pdfcat = gs \
$(PDFTOOLS_GSFLAGS) \ $(__PDFTOOLS_GSFLAGS) \
-sPAPERSIZE=a4 \ -dCompatibilityLevel=$(or $(GS_CompatibilityLevel),1.7) \
-dFIXEDMEDIA \ $(if $(GSNOFORCE),,-sPAPERSIZE=$(or $(GS_PAPERSIZE),a4) -dFIXEDMEDIA -dPDFFitPage) \
-dPDFFitPage \ $(if $(GSNOCOMPRESS),,-dPDFSETTINGS=$(or $(GS_PDFSETTINGS),/ebook)) \
-dCompatibilityLevel=1.7 \
-dPDFSETTINGS=/ebook \
-sOutputFile=$(2) \ -sOutputFile=$(2) \
$(GSFLAGS) \
$(1) $(1)
# use ghostscript to concatenate PDF file(s) into a PDF/A
#
# params:
# 1. input file(s)
# 2. output file
#
# vars:
# - GS_PDFA (default: 3): Refer to gs "dPDFA"
# - GS_PDFACompatibilityPolicy (default: 1): Refer to gs "dPDFACompatibilityPolicy"
# - GSFLAGS: additional flags for `gs` commands
pdftools_mkpdfa = gs \ pdftools_mkpdfa = gs \
$(PDFTOOLS_GSFLAGS) \ $(__PDFTOOLS_GSFLAGS) \
-dPDFA=$(1) \ -dPDFA=$(or $(GS_PDFA),3) \
-dPDFACompatibilityPolicy=$(or $(GS_PDFACompatibilityPolicy),1) \
-sColorConversionStrategy=RGB \ -sColorConversionStrategy=RGB \
-dPDFACompatibilityPolicy=1 \
--permit-file-read=/usr/local/share/autodoc/ \ --permit-file-read=/usr/local/share/autodoc/ \
-sOutputFile=$(3) \ -sOutputFile=$(2) \
$(GSFLAGS) \
/usr/local/share/autodoc/PDFA_def.ps \ /usr/local/share/autodoc/PDFA_def.ps \
$(2) $(1)
############ # shorthands for `pdftools_pdfcat` and `pdftools_mkpdfa` reading from stdin (param is just output file, vars applicable)
# PATTERNS # pdftools_pdfpipe = $(call pdftools_pdfcat,-,$(1))
############ pdftools_pdfapipe = $(call pdftools_mkpdfa,-,$(1))
# convert PDF to PDF/A-2B # shorthands for `pdftools_pdmd` to compile into LaTeX, PDF and PDF/A
%_pdfa2.pdf: %.pdf #
$(call pdftools_mkpdfa,2,$<,$@) # vars applicable from `pdftools_pdmd`, `pdftools_pdfcat` and `pdftools_mkpdfa` as expected
#
# params:
# 1. input file
# 2. pandoc template
# 3. output file
pdftools_md2tex = $(call pdftools_pdmd,$(1),$(2),latex,$(3))
pdftools_md2pdf = $(call pdftools_pdmd,$(1),$(2),pdf,-) | $(call pdftools_pdfpipe,$(3))
pdftools_md2pdfa = $(call pdftools_md2pdf,$(1),$(2),-) | $(call pdftools_pdfapipe,$(3))
# convert PDF to PDF/A-3B # shorthands based on automatic Make variables
%_pdfa3.pdf: %.pdf pdftools_pdfcat_auto = $(call pdftools_pdfcat,$^,$@)
$(call pdftools_mkpdfa,3,$<,$@) pdftools_mkpdfa_auto = $(call pdftools_mkpdfa,$^,$@)
pdftools_md2tex_auto = $(call pdftools_md2tex,$<,$(1),$@)
# convert PDF to PDF/A (default variant 3B) pdftools_md2pdf_auto = $(call pdftools_md2pdf,$<,$(1),$@)
%_pdfa.pdf: %.pdf pdftools_md2pdfa_auto = $(call pdftools_md2pdfa,$<,$(1),$@)
$(call pdftools_mkpdfa,3,$<,$@)