% $Id: ivbook.sty 368 2009-06-24 19:04:28Z karl $
% style for interview book, on top of the standard book class.

\usepackage[paperwidth=7in,paperheight=10in,
            width=5.1in,lines=49,
            hmarginratio=1:1,vmarginratio=10:10,
           ]{geometry}
\raggedbottom

\usepackage[vietnam,UKenglish,USenglish]{babel}

% Use Inconsolata for typewriter.
\usepackage[scaled=.98]{inconsolata} % design size a little too big for charter
\pdfmapfile{+fi4.map}

% Our basic font: Charter.
% The default ttscaling makes cmtt much too large for Chater; we made
% our own mdfont.def to change the ratio, but it doesn't matter now that
% we use Inconsolata for typewriter.
%
%\renewcommand{\sfdefault}{fvs} % tried sans serif in failed experiments
\usepackage[bitstream-charter,sfscaled=true,ttscaled=true]{mathdesign}

% each interview is a chapter*.  This specifies the title's formatting.
\usepackage[rm,medium,compact,raggedright]{titlesec}
\titlespacing*{\chapter}{0pt}{-2.5pc}{1pc}

% avoid blank pages between chapters.
% http://www.tex.ac.uk/cgi-bin/texfaq2html?label=reallyblank
\let\cleardoublepage = \clearpage

\input{ushyphex} % hyphenation exceptions

\usepackage[noname]{compactbib} % mostly for the noname
\usepackage{fancyvrb}
\usepackage{graphicx}
\usepackage{mflogo}
\usepackage{microtype} % avoid half a dozen or so overfull boxes
\usepackage{multicol}  % \twocolumn does not balance
\usepackage{picinpar}  % for mittelbach
\usepackage{url}

\usepackage{fancyhdr}
\pagestyle{fancy}
%
\renewcommand{\headrulewidth}{0pt} % no rule below header
%
% No "Chapter 1." in our marks, just the title.
%\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
%
% The \nouppercase is provided by fancyhdr and undoes book's \uppercase.
\fancyhead[LE,RO]{\thepage} % page number on outside
% chapter name on inside, change "and" to ampersand:
\fancyhead[LO,RE]{\it \def\ivand{{\& }}\nouppercase{\leftmark}} 
%
% no footers except on chapter openings; the standard classes issue
% \pagestyle{plain} there, overriding the \pagestyle{fancy}.
\fancyfoot{}

% fancyhdr told us to do this because of Thanh.
\setlength\headheight{14pt}

% write .aux and other files.
\@fileswtrue

% we do not want indentation of the toc entries, change to {0pt}.
\renewcommand*\l@section{\@dottedtocline{1}{0pt}{2.3em}}

% make page numbers occupy this much space.  The default is 1.55em,
% which is (unlike CM) not enough for a three-digit number.
% \@tocrmarg is 2.55em, which is supposed to be >= \@pnumwidth, although
% I don't think it matters for us.
\renewcommand*\@pnumwidth{2.5em}

% \ivand is inserted as the "and" of double interviews.
% Normally, just output "and", but in the toc, force a line break.
\def\ivtocand{and \newline}
\def\ivand{and }

% General formatting changes.
%\vbadness = 2700 % avoid warning, it's not so bad
\interlinepenalty = -500
% default \parindent is 15pt, which seems ok.
\parskip = 0pt
\partopsep = 0pt
\newlength{\ivlisttopsep}\setlength{\ivlisttopsep}{1pt plus2pt minus1pt}
\topsep = \ivlisttopsep
\@itempenalty = -55 % default is 51
% fancyvrb uses \topsep above and below

% indent verbatim environments same as lists.
% unfortunately using frame=lines,framerule=0pt yields too much space,
% even with framesep=0pt.
\fvset{xleftmargin=\leftmargini}

% http://www.tex.ac.uk/cgi-bin/texfaq2html?label=complist incomplete. xx
% This seems to be the only way to change \topsep.
% This \@listI macro is called after every font change.
% \parsep and \itemsep could be changed after starting the environment,
% but may as well change them here.
\def\@listI{\leftmargin\leftmargini
            \topsep=\ivlisttopsep
            \parsep=\topsep  \divide\parsep by 2
            \itemsep=0pt plus1pt}%

% (no longer relevant since we're using fancyvrb)
% \verbatim calls \trivlist (with one item).
% \trivlist starts by setting \parsep=\parskip; we've already redefined
% \parskip, so ok on that.  However, \topsep remains at its default
% (from \@listi, for 10pt): 8pt plus2pt minus4pt.  There seems to be no
% way to change this within \trivlist or \@trivlist, so reset it in this
% brute-force way:
%\newlength{\ivverbtopsep}\setlength{\ivverbtopsep}{4pt plus2pt minus2pt}
%\let\savetrivlist=\trivlist
%\def\trivlist{\topsep=\ivverbtopsep \savetrivlist}


%  Interview header.
%
% #1 is an optional argument specifying a Babel language to use for the
% interview -- UKenglish for taylor, empty string for everything else.
%
% #2 is always the interviewee name(s).
%
\newcommand{\ivchapter}[2][opt]{%
  \chapter*{#2}% start a new chapter
  \markboth{#2}{}% latex does not issue a mark with the *-form, so we do.
  \addcontentsline{toc}{section}{#2}% ditto toc entry
  \setcounter{footnote}{0}% ditto footnote resetting, evidently
  %
  \gdef\ivchapterlanguage{#1}%
  \def\ivbeginlanguage{\begin{otherlanguage}{#1}}%
  \def\ivendlanguage{\end{otherlanguage}}%
  %
  \ifx\ivchapterlanguage\empty \else
    \expandafter\ivbeginlanguage
  \fi
}

\def\ivfooter{%
  \ifx\ivchapterlanguage\empty \else
    \expandafter\ivendlanguage
  \fi
}
% text description at beginning of each interview.  #1 is text,
% #2 is date completed/done, including preceding text "completed" or
% "done in" as needed.
% #3 is photo filename, or empty if none.
\def\figwidth{2in}%
\def\gutter{.25in}%
\long\def\ivblurb#1#2#3{%
  \hbox to \hsize{% one big line
    \vtop{%
      \advance\hsize by -\figwidth
      \advance\hsize by -\gutter
      \rightskip=0pt plus2em
      \strut#1%
      % this comes from TUGboat's cahiers.sty; it makes the
      % following text be on the last line of the paragraph if it
      % fits, else on a line by itself, flush right.
      \unskip\nobreak\hfil\null\hskip2pt\penalty0\hskip0pt\hskip2pt\null\hfil
      \hbox{[Interview \ignorespaces #2\unskip.]}%
      \parfillskip=0pt\par
    }%
    \kern\gutter
    \vtop{%
      % we want the top of the photo to more or less align with the top
      % of the type in the blurb.  First put the photo in a box:
      \setbox0=\hbox{%
        \def\figfile{#3}%
        \ifx\figfile\empty \kern\figwidth \else
          \includegraphics[width=\figwidth]{\figfile}%
        \fi
      }%
      % Compute the space for the photo and vskip explicitly,
      % then change the height of the photo box.
      \dimen0=\ht0 \advance\dimen0 by -\ht\strutbox
      \advance\dimen0 by -\baselineskip
      \vskip\dimen0
      \ht0=\ht\strutbox \box0
    }%
  }
  \bigskip
}

% fonts for the names (labels) in the questions and answers: tried using
% \textsc for the first questions&answers, when we spell out the whole
% names, and \acro for the subsequent questions&answers, when it is just
% initials.  Unfortunately \textsc is faked, so don't do that.  The
% \acro is still there, in texdefs.m4.
\let\nameonefont=\relax

% The macros below induce slanted for interviewers and bold for
% interviewees in all cases.

% #1 is questioner id, #2 is text of question.
\long\def\question#1#2{%
  \penalty-1000\vskip4pt plus4pt minus2pt
  \noindent
  \textsl{#1\/\kern.08em}:\hskip.75em \relax
  #2\par
}

% #1 is interviewee id; text of answer follows.
\long\def\answer#1{%
  \penalty-200\vskip3pt plus3pt minus2pt  % extra stretch avoids underfull msgs
  \noindent
  \textbf{#1\/}:\hskip.75em
}

% entire image command is #1.
\def\ivimage#1{%
  \medskip
  \centerline{#1}
  \medskip
}

% images that should take up a whole line, in bj-jmn.
\def\ivlineimage#1{%
  \medskip
  \leftline{#1}
  \bigskip
}



%  other small macros
\def\acrofont{\ifx\@currsize\footnotesize \scriptsize \else \small \fi}
\def\acro#1{{\acrofont #1\relax \ifnum\fntsl>0\/\fi}}
\def\cs#1{{\tt \char`\\#1}}
\def\dash{\unskip--\ignorespaces}
\def\Dash{\unskip\thinspace---\thinspace\ignorespaces}
\def\fntsl{\fontdimen1\the\font}% font slant
\def\hyph{-\penalty\z@\hskip\z@skip }
\def\ivtitle#1{\textsl{#1\/}}
% \ldots ends with a \kern, so get rid of it:
\def\sentencespace{\unkern\spacefactor=3000 \space\ignorespaces}
\def\slash{/\penalty\z@\hskip\z@skip }

% Two Vietnamese "horned" letters used in taylor.  Thankfully,
% Vietnamese support was added to Charter (by Thanh).  We tell
% babel to switch into using the language "vietnam" (declared in the
% babel invocation above), and that is it.  \uhorn and \ohorn are
% defined in there.  Since all we need are these single glyphs, Babel's
% \foreignlanguage command suffices.
\def\ivuhorn{\ivvn{\uhorn}}
\def\ivohorn{\ivvn{\ohorn}}
\def\ivvn#1{\foreignlanguage{vietnam}{#1}}%


%  simple logos
% with our fonts, \TeX is T\kern-.1667em\lower.4ex\hbox{E}\kern-.07emX.
\DeclareRobustCommand\AmS{\acro{AMS}}% looks cleaner than \cal
\def\BibTeX{B{\footnotesize IB}\kern-.04em \TeX} % sc not good in charter
\DeclareRobustCommand{\ConTeXt}{C\kern-.0333em on\-\kern-.0667em
                                \TeX\kern-.0333em t}
\DeclareRobustCommand{\Cplusplus}{C\raisebox{.2ex}{{\footnotesize ++}}}
\DeclareRobustCommand{\eTeX}{\leavevmode\hbox{$\varepsilon$}-\TeX}
\DeclareRobustCommand\ExTeX{%
  \ensuremath{\textstyle\varepsilon_{\kern-0.1em\cal{X}}}\kern-.27em\TeX}
\def\LeXrm{L\kern-.03em\lower.4ex\hbox{E}\kern-.07emX\@}
\def\LeXsl{L\kern-.03em\lower.4ex\hbox{E}\kern-.07emX\@}
\def\MacOS{Mac\,\acro{OS}}
\def\MacOSX{Mac\,\acro{OS\,X}}
\def\MeXrm{M\kern-.02em\lower.4ex\hbox{E}\kern-.07emX\@}
\def\MeXsl{M\kern-.02em\lower.4ex\hbox{E}\kern-.07emX\@}
\def\OSX{\acro{OS\,X}}
\def\TPJrm{\textrm{The Prac\TeX{} Journal}}
\def\TPJsl{\ivtitle{The Prac\TeX{} Journal}}
\DeclareRobustCommand{\TUGboat}{\ivtitle{TUGboat}}
\def\unisheng{{\font\shengfont=bsmiu7b \shengfont \char25}}

% just for the preface:
\def\GNU{\acro{GNU}}
\def\HTML{\acro{HTML}}
\def\TUG{\acro{TUG}}


%  more complicated logos
% from tb 29-3 (Murzynowski_3)
\DeclareRobustCommand{\gmLa}{%
  {%
    L%
    \setbox\z@\hbox{\check@mathfonts
      \fontsize\sf@size\z@
      \math@fontsfalse\selectfont
      A}%
    \kern-.57\wd\z@
    \sbox\tw@ T%
    \vbox to1.01\ht\tw@{\copy\z@ \vss}%
    \kern-.2\wd\z@}% originally $-,15$\,em for T.
  {%
    \ifdim\fontdimen1\font=\z@
    \else
      \count\z@=\fontdimen5\font
      \multiply\count\z@ by 64\relax
      \divide\count\z@ by\p@
      \count\tw@=\fontdimen1\font
      \multiply\count\tw@ by\count\z@
      \divide\count\tw@ by 64\relax
      \divide\count\tw@ by\tw@
      \kern-\the\count\tw@ sp\relax
%^^A      \typeout{@@@@ \the\count\tw@\space sp}%
    \fi}}
\def\La{\gmLa}
\def\LaTeX{\gmLa\TeX{}}
\def\AllTeX{(\La\kern-.025em)\kern-.025em\TeX{}}
\def\TeX{T\kern-.1667em\lower.4ex\hbox{E}\kern-.07emX\spacefactor1000 }

% Xe\TeX{} requires reflecting the first E, hence we complain if the
% graphics package is not present.  (For plain documents, this can be
% loaded via Eplain.)  Also, at Barbara's suggestion, if the current
% font is slanted, we rotate by 180 instead of reflecting so there is at
% least a chance to look ok.  (The magic values here seem more or less
% ok for \texttt{cmsl} and \texttt{cmti}.)
%
%    \begin{macrocode}
\def\tubreflect#1{%
  \@ifundefined{reflectbox}{%
    \TBerror{A graphics package must be loaded for \string\XeTeX}%
  }{%
    \ifdim \fontdimen1\font>0pt
      \raise 1.75ex \hbox{\kern.1em\rotatebox{180}{#1}}\kern-.1em
    \else
      \reflectbox{#1}%
    \fi
  }%
}
\def\tubhideheight#1{\setbox0=\hbox{#1}\ht0=0pt \dp0=0pt \box0 }
\DeclareRobustCommand\Xe[1]{\leavevmode
  \tubhideheight{\hbox{X\kern.05em
    \setbox0=\hbox{\TeX}\setbox1=\hbox{E}%
    \lower\dp0\hbox{\raise\dp1\hbox{\kern-.125em\tubreflect{E}}}%
    \kern-.12em #1}}}
\def\XeTeX{\Xe\TeX}
\def\XeLaTeX{\Xe{\,\LaTeX}}

% to omit font warnings and info messages:
%\def\@font@info#1{}
%\def\@font@warning#1{}

% lsi sizes: http://www.lightningsource.com/products_paperback.aspx
%     5 x 8"        (203 x 127mm)
%     5.06 x 7.81"  (198 x 129mm)
%     5.5 x 8.5"    (216 x 140mm)
%     6 x 9"        (229 x 152mm)
%     6.14 x 9.21"  (234 x 156mm)
%     6.69 x 9.61"  (244 x 170 mm)  (Pinched Crown)
%     7 x 10"       (254 x 178 mm)
%     7.44 x 9.69"  (246 x 189mm)
%     7.5 x 9.25"   (235 x 191mm)
%     8.25 x 11"    (280 x 210mm)
%     8.268 x 11.693"   (297 x 210 mm) A4

% we don't need the TeX meanings of these common characters.
\catcode`\$ = 12
\catcode`\& = 12

\catcode`\^^? = 14  % use DEL for a comment character
% let % be normal, but
% supp-pdf.tex needs %'s and is loaded \AtBeginDocument, so reset % after.
\AtBeginDocument{\catcode`\% = 12}
