Browse files

A basic layout, with a test book.

  • Loading branch information...
1 parent 00b8fc7 commit c53c252aedf7314aa98056065b65a2fe244acda1 @lucs lucs committed Jul 8, 2010
Showing with 4,104 additions and 66 deletions.
  1. +40 −22 Makefile
  2. +8 −8 README
  3. +57 −36 bin/book-to-latex
  4. +3,496 −0 lib/Makefile
  5. +152 −0 lib/Perl6BookLatex.pm
  6. +86 −0 lib/book.sty
  7. +88 −0 test/00.para.pod
  8. +73 −0 test/30.formatting_codes.pod
  9. +104 −0 test/70.code.pod
View
62 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/*
View
16 README
@@ -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,
View
93 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
View
3,496 lib/Makefile
3,496 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
152 lib/Perl6BookLatex.pm
@@ -0,0 +1,152 @@
+# --------------------------------------------------------------------
+use strict;
+use warnings;
+use feature ':5.10';
+
+package Perl6BookLatex;
+use Pod::PseudoPod::LaTeX 1.101650;
+use base 'Pod::PseudoPod::LaTeX';
+
+# --------------------------------------------------------------------
+
+BEGIN {
+ for my $level ( 1 .. 5 ) {
+ my $prefix = '\\' . ( 'sub' x ( $level - 1 ) ) . 'section{';
+ my $start_sub = sub {
+ my $self = shift;
+ $self->{scratch} .= $prefix;
+ };
+
+ my $end_sub = sub {
+ my $self = shift;
+ $self->{scratch} .= "}\n\n";
+ $self->emit();
+ };
+
+ no strict 'refs';
+ *{ 'start_head' . $level } = $start_sub;
+ *{ 'end_head' . $level } = $end_sub;
+ }
+}
+
+# --------------------------------------------------------------------
+sub start_B {
+ my $self = shift;
+ my $target = eval { $self->{curr_open}[-1][-1]{target} } || '';
+ return if $target eq 'programlisting';
+ $self->{scratch} .= '\\textbf{';
+}
+
+sub end_B {
+ my $self = shift;
+ my $target = eval { $self->{curr_open}[-1][-1]{target} } || '';
+ return if $target eq 'programlisting';
+ $self->{scratch} .= '}';
+}
+
+# --------------------------------------------------------------------
+sub start_U {
+ my $self = shift;
+ $self->{scratch} .= '\\url{';
+}
+
+sub end_U {
+ my $self = shift;
+ $self->{scratch} .= '}';
+}
+
+# --------------------------------------------------------------------
+sub encode_verbatim_text {
+ my ($self, $text) = @_;
+ # Needs fixing.
+ return $text;
+}
+
+ # Overload because of custom formatting for programlisting sections.
+sub start_Verbatim {
+ my $self = shift;
+ my $flags = shift;
+
+ my $target = eval { $self->{curr_open}[-1][-1]{target} } || '';
+
+ if ( $target eq 'screen' ) {
+ my $verb_options = 'label=' . $self->{labels}{screen};
+ $self->{scratch} .= "\\begin{Verbatim}[$verb_options]\n";
+ }
+ # elsif ( $target eq 'programlisting' ) {
+ # $self->{scratch} .= "\\begin{perlcode}\n";
+ # }
+ else {
+ $self->{scratch} .= "\\begin{Verbatim}\n";
+ }
+
+ $self->{flags}{in_verbatim}++;
+}
+
+sub end_Verbatim {
+ my $self = shift;
+
+ my $target = eval { $self->{curr_open}[-1][-1]{target} } || '';
+
+ # if ( $target eq 'programlisting' ) {
+ # $self->{scratch} .= "\n\\end{perlcode}\n";
+ # }
+ # else {
+ $self->{scratch} .= "\n\\end{Verbatim}\n";
+ # }
+
+ $self->{flags}{in_verbatim}--;
+ $self->emit();
+}
+
+# --------------------------------------------------------------------
+# This sub is overloaded because one line has been removed. We do want
+# ligatures to look good, gotta find out why it got removed in the
+# first place.
+
+sub encode_text {
+ my ( $self, $text ) = @_;
+
+ return $self->encode_verbatim_text($text)
+ if $self->{flags}{in_verbatim};
+ return $text
+ if $self->{flags}{in_xref} || $self->{flags}{in_figure};
+
+ # Escape LaTeX-specific characters.
+
+ # Backslashes are special.
+ $text =~ s/\\/\\backslash/g;
+ $text =~ s/([#\$&%_{}])/\\$1/g;
+ # Carets are special.
+ $text =~ s/(\^)/\\char94{}/g;
+ $text =~ s/</\\textless{}/g;
+ $text =~ s/>/\\textgreater{}/g;
+
+ # Add unescaped dollars.
+ $text =~ s/(\\backslash)/\$$1\$/g;
+
+ # FIXME Quotes are gone now too -- csquotes is the right package for that
+
+ # Fix the ellipses
+ $text =~ s/\.{3}\s*/\\ldots /g;
+
+ # Better be fixed in text directly!
+ # $text =~ s/\s--\s/---/g;
+
+ # Probably not needed, since tildes should look nice when
+ # we've got the right font
+ # $text =~ s/~/\$\\sim\$/g;
+
+ # Suggest hyphenation points for module names.
+ $text =~ s/::/::\\-/g;
+
+ # Non-breakable spaces.
+ $text =~ s/Perl 6/Perl~6/g;
+ $text =~ s/Perl 5/Perl~5/g;
+
+ return $text;
+}
+
+# --------------------------------------------------------------------
+1;
+
View
86 lib/book.sty
@@ -0,0 +1,86 @@
+\documentclass[
+ [% paper %]paper,
+ DIV=12,
+ parskip=full,
+ headsepline=on,
+ footsepline=off,
+ chapterprefix=on,
+ oneside,
+]{scrbook}
+
+ % For the sidebars.
+\usepackage{fancybox}
+
+ % For index generation. Supplies \printindex.
+\usepackage{index}
+
+ % Fonts.
+\usepackage{fontspec}
+\setromanfont[Mapping=tex-text]{DejaVu Serif}
+\setsansfont[Mapping=tex-text]{DejaVu Sans}
+\setmonofont{Inconsolata}
+
+ % Supplies 'tabular' environment and \rowcolor.
+\usepackage{colortbl}
+
+ % Optimize for this language.
+\usepackage[english]{babel}
+
+ % For code blocks.
+\usepackage{fancyvrb}
+\RecustomVerbatimEnvironment
+{Verbatim}{Verbatim}
+{xleftmargin=0.35in,fontsize=\small,gobble=4,labelposition=topline}
+
+ % Allows among other things the \documentclass '...paper' option
+ % to be passed on to the DVI processor.
+\usepackage{hyperref}
+\hypersetup{
+ pdftitle={Using Perl~6},
+ colorlinks,
+ linkcolor=black,
+ urlcolor=black,
+}
+
+ % Needed for \includegraphics from '=for figure' in some src/*.pod.
+\usepackage{graphics,graphicx}
+
+ % Shadow box, for sidebars.
+\newsavebox{\sidebarcontent}
+\newenvironment{sidebar}[1][]{\begin{lrbox}{\sidebarcontent}\begin{minipage}{3.5in}\sloppy
+\ifx\relax#1\else\centerline{\large\bfseries #1}\par\fi}
+{\end{minipage}\end{lrbox}
+\begin{center}
+\shadowbox{\usebox{\sidebarcontent}}
+\end{center}}
+
+\makeindex
+
+[% page_dim %]
+
+\newcommand*\mytitle{Using Perl~6}
+\title{\mytitle}
+
+\author{
+ Jonathan S. Duff \\
+ Moritz Lenz \\
+ Carl Mäsak \\
+ Patrick R. Michaud \\
+ Jonathan Worthington \\
+}
+
+ % Clear title page date.
+\date{}
+
+\begin{document}
+
+\maketitle
+
+\tableofcontents
+
+[% content %]
+
+\printindex
+
+\end{document}
+
View
88 test/00.para.pod
@@ -0,0 +1,88 @@
+=head0 This test book
+
+This test book can be built with the same options as the real book, to
+see how the fonts, features, and spacing come out. It takes less time
+to build too, so it's easier to try out things.
+
+It tries to use most of the POD and PseudoPod directives, as listed in
+C<perldoc perlpod> and C<perldoc Pod::PseudoPod::Tutorial>, although
+perhaps many of them are not actually used in the actual book. This
+chapter shows how ordinary paragraphs appear. Here is a "verbatim
+paragraph":
+
+ Indented four spaces
+ Indented one tab. Next line blank.
+
+ Indented one space. A backslash: \
+ Indented two spaces. A backslash: \
+
+Now, let's look at C<=head1>, C<=head2>, C<=head3>.
+C<Pod::PseudoPod::Latex> also gives us a C<=head0> for our chapter
+titles, but C<=head4> appears to be unsupported.
+
+=head1 This is a =head1
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=head2 This is a =head2
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=head3 This is a =head3
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=head1 (back to =head1)
+
+What will now follow is:
+
+ =over 4
+ =item First item
+ =item Second item
+ ...
+ =back
+
+=over 4
+
+=item First item (no content)
+
+=item Second item (no content)
+
+=item Third item
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=item Fourth item
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=back
+
+Finally, we close this chapter with a C<=pod/=cut>. Note that anything
+that follows the C<=cut> will not be processed (unless it is preceded
+by another paragraph directive, which it isn't).
+
+=pod
+
+This is a C<=pod/=cut> paragraph.
+
+=cut
+
+This will not appear.
+
+=for vim: tw=70
View
73 test/30.formatting_codes.pod
@@ -0,0 +1,73 @@
+=head0 Formatting codes
+
+Italic, bold, and code:
+
+C<IZ<>E<lt>The quick brown ... lazy dog.E<gt>>: I<The quick brown ... lazy dog.>
+
+C<BZ<>E<lt>The quick brown ... lazy dog.E<gt>>: B<The quick brown ... lazy dog.>
+
+C<CZ<>E<lt>The quick brown ... lazy dog.E<gt>>: C<The quick brown ... lazy dog.>
+
+Links:
+
+C<LZ<>E<lt>nameE<gt> >: L<name>
+
+C<LZ<>E<lt>Net::PingE<gt> >: L<Net::Ping>
+
+C<LZ<>E<lt>crontab(5)E<gt> >: L<crontab(5)>
+
+C<LZ<>E<lt>name/secE<gt> >: L<name/sec>
+
+C<LZ<>E<lt>perlsyn/"For Loops"E<gt> >: L<perlsyn/"For Loops">
+
+C<LZ<>E<lt>/"Object Methods"E<gt> >: L</"Object Methods">
+
+C<LZ<>E<lt>text|nameE<gt> >: L<text|name>
+
+C<LZ<>E<lt>Error Messages|perldiagE<gt>>: L<Error Messages|perldiag>
+
+C<LZ<>E<lt>text|name/secE<gt> >: L<text|name/sec>
+
+C<LZ<>E<lt>http://www.perl.org/E<gt> >: L<http://www.perl.org/>
+
+Miscellaneous:
+
+C<EZ<>E<lt>ltE<gt>>: E<lt>
+
+C<EZ<>E<lt>gtE<gt>>: E<gt>
+
+C<EZ<>E<lt>verbarE<gt>>: E<verbar>
+
+C<EZ<>E<lt>solE<gt>>: E<sol>
+
+C<EZ<>E<lt>eacuteE<gt>>: E<eacute>
+
+C<EZ<>E<lt>075E<gt>> (equals sign): E<075>
+
+C<EZ<>E<lt>181E<gt>> (micro sign): E<181>
+
+BROKEN: C<EZ<>E<lt>0x2260E<gt>> method of Unicode entry appears to break files.
+
+C<EZ<>E<lt>filenameE<gt>>: F<filename>
+
+BROKEN: C<SZ<>E<lt>$blabla ? $blublublu : $bleE<gt>>: S<$blabla ? $blublublu : $ble>
+
+There is an index entry for the topic "index entries" right here.
+X<index entries>
+
+C<$a E<lt>=E<gt> $b>
+
+C<< $a <=> $b >>
+
+C<<< $a <=> $b >>>
+
+And here are different ways of producing in code style "open(X,
+">>thing.dat") || die $! $foo->bar();" (some things appear not to be
+working correctly):
+
+C<<< open(X, ">>thing.dat") || die $! >>> C<< $foo->bar(); >>
+
+C<open(X, "E<gt>E<gt>thing.dat") || die $!> C<$foo-E<gt>bar();>
+
+=for vim: tw=70
+
View
104 test/70.code.pod
@@ -0,0 +1,104 @@
+=head0 Code blocks
+
+See how UTF-8 is handled: »ö« é À (camelia, eacute, Agrave).
+
+Following is "=begin/=end programlisting" wrapped:
+
+=begin programlisting
+
+ my $s = 'the quick brown fox jumped over the the lazy dog';
+ my $camelia = "»ö«";
+
+=end programlisting
+
+=head1 "=begin/=end screen"
+
+=begin screen
+
+ Screen line 1.
+ Screen line 2.
+
+ Screen line 4.
+
+=end screen
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo
+
+=begin screen
+
+ Screen line 1.
+ Screen line 2.
+
+ Screen line 4.
+
+=end screen
+
+=begin screen
+
+ Screen line 1.
+ Screen line 2.
+
+ Screen line 4.
+
+=end screen
+
+=head1 Indented lines
+
+The following is simply two indented lines in the source:
+
+ This is line 1.
+ And this, line 2.
+
+=head1 "=begin/=end sidebar"
+
+=begin sidebar
+
+Sidebar text.
+
+=end sidebar
+
+=head1 Head 1
+
+Foo
+
+=head2 Head 2
+
+=head1 "=begin/=end table"
+
+=begin table This is the table title
+
+=headrow
+
+=row
+
+=cell First cell head row.
+
+=cell Second cell head row.
+
+=bodyrows
+
+=row
+
+=cell Cell 1, row 1.
+
+=cell Cell 2, row 1.
+
+=row
+
+=cell Cell 1, row 2.
+
+=cell Cell 2, row 2.
+
+=end table
+
+=head1 "=for figure"
+
+=for figure
+ \includegraphics[width=0.8\textwidth]{mmd-table.pdf}
+ \caption{Who wins the \emph{Rock, Paper, Scissors} game?}
+ \label{fig:mmd-rock-paper-scissors}
+
+=for vim: tw=70

0 comments on commit c53c252

Please sign in to comment.