<newsletter:port_old_newsletter_to_new_system> Try an alternative way to generate PDF

Colomban Wendling git-noreply at xxxxx
Fri Jun 10 23:36:09 UTC 2011


Updating branch refs/heads/port_old_newsletter_to_new_system
         to bf1361a04b754afd2f2d9e4f7b9a33a1bf6cbde8 (commit)
       from 58ecead3e96130b1086ca842dd4baf42a91938f9 (commit)

commit bf1361a04b754afd2f2d9e4f7b9a33a1bf6cbde8
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Tue May 24 15:48:34 2011 +0200

    Try an alternative way to generate PDF
    
    This is a bit ugly since it post-processes rst2latex output with sed,
    but the input template isn't totally flexible enough.

 Makefile      |   21 ++++++++++++++++++---
 rst2latex.sed |   11 +++++++++++
 template.tex  |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index f272f52..23115b1 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,11 @@ OUTPUTS		=	$(OUTPUT_HTML) \
 				$(OUTPUT_ODT) \
 				$(OUTPUT_TEX)
 
+PDFLATEX_FLAGS	= -interaction batchmode
+RST2LATEX_FLAGS	= --template=template.tex \
+				  --latex-preamble='% avoids weird fonts' \
+				  --no-section-numbering
+
 .PHONY: all clean html pdf odt tex
 
 .SUFFIXES: .rst .html .pdf .tex .odt
@@ -34,14 +39,24 @@ clean:
 .rst.html:
 	rst2html --stylesheet=style.css --toc-top-backlinks $< > $@
 
-.rst.pdf:
-	rst2pdf $< -o $@
+.tex.pdf:
+	maxpasses=5; \
+	file=`basename $< .tex`; \
+	cd `dirname $<` && \
+	pdflatex $(PDFLATEX_FLAGS) "$$file.tex" > /dev/null && \
+	while test $$maxpasses -gt 0 && grep -q -i 'rerun' $$file.log; do \
+		pdflatex $(PDFLATEX_FLAGS) "$$file.tex" >/dev/null || exit 1; \
+		maxpasses=`expr $$maxpasses - 1`; \
+	done; \
+	rm "$$file.log" "$$file.toc" "$$file.out" "$$file.aux"
 
 .rst.tex:
-	rst2latex $< > $@
+	(rst2latex $(RST2LATEX_FLAGS) $< | \
+	 sed -f rst2latex.sed) > $@
 
 .rst.odt:
 	rst2odt $< > $@
 
 # extra dependencies we cannot add to suffix rules
 $(OUTPUT_HTML): style.css
+$(OUTPUT_TEX): template.tex rst2latex.sed
diff --git a/rst2latex.sed b/rst2latex.sed
new file mode 100644
index 0000000..f89d428
--- /dev/null
+++ b/rst2latex.sed
@@ -0,0 +1,11 @@
+# sed script to modify rst2latex output
+# this is used to fix a few flaws rst2latex has
+
+# remove \setcounter...{0} to get proper section numbering
+/^\\setcounter.*$/d
+
+# put the TOC on its own page
+/^\\tableofcontents/{
+	n
+	i \\\newpage
+}
diff --git a/template.tex b/template.tex
new file mode 100644
index 0000000..e7cc36c
--- /dev/null
+++ b/template.tex
@@ -0,0 +1,38 @@
+% generated by Docutils <http://docutils.sourceforge.net/>
+\documentclass[%
+paper=a4,%
+fontsize=12pt,%
+twoside=false,%
+DIV18,
+headsepline,
+plainheadsepline,
+footsepline,
+plainfootsepline,
+parskip=half,%
+openany,%
+english]{scrartcl}
+% $head_prefix
+\usepackage{fixltx2e} % LaTeX patches, \textsubscript
+\usepackage{cmap} % fix search and cut-and-paste in PDF
+\usepackage[pdfborder={0 0 0}]{hyperref}
+$requirements
+%%% Custom LaTeX preamble
+$latex_preamble
+\hypersetup{%
+	colorlinks,
+	linkcolor=black,
+	urlcolor=blue,
+}
+%%% User specified packages and stylesheets
+$stylesheet
+%%% Fallback definitions for Docutils-specific commands
+$fallbacks
+$pdfsetup
+%%% Body
+\begin{document}
+$body_pre_docinfo
+$docinfo
+$dedication
+$abstract
+$body
+\end{document}



More information about the Newsletter-Commits mailing list