From a1cb36a19a975de7420d4b3edb98eac035d1868f Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 18 Jun 2019 22:32:14 +0100 Subject: [PATCH] Protocol spec: fix optimization and links. Signed-off-by: Daira Hopwood --- protocol/Makefile | 46 +++++++++++++++++++++---------------------- protocol/README.rst | 7 +++++-- protocol/protocol.tex | 17 +++++++++++++++- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/protocol/Makefile b/protocol/Makefile index ff1d69a6..ee254d64 100644 --- a/protocol/Makefile +++ b/protocol/Makefile @@ -1,6 +1,16 @@ LATEXMK=latexmk --halt-on-error -bibtex -pdf LATEX=pdflatex --halt-on-error +# extractpdfmark is needed to produce optimized PDFs that preserve "named destinations" +# (needed for external links into the file to work correctly). +# +EXTRACTPDFMARK=extractpdfmark + +# Options are documented at +OPTIMIZER=gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH \ + -r450 -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dFastWebView=true \ + -dSubsetFonts=true -dCompressPages=true + sprout.pdf: protocol.tex zcash.bib incremental_merkle.png key_components.png $(MAKE) sprout @@ -118,39 +128,27 @@ clean: blossom.dvi blossom.pdf blossom.bbl blossom.blg blossom.brf blossom.toc \ blossom.aux blossom.out blossom.log blossom.bcf blossom.run.xml blossom.fls blossom.fdb_latexmk -optimizer-installed.flag2: - rm -rf sam2p tif22pnm pdfsizeopt - # Nail down git commits to make backdooring somewhat harder. - git clone https://github.com/pts/sam2p.git - cd sam2p && git reset --hard cafd4b8910a56e4b0af833f943a2ae85c7bc0a4d && $(MAKE) - git clone https://github.com/pts/tif22pnm.git - cd tif22pnm && git reset --hard 22217c1a3ea355a899e9c7c79903488ca13d1dfe && $(MAKE) - git clone https://github.com/pts/pdfsizeopt.git - cd pdfsizeopt && git reset --hard 5a42db5bef4df1652adb3ef49a9d14bcb58442eb - touch optimizer-installed.flag2 - -.PHONY: clean-optimizer -clean-optimizer: - rm -rf sam2p tif22pnm pdfsizeopt optimizer-installed.flag* - .PHONY: optsprout -optsprout: optimizer-installed.flag2 +optsprout: $(MAKE) auxsprout - PATH="${PATH}:$(CURDIR)/sam2p:$(CURDIR)/tif22pnm" pdfsizeopt/pdfsizeopt --v=40 --use-image-optimizer=sam2p \ - --tmp-dir=aux aux/sprout.pdf sprout.pdf + $(EXTRACTPDFMARK) aux/sprout.pdf >aux/sprout-pdfmark.ps + $(OPTIMIZER) -sOutputFile=sprout.pdf aux/sprout.pdf aux/sprout-pdfmark.ps 2>/dev/null |awk '{printf "."}' + ls -l aux/sprout.pdf sprout.pdf .PHONY: optsapling -optsapling: optimizer-installed.flag2 +optsapling: $(MAKE) auxsapling - PATH="${PATH}:$(CURDIR)/sam2p:$(CURDIR)/tif22pnm" pdfsizeopt/pdfsizeopt --v=40 --use-image-optimizer=sam2p \ - --tmp-dir=aux aux/sapling.pdf sapling.pdf + $(EXTRACTPDFMARK) aux/sapling.pdf >aux/sapling-pdfmark.ps + $(OPTIMIZER) -sOutputFile=sapling.pdf aux/sapling.pdf aux/sapling-pdfmark.ps 2>/dev/null |awk '{printf "."}' + ls -l aux/sapling.pdf sapling.pdf cp -f sapling.pdf protocol.pdf .PHONY: optblossom -optblossom: optimizer-installed.flag2 +optblossom: $(MAKE) auxblossom - PATH="${PATH}:$(CURDIR)/sam2p:$(CURDIR)/tif22pnm" pdfsizeopt/pdfsizeopt --v=40 --use-image-optimizer=sam2p \ - --tmp-dir=aux aux/blossom.pdf blossom.pdf + $(EXTRACTPDFMARK) aux/blossom.pdf >aux/blossom-pdfmark.ps + $(OPTIMIZER) -sOutputFile=blossom.pdf aux/blossom.pdf aux/blossom-pdfmark.ps 2>/dev/null |awk '{printf "."}' + ls -l aux/blossom.pdf blossom.pdf .PHONY: optimized optimized: optsapling optsprout optblossom diff --git a/protocol/README.rst b/protocol/README.rst index 1c1fd04c..c1d3eb58 100644 --- a/protocol/README.rst +++ b/protocol/README.rst @@ -9,6 +9,9 @@ Build dependencies on Debian-based systems include, at least: apt-get install texlive texlive-science texlive-fonts-extra \ texlive-generic-recommended texlive-bibtex-extra biber latexmk +To use the targets described under "Optimizing PDF size", you will also +need the `ghostscript` and `extractpdfmark` packages. + Building -------- @@ -36,8 +39,8 @@ Manual intervention is still needed when there are LaTeX errors. Optimizing PDF size ------------------- -Optionally, you can use `Péter Szabó `_'s -``pdfsizeopt`` program to optimize the size of the resulting PDF files. +Optionally, you can use Ghostscript to optimize the size of the resulting +PDF files. Use: diff --git a/protocol/protocol.tex b/protocol/protocol.tex index 7e1a42b2..bb7e4a80 100644 --- a/protocol/protocol.tex +++ b/protocol/protocol.tex @@ -19,8 +19,20 @@ \usepackage[hang]{footmisc} \usepackage{xstring} \usepackage[usenames,dvipsnames]{xcolor} + +% The pdfa option has the side effect of preserving hyperlinks when the PDF is +% processed by Ghostscript (an alternative way of doing that would be to use +% -dPrinted=false on the Ghostscript command line). The resulting document will +% not actually be PDF/A. +% +% The destlabel option creates "destination names" in the PDF, which allows +% linking to sections in URL fragments when viewing the PDF in a web browser: +% +% In order to preserve destination names through Ghostscript processing, we need +% to use extractpdfmark as described at . +% \usepackage[unicode,bookmarksnumbered,bookmarksopen,allbordercolors=MidnightBlue, - citebordercolor=Plum,urlbordercolor=BrickRed]{hyperref} + citebordercolor=Plum,urlbordercolor=BrickRed,pdfa,destlabel]{hyperref} \usepackage{cleveref} \usepackage{nameref} \usepackage{etoolbox} @@ -9974,6 +9986,9 @@ Peter Newell's illustration of the Jubjub bird, from \cite{Carroll1902}. \begin{itemize} \item Ensure that this document builds correctly and without missing characters on recent versions of \TeX Live. + \item Update the \texttt{Makefile} to use Ghostscript for PDF optimization. + \item Ensure that hyperlinks are preserved, and available as "Destination names" + in URL fragments and links from other PDF documents. \end{itemize} \introlist