Skip to content

Commit

Permalink
Initial layout of the book, going with TeX.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedshaw committed Jul 2, 2011
1 parent 1c74b7e commit 225f320
Show file tree
Hide file tree
Showing 14 changed files with 1,936 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dexy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"*.tex|jinja" : { "allinputs" : true },
"*.py|pyg|l": {},
"*.c|pyg|l": {},
"*.sh|pyg|l": {},
"*.conf|dexy": {}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*.sw*
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
JUNK_FILES=$(FINAL).* *.aux *.log styles/*.aux
SOURCE=book
WEBSITE=$(USER)@mongrel2.org:/var/www/mongrel2.org/static/
FINAL=book-final

book:
dexy
cp Makefile output/
cp pastie.sty output/
${MAKE} -C output clean book-final.pdf
rm -rf output/*.dvi output/*.pdf
${MAKE} -C output $(FINAL).pdf

draft: $(FINAL).dvi

$(FINAL).dvi:
cp $(SOURCE).tex $(FINAL).tex
latex -halt-on-error $(FINAL).tex

html:
htlatex $(FINAL).tex
tidy -quiet -ashtml -omit -ic -m $(FINAL).html || true

$(FINAL).pdf: $(FINAL).dvi
dvipdf $(FINAL).dvi

view: $(FINAL).pdf
evince $(FINAL).pdf

clean:
rm -rf $(JUNK_FILES)
find . -name "*.aux" -exec rm {} \;
rm -rf output

release: clean $(FINAL).pdf draft $(FINAL).pdf sync

sync:
rsync -vz $(FINAL).pdf $(WEBSITE)/book/LearnCTheHardWay-preview.pdf
rsync -vz $(FINAL).html $(WEBSITE)/book/LearnCTheHardWay.html
rsync -vz $(FINAL).css $(FINAL)[0-9]*.html $(WEBSITE)/book/

4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Nothing here yet.
This will be a book teaching C programming to anyone who has already learned
one other programming language. It will teach modern C with heavey emphasis
on reliable programming.
28 changes: 28 additions & 0 deletions book.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\include{preamble}
\include{commands}

\title{
Learn C The Hard Way\\
\textit{A Clear \& Direct Guide To Modern C Programming}
}
\author{Zed A. Shaw}
\date{July 2011}

\begin{document}

\frontmatter

\maketitle

\tableofcontents

\include{preface}

\mainmatter

\include{introduction}

\appendix

\end{document}

5 changes: 5 additions & 0 deletions clean.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
s/\[/\[/g
s/\]/\]/g
s/‘/`/g
s/’/'/g
1,18d
5 changes: 5 additions & 0 deletions code/ex1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void main()
{
puts("Hello world.");
}

68 changes: 68 additions & 0 deletions commands.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
% Alter some LaTeX defaults for better treatment of figures:
% See p.105 of "TeX Unbound" for suggested values.
% See pp. 199-200 of Lamport's "LaTeX" book for details.
% General parameters, for ALL pages:
\renewcommand{\topfraction}{0.9} % max fraction of floats at top
\renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
% Parameters for TEXT pages (not float pages):
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{2} % 2 may work better
\renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
\renewcommand{\textfraction}{0.07} % allow minimal text w. figs
% Parameters for FLOAT pages (not text pages):
\renewcommand{\floatpagefraction}{0.7} % require fuller float pages
% N.B.: floatpagefraction MUST be less than topfraction !!
\renewcommand{\dblfloatpagefraction}{0.7} % require fuller float pages

% remember to use [htp] or [htpb] for placement


\newcommand{\versal}[1]{\noindent{\Huge #1\kern-.10em}}
\newcommand{\file}[1]{{\bf\ttfamily #1}}
\newcommand{\ident}[1]{{\it\ttfamily #1}}
\newcommand{\shell}[1]{{\it\ttfamily #1}}
\newcommand{\python}[1]{{\it\ttfamily #1}}
\newcommand{\ruby}[1]{{\it\ttfamily #1}}
\newcommand{\book}[2]{{\it\ttfamily #1} by {\it #2}}
\newcommand{\program}[1]{\it\ttfamily #1}

\newenvironment{aside}[1]
{
\begin{note}
\caption{\hfill\it #1}
\begin{quote}
\parindent 7.2pt
\parskip 5pt
}
{ \end{quote} \end{note} }

\newenvironment{code}[1]
{
\begin{source}
\caption{\hfill\it #1}
\sffamily\small
}
{\end{source}}

\floatstyle{ruled}
\newfloat{note}{thp}{lon}
\floatname{note}{Note}
\newfloat{source}{thp}{los}
\floatname{source}{Source}
\newcommand{\listofnotes}{\listof{note}{List Of Notes}}
\newcommand{\listofsource}{\listof{source}{List Of Source}}

\newcommand{\rfc}[2]
{
\begin{center}
\ovalbox{
\begin{minipage}{.8\textwidth}
\begin{center}
{\bf #1:} {\it #2}
\end{center}
\end{minipage}
}
\end{center}
}

22 changes: 22 additions & 0 deletions introduction.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
\chapter{Introduction}

The introduction to "Learn C The Hard Way".

Here is a simple first program you can make in C:

\begin{code}{Simple C Program}
<< d['code/ex1.c|pyg|l'] >>
\end{code}

You can put this into a \file{ex1.c} then type:

\begin{code}{Building ex1}
\begin{Verbatim}
make ex1
./ex1
\end{Verbatim}
\end{code}

Try it and let me know if it worked.


87 changes: 87 additions & 0 deletions pastie.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

\makeatletter
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
\let\PY@ul=\relax \let\PY@tc=\relax%
\let\PY@bc=\relax \let\PY@ff=\relax}
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
\def\PY@toks#1+{\ifx\relax#1\empty\else%
\PY@tok{#1}\expandafter\PY@toks\fi}
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}

\def\PY@tok@gd{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.87,0.87}{##1}}}
\def\PY@tok@gu{\def\PY@tc##1{\textcolor[rgb]{0.38,0.38,0.38}{##1}}}
\def\PY@tok@gt{\def\PY@tc##1{\textcolor[rgb]{0.67,0.00,0.00}{##1}}}
\def\PY@tok@gs{\let\PY@bf=\textbf}
\def\PY@tok@gr{\def\PY@tc##1{\textcolor[rgb]{0.67,0.00,0.00}{##1}}}
\def\PY@tok@cm{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\def\PY@tok@vg{\def\PY@tc##1{\textcolor[rgb]{0.87,0.47,0.00}{##1}}}
\def\PY@tok@m{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@mh{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@cs{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.80,0.00,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@ge{\let\PY@it=\textit}
\def\PY@tok@vc{\def\PY@tc##1{\textcolor[rgb]{0.20,0.40,0.60}{##1}}}
\def\PY@tok@il{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@go{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\def\PY@tok@cp{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.80,0.00,0.00}{##1}}}
\def\PY@tok@gi{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{0.87,1.00,0.87}{##1}}}
\def\PY@tok@gh{\def\PY@tc##1{\textcolor[rgb]{0.19,0.19,0.19}{##1}}}
\def\PY@tok@s2{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@nl{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.20,0.40,0.60}{##1}}}
\def\PY@tok@nn{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.00,0.40}{##1}}}
\def\PY@tok@no{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.20,0.40}{##1}}}
\def\PY@tok@na{\def\PY@tc##1{\textcolor[rgb]{0.20,0.40,0.60}{##1}}}
\def\PY@tok@nb{\def\PY@tc##1{\textcolor[rgb]{0.00,0.20,0.53}{##1}}}
\def\PY@tok@nc{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.00,0.40}{##1}}}
\def\PY@tok@nd{\def\PY@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
\def\PY@tok@ne{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.00,0.40}{##1}}}
\def\PY@tok@nf{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.40,0.73}{##1}}}
\def\PY@tok@si{\def\PY@tc##1{\textcolor[rgb]{0.20,0.20,0.73}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@sh{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@vi{\def\PY@tc##1{\textcolor[rgb]{0.20,0.20,0.73}{##1}}}
\def\PY@tok@py{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.20,0.40,0.60}{##1}}}
\def\PY@tok@nt{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.00,0.40}{##1}}}
\def\PY@tok@nv{\def\PY@tc##1{\textcolor[rgb]{0.20,0.40,0.60}{##1}}}
\def\PY@tok@s1{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@gp{\def\PY@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
\def\PY@tok@ow{\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@sx{\def\PY@tc##1{\textcolor[rgb]{0.13,0.73,0.13}{##1}}\def\PY@bc##1{\colorbox[rgb]{0.94,1.00,0.94}{##1}}}
\def\PY@tok@bp{\def\PY@tc##1{\textcolor[rgb]{0.00,0.20,0.53}{##1}}}
\def\PY@tok@c1{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\def\PY@tok@kc{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@c{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\def\PY@tok@mf{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@err{\def\PY@tc##1{\textcolor[rgb]{0.65,0.09,0.09}{##1}}\def\PY@bc##1{\colorbox[rgb]{0.89,0.82,0.82}{##1}}}
\def\PY@tok@kd{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@ss{\def\PY@tc##1{\textcolor[rgb]{0.67,0.40,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@sr{\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,1.00}{##1}}}
\def\PY@tok@mo{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@mi{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.87}{##1}}}
\def\PY@tok@kn{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@kr{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@s{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@kp{\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@w{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\def\PY@tok@kt{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\def\PY@tok@sc{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@sb{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@k{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.53,0.00}{##1}}}
\def\PY@tok@se{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}
\def\PY@tok@sd{\def\PY@tc##1{\textcolor[rgb]{0.87,0.13,0.00}{##1}}\def\PY@bc##1{\colorbox[rgb]{1.00,0.94,0.94}{##1}}}

\def\PYZbs{\char`\\}
\def\PYZus{\char`\_}
\def\PYZob{\char`\{}
\def\PYZcb{\char`\}}
\def\PYZca{\char`\^}
\def\PYZsh{\char`\#}
\def\PYZpc{\char`\%}
\def\PYZdl{\char`\$}
\def\PYZti{\char`\~}
% for compatibility with earlier versions
\def\PYZat{@}
\def\PYZlb{[}
\def\PYZrb{]}
\makeatother

51 changes: 51 additions & 0 deletions preamble.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
\documentclass{book}
\usepackage{iwona,palatino}
\usepackage{pastie}
%\usepackage{palatino}
\usepackage[
pdftitle={Learn C The Hard Way: A Clear and Direct Introduction To Programming In C},
pdfauthor={Zed A. Shaw},
pdfsubject={An introduction to C programming for people who know one other language.},
pdfkeywords={C, Programming},
bookmarks, bookmarksopen,
pdfstartview=FitH,
colorlinks,linkcolor=blue,citecolor=blue,
urlcolor=red,
]{hyperref}
\usepackage{float}
\usepackage{fancybox}
\usepackage{savetrees}
\usepackage{fancyvrb}
\usepackage{color}
\usepackage{parskip}
\usepackage{textcomp}
\usepackage{listings}
\parskip 7.2pt

\lstset{basicstyle=\ttfamily,
upquote=true,
breaklines=true,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookrightarrow}},
breakatwhitespace=true
}

% taken from http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html
% Alter some LaTeX defaults for better treatment of figures:
% See p.105 of "TeX Unbound" for suggested values.
% See pp. 199-200 of Lamport's "LaTeX" book for details.
% General parameters, for ALL pages:
\renewcommand{\topfraction}{0.9} % max fraction of floats at top
\renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
% Parameters for TEXT pages (not float pages):
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4} % 2 may work better
\setcounter{dbltopnumber}{2} % for 2-column pages
\renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
\renewcommand{\textfraction}{0.07} % allow minimal text w. figs
% Parameters for FLOAT pages (not text pages):
\renewcommand{\floatpagefraction}{0.7} % require fuller float pages
% N.B.: floatpagefraction MUST be less than topfraction !!
\renewcommand{\dblfloatpagefraction}{0.7} % require fuller float pages

% remember to use [htp] or [htpb] for placement
3 changes: 3 additions & 0 deletions preface.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Preface}

Preface to Learn C The Hard Way.
Loading

0 comments on commit 225f320

Please sign in to comment.