Skip to content
Newer
Older
100644 479 lines (423 sloc) 13.8 KB
11008ab @armandofox initial checkin
authored May 7, 2012
1 % line breaking tolerances
2 \tolerance=1000 % usually 200, infinite=10000
3 % last ditch effort: how much space OK to insert
4 % in a line to avoid overfull
5 \setlength{\emergencystretch}{3em}
6
1892d1e @armandofox works for pdf, almost works for mobi
authored May 8, 2012
7 \newcommand{\sidebarfont}{%
8 \fontencoding{\encodingdefault}%
9 \fontfamily{phv}%
10 \fontseries{mc}%
11 \fontshape{\shapedefault}%
12 \footnotesize
13 \selectfont}
14
11008ab @armandofox initial checkin
authored May 7, 2012
15
16 \ifhtmloutput
17 % \newcommand{\mtctitle}{}
18 \else
19 \usepackage{minitoc}
20 \renewcommand{\mtctitle}{}
21 \usepackage[dvips,color,innerbars]{changebar}
22 \fi
23 \usepackage{xstring} % provides StrSubstitute
24 \usepackage{natbib}
25 % natbib redefines the bibliography environment, so we have to override
26 % its definition after loading it to make the chapter bibs section-like
27 % rather than chapter-like
28 \makeatletter
29 \renewenvironment{thebibliography}[1]
30 {%\addtocounter{section}{1}
31 %\section*{References In This Chapter}%
32 \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
33 \list{\@biblabel{\@arabic\c@enumiv}}%
34 {\settowidth\labelwidth{\@biblabel{#1}}%
35 \leftmargin\labelwidth
36 \advance\leftmargin\labelsep
37 \@openbib@code
38 \usecounter{enumiv}%
39 \let\p@enumiv\@empty
40 \renewcommand\theenumiv{\@arabic\c@enumiv}}%
41 \sloppy
42 \clubpenalty4000
43 \@clubpenalty \clubpenalty
44 \widowpenalty4000%
45 \sfcode`\.\@m}
46 {\def\@noitemerr
47 {\@latex@warning{Empty `thebibliography' environment}}%
48 \endlist}
49 \makeatother
50
51 \usepackage{bibunits}
52 \usepackage{ifthen}
53 \usepackage{tabularx}
54 \usepackage{array}
55 \usepackage{graphicx}
56 \usepackage{fancyvrb}
57 \usepackage{verbatim}
58 %\usepackage[font=small,labelfont=bf,margin=10pt]{caption}
59
60 % Textual ``figures''
61 \ifhtmloutput
62 \newenvironment{textfigure}{}{}
63 \else
64 \newenvironment{textfigure}{\hrule\small}{\vspace{0.5ex}\hrule}
65 \fi
66
67 % highlighting deltas from a previous explanation
68
69 \ifhtmloutput
70 \newenvironment{changebar}{\HCode{<span class="changebar">}}{\HCode{</span>}}
71 \else
72 \setlength{\changebarwidth}{0.5em}
73 \definecolor{ChangebarColor}{rgb}{0.05,0,0.5}
74 \cbcolor{ChangebarColor}
75 \fi
76 \usepackage{endnotes}
77 \usepackage{listings} \input{listingdefaults}
78 \usepackage[figuresright]{rotating}
79 \usepackage{floatpag}
80 \rotfloatpagestyle{empty}
81 \usepackage{makeidx}
82 \makeindex
83 \usepackage{enumerate}
84 \usepackage{fancybox}
85
86 \usepackage{hyperref}
87 \ifhtmloutput
88 \hypersetup{hyperfootnotes=false}
89 \fi
90
91
92 %\usepackage{glossaries}
93
94 % shortcuts
95 \newcommand{\fillinblank}{\_\_\_\_}
96 \newcommand{\n}{\tabularnewline}
97 \newcommand{\tg}{\textgreater}
98 \newcommand{\tl}{\textless}
99 \newcommand{\ttil}{\textasciitilde}
100 \newcommand{\tcaret}{\textasciicircum}
101 \ifhtmloutput
102 \ifmobioutput
103 \newcommand{\T}[1]{\HCode{<tt>}#1\HCode{</tt>}}
104 \newcommand{\B}[1]{\HCode{<strong>}#1\HCode{</strong>}}
105 \newcommand{\Sf}[1]{\HCode{<span class="sans-serif">}#1\HCode{</span>}}
106 \newcommand{\C}[1]{\HCode{<span style="color: \#800;"><tt>}#1\HCode{</tt></span>}}
107 \else
108 \newcommand{\T}[1]{\HCode{<span class="typewriter">}#1\HCode{</span>}}
109 \newcommand{\B}[1]{\HCode{<span class="strong">}#1\HCode{</span>}}
110 \newcommand{\Sf}[1]{\HCode{<span class="sans-serif">}#1\HCode{</span>}}
111 \newcommand{\C}[1]{\HCode{<span class="code-example">}#1\HCode{</span>}}
112 \fi
113 \else
114 \newcommand{\T}{\texttt}
115 \newcommand{\B}{\textbf}
116 \newcommand{\Sf}[1]{\textsf{\emph{#1}}}
117 %\definecolor{TextHighlight}{rgb}{0.05,0,0.50}
118 \definecolor{TextHighlight}{rgb}{0.1,0.1,0.1}
119 \newcommand{\C}[1]{\textsf{\upshape{\textbf{#1}}}}
120 \fi
121
122 % make caption font smaller (tip from
123 % http://dcwww.camd.dtu.dk/~schiotz/comp/LatexTips/LatexTips.html#captfont)
124 \newcommand{\captionfonts}{\scriptsize\bf}
125 \ifhtmloutput
126 %
127 \else
128 \makeatletter % Allow the use of @ in command names
129 \long\def\@makecaption#1#2{%
130 \begin{centering}
131 \vskip\abovecaptionskip % space between figure & caption
132 \sbox\@tempboxa{{\captionfonts #1: #2}}%
133 \ifdim \wd\@tempboxa >\hsize
134 {\captionfonts #1: #2\par}
135 \else
136 \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
137 \fi
138 \end{centering}
139 \vskip\belowcaptionskip% space between caption & text
140 }
141 \makeatother % Cancel the effect of \makeatletter
142 \fi
143
144 % hyperlinks
145
146 \ifhtmloutput
147 \newcommand{\weblink}[2]{\href{#1}{#2}}
148 \else
149 \newcommand{\weblink}[2]{#2\endnote{\expandafter \url{#1}}}
150 %\newcommand{\weblink}[2]{#2 ({\url{#1}})}
151 \fi
152
153
154 % Quotation in small-ish type with attribution
155 % Example use:
156 % \makequotation{There's a sucker born every minute.}{W.C. Fields}
157
158 \ifhtmloutput
159 \ifmobioutput
160 \newcommand{\makequotation}[2]{\HCode{%
161 <div class="makequotation" align="center">
162 <table cellpadding="10" style="margin-left: 0;">
163 <tr><td align="center" border="1" style="background-color: \#c0c0c0">}%
164 #1\HCode{<i>} #2\HCode{</i>
165 </td></tr>
166 </table>
167 </div>}}
168 \else
169 \newcommand{\makequotation}[2]{\begin{quote}\small\emph{#1} ---#2\end{quote}}
170 \fi
171 \else
172 \newcommand{\makequotation}[2]{\begin{quote}\small\emph{#1}
173
174 \hfill---#2\end{quote}}
175 \fi
176
177 % Chapter front matter (used only by html build)
178 \newenvironment{chapterfrontmatter}{}{}
179
180 % Chapter overview (key messages)
181 % Example use:
182 % \chapteroverview{User stories are important. Let's learn about them.}
183 %
184 % implemented as Subsection for TOC inclusion:
185 \newcommand{\chapteroverview}[1]{
186 \addtocontents{toc}{#1}
187 \subsection*{#1}
188 \vspace{0.25in}
189 \ifhtmloutput\else\minitoc\fi
190 \vfill\clearpage}
191
192 % Sidebar - appearance will vary depending on output target, and may not
193 % actually be along the side.
194 % Example use:
195 % \begin{sidebar}{Historical note}
196 % All this stuff will be in a sidebar.
197 % You can include most elements that would go in normal text, like
198 % figures, citations, etc.
199 % \end{sidebar}
200
201 \definecolor{SidebarColor}{rgb}{0.9,0.9,0.9}
202 \ifhtmloutput
203 \newenvironment{sidebar}[2][]%
204 {\HCode{<span class="sidebar_name"><b><i>}#2{\HCode{</i></b></span>}}}
205 {}
206 \else
207 \newcommand{\thesidebarraise}{}
208 \newenvironment{sidebar}[2][-2ex]%
209 {\renewcommand{\thesidebarraise}{#1}%
210 \begin{Sbox}\begin{minipage}{\marginparwidth}\sidebarfont\raggedright \textbf{#2}}%
211 {\end{minipage}\end{Sbox}\marginpar{\vspace{\thesidebarraise}\colorbox{SidebarColor}{\TheSbox}}}
212 \fi
213
214 % Sidebars with photos - need to be small in PDF Output
215 % Small Kindle is 520x622 px; images 260x311 or smaller won't be resized on device
216 \ifhtmloutput
217 \ifmobioutput
218 \newenvironment{sidebargraphic}[3][]%
219 {\HCode{<img width="150" src="#2_SB.jpg"/>}
220 \HCode{<span class="sidebar_name"><b><i>}#3{\HCode{</i></b></span>}}}
221 {}
222 \else
223 \newenvironment{sidebargraphic}[3][]%
224 {\HCode{<img class="sidebarimage" src="#2.jpg">}
225 \HCode{<span class="sidebar_name">}#3\HCode{</span>}}
226 {}
227 \fi
228 \else
229 \newcommand{\thesidebarimg}{}% hack- numbered params can't appear in end content of \newenvironment
230 \newenvironment{sidebargraphic}[3][0in]%
231 {\renewcommand{\thesidebarraise}{#1}%
232 \renewcommand{\thesidebarimg}{#2}%
233 \begin{Sbox}\begin{minipage}{\marginparwidth}\sidebarfont\raggedright \textbf{#3}}%
234 {\hfill\\ \includegraphics[width=\marginparwidth]{\thesidebarimg}\end{minipage}\end{Sbox}\marginpar{\vspace{\thesidebarraise}\colorbox{SidebarColor}{\TheSbox}}}
235 \fi
236
237
238
239 % Endnotes - in print version, footnotes/endnotes come at end of
240 % chapters
241
242 \newenvironment{tolearnmore}{\section{To Learn More}}{%
243 % per-chapter bibliography
244 \putbib
245 % Endnotes
246 \ifhtmloutput\else%
247 \theendnotes
248 \setcounter{endnote}{0}
249 \fi
250 }
251
252 % Code - uses \verbatiminput to put in file 'undecorated' for HTML use,
253 % or \lstlisting to decorate it with styling and line numbers for PDF
254 \ifhtmloutput
255 \ifmobioutput
1892d1e @armandofox works for pdf, almost works for mobi
authored May 9, 2012
256 \newcommand{\codefile}[2][\pastebinbase]{\HCode{<a class="pastebin" href="http://pastebin.com/#1">http://pastebin.com/#1</a><br/><pre class="code">}
11008ab @armandofox initial checkin
authored May 7, 2012
257
258 \begin{minipage}{\textwidth}% prevent gratuitous blank lines
259 \verbatiminput{#2}%
260 \end{minipage}%
261 \HCode{</pre><hr>}}
262 \else
1892d1e @armandofox works for pdf, almost works for mobi
authored May 9, 2012
263 \newcommand{\codefile}[2][\pastebinbase]{\HCode{<a class="pastebin" href="http://pastebin.com/#1">http://pastebin.com/#1</a><pre class="code">}
11008ab @armandofox initial checkin
authored May 7, 2012
264 \verbatiminput{#2}
265
266 \HCode{</pre>}}
267 \fi
268 \else
1892d1e @armandofox works for pdf, almost works for mobi
authored May 9, 2012
269 \newcommand{\codefile}[2][\pastebinbase]{%
11008ab @armandofox initial checkin
authored May 7, 2012
270 \noindent\begin{minipage}{\textwidth}%
271 \Sf{\scriptsize{}http://pastebin.com/#1}%
272 \vspace{-1ex}%
273 \lstinputlisting{#2}%
274 \end{minipage}}
275 \fi
276
277
278 % Screencast - in print version, just a URL link; in HTML5 version,
279 % embedded quicktime player or youtube player??
280
281 \newcounter{screencast}[section]
282 \renewcommand*\thescreencast{\thesection.\arabic{screencast}}
283 \newcommand{\screencastprefix}{http://vimeo.com/}
284 \newcommand{\screencastsuffix}{}
285
286 \newcommand{\screencast}[5][saasbook/videos]{%
287 \refstepcounter{screencast}
288 \label{#2}\relax%
289 % write metadata to output file
290 \write\screencastdata{\thescreencast: #2@@#3@@#4##@5}
291 %
292 \ifhtmloutput
293 \ifmobioutput
294 \HCode{<hr>
295 <div class="screencast"> Screencast \thescreencast: <a class="screencast-url" %
296 href="\screencastprefix#1\screencastsuffix">#3</a>}%
297 \HCode{<div class="screencastsummary">}#5\HCode{</div></div>
298 <hr>}
299 \else
300 \HCode{<div class="screencast"><h2>Screencast \thescreencast: <span class="screencast_title">}#3\HCode{</span></h2>}
301 \HCode{ <video src="#4" width="600" controls="controls">}
302 \HCode{ <!-- for browsers that don't support embedded video tag -->}
303 \HCode{ <a class="screencast-url" href="\screencastprefix#1\screencastsuffix">Watch on Vimeo</a>}
304 \HCode{ </video>}
305 \HCode{<div class="screencastsummary">}#5\HCode{</div></div>}
306 \fi
307 \else
308 \hfill
309 \begin{minipage}{0.9\textwidth}
310 \rule{\textwidth}{0.5pt}\hfill\\
311 \small\textbf{Screencast \thescreencast: #3.} \\
312 \url{\screencastprefix#1\screencastsuffix}\\
313 #5\relax \\
314 \rule{\textwidth}{0.5pt}\hfill\\
315 \end{minipage}
316 \hfill
317 \fi
318 }
319
320 % Elaboration - optional material that's longer than a sidebar
321
322 %\definecolor{ElaborationColor}{rgb}{0.05,0.0,0.50}
323 \definecolor{ElaborationColor}{rgb}{0.1,0.1,0.1}
324 \ifhtmloutput
325 \ifmobioutput
326 \newenvironment{elaboration}[1]%
327 {\HCode{<hr><b>E</b><small><b>LABORATION:</b> #1<br/> }}
328 {\HCode{</small><hr>}}
329 \else
330 \newenvironment{elaboration}[1]%
331 {\HCode{<span class="elaboration_name">#1</span> }}
332 {}
333 \fi
334 \else
335 \newcommand{\aboveelaborationskip}{1.5ex}
336 \newcommand{\belowelaborationskip}{1.5ex}
337 \newcommand{\elaborationpadding}{0.5ex}
338 \newenvironment{elaboration}[1]%
339 {\color{ElaborationColor} %
340 \begin{Sbox}\begin{minipage}[r]{0.9\textwidth}%
341 \vspace{\aboveelaborationskip}
342 \rule{\textwidth}{2pt}
343 \vspace{\elaborationpadding}
344 \rule{1ex}{1ex}\hspace{2pt}\small\emph{\textbf{Elaboration: #1\relax}}
345 \vspace{\elaborationpadding}
346 \hrule
347 \vspace{\elaborationpadding}
348 }%
349 {\vspace{\elaborationpadding}
350 \hrule
351 \end{minipage}\end{Sbox}
352 \hfill\mbox{\TheSbox}
353 \vspace{\belowelaborationskip}
354 }
355 \fi
356
357 % LaTeX macros that aren't automatically translated to HTML
358 \ifhtmloutput
359 \renewcommand{\copyright}{\HCode{&copy;}}
360 \fi
361
362 % forced page breaks
363 \ifhtmloutput
364 \newcommand{\flushpage}{\clearpage\HCode{<mbp:pagebreak/>}}
365 \else
366 \newcommand{\flushpage}{\clearpage}
367 \fi
368
369 % graphics - for HTML/mobi, use the gif version
370 \ifhtmloutput
371 \newcommand{\picfigure}[4][width=\textwidth]{%
372 \begin{figure}
373 \Picture{#2.gif id="#3"}
374 \ifthenelse{\equal{#4}{}}{}{\caption{\label{#3}#4}}
375 \end{figure}}
376 \else
377 \newcommand{\picfigure}[4][width=\textwidth]{%
378 \begin{figure}
379 \includegraphics[#1]{#2}
380 \ifthenelse{\equal{#4}{}}{}{\caption{\label{#3}#4}}
381 \end{figure}}
382 \fi
383
384 % table figures - will eventually do something different for mobi
385 \newcommand{\tablefigure}[3]{%
386 \begin{figure}
387 \input{#1}
388 \caption{\label{#2}%
389 #3}
390 \end{figure}
391 }
392
393
394 % Summary - key points summarizing a chapter or section
395
396 \ifhtmloutput
397 \ifmobioutput
398 \newenvironment{summary}{}{}
399 \else
400 \newenvironment{summary}%
401 {\HCode{<div class="summary">}}%
402 {\HCode{</div>}}
403 \fi
404 \else
405 \renewcommand{\shadowsize}{2pt}
406 \newenvironment{summary}%
407 {\vspace{2ex}\begin{Sbox}\begin{minipage}{0.96\textwidth}\noindent}
408 {\vspace{0.25\baselineskip}\end{minipage}\end{Sbox}\noindent\hspace{0in}\shadowbox{\TheSbox}}
409 \fi
410
411 % Note to self
412 \newcommand{\note}[1]{\fbox{#1}}
413
414 % DRYing out codefile examples
1892d1e @armandofox works for pdf, almost works for mobi
authored May 9, 2012
415 \newcommand{\codefilefigure}[4][\pastebinbase]{% filename, reflabel, caption
11008ab @armandofox initial checkin
authored May 7, 2012
416 \begin{figure}
417 \codefile[#1]{#2}
418 \caption{\label{#3}
419 #4
420 }
421 \end{figure}%
422 }
423
424
425 % Table of contents formatting
426 \setcounter{tocdepth}{5}
427 %\newcommand{\chapteroverview}[1]{\addcontentsline{toc}{section}{#1}}
428
429 \newcommand{\gloss[1]}{\textbf{#1}}
430
431 % Exercises
432 \newtheorem{exercise}{Exercise}[chapter]
433 % Check Yourself
434 \newtheorem{checkyourself}{Self-Check}[section]
435 % answers embedded in self-checks
436 \ifhtmloutput
437 \ifmobioutput
438 \newenvironment{answer}{\HCode{<img height="15" width="15" src="icons/mobi/green_dot.gif"/>}}{}
439 \else
440 \newenvironment{answer}{}{}
441 \fi
442 \else
443 \newenvironment{answer}%
444 {\hfill \\ \noindent\upshape$\diamond$ }%
445 {\rule{1ex}{1ex}~~}
446 \fi
447
448 % answers to exercises: omit from book, collect elsewhere
449 %\newenvironment{exanswer}{}{}
450 \let\exanswer=\comment
451 \let\endexanswer=\endcomment
452
453
454 % Wikipedia link
455
456 \newcommand{\w}[2][]{%
457 \ifhtmloutput
458 \ifthenelse{\equal{#1}{}}{%
459 \StrSubstitute{#2}{ }{_}[\thewikilink]%
460 \weblink{http://en.wikipedia.org/wiki/\thewikilink}{\emph{\B{#2}}}%
461 }{%
462 \StrSubstitute{#1}{ }{_}[\thewikilink]%
463 \weblink{http://en.wikipedia.org/wiki/\thewikilink}{\emph{\B{#2}}}%
464 }%
465 \else%
466 \textsf{\slshape\B{#2}}%
467 \fi%
468 \ifhtmloutput%
469 \else%
470 \index{#2}%
471 \ifthenelse{\equal{#1}{}}{}{\index{#1}}%
472 \relax%
473 \fi%
474 }
475
476
477 % important term - not a link
478 \newcommand{\x}[1]{\emph{\B{#1}}}
Something went wrong with that request. Please try again.