Skip to content

Commit

Permalink
A basic layout, with a test book.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucs committed Jul 8, 2010
1 parent 00b8fc7 commit c53c252
Show file tree
Hide file tree
Showing 9 changed files with 4,104 additions and 66 deletions.
62 changes: 40 additions & 22 deletions Makefile
@@ -1,33 +1,51 @@
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

# 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.
ifeq "$(PAPER)" ""
PAPER = a4
endif

ifneq "$(TEST)" ""
BOOK = build/test.$(PAPER)
CHAPTERS = $(wildcard test/*.pod)
else
BOOK = build/UsingPerl6.$(PAPER)
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 \

endif

# 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: print

release: build/book.pdf
cp build/book.pdf build/book-$$(date +"%Y-%m").pdf
html: $(CHAPTERS) bin/book-to-html
perl bin/book-to-html $(CHAPTERS) > $(BOOK).html

build/mmd-table.pdf: src/mmd-table.svg
$(INKSCAPE) --export-pdf=build/mmd-table.pdf -D src/mmd-table.svg
print: $(BOOK).pdf

release: print
cp $(BOOK).pdf build/book-$$(date +"%Y-%m").$(PAPER).pdf

build/book.html: $(CHAPTERS) bin/book-to-html
perl bin/book-to-html $(CHAPTERS) > build/book.html
build/Makefile: lib/Makefile
cp $< $@

build/book.pdf: build/book.tex build/mmd-table.pdf
cd build && pdflatex book.tex && makeindex book && pdflatex book.tex
$(BOOK).pdf: $(BOOK).tex build/Makefile build/mmd-table.pdf
cd build && make $*

build/book.tex: $(CHAPTERS) bin/book-to-latex
perl bin/book-to-latex $(CHAPTERS) > build/book.tex
$(BOOK).tex: $(CHAPTERS) lib/Perl6BookLatex.pm lib/book.sty bin/book-to-latex
perl -Ilib bin/book-to-latex --paper $(PAPER) $(CHAPTERS) > $(BOOK).tex

build/mmd-table.pdf: src/mmd-table.svg
$(INKSCAPE) --export-pdf=build/mmd-table.pdf -D src/mmd-table.svg

clean:
rm -rf build/*
Expand Down
16 changes: 8 additions & 8 deletions README
Expand Up @@ -14,19 +14,19 @@ 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
* the 'bera' font as a LaTeX package
* the 'fancyvrb' package for LaTex
* A number of LaTeX packages (see lib/*.sty). Ubuntu 10.04 supplies
most of what is needed with its texlive-latex-base,
texlive-fonts-extra, and texlive-latex-recommended packages.

In Ubuntu 10.04 the last three bullet items are available from
the texlive-latex-base, texlive-fonts-extra, and
texlive-latex-recommended packages.
The book is produced from src/*.pod chapters ultimately rendered into
build/*.pdf using bin/* and lib/* files.

Just type 'make' on your command line, and the book should be built in
build/book.pdf
build/UsingPerl6.a4.pdf, with an A4 paper size; to get U.S. letter size,
type 'make PAPER=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,
Expand Down
93 changes: 57 additions & 36 deletions bin/book-to-latex
@@ -1,40 +1,61 @@
#!perl -w
# --------------------------------------------------------------------
use strict;
use Pod::PseudoPod::LaTeX 1.101050;
use warnings;
use feature ':5.10';
use Getopt::Long;
use Perl6BookLatex;
use Template;

# --------------------------------------------------------------------
main();
sub main {
my $paper;
GetOptions(
# Should be one of: a4, letter.
'paper:s' => \$paper,
) or die;
# We set these two dimensions the same for both A4 and letter
# paper sizes, so that the page breaks occur at the same place
# in both versions.
my $textheight = 611;
my $textwidth = 360;
# This value is based on knowing the paper widths (A4: 595,
# paper: 612) and the LaTeX \oddsidemargin for those paper
# sizes.
my $hoffset;
if ($paper eq 'a4') {
$hoffset = ((595 - $textwidth) / 2) - 72 - 2;
}
elsif ($paper eq 'letter') {
$hoffset = ((612 - $textwidth) / 2) - 72 - 4;
}
else {
die "Invalid 'paper' option: '$paper'. Should be 'a4' or 'letter'.";
}
my $page_dim = << "EOT";
\\textheight ${textheight}pt
\\textwidth ${textwidth}pt
\\hoffset ${hoffset}pt
EOT

my $output;
for (@ARGV) {
my $parser = Perl6BookLatex->new();
$parser->emit_environments( sidebar => "sidebar" );
$parser->codes_in_verbatim(1);
$parser->output_string( \$output );
$parser->parse_file($_);
}

my $tt = Template->new( {
INCLUDE_PATH => 'lib',
} );

print $tt->process( 'book.sty', {
content => $output,
paper => $paper,
page_dim => $page_dim,
} );

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}
\makeindex
\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->codes_in_verbatim(1);
$parser->output_fh( *STDOUT );
$parser->parse_file( $_ );
}

print <<'FOOTER';
\printindex
\end{document}
FOOTER

0 comments on commit c53c252

Please sign in to comment.