\NeedsTeXFormat{LaTeX2e}[1994/06/01]

\ProvidesPackage{tufte-common}[2008/11/16 v3.0.0 Common code for the Tufte-LaTeX styles]

%%
% We use the `xifthen' package to handle our package option switches
\RequirePackage{xifthen}


%%
% `debug' option -- provides more information in the .log file for use in
% troubleshooting problems
\newboolean{@tufte@debug}
\DeclareOption{debug}{\setboolean{@tufte@debug}{true}}

%%
% `nofonts' option -- doesn't load any fonts
% `fonts' option -- tries to load fonts
\newboolean{@tufte@loadfonts}\setboolean{@tufte@loadfonts}{true}
\DeclareOption{fonts}{\setboolean{@tufte@loadfonts}{true}}
\DeclareOption{nofonts}{\setboolean{@tufte@loadfonts}{false}}

%%
% `nols' option -- doesn't configure letterspacing
% `ls' option -- configures letterspacing
\newboolean{@tufte@letterspace}\setboolean{@tufte@letterspace}{true}
\DeclareOption{ls}{\setboolean{@tufte@letterspace}{true}}
\DeclareOption{nols}{\setboolean{@tufte@letterspace}{false}}

%%
% `book' and `handout' options
\newcommand{\@tufte@class}{article}% the base LaTeX class (defaults to the article/handout style)
\newcommand{\@tufte@pkgname}{tufte-handout}% the name of the package (defaults to tufte-handout)
\DeclareOption{book}{%
  \renewcommand{\@tufte@class}{book}
  \renewcommand{\@tufte@pkgname}{tufte-book}
  \setboolean{@tufte@titlepage}{true}
}
\DeclareOption{handout}{%
  \renewcommand{\@tufte@class}{article}
  \renewcommand{\@tufte@pkgname}{tufte-handout}
  \setboolean{@tufte@titlepage}{false}
}
\DeclareOption{article}{% `article' is just an alias for `handout'
  \renewcommand{\@tufte@class}{article}
  \renewcommand{\@tufte@pkgname}{tufte-handout}
  \setboolean{@tufte@titlepage}{false}
}

%%
% `titlepage' option -- creates a full title page with \maketitle

\newboolean{@tufte@titlepage}
\DeclareOption{titlepage}{\setboolean{@tufte@titlepage}{true}}
\DeclareOption{notitlepage}{\setboolean{@tufte@titlepage}{false}}

%%
% `a4paper' option

\newboolean{@tufte@afourpaper}
\DeclareOption{a4paper}{\setboolean{@tufte@afourpaper}{true}}

%%
% `sfsidenotes' option -- typesets sidenotes in sans serif typeface

\newboolean{@tufte@sfsidenotes}
\DeclareOption{sfsidenotes}{\setboolean{@tufte@sfsidenotes}{true}}

%%
% `symmetric' option -- puts marginpar space to the outside edge of the page
%   Note: this option forces the twoside option

\newboolean{@tufte@symmetric}
\DeclareOption{symmetric}{
  \setboolean{@tufte@symmetric}{true}
  \PassOptionsToClass{twoside}{\@tufte@class}
}

%%
% `justified' option -- uses fully justified text (flush left and flush
% right) instead of ragged right.

\newboolean{@tufte@justified}
\DeclareOption{justified}{\setboolean{@tufte@justified}{true}}


% FIXME: should probably specify options not supported like Mittelbach's aipproc.cls

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@tufte@class}}
\ProcessOptions

%\LoadClass{\@tufte@class}

%%
% Detect whether we're in two-side mode or not.  (Used to set up running
% heads later.)

\newboolean{@tufte@twoside}
\ifthenelse{\boolean{@twoside}}
  {\setboolean{@tufte@twoside}{true}}
  {\setboolean{@tufte@twoside}{false}}

%%
% Detect if we're using pdfLaTeX

\newboolean{@tufte@pdf}
\IfFileExists{ifpdf.sty}{%
  \RequirePackage{ifpdf}
  \ifthenelse{\boolean{pdf}}
    {\setboolean{@tufte@pdf}{true}}
    {\setboolean{@tufte@pdf}{false}}
}{% assume we're not using pdfTex?
  \setboolean{@tufte@pdf}{false}
}

%%
% Detect if we're using XeLaTeX

\newboolean{@tufte@xetex}
\IfFileExists{ifxetex.sty}{%
  \RequirePackage{ifxetex}
  \ifthenelse{\boolean{xetex}}
    {\setboolean{@tufte@xetex}{true}}
    {\setboolean{@tufte@xetex}{false}}
}{% not using xelatex
  \setboolean{@tufte@xetex}{false}
}

%%
% Load the `hyperref' package.  We will set more options later.
% TODO Set nice defaults for hyperref options
\ifthenelse{\boolean{@tufte@xetex}}
  {\RequirePackage[xetex]{hyperref}}
  {\RequirePackage{hyperref}}

\hypersetup{%
  pdfborder = {0 0 0}
}

%%
% Set page layout geometry

\RequirePackage[letterpaper,includemp,width=6.5in,marginparsep=0.375in,marginparwidth=2in]{geometry}

\ifthenelse{\boolean{@tufte@afourpaper}}
  {\geometry{a4paper,includemp,width=170mm,marginparsep=10mm,marginparwidth=50mm}}
  {}

\ifthenelse{\boolean{@tufte@symmetric}}
  {}
  {\geometry{asymmetric}}


%%
% Separation marginpars by a line's worth of space.

\setlength\marginparpush{\baselineskip}

%%
% Font for margin items

\ifthenelse{\boolean{@tufte@sfsidenotes}}
  {\newcommand{\@tufte@marginfont}{\normalfont\scriptsize\sffamily}}
  {\newcommand{\@tufte@marginfont}{\normalfont\scriptsize}}

%%
% \RaggedRight allows hyphenation

\RequirePackage{ragged2e}
\setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize}

%%
% Set the justification baesed on the `justified' class option

\newcommand{\@tufte@justification}{%
  \ifthenelse{\boolean{@tufte@justified}}
    {\justifying}
    {\RaggedRight}
}

%%
% Turn off section numbering

\setcounter{secnumdepth}{-1}

%%
% Tighten up space between displays (e.g., a figure or table) and make symmetric

\setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
\setlength\belowdisplayskip{6pt plus 2pt minus 4pt}

%%
% To implement full-width display environments

\RequirePackage[strict]{chngpage}
% TODO this package may be obsolete -- see the changepage package for a replacement



% Compute length used for full-width displays

\newlength{\@tufte@overhang}
\setlength{\@tufte@overhang}{\marginparwidth}
\addtolength{\@tufte@overhang}{\marginparsep}

%%
% Modified \title, \author, and \date commands.  These store the
% (footnote-less) values in \thetitle, \theauthor, and \thedate, respectively.

\newcommand{\thetitle}{}%     plain-text-only title
\newcommand{\theauthor}{}%    plain-text-only author
\newcommand{\thepublisher}{}% plain-text-only publisher

\newcommand{\thanklesstitle}{}%     full title text minus \thanks{}
\newcommand{\thanklessauthor}{}%    full author text minus \thanks{}
\newcommand{\thanklesspublisher}{}% full publisher minus \thanks{}

\newcommand{\@publisher}{}% full publisher with \thanks{}
\newcommand{\thedate}{\today}

% TODO Fix it so that \thanks is not spaced out (with `soul') and can be
% used in \maketitle when the `sfsidenotes' option is provided.
\renewcommand{\thanks}[1]{\NoCaseChange{\footnote{#1}}}

\renewcommand{\title}[2][]{%
  \gdef\@title{#2}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \protected@xdef\thanklesstitle{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}%
    {\renewcommand{\thetitle}{\thanklesstitle}}% use thankless title
    {\renewcommand{\thetitle}{#1}}% use provided plain-text title
  \hypersetup{pdftitle={\thetitle}}% set the PDF metadata title
}

\renewcommand*{\author}[2][]{%
  \gdef\@author{#2}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \protected@xdef\thanklessauthor{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}
    {\renewcommand{\theauthor}{\thanklessauthor}}% use thankless author
    {\renewcommand{\theauthor}{#1}}% use provided plain-text author
  \hypersetup{pdfauthor={\theauthor}}% set the PDF metadata author
}

\renewcommand*{\date}[1]{%
  \gdef\@date{#1}%
  \begingroup%
    % TODO store contents of \thanks command
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \protected@xdef\thedate{#1}%
  \endgroup%
}

%%
% Provides a \publisher command to set the publisher

\newcommand{\publisher}[2][]{%
  \gdef\@publisher{#2}%
  \begingroup%
    \renewcommand{\thanks}[1]{}% swallow \thanks contents
    \protected@xdef\thanklesspublisher{#2}%
  \endgroup%
  \ifthenelse{\isempty{#1}}
    {\renewcommand{\thepublisher}{\thanklesspublisher}}% use thankless publisher
    {\renewcommand{\thepublisher}{#1}}% use provided plain-text publisher
}

% TODO: Test \hypersetup{pdfauthor,pdftitle} with DVI and XeTeX

%%
% Require paralist package for tighter lists

\RequirePackage{paralist}

% Add rightmargin to compactenum

\def\@compactenum@{%
  \expandafter\list\csname label\@enumctr\endcsname{%
    \usecounter{\@enumctr}%
    \rightmargin=2em% added this
    \parsep\plparsep
    \itemsep\plitemsep
    \topsep\pltopsep
    \partopsep\plpartopsep
    \def\makelabel##1{\hss\llap{##1}}}}

%%
% Improved letterspacing of small caps and all-caps text.
%
% First, try to use the `microtype' package, if it's available. 
% Failing that, try to use the `soul' package, if it's available.
% Failing that, well, I give up.

\RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase
\def\allcapsspacing{\relax}
\def\smallcapsspacing{\relax}
\newcommand{\allcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}}
\newcommand{\smallcaps}[1]{\MakeTextLowercase{\textsc{#1}}}

\newcommand{\@tufte@loadsoul}{%
  \IfFileExists{soul.sty}{%
    \RequirePackage{soul}
    \sodef\allcapsspacing{\upshape}{0.15em}{0.65em}{0.6em}
    \sodef\smallcapsspacing{\scshape}{0.075em}{0.5em}{0.6em}
  }{
    \PackageWarningNoLine{\@tufte@pkgname}{Couldn't locate `soul' package.}
  }% soul not installed... giving up.
}

% If we're using pdfLaTeX v1.40+, use the letterspace package. 
% If we're using pdfLaTex < v1.40, use the soul package.
% If we're using XeLaTeX, use XeLaTeX letterspacing options.
% Otherwise fall back on the soul package.

\ifthenelse{\boolean{@tufte@pdf}}
  {\PackageInfo{\@tufte@pkgname}{ifpdf = true}}
  {\PackageInfo{\@tufte@pkgname}{ifpdf = false}}

\ifthenelse{\boolean{@tufte@xetex}}
  {\PackageInfo{\@tufte@pkgname}{ifxetex = true}}
  {\PackageInfo{\@tufte@pkgname}{ifxetex = false}}

% Check pdfLaTeX version
\def\@tufte@pdftexversion{0}
\ifx\normalpdftexversion\@undefined \else
  \let\pdftexversion \normalpdftexversion
  \let\pdftexrevision\normalpdftexrevision
  \let\pdfoutput     \normalpdfoutput
\fi
\ifx\pdftexversion\@undefined \else
  \ifx\pdftexversion\relax \else
    \def\@tufte@pdftexversion{6}
    \ifnum\pdftexversion < 140
      \def\@tufte@pdftexversion{5}
    \fi
  \fi
\fi

\ifthenelse{\boolean{@tufte@letterspace}}
  {%
  \ifnum\@tufte@pdftexversion<6
    % pdfLaTeX version is too old or not using pdfLaTeX
    \ifthenelse{\boolean{@tufte@xetex}}
      {% TODO use xetex letterspacing
      \PackageInfo{\@tufte@pkgname}{XeTeX detected. Reverting to `soul' package for letterspacing.}
      \@tufte@loadsoul}
      {% use `soul' package for letterspacing
      \PackageInfo{\tufte@pkgname}{Old version of pdfTeX detected.  Reverting to `soul' package for letterspacing.}
      \@tufte@loadsoul}
  \else
    \IfFileExists{letterspace.sty}{% 
      \PackageInfo{\@tufte@pkgname}{Modern version of pdfTeX detected.  Using `letterspace' package.}
      \RequirePackage{letterspace}
      % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
      \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
      \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
      \renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
      \renewcommand{\smallcaps}[1]{\textsc{\MakeTextLowercase{##1}}}
    }{% microtype failed, check for soul
      \PackageInfo{\@tufte@pkgname}{Modern version of pdfTeX detected, but `letterspace' package not installed.  Reverting to  `soul' package for letterspacing.}
      \@tufte@loadsoul
    }
  \fi}
  {}


\DeclareTextFontCommand{\textsmallcaps}{\scshape}
\renewcommand{\textsc}[1]{\textsmallcaps{\smallcapsspacing{#1}}}


%%
% An environment for paragraph-style section

\providecommand\newthought[1]{\vspace{1.8\baselineskip plus 3pt minus 2pt}%
                           {\noindent\textsc{#1}}}

%%
% Used for doublespacing, and other linespacing
% Note that setspace must be loaded before footmisc or it'll break sidenotes
\usepackage{setspace}


%%
% Transform existing \footnotes into \sidenotes
% Sidenote: ``Where God meant footnotes to go.'' ---Tufte

\RequirePackage[side,multiple,stable]{footmisc}
\providecommand*{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
\renewcommand{\footnotelayout}{\@tufte@marginfont\@tufte@justification}

% Override footmisc's definition to set the sidenote marks (numbers) inside the
% sidenote's text block.
\long\def\@makefntext#1{\@textsuperscript{\@tufte@marginfont\tiny\@thefnmark}\,\footnotelayout#1}

% Set the in-text footnote mark in the same typeface as the body text itself.
\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\scriptsize\@thefnmark}}}

\let\sidenote\footnote

%%
% Sidenote without the footnote mark

\providecommand\marginnote[1]%
  {\marginpar{\@tufte@marginfont\@tufte@justification #1}}

%%
% Citations should go in the margin as well

\RequirePackage{natbib}
\RequirePackage{bibentry}	% allows bibitems to be typeset outside thebibliography environment
\nobibliography*		% pre-loads the bibliography keys
\providecommand{\doi}[1]{\textsc{doi:} #1} % pre-defining this so it may be used before the \bibliography command it issued
\renewcommand{\cite}[1]{%
  \@for\@temp@bibkey:=#1\do{%
    \sidenote{\bibentry{\@temp@bibkey}.}%
  }
}

% TODO: Combine sequences of citations so that 2,3,4,6 becomes 2--4,6
%       but be careful of hyperref interaction

%%
% The placeins package provides the \FloatBarrier command.  This forces
% LaTeX to place all of the floats before proceeding.  We'll use this to
% keep the float (figure and table) numbers in sequence.
\RequirePackage{placeins}

%%
% Margin figure environment

\newsavebox{\@tufte@marginfigbox}
\newenvironment{marginfigure}[1]
    [-1.2ex]
    {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
    \begin{lrbox}{\@tufte@marginfigbox}
    \begin{minipage}{\marginparwidth}
        \@tufte@marginfont
        \def\@captype{figure}
        \vspace*{#1}
        \@tufte@justification
    }    
    {\end{minipage}%
     \end{lrbox}%
     \marginpar{\usebox{\@tufte@marginfigbox}}}


%%
% Margin table environment
\newsavebox{\@tufte@margintablebox}
\newenvironment{margintable}[1]
   [-1.2ex]
   {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
   \begin{lrbox}{\@tufte@margintablebox}
   \begin{minipage}{\marginparwidth}
       \@tufte@marginfont
       \def\@captype{table}
       \vspace*{#1}
       \@tufte@justification
   }
   {\end{minipage}%
    \end{lrbox}%
    \marginpar{\usebox{\@tufte@margintablebox}}}


%%
% Full-width figure

\renewenvironment{figure*}[1]%
  [htbp]%
  {\@float{figure}[#1]%
   \ifthenelse{\boolean{@tufte@symmetric}}
     {\begin{adjustwidth}[]{}{-\@tufte@overhang}}
     {\begin{adjustwidth}{}{-\@tufte@overhang}}
   \begin{minipage}{\linewidth}}%
  {\end{minipage}%
   \end{adjustwidth}%
   \end@float}

%%
% Full-width table

\renewenvironment{table*}[1]
  [htbp]%
  {\@float{table}[#1]%
   \ifthenelse{\boolean{@tufte@symmetric}}
     {\begin{adjustwidth}[]{}{-\@tufte@overhang}}
     {\begin{adjustwidth}{}{-\@tufte@overhang}}
   \begin{minipage}{\linewidth}}%
  {\end{minipage}%
   \end{adjustwidth}%
   \end@float}

%%
% Full-page-width area

\newenvironment{fullwidth}
  {\ifthenelse{\boolean{@tufte@symmetric}}
     {\begin{adjustwidth}[]{}{-\@tufte@overhang}}
     {\begin{adjustwidth}{}{-\@tufte@overhang}}
  }
  {\end{adjustwidth}}

%%
% Format the captions in a style similar to the sidenotes

\RequirePackage[format=default,font={rm,scriptsize},justification=raggedright,singlelinecheck=false]{caption}

% if the `sfsidenotes' option is specified, set the captions in sf, too.
\ifthenelse{\boolean{@tufte@sfsidenotes}}
  {\captionsetup{font={sf,scriptsize}}}
  {\captionsetup{font={rm,scriptsize}}}

% if the `justified' option is specified, set the captions in flush left
% and flush right
\ifthenelse{\boolean{@tufte@justified}}
  {\captionsetup{justification=justified}}
  {\captionsetup{justification=raggedright}}

%%
% If the Palatino typeface (and its math symbol set) are installed, load
% them unless the `nofonts' class option was provided, or if we're
% compiling with XeLaTeX.

\ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  \IfFileExists{palatino.sty}{%
    \RequirePackage{palatino}
    \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
  }{} % if the Palatino typefaces aren't found, do nothing.
}{}


%%
% If the Bera Mono typeface is available, use it unless the `nofonts' class
% option was provided, or if we're compiling with XeLaTeX.

\ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  \IfFileExists{beramono.sty}{%
    \RequirePackage[T1]{fontenc}
    \RequirePackage[scaled=0.85]{beramono}
  }{}
}{}


%%
% Sets up the running heads and folios.

\RequirePackage{fancyhdr}

% Set the default page style to 'fancy'
\pagestyle{fancy}

% Set the header/footer width to be the body text block plus the margin
% note area.
\ifthenelse{\boolean{@tufte@symmetric}}
  {\fancyhfoffset[LE,RO]{\@tufte@overhang}}
  {\fancyhfoffset[RE,RO]{\@tufte@overhang}}

% The running heads/feet don't have rules
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

% The 'fancy' page style is the default style for all pages.
\fancyhf{} % clear header and footer fields
\ifthenelse{\boolean{@tufte@twoside}}
  {\fancyhead[LE]{\thepage\quad\smallcaps{\theauthor}}%
    \fancyhead[RO]{\smallcaps{\thetitle}\quad\thepage}}
  {\fancyhead[RE,RO]{\smallcaps{\thetitle}\quad\thepage}}


% The `plain' page style is used on chapter opening pages.
% In Tufte's /Beautiful Evidence/ he never puts page numbers at the
% bottom of pages -- the folios are unexpressed.
\fancypagestyle{plain}{
  \fancyhf{} % clear header and footer fields
  % Uncomment the following five lines of code if you want the opening page
  % of the chapter to express the folio in the lower outside corner.
  %\ifthenelse{\boolean{@tufte@twoside}}
  %  {\fancyfoot[LE,RO]{\thepage}}
  %  {\fancyfoot[RE,RO]{\thepage}}
}

% The `empty' page style suppresses all headers and footers.
% It's used on title pages and `intentionally blank' pages.
\fancypagestyle{empty}{
  \fancyhf{} % clear header and footer fields
}




%%
% Set raggedright and paragraph indentation for document

\AtBeginDocument{\@tufte@justification\setlength\parindent{1em}}


%%
% Prints the list of class options and their states.

\newcommand{\typeoutbool}[2]{%
  \ifthenelse{\boolean{#2}}
    {\typeout{#1: true}}
    {\typeout{#1: false}}
}

\newcommand{\PrintTufteSettings}{%
  \typeout{-------------------- Tufte-LaTeX settings ----------}
  \typeoutbool{a4paper}{@tufte@afourpaper}
  \typeoutbool{load fonts}{@tufte@loadfonts}
  \typeoutbool{fully-justified}{@tufte@justified}
  \typeoutbool{letterspacing}{@tufte@letterspace}
  \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes}
  \typeoutbool{symmetric margins}{@tufte@symmetric}
  \typeoutbool{titlepage}{@tufte@titlepage}
  \typeout{----------------------------------------------------}
}



%%
% Color
\RequirePackage{xcolor}

%%
% Produces a full title page

\newcommand{\maketitlepage}[0]{%
  \cleardoublepage
  {
  \sffamily
  \begin{fullwidth}
  \par\noindent\fontsize{18}{18}\selectfont\textcolor{darkgray}{\allcaps{\thanklessauthor}}
  \end{fullwidth}

  \vspace{11.5pc}
  \begin{fullwidth}
  \par\noindent\fontsize{36}{36}\selectfont\textcolor{darkgray}{\allcaps{\thanklesstitle}}
  \end{fullwidth}

  \vfill
  \begin{fullwidth}
  \par\noindent\fontsize{14}{14}\selectfont\allcaps{\thanklesspublisher}
  \end{fullwidth}
  }
  \thispagestyle{empty}
  \clearpage
}

%%
% Title block

\renewcommand{\maketitle}{%
  \newpage
  \global\@topnum\z@% prevent floats from being placed at the top of the page
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{4pt}
  \ifthenelse{\boolean{@tufte@sfsidenotes}}
    {\begingroup
      % FIXME fails with \thanks
      \sffamily
      \par{\Large\allcaps{\@title}}
      \par{\large\allcaps{\@author}}
      \par{\large\allcaps{\@date}}
    \endgroup}
    {\begingroup
      \par{\Large\textit{\@title}}
      \par{\large\textit{\@author}}
      \par{\large\textit{\@date}}
    \endgroup}
  \thispagestyle{plain}% suppress the running head
}


%%
% Title page (if the `titlepage' option was passed to the tufte-handout
% class.)

\ifthenelse{\boolean{@tufte@titlepage}}
  {\renewcommand{\maketitle}{\maketitlepage}}
  {}

%%
% When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
% without headers and footers
\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
  \hbox{}
  %\vspace*{\fill}
  %\begin{center}
  %  This page intentionally contains only this sentence.
  %\end{center}
  %\vspace{\fill}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}

%%
% Make Tuftian-style section headings and TOC formatting

\RequirePackage{titlesec,titletoc}

% TODO: I'd prefer to use the 'titlesec' package for this formatting, but
%       I'll do it old-style for now.  --Kevin

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\large\it}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\it}}

% Subsubsection and following section headings shouldn't be used.
% See Bringhurst's _The Elements of Typography_, section 4.2.2.
\renewcommand\subsubsection{%
  \PackageError{\@tufte@pkgname}{\noexpand\subsubsection is undefined by this class.%
    \MessageBreak See Robert Bringhurst's _The Elements of 
    \MessageBreak Typographic Style_, section 4.2.2.
    \MessageBreak \noexpand\subsubsection was used}
    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as 
    \MessageBreak many levels of headings as you need, no more and no fewer.  Also see the many 
    \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
}

\renewcommand\paragraph{%
  \PackageError{\@tufte@pkgname}{\noexpand\paragraph is undefined by this class.%
    \MessageBreak See Robert Bringhurst's _The Elements of 
    \MessageBreak Typographic Style_, section 4.2.2.
    \MessageBreak \noexpand\paragraph was used}
    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as 
    \MessageBreak many levels of headings as you need, no more and no fewer.  Also see the many 
    \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
}

\renewcommand\subparagraph{%
  \PackageError{\@tufte@pkgname}{\noexpand\subparagraph is undefined by this class.%
    \MessageBreak See Robert Bringhurst's _The Elements of 
    \MessageBreak Typographic Style_, section 4.2.2.
    \MessageBreak \noexpand\subparagraph was used}
    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as 
    \MessageBreak many levels of headings as you need, no more and no fewer.  Also see the many 
    \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
}


% Formatting for main TOC (printed in front matter)
% {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
\titlecontents{chapter}%
        [0em] % distance from left margin
        {\begin{fullwidth}\fontsize{13pt}{18pt}\selectfont} % above (global formatting of entry)
        {\contentslabel{2em}\rm\itshape} % before w/label (label = ``Chapter 1'')
        {\rm\itshape} % before w/o label
        {\rm\qquad\thecontentspage} % filler + page (leaders and page num)
        [\vspace{1.5\baselineskip}\end{fullwidth}] % after

%\titlecontents{chapter}%
%	[0em]% distance from left margin
%	{\fontsize{12pt}{18pt}\selectfont}% above (global formatting of entry)
%	{\textit}% before w/ label (label = ``Chapter 1'')
%	{\textit}% before w/o label
%	{\qquad\thecontentspage}% filler and page (leaders and page num)
%	[\vspace{1.5\baselineskip}]% after

\titleformat{\chapter}%
	[display]% shape
        {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
        {\itshape\fontsize{22}{24}\selectfont\thechapter}% label
        {0pt}% horizontal separation between label and title body
        {\fontsize{22}{24}\rm\itshape}% before the title body
        [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body




%%
% A handy command to disable hyphenation for short bits of text.
% Borrowed from Peter Wilson's `hyphenat' package.

\newlanguage\langwohyphens% define a language without hyphenation rules
\newcommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text
\newcommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text


%%
% If debugging is enabled, print the Tufte-LaTeX options and the list of
% files.

\ifthenelse{\boolean{@tufte@debug}}
  {\PrintTufteSettings\listfiles}
  {}


%%
% If there is a `tufte-common-local.sty' file, load it up.

\IfFileExists{tufte-common-local.sty}
  {\RequirePackage{tufte-common-local.sty}}
  {}


%%
% End of file
\endinput

