For your consideration.

>From 77a401211c68d090748e7641e0073484a41f835c Mon Sep 17 00:00:00 2001
From: Luc St-Louis <l...@pobox.com>
Date: Sat, 12 Jun 2010 22:01:58 -0400
Subject: [PATCH] Can build both for A4 and letter paper sizes.

---
 Makefile          |   40 +++++++++++++++---------
 README            |    5 ++-
 bin/book-to-latex |   85 ++++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 86 insertions(+), 44 deletions(-)

diff --git a/Makefile b/Makefile
index 925c61c..bfcd34a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,28 @@
-CHAPTERS =src/preface.pod \
-          src/basics.pod \
-          src/operators.pod \
-		  src/subs-n-sigs.pod \
-		  src/multi-dispatch.pod \
-		  src/classes-and-objects.pod \
-		  src/regexes.pod \
-		  src/grammars.pod
+CHAPTERS = \
+    src/preface.pod \
+    src/basics.pod \
+    src/operators.pod \
+    src/subs-n-sigs.pod \
+    src/multi-dispatch.pod \
+    src/classes-and-objects.pod \
+    src/regexes.pod \
+    src/grammars.pod \
+
+ifeq "$(SIZE)" ""
+SIZE=a4
+endif
+
+BOOK = book.$(SIZE)
 
 # If you're on a Mac, and installed Inkscape via MacPorts, you might want to
 # manually uncomment the next line, and remove the one after it.
 #INKSCAPE = /Applications/Inkscape.app/Contents/Resources/bin/inkscape
 INKSCAPE = inkscape
 
-default: build/book.pdf
+default: build/$(BOOK).pdf
 
-release: build/book.pdf
-	cp build/book.pdf build/book-$$(date +"%Y-%m").pdf
+release: build/$(BOOK).pdf
+	cp build/$(BOOK).pdf build/book-$$(date +"%Y-%m").$(SIZE).pdf
 
 build/mmd-table.pdf: src/mmd-table.svg
 	$(INKSCAPE) --export-pdf=build/mmd-table.pdf -D src/mmd-table.svg
@@ -23,11 +30,14 @@ build/mmd-table.pdf: src/mmd-table.svg
 build/book.html: $(CHAPTERS) bin/book-to-html
 	perl bin/book-to-html $(CHAPTERS) > build/book.html
 
-build/book.pdf:	build/book.tex build/mmd-table.pdf
-	cd build && pdflatex book.tex && makeindex book && pdflatex book.tex
+build/$(BOOK).pdf: build/$(BOOK).tex build/mmd-table.pdf
+	cd build && pdflatex $(BOOK).tex && makeindex $(BOOK).idx && pdflatex $(BOOK).tex
 
-build/book.tex: $(CHAPTERS) bin/book-to-latex
-	perl bin/book-to-latex $(CHAPTERS) > build/book.tex
+build/$(BOOK).tex: $(CHAPTERS) bin/book-to-latex
+	perl bin/book-to-latex \
+	    -size $(SIZE) \
+	    -build_dir $(realpath build) \
+	    $(CHAPTERS) \
 
 clean: 
 	rm -rf build/*
diff --git a/README b/README
index c75f6fa..14fa0c8 100644
--- a/README
+++ b/README
@@ -14,7 +14,7 @@ You can find us on #perl6book on irc.freenode.net.
 To build the book, you need to have the following software installed:
 
     * GNU make
-    * perl 5
+    * perl 5.10
     * the Perl 5 module Pod::PseudoPod::LaTeX version 1.101050 or newer
     * inkscape (for svg -> pdf conversion)
     * pdflatex
@@ -26,7 +26,8 @@ To build the book, you need to have the following software installed:
       texlive-latex-recommended packages.
 
 Just type 'make' on your command line, and the book should be built in
-build/book.pdf
+build/book.a4.pdf, with an A4 paper size; to get U.S. letter size, type
+'make SIZE=letter'.
 
 All material in this repository is licensed under a CC-by-nc-sa license:
 <http://creativecommons.org/licenses/by-nc-sa/2.5/> (attribution,
diff --git a/bin/book-to-latex b/bin/book-to-latex
index a909a46..6ef7651 100644
--- a/bin/book-to-latex
+++ b/bin/book-to-latex
@@ -1,40 +1,71 @@
-#!perl -w
+#!perl
+
 use strict;
+use warnings;
+use feature ':5.10';
+use Getopt::Long;
 use Pod::PseudoPod::LaTeX 1.101050;
 
-print <<'HEADER';
-\documentclass[11pt,a4paper,oneside]{report}
-\usepackage{graphics,graphicx}
-\usepackage{colortbl}
-\usepackage{fancyvrb}
-\usepackage[T1]{fontenc}
-\usepackage{bera}
-\usepackage[utf8]{inputenc}
-\usepackage{makeidx}
-\usepackage[colorlinks=true,pagebackref]{hyperref}
+# --------------------------------------------------------------------
+# A few globals.
 
-\makeindex
+my $size;
+my $build_dir;
 
-\title{Using Perl~6}
-\author{Jonathan S. Duff, Moritz Lenz, Carl Mäsak, Patrick R. Michaud, Jonathan Worthington}
- 
-\begin{document}
+# --------------------------------------------------------------------
+main();
 
-\maketitle
+sub main {
+    GetOptions(
+            # Should be one of: a4, letter.
+        'size:s' => \$size,
+            # The full path to our LaTeX build directory.
+        'build_dir:s' => \$build_dir,
+    ) or die;
+    build_latex_book();
+}
 
-\tableofcontents
-HEADER
+# --------------------------------------------------------------------
+sub build_latex_book {
+    my $file_spec = "$build_dir/book.$size.tex";
+    open my $latex_book, ">", $file_spec
+      or die "Couldn't write to $file_spec: $!\n";
+    print {$latex_book} << "HEADER";
+\\documentclass[11pt,${size}paper,oneside]{report}
+\\usepackage{graphics,graphicx}
+\\usepackage{colortbl}
+\\usepackage{fancyvrb}
+\\usepackage[T1]{fontenc}
+\\usepackage{bera}
+\\usepackage[utf8]{inputenc}
+\\usepackage{makeidx}
+\\usepackage[colorlinks=true,pagebackref]{hyperref}
 
-for (@ARGV) {
-    my $parser = Pod::PseudoPod::LaTeX->new();
-    $parser->codes_in_verbatim(1);
-    $parser->output_fh( *STDOUT );
-    $parser->parse_file( $_ );
-}
+    % A compromise of dimensions between A4 and letter.
+\\textheight 571pt
+\\topmargin 18pt
+\\oddsidemargin 49pt
+\\marginparwidth 53pt
 
-print <<'FOOTER';
+\\makeindex
 
-\printindex
+\\title{Using Perl~6}
+\\author{Jonathan S. Duff, Moritz Lenz, Carl Mäsak, Patrick R. Michaud, Jonathan Worthington}
+\\begin{document}
+\\maketitle
+\\tableofcontents
+HEADER
+
+    for (@ARGV) {
+        my $parser = Pod::PseudoPod::LaTeX->new();
+        $parser->output_fh($latex_book);
+        $parser->codes_in_verbatim(1);
+        $parser->parse_file( $_ );
+    }
 
+    print {$latex_book} << 'FOOTER';
+\printindex
 \end{document}
 FOOTER
+}
+
-- 
1.6.5

Reply via email to