Skip to contentSkip to conversation

Makefile: Add alternative eps --> pdf rules

PATCH New Akira Yokosawa 1 participant 7 messages Oct 3, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Makefile: Add alternative eps --> pdf rules

Hi Paul,

This patch series attempts to add alternative rules for "eps --> pdf" conversion independent of a2ping.

Patches 1/6 and 2/6 are preparatory changes.
Patch 1/6 adds targets for cleaning/building figure files. They are convenient for switching between two sets of rules.

Build time of figure files listed below are measured using the new targets, namely cleanfigs-eps and figs:

make cleanfigs-eps; env time make -j4 figs

, and the baseline data corresponds to patch 1/6.

Patch 2/6 splits rules related to a2ping into a sub-makefile, a2ping-rule.mk. No behavior change is expected at this point.

Patch 3/6 adds the alternative rules in epstopdf-rule.mk. They combine "eps2eps" and "epstopdf" commands.
eps2eps belongs to the Ghostscript bundle.
It generates normalized eps format, with proper bounding-boxes. epstopdf accepts a proper eps file and convert it to pdf using Ghostscript.
Using them together gives mostly the same pdf images as a2ping does.

As a matter of fact, a2ping was inspired from an old version of epstopdf back in 2003 or so.

Patches 4/6 -- 6/6 are minor improvements to reduce file size and build time of those pdf files.

Build time comparisons at patches 1/6 and 6/6 are shown below. They are measured in container images hosted on a Ubuntu 18.04 box. (Actual timing can be quite different on real systems.)

"focal" -- Ubuntu 20.04 (Ghostscript 9.50, distro TeX Live 2019/Debian,
no "NimbusSanL-Regu", with "NimbusSans-Regular")
"bionic" -- Ubuntu 18.04 (Ghostscript 9.26, distro TeX Live 2017/Debian
+ required up-to-date LaTeX packages)
"fedora" -- Fedora 34 (Ghostscript 9.54.0, distro TeX Live 2019,
no "NimbusSanl-Regu", with "NimbusSans-Regular")
"vanilla" -- Ubuntu 20.04 (Vanilla TeX Live 2021 as of Sep. 28, 2021,
Ghostscript 9.55.0 built from source,
no "NimbusSanL-Regu", with "NimbusSans-Regular")

Elapsed time of "make -j4 figs" after "make cleanfigs-eps":

Patch 1/6 Patch 6/6
------------ ---------------------
a2ping a2ping epstopdf

----------- ------------  ------------ --------
focal       0:41.77       0:40.19      0:24.56
bionic      0:39.30       0:38.42      0:22.47
fedora      0:41.63       0:40.09      0:23.30
vanilla     0:16.55       0:15.02      0:12.55
----------- ------------  ------------ --------

The lighter weight behavior of built-from-source Ghostscript is likely due to the minimal config options I chose.

Anyway, the alternative rules are quicker on every container image I have tested.

The alternative rules can be enabled by giving a "NO_A2PING=1" option to "make", or by defining NO_A2PING as an environment variable.

I'll invert the conditional include and make "epstopdf-rule.mk" the default choice once we are confident enough of the new rules.

Thanks, Akira
--
Akira Yokosawa (6):
Makefile: Add targets to build/clean figure files
Makefile: Split rules related to a2ping into a2ping-rule.mk epstopdf-rule.mk: Add alternative rules for .eps --> .pdf conversion epstopdf-rule.mk: Reduce converted pdf size epstopdf-rule.mk: Save a 'cp' by running fixfonts script directly
Makefile: Don't run fixfonts on .eps with embedded font

 Makefile         | 85 ++++++++++++++----------------------------------
 a2ping-rule.mk   | 69 +++++++++++++++++++++++++++++++++++++++
 epstopdf-rule.mk | 42 ++++++++++++++++++++++++
 3 files changed, 136 insertions(+), 60 deletions(-)
 create mode 100644 a2ping-rule.mk
 create mode 100644 epstopdf-rule.mk
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/6 Makefile: Add targets to build/clean figure files

For ease of switching rules for "eps --> pdf" conversion, add targets "cleanfigs", "cleanfigs-eps", "cleanfigs-svg", and "figs".

---
 Makefile | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Makefile +12 -0
index eca23aab..e2838779 100644
@@ -204,6 +204,7 @@ BASE_DEPENDS := perfbook.tex $(foreach v,tcb 1c msns mss mstx msr msn msnt sf nq
 .PHONY: help help-official help-full help-semiofficial help-paper help-draft
 .PHONY: help-experimental help-prefixed
 .PHONY: paper-clean periodcheck punctcheck punctcheck-auto
+.PHONY: cleanfigs cleanfigs-eps cleanfigs-svg figs
 
 all: punctcheck-auto
 
@@ -625,6 +626,17 @@ ls-unused:
 neatfreak: distclean
 	find . -name '*.pdf' | xargs rm -f
 
+cleanfigs-eps:
+	rm -f $(EPSSOURCES_FROM_TEX) $(EPSSOURCES_FROM_DOT) $(EPSSOURCES_FROM_FIG)
+	rm -f $(PDFTARGETS_OF_EPS)
+
+cleanfigs-svg:
+	rm -f $(PDFTARGETS_OF_SVG)
+
+cleanfigs: cleanfigs-eps cleanfigs-svg
+
+figs: $(PDFTARGETS_OF_EPS) $(PDFTARGETS_OF_SVG)
+
 punctcheck:
 	utilities/punctcheck.sh
 	utilities/cleverefcheck.sh
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/6 Makefile: Split rules related to a2ping into a2ping-rule.mk

In reply to Akira Yokosawa

Preparatory change for adding alternative rules for "eps --> pdf" conversion.
No behavior change is intended.

---
 Makefile       | 64 ++--------------------------------------------
 a2ping-rule.mk | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 62 deletions(-)
 create mode 100644 a2ping-rule.mk
Makefile +2 -62
index e2838779..5d9ef4b9 100644
@@ -88,7 +88,6 @@ BIBSOURCES := bib/*.bib alphapf.bst
 # required commands
 DOT := $(shell which dot 2>/dev/null)
 FIG2EPS := $(shell which fig2eps 2>/dev/null)
-A2PING := $(shell which a2ping 2>/dev/null)
 INKSCAPE := $(shell which inkscape 2>/dev/null)
 ifdef INKSCAPE
   INKSCAPE_ONE := $(shell inkscape --version 2>/dev/null | grep -c "Inkscape 1")
@@ -137,29 +136,6 @@ endif
 
 STEELFONTID := $(shell fc-list | grep -i steel | grep -c Steel)
 
-ifdef A2PING
-  GS_950_OR_LATER := $(shell gs --version | grep -c -E "9\.[5-9].?")
-  A2PING_277P := $(shell a2ping --help 2>&1 | grep -c "2.77p,")
-  A2PING_283P := $(shell a2ping --help 2>&1 | grep -c "2.83p,")
-  GS_953_OR_LATER := $(shell gs --version | grep -c -E "9\.5[3-9].?")
-  ifeq ($(A2PING_277P),1)
-    A2PING_GSCNFL = 1
-  else
-    ifeq ($(A2PING_283P),1)
-      ifeq ($(GS_950_OR_LATER),1)
-        A2PING_GSCNFL = 1
-      else
-        A2PING_GSCNFL = 0
-      endif
-    else
-      A2PING_GSCNFL = 0
-    endif
-  endif
-  ifeq ($(GS_953_OR_LATER),1)
-    A2PING_GSCNFL = 2
-  endif
-endif
-
 LINELABEL_ENV_BEGIN := $(shell grep -l -F '\begin{linelabel}' $(LATEXSOURCES))
 LINELABEL_ENV_END   := $(shell grep -l -F '\end{linelabel}'   $(LATEXSOURCES))
 LINEREF_ENV_BEGIN   := $(shell grep -l -F '\begin{lineref}'   $(LATEXSOURCES))
@@ -431,44 +407,8 @@ endif
 	@fig2eps --nogv $< > /dev/null 2>&1
 	@sh $(FIXANEPSFONTS) $@
 
-$(PDFTARGETS_OF_EPSORIG): %.pdf: %.eps
-	@echo "$< --> $@"
-ifndef A2PING
-	$(error $< --> $@: a2ping not found. Please install it)
-endif
-ifeq ($(A2PING_GSCNFL),1)
-	$(error You need to update a2ping. See #7 in FAQ-BUILD.txt)
-endif
-	@cp $< $<i
-	@sh $(FIXANEPSFONTS) $<i
-	@a2ping --below --hires --bboxfrom=compute-gs $<i $@ > /dev/null 2>&1
-	@rm -f $<i
-
-$(PDFTARGETS_OF_TEX): %.pdf: %.eps
-	@echo "$< --> $@"
-ifndef A2PING
-	$(error $< --> $@: a2ping not found. Please install it)
-endif
-ifeq ($(A2PING_GSCNFL),1)
-	$(error a2ping version conflict. See #7 in FAQ-BUILD.txt)
-endif
-ifeq ($(A2PING_GSCNFL),2)
-	@a2ping --below --gsextra=-dALLOWPSTRANSPARENCY $< $(basename $@)__.pdf > /dev/null 2>&1
-	@pdfcrop --hires $(basename $@)__.pdf $@ > /dev/null
-	@rm -f $(basename $@)__.pdf
-else
-	@a2ping --below --hires --bboxfrom=compute-gs $< $@ > /dev/null 2>&1
-endif
-
-$(PDFTARGETS_OF_EPSOTHER): %.pdf: %.eps
-	@echo "$< --> $@"
-ifndef A2PING
-	$(error $< --> $@: a2ping not found. Please install it)
-endif
-ifeq ($(A2PING_GSCNFL),1)
-	$(error a2ping version conflict. See #7 in FAQ-BUILD.txt)
-endif
-	@a2ping --below --hires --bboxfrom=compute-gs $< $@ > /dev/null 2>&1
+# .eps --> .pdf rules
+include a2ping-rule.mk
 
 $(PDFTARGETS_OF_SVG): %.pdf: %.svg
 	@echo "$< --> $@"
a2ping-rule.mk new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/6 epstopdf-rule.mk: Add alternative rules for .eps --> .pdf conversion

In reply to Akira Yokosawa

a2ping is convenient in that it accepts most eps/ps files (not necessarily EPS conformant) and generates properly cropped figures in most cases.

However, recent updates of Ghostscript have conflicted with a2ping's internal postscript and perl code.

As a2ping has limited active users, it tends to lag behind Ghostscript changes.

So this commit attempts to achieve the same effect by adding rules using other similar tools that have larger user bases in the hope of getting timely fixes to catch up changes in Ghostscript.

It is enabled when NO_A2PING is defined, for example:

make NO_A2PING=1

The pair of commands, eps2eps and epstopdf, work similarly as a2ping.

The alternative rules generate much larger .pdf files than those with a2ping does as of this change.
Size reduction will be attempted in a later change.

Current maintainer of epstopdf is Karl Berry, who has been active in TeX Live and CTAN communities.
eps2eps is a command in the Ghostscript bundle.

Notes:
o On Fedora, epstopdf is in texlive-collection-fontutils, or just installing texlive-esptopdf should suffice.
o On Ubuntu, it is covered by the existing list of dependent packages in FAQ-BUILD.txt, namely "texlive-pstricks".

---
 Makefile         |  6 +++++-
 epstopdf-rule.mk | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 epstopdf-rule.mk
Makefile +5 -1
index 5d9ef4b9..d3fcffca 100644
@@ -408,7 +408,11 @@ endif
 	@sh $(FIXANEPSFONTS) $@
 
 # .eps --> .pdf rules
-include a2ping-rule.mk
+ifndef NO_A2PING
+  include a2ping-rule.mk
+else
+  include epstopdf-rule.mk
+endif
 
 $(PDFTARGETS_OF_SVG): %.pdf: %.svg
 	@echo "$< --> $@"
epstopdf-rule.mk new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/6 epstopdf-rule.mk: Reduce converted pdf size

In reply to Akira Yokosawa

By adding "-dPDFSETTINGS=/ebook" in options passed to gs from epstopdf, pdf size of scanned images can be reduced. The image quality should be acceptable for perfbook.

Now the size of perfbook.pdf becomes around 500KB smaller than the one built with a2ping.

---
 epstopdf-rule.mk | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
epstopdf-rule.mk +5 -4
index 51425972..83d335f0 100644
@@ -6,6 +6,7 @@
 
 EPSTOPDF := $(shell which epstopdf 2>/dev/null)
 GS_953_OR_LATER := $(shell gs --version | grep -c -E "9\.5[3-9].?")
+GS_OPT=--gsopt=-dPDFSETTINGS=/ebook
 
 $(PDFTARGETS_OF_EPSORIG): %.pdf: %.eps
 	@echo "$< --> $@"
@@ -15,7 +16,7 @@ endif
 	@cp $< $(basename $<)__.eps
 	@sh $(FIXANEPSFONTS) $(basename $<)__.eps
 	@eps2eps $(basename $<)__.eps $(basename $<)___.eps
-	@epstopdf $(basename $<)___.eps $@
+	@epstopdf $(GS_OPT) $(basename $<)___.eps $@
 	@rm -f $(basename $<)__.eps $(basename $<)___.eps
 
 $(PDFTARGETS_OF_TEX): %.pdf: %.eps
@@ -25,10 +26,10 @@ ifndef EPSTOPDF
 endif
 ifeq ($(GS_953_OR_LATER),1)
 	@eps2eps -dALLOWPSTRANSPARENCY $< $(basename $<)__.eps
-	@epstopdf --gsopt=-dALLOWPSTRANSPARENCY $(basename $<)__.eps $@
+	@epstopdf --gsopt=-dALLOWPSTRANSPARENCY $(GS_OPT) $(basename $<)__.eps $@
 else
 	@eps2eps $< $(basename $<)__.eps
-	@epstopdf --nosafer $(basename $<)__.eps $@
+	@epstopdf --nosafer $(GS_OPT) $(basename $<)__.eps $@
 endif
 	@rm -f $(basename $<)__.eps
 
@@ -38,5 +39,5 @@ ifndef EPSTOPDF
 	$(error $< --> $@: epstopdf not found. Please install it)
 endif
 	@eps2eps $< $(basename $<)__.eps
-	@epstopdf $(basename $<)__.eps $@
+	@epstopdf $(GS_OPT) $(basename $<)__.eps $@
 	@rm -f $(basename $<)__.eps
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/6 epstopdf-rule.mk: Save a 'cp' by running fixfonts script directly

In reply to Akira Yokosawa

In the recipe of PDFTARGETS_OF_EPSORIG, first "cp" can be saved by directly running FIXFONTS script.

---
 Makefile         | 2 ++
 epstopdf-rule.mk | 3 +--
 2 files changed, 3 insertions(+), 2 deletions(-)
Makefile +2 -0
index d3fcffca..29c067c0 100644
@@ -119,9 +119,11 @@ endef
 ifeq ($(URWPS),0)
 FIXSVGFONTS   = utilities/fixsvgfonts.sh
 FIXANEPSFONTS = utilities/fixanepsfonts.sh
+FIXFONTS      = utilities/fixfonts.sh
 else
 FIXSVGFONTS   = utilities/fixsvgfonts-urwps.sh
 FIXANEPSFONTS = utilities/fixanepsfonts-urwps.sh
+FIXFONTS      = utilities/fixfonts-urwps.sh
 endif
 ifeq ($(FREESANS),0)
   RECOMMEND_FREEFONT := 1
epstopdf-rule.mk +1 -2
index 83d335f0..5bf4a435 100644
@@ -13,8 +13,7 @@ $(PDFTARGETS_OF_EPSORIG): %.pdf: %.eps
 ifndef EPSTOPDF
 	$(error $< --> $@: epstopdf not found. Please install it)
 endif
-	@cp $< $(basename $<)__.eps
-	@sh $(FIXANEPSFONTS) $(basename $<)__.eps
+	@sh $(FIXFONTS) < $< > $(basename $<)__.eps
 	@eps2eps $(basename $<)__.eps $(basename $<)___.eps
 	@epstopdf $(GS_OPT) $(basename $<)___.eps $@
 	@rm -f $(basename $<)__.eps $(basename $<)___.eps
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/6 Makefile: Don't run fixfonts on .eps with embedded font

In reply to Akira Yokosawa

Most of our .eps files from gnuplot have the NimbusSanL font embedded. Therefore, they don't need font adjustment by the fixfonts script even on systems without NimbusSanL font installed.

Embedded font data has the keyword of "/FontMatrix".
Use it as a hint for determining whether fixfonts is necessary or not.

.eps files of scanned images under cartoons/ don't need fixfonts, either.

Create lists of .pdf files of those files and use the recipe with fixfonts only for PDF_TARGETS_OF_GNUPLOT_NEEDFIXFONTS.

Move other targets of EPSORIG files (PDFTARGETS_OF_EPSORIG_NOFIXFONTS) to the recipe of PDFTARGETS_OF_EPSOTHER, which consists of figures originating from .fig and .dot files and already taken care of by the FIXANEPSFONTS script.

---
 Makefile         | 7 +++++++
 a2ping-rule.mk   | 4 ++--
 epstopdf-rule.mk | 4 ++--
 3 files changed, 11 insertions(+), 4 deletions(-)
Makefile +7 -0
index 29c067c0..3202ad6f 100644
@@ -79,7 +79,14 @@ PDFTARGETS_OF_EPS := $(EPSSOURCES:%.eps=%.pdf)
 
 EPSORIGIN := $(filter-out $(EPSSOURCES_FROM_TEX) $(EPSSOURCES_FROM_DOT) $(EPSSOURCES_FROM_FIG),$(EPSSOURCES))
 
+GNUPLOT_ORIG := $(shell grep -l gnuplot $(EPSORIGIN))
+GNUPLOT_ORIG_NOFIXFONTS := $(shell grep -l '/FontMatrix' $(GNUPLOT_ORIG))
+GNUPLOT_ORIG_NEEDFIXFONTS := $(filter-out $(GNUPLOT_ORIG_NOFIXFONTS),$(GNUPLOT_ORIG))
+EPSORIG_NOFIXFONTS := $(filter-out $(GNUPLOT_ORIG_NEEDFIXFONTS),$(EPSORIGIN))
+
 PDFTARGETS_OF_EPSORIG := $(EPSORIGIN:%.eps=%.pdf)
+PDFTARGETS_OF_GNUPLOT_NEEDFIXFONTS := $(GNUPLOT_ORIG_NEEDFIXFONTS:%.eps=%.pdf)
+PDFTARGETS_OF_EPSORIG_NOFIXFONTS := $(EPSORIG_NOFIXFONTS:%.eps=%.pdf)
 
 PDFTARGETS_OF_EPSOTHER := $(filter-out $(PDFTARGETS_OF_EPSORIG) $(PDFTARGETS_OF_TEX),$(PDFTARGETS_OF_EPS))
 
a2ping-rule.mk +2 -2
index 296fc575..c0e170f1 100644
@@ -29,7 +29,7 @@ ifdef A2PING
   endif
 endif
 
-$(PDFTARGETS_OF_EPSORIG): %.pdf: %.eps
+$(PDFTARGETS_OF_GNUPLOT_NEEDFIXFONTS): %.pdf: %.eps
 	@echo "$< --> $@"
 ifndef A2PING
 	$(error $< --> $@: a2ping not found. Please install it)
@@ -58,7 +58,7 @@ else
 	@a2ping --below --hires --bboxfrom=compute-gs $< $@ > /dev/null 2>&1
 endif
 
-$(PDFTARGETS_OF_EPSOTHER): %.pdf: %.eps
+$(PDFTARGETS_OF_EPSORIG_NOFIXFONTS) $(PDFTARGETS_OF_EPSOTHER): %.pdf: %.eps
 	@echo "$< --> $@"
 ifndef A2PING
 	$(error $< --> $@: a2ping not found. Please install it)
epstopdf-rule.mk +2 -2
index 5bf4a435..1c3a2041 100644
@@ -8,7 +8,7 @@ EPSTOPDF := $(shell which epstopdf 2>/dev/null)
 GS_953_OR_LATER := $(shell gs --version | grep -c -E "9\.5[3-9].?")
 GS_OPT=--gsopt=-dPDFSETTINGS=/ebook
 
-$(PDFTARGETS_OF_EPSORIG): %.pdf: %.eps
+$(PDFTARGETS_OF_GNUPLOT_NEEDFIXFONTS): %.pdf: %.eps
 	@echo "$< --> $@"
 ifndef EPSTOPDF
 	$(error $< --> $@: epstopdf not found. Please install it)
@@ -32,7 +32,7 @@ else
 endif
 	@rm -f $(basename $<)__.eps
 
-$(PDFTARGETS_OF_EPSOTHER): %.pdf: %.eps
+$(PDFTARGETS_OF_EPSORIG_NOFIXFONTS) $(PDFTARGETS_OF_EPSOTHER): %.pdf: %.eps
 	@echo "$< --> $@"
 ifndef EPSTOPDF
 	$(error $< --> $@: epstopdf not found. Please install it)
Signature · 1 line
2.17.1