1%%
2%% This file contains the code that is common to the Tufte-LaTeX document classes.
3%%
4
5\ProvidesFile{tufte-common.def}[2015/06/21 v3.5.2 Common code for the Tufte-LaTeX styles]
6
7%%
8% The `xkeyval' package simplifies the user interface for the document class options
9\RequirePackage{xkeyval}
10
11%%
12% We use the `xifthen' package to handle our package option switches
13\RequirePackage{xifthen}
14
15%%
16% Define some shortcut macros for error/warning/info logging.
17\RequirePackage{hardwrap}
18\GenerateClassLogMacros[@tufte]{\@tufte@pkgname}
19\newcommand{\@tufte@debug@info}[1]{\ifthenelse{\boolean{@tufte@debug}}{\@tufte@info{#1}}{}}
20\newcommand{\@tufte@debug@info@noline}[1]{\ifthenelse{\boolean{@tufte@debug}}{\@tufte@info@noline{#1}}{}}
21
22%%
23% `debug' option -- provides more information in the .log file for use in
24% troubleshooting problems
25\newboolean{@tufte@debug}
26\DeclareOptionX[tufte]<common>{debug}{\setboolean{@tufte@debug}{true}}
27
28%%
29% `nofonts' option -- doesn't load any fonts
30% `fonts' option -- tries to load fonts
31\newboolean{@tufte@loadfonts}\setboolean{@tufte@loadfonts}{true}
32\DeclareOptionX[tufte]<common>{fonts}{\setboolean{@tufte@loadfonts}{true}}
33\DeclareOptionX[tufte]<common>{nofonts}{\setboolean{@tufte@loadfonts}{false}}
34
35%%
36% `nols' option -- doesn't configure letterspacing
37% `ls' option -- configures letterspacing
38\newboolean{@tufte@letterspace}\setboolean{@tufte@letterspace}{true}
39\DeclareOptionX[tufte]<common>{ls}{\setboolean{@tufte@letterspace}{true}}
40\DeclareOptionX[tufte]<common>{nols}{\setboolean{@tufte@letterspace}{false}}
41
42%%
43% `nobib' option -- doesn't load natbib or adjust the \cite command
44\newboolean{@tufte@loadnatbib}\setboolean{@tufte@loadnatbib}{true}
45\DeclareOptionX[tufte]<common>{nobib}{\setboolean{@tufte@loadnatbib}{false}}
46
47%%
48% `titlepage' option -- creates a full title page with \maketitle
49
50\newboolean{@tufte@titlepage}
51\DeclareOptionX[tufte]<common>{titlepage}{\setboolean{@tufte@titlepage}{true}}
52\DeclareOptionX[tufte]<common>{notitlepage}{\setboolean{@tufte@titlepage}{false}}
53
54%%
55% `a4paper' option
56
57\newboolean{@tufte@afourpaper}
58\DeclareOptionX[tufte]<common>{a4paper}{\setboolean{@tufte@afourpaper}{true}}
59
60%%
61% `b5paper' option
62
63\newboolean{@tufte@bfivepaper}
64\DeclareOptionX[tufte]<common>{b5paper}{\setboolean{@tufte@bfivepaper}{true}}
65
66%%
67% `sfsidenotes' option -- typesets sidenotes in sans serif typeface
68
69\newboolean{@tufte@sfsidenotes}
70\DeclareOptionX[tufte]<common>{sfsidenotes}{\setboolean{@tufte@sfsidenotes}{true}}
71
72%%
73% `symmetric' option -- puts marginpar space to the outside edge of the page
74%   Note: this option forces the twoside option (see the .cls files)
75
76\newboolean{@tufte@symmetric}
77\DeclareOptionX[tufte]<common>{symmetric}{
78  \setboolean{@tufte@symmetric}{true}
79  \@tufte@info@noline{The `symmetric' option implies `twoside'}
80  \ExecuteOptionsX[tufte]<common>{twoside}
81}
82
83%%
84% `twoside' option -- alternates running heads
85
86\newboolean{@tufte@twoside}
87\DeclareOptionX[tufte]<common>{twoside}{%
88  \setboolean{@tufte@twoside}{true}
89  \@tufte@info@noline{Passing the `twoside' option to the `\@tufte@class' class}
90  \PassOptionsToClass{twoside}{\@tufte@class}
91}
92
93%%
94% `notoc' option -- suppresses the Tufte-style table of contents
95
96\newboolean{@tufte@toc}
97\setboolean{@tufte@toc}{true}
98\DeclareOptionX[tufte]<common>{notoc}{\setboolean{@tufte@toc}{false}}
99\DeclareOptionX[tufte]<common>{toc}{\setboolean{@tufte@toc}{true}}
100
101%%
102% `justified' option -- uses fully justified text (flush left and flush
103% right) instead of ragged right.
104
105\newboolean{@tufte@justified}
106\DeclareOptionX[tufte]<common>{justified}{\setboolean{@tufte@justified}{true}}
107
108%%
109% `bidi' option -- loads the bidi package for bi-directional text
110
111\newboolean{@tufte@loadbidi}
112\DeclareOptionX[tufte]<common>{bidi}{\setboolean{@tufte@loadbidi}{true}}
113\DeclareOptionX[tufte]<common>{nobidi}{\setboolean{@tufte@loadbidi}{false}}
114
115%%
116% `nohyper' option -- suppresses loading of the hyperref package
117
118\newboolean{@tufte@loadhyper}
119\setboolean{@tufte@loadhyper}{true}
120\DeclareOptionX[tufte]<common>{hyper}{\setboolean{@tufte@loadhyper}{true}}
121\DeclareOptionX[tufte]<common>{nohyper}{\setboolean{@tufte@loadhyper}{false}}
122
123%%
124% `sidenote', `marginnote', `caption', `citation', `marginals' options
125% Each allows one of {justified,raggedleft,raggedright,raggedouter,auto}.
126
127\newcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect}
128\define@choicekey*+[tufte]{common}{sidenote}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{%
129  \ifcase\@tufte@kvnum\relax
130    \renewcommand*{\@tufte@sidenote@justification}{\justifying}% justified
131  \or
132    \renewcommand*{\@tufte@sidenote@justification}{\RaggedLeft}% ragged left
133  \or
134    \renewcommand*{\@tufte@sidenote@justification}{\RaggedRight}% ragged right
135  \or
136    \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages)
137  \or
138    \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
139  \fi
140}{%
141  \@tufte@warning@noline{Invalid option `#1' for sidenote key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto}
142  \renewcommand*{\@tufte@sidenote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
143}
144
145\newcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect}
146\define@choicekey*+[tufte]{common}{marginnote}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{%
147  \ifcase\@tufte@kvnum\relax
148    \renewcommand*{\@tufte@marginnote@justification}{\justifying}% justified
149  \or
150    \renewcommand*{\@tufte@marginnote@justification}{\RaggedLeft}% ragged left
151  \or
152    \renewcommand*{\@tufte@marginnote@justification}{\RaggedRight}% ragged right
153  \or
154    \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages)
155  \or
156    \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
157  \fi
158}{%
159  \@tufte@warning@noline{Invalid option `#1' for marginnote key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto}
160  \renewcommand*{\@tufte@marginnote@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
161}
162
163\newcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect}
164\define@choicekey*+[tufte]{common}{caption}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{%
165  \ifcase\@tufte@kvnum\relax
166    \renewcommand*{\@tufte@caption@justification}{\justifying}% justified
167  \or
168    \renewcommand*{\@tufte@caption@justification}{\RaggedLeft}% ragged left
169  \or
170    \renewcommand*{\@tufte@caption@justification}{\RaggedRight}% ragged right
171  \or
172    \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@caption@outer}% ragged outer (flush right on verso pages, flush left on recto pages)
173  \or
174    \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
175  \fi
176}{%
177  \@tufte@warning@noline{Invalid option `#1' for caption key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto}
178  \renewcommand*{\@tufte@caption@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
179}
180
181\newcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect}
182\define@choicekey*+[tufte]{common}{citation}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{%
183  \ifcase\@tufte@kvnum\relax
184    \renewcommand*{\@tufte@citation@justification}{\justifying}% justified
185  \or
186    \renewcommand*{\@tufte@citation@justification}{\RaggedLeft}% ragged left
187  \or
188    \renewcommand*{\@tufte@citation@justification}{\RaggedRight}% ragged right
189  \or
190    \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@outer}% ragged outer (flush right on verso pages, flush left on recto pages)
191  \or
192    \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
193  \fi
194}{%
195  \@tufte@warning@noline{Invalid option `#1' for citation key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto}
196  \renewcommand*{\@tufte@citation@justification}{\@tufte@justification@autodetect}% autodetects best justification mode based on all class options
197}
198
199% The ``marginals'' key simultaneously sets the same justification for all marginal material
200\define@choicekey*+[tufte]{common}{marginals}[\@tufte@kvtext\@tufte@kvnum]{justified,raggedleft,raggedright,raggedouter,auto}[auto]{%
201  \ifcase\@tufte@kvnum\relax
202    \ExecuteOptionsX[tufte]<common>{citation=justified,sidenote=justified,caption=justified,marginnote=justified}% justified
203  \or
204    \ExecuteOptionsX[tufte]<common>{citation=raggedleft,sidenote=raggedleft,caption=raggedleft,marginnote=raggedleft}% ragged left
205  \or
206    \ExecuteOptionsX[tufte]<common>{citation=raggedright,sidenote=raggedright,caption=raggedright,marginnote=raggedright}% ragged right
207  \or
208    \ExecuteOptionsX[tufte]<common>{citation=raggedouter,sidenote=raggedouter,caption=raggedouter,marginnote=raggedouter}% ragged outer (flush right on verso pages, flush left on recto pages)
209  \or
210    \ExecuteOptionsX[tufte]<common>{citation=auto,sidenote=auto,caption=auto,marginnote=auto}% autodetects best justification mode based on all class options
211  \fi
212}{%
213  \@tufte@warning@noline{Invalid option `#1' for marginals key. Must be one of: justified, raggedleft, raggedright, raggedouter, auto}
214  \ExecuteOptionsX[tufte]<common>{citation=auto,sidenote=auto,caption=auto,marginnote=auto}% autodetects best justification mode based on all class options
215}
216
217
218%%
219% Unsupported options
220
221\newcommand{\@tufte@unsupported@option}[1]{\@tufte@warning@noline{Option `#1' is not supported -- ignoring option}\OptionNotUsed}
222
223\DeclareOptionX[tufte]<common>{10pt}{\@tufte@unsupported@option{\CurrentOption}}
224\DeclareOptionX[tufte]<common>{11pt}{\@tufte@unsupported@option{\CurrentOption}}
225\DeclareOptionX[tufte]<common>{12pt}{\@tufte@unsupported@option{\CurrentOption}}
226\DeclareOptionX[tufte]<common>{a5paper}{\@tufte@unsupported@option{\CurrentOption}}
227\DeclareOptionX[tufte]<common>{executivepaper}{\@tufte@unsupported@option{\CurrentOption}}
228\DeclareOptionX[tufte]<common>{legalpaper}{\@tufte@unsupported@option{\CurrentOption}}
229\DeclareOptionX[tufte]<common>{landscape}{\@tufte@unsupported@option{\CurrentOption}}
230\DeclareOptionX[tufte]<common>{onecolumn}{\@tufte@unsupported@option{\CurrentOption}}
231\DeclareOptionX[tufte]<common>{twocolumn}{\@tufte@unsupported@option{\CurrentOption}}
232
233%%
234% Default `book' and `handout' options
235
236\ifthenelse{\equal{\@tufte@pkgname}{tufte-book}}
237  {\ExecuteOptionsX[tufte]<common>{titlepage}}
238  {\ExecuteOptionsX[tufte]<common>{notitlepage}}
239
240
241\DeclareOptionX*{%
242  \@tufte@info@noline{Passing \CurrentOption\space to the `\@tufte@class' class.}%
243  \PassOptionsToClass{\CurrentOption}{\@tufte@class}%
244}
245\ProcessOptionsX*[tufte]<common>\relax
246
247%%
248% Load the appropriate base class
249\@tufte@info@noline{Loading the base class `\@tufte@class'}
250\LoadClass{\@tufte@class}
251
252%%
253% Detect whether we're in two-side mode or not.  (Used to set up running
254% heads later.)
255
256\ifthenelse{\boolean{@twoside}}
257  {\setboolean{@tufte@twoside}{true}}
258  {}
259
260
261
262%%
263% Detect if we're using pdfLaTeX
264
265\newboolean{@tufte@pdf}
266\IfFileExists{ifpdf.sty}{%
267  \RequirePackage{ifpdf}
268  \ifthenelse{\boolean{pdf}}
269    {\setboolean{@tufte@pdf}{true}}
270    {\setboolean{@tufte@pdf}{false}}
271}{% assume we're not using pdfTex?
272  \setboolean{@tufte@pdf}{false}
273}
274
275%%
276% Detect if we're using XeLaTeX
277
278\newboolean{@tufte@xetex}
279\IfFileExists{ifxetex.sty}{%
280  \RequirePackage{ifxetex}
281  \ifthenelse{\boolean{xetex}}
282    {\setboolean{@tufte@xetex}{true}}
283    {\setboolean{@tufte@xetex}{false}}
284}{% not using xelatex
285  \setboolean{@tufte@xetex}{false}
286}
287
288\ifthenelse{\boolean{@tufte@xetex}}{%
289  \RequirePackage{xltxtra}% xltxtra loads xunicode and fontspec; must be loaded before bidi
290}{}
291
292%%
293% Detect if we're using LuaTeX
294
295\newboolean{@tufte@luatex}
296\IfFileExists{ifluatex.sty}{%
297  \RequirePackage{ifluatex}
298  \ifthenelse{\boolean{luatex}}
299    {\setboolean{@tufte@luatex}{true}}
300    {\setboolean{@tufte@luatex}{false}}
301}{% not using luatex
302  \setboolean{@tufte@luatex}{false}
303}
304
305\ifthenelse{\boolean{@tufte@luatex}}{%
306  \RequirePackage{fontspec}
307  \RequirePackage[osf,sc]{mathpazo}
308  \setmainfont[Renderer=Basic, Numbers=OldStyle, Scale = 1.0]{TeX Gyre Pagella}
309  \setsansfont[Renderer=Basic, Scale=0.90]{TeX Gyre Heros}
310  \setmonofont[Renderer=Basic]{TeX Gyre Cursor}
311}{}
312
313%%
314% Globally sets the length
315
316\newcommand*{\gsetlength}[2]{%
317  \setlength{#1}{#2}%
318  \global#1=#1\relax%
319}
320
321%%
322% Globally sets a boolean
323
324\newcommand*{\gsetboolean}[2]{% based on code from ifthen pkg
325  \lowercase{\def\@tempa{#2}}%
326  \@ifundefined{@tempswa\@tempa}%
327    {\PackageError{ifthen}{You can only set a boolean to `true' or `false'}\@ehc}%
328    {\@ifundefined{#1\@tempa}%
329      {\PackageError{ifthen}{Boolean #1 undefined}\@ehc}%
330      {\global\csname#1\@tempa\endcsname}%
331    }%
332}
333
334%%
335% The titlesec and titletoc packages are used to change the style of the
336% section headings.  These packages should be loaded before the hyperref
337% package.
338
339\RequirePackage{titlesec,titletoc}
340
341%%%
342%% Loads the hyperref package and sets some default options.
343
344\newcommand{\TufteLoadHyperref}{%
345  \ifthenelse{\boolean{@tufte@xetex}}
346    {\RequirePackage[unicode,hyperfootnotes=false,xetex]{hyperref}}
347    {\RequirePackage[unicode,hyperfootnotes=false]{hyperref}}
348  \hypersetup{%
349    pdfborder = {0 0 0},
350    bookmarksdepth = section,
351    citecolor = DarkGreen,
352    linkcolor = DarkBlue,
353    urlcolor = DarkGreen,
354  }%
355}
356
357%%%
358%% Load the `hyperref' package.
359
360\ifthenelse{\boolean{@tufte@loadhyper}}{%
361  \TufteLoadHyperref%
362}{% hyperfootnotes override our modifications to the \footnote* and \@footnote* commands.
363  \PassOptionsToPackage{hyperfootnotes=false}{hyperref}
364}
365
366%%
367% Set the font sizes and baselines to match Tufte's books
368\renewcommand\normalsize{%
369   \@setfontsize\normalsize\@xpt{14}%
370   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
371   \abovedisplayshortskip \z@ \@plus3\p@
372   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
373   \belowdisplayskip \abovedisplayskip
374   \let\@listi\@listI}
375\normalbaselineskip=14pt
376\normalsize
377\renewcommand\small{%
378   \@setfontsize\small\@ixpt{12}%
379   \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
380   \abovedisplayshortskip \z@ \@plus2\p@
381   \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
382   \def\@listi{\leftmargin\leftmargini
383               \topsep 4\p@ \@plus2\p@ \@minus2\p@
384               \parsep 2\p@ \@plus\p@ \@minus\p@
385               \itemsep \parsep}%
386   \belowdisplayskip \abovedisplayskip
387}
388\renewcommand\footnotesize{%
389   \@setfontsize\footnotesize\@viiipt{10}%
390   \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
391   \abovedisplayshortskip \z@ \@plus\p@
392   \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
393   \def\@listi{\leftmargin\leftmargini
394               \topsep 3\p@ \@plus\p@ \@minus\p@
395               \parsep 2\p@ \@plus\p@ \@minus\p@
396               \itemsep \parsep}%
397   \belowdisplayskip \abovedisplayskip
398}
399\renewcommand\scriptsize{\@setfontsize\scriptsize\@viipt\@viiipt}
400\renewcommand\tiny{\@setfontsize\tiny\@vpt\@vipt}
401\renewcommand\large{\@setfontsize\large\@xipt{15}}
402\renewcommand\Large{\@setfontsize\Large\@xiipt{16}}
403\renewcommand\LARGE{\@setfontsize\LARGE\@xivpt{18}}
404\renewcommand\huge{\@setfontsize\huge\@xxpt{30}}
405\renewcommand\Huge{\@setfontsize\Huge{24}{36}}
406
407\setlength\leftmargini   {1pc}
408\setlength\leftmarginii  {1pc}
409\setlength\leftmarginiii {1pc}
410\setlength\leftmarginiv  {1pc}
411\setlength\leftmarginv   {1pc}
412\setlength\leftmarginvi  {1pc}
413\setlength\labelsep      {.5pc}
414\setlength\labelwidth    {\leftmargini}
415\addtolength\labelwidth{-\labelsep}
416
417%%
418% \RaggedRight allows hyphenation
419
420\setlength{\parindent}{1.0pc}%
421\setlength{\parskip}{0pt}%
422\RequirePackage{ragged2e}
423\setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize}
424
425% Paragraph indentation and separation for normal text
426\newcommand{\@tufte@reset@par}{%
427  \setlength{\RaggedRightParindent}{1.0pc}%
428  \setlength{\JustifyingParindent}{1.0pc}%
429  \setlength{\parindent}{1pc}%
430  \setlength{\parskip}{0pt}%
431}
432\@tufte@reset@par
433
434% Paragraph indentation and separation for marginal text
435\newcommand{\@tufte@margin@par}{%
436  \setlength{\RaggedRightParindent}{0.5pc}%
437  \setlength{\JustifyingParindent}{0.5pc}%
438  \setlength{\parindent}{0.5pc}%
439  \setlength{\parskip}{0pt}%
440}
441
442
443%%
444% Set page layout geometry
445
446\RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
447
448\ifthenelse{\boolean{@tufte@afourpaper}}
449  {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
450  {}
451
452\ifthenelse{\boolean{@tufte@bfivepaper}}
453  {\geometry{paperwidth=176mm,paperheight=250mm,left=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
454  {}
455
456\ifthenelse{\boolean{@tufte@symmetric}}
457  {}
458  {\geometry{asymmetric}}% forces internal LaTeX `twoside'
459
460
461%%
462% Separation marginpars by a line's worth of space.
463
464\setlength\marginparpush{10pt}
465
466%%
467% Font for margin items
468
469\ifthenelse{\boolean{@tufte@sfsidenotes}}
470  {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize\sffamily}}
471  {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize}}
472
473\newcommand*{\@tufte@sidenote@font}{\@tufte@marginfont}
474\newcommand*{\@tufte@caption@font}{\@tufte@marginfont}
475\newcommand*{\@tufte@marginnote@font}{\@tufte@marginfont}
476\newcommand*{\@tufte@citation@font}{\@tufte@marginfont}
477
478\newcommand*{\setsidenotefont}[1]{\renewcommand*{\@tufte@sidenote@font}{#1}}
479\newcommand*{\setcaptionfont}[1]{\renewcommand*{\@tufte@caption@font}{#1}}
480\newcommand*{\setmarginnotefont}[1]{\renewcommand*{\@tufte@marginnote@font}{#1}}
481\newcommand*{\setcitationfont}[1]{\renewcommand*{\@tufte@citation@font}{#1}}
482
483%%
484% Set the justification baesed on the `justified' class option
485
486\newcommand{\@tufte@justification}{%
487  \ifthenelse{\boolean{@tufte@justified}}%
488    {\justifying}%
489    {\RaggedRight}%
490}
491
492%%
493% Turn off section numbering
494
495\setcounter{secnumdepth}{-1}
496
497%%
498% Tighten up space between displays (e.g., a figure or table) and make symmetric
499
500\setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
501\setlength\belowdisplayskip{6pt plus 2pt minus 4pt}
502
503%%
504% To implement full-width display environments
505
506\newboolean{@tufte@changepage}
507\IfFileExists{changepage.sty}{%
508  \@tufte@debug@info@noline{Found changepage.sty}
509  \RequirePackage[strict]{changepage}
510  \setboolean{@tufte@changepage}{true}
511}{%
512  \@tufte@debug@info@noline{Found chngpage.sty}
513  \RequirePackage[strict]{chngpage}
514  \setboolean{@tufte@changepage}{false}
515}
516
517% Write our own aliases for the \checkoddpage and \ifoddpage or \ifcpoddpage commands
518\newboolean{@tufte@odd@page}
519\setboolean{@tufte@odd@page}{true}
520\newcommand*{\@tufte@checkoddpage}{%
521  \checkoddpage%
522  \ifthenelse{\boolean{@tufte@changepage}}{%
523    \ifoddpage%
524      \setboolean{@tufte@odd@page}{true}%
525    \else%
526      \setboolean{@tufte@odd@page}{false}%
527    \fi%
528  }{%
529    \ifcpoddpage%
530      \setboolean{@tufte@odd@page}{true}%
531    \else%
532      \setboolean{@tufte@odd@page}{false}%
533    \fi%
534  }%
535}
536
537%%
538% Compute lengths used for full-width displays
539
540\newlength{\@tufte@overhang}% used by the fullwidth environment and the running heads
541\newlength{\@tufte@fullwidth}
542\newlength{\@tufte@caption@fill}
543
544\newcommand{\TufteRecalculate}{%
545  \setlength{\@tufte@overhang}{\marginparwidth}
546  \addtolength{\@tufte@overhang}{\marginparsep}
547
548  \setlength{\@tufte@fullwidth}{\textwidth}
549  \addtolength{\@tufte@fullwidth}{\marginparsep}
550  \addtolength{\@tufte@fullwidth}{\marginparwidth}
551
552  \setlength{\@tufte@caption@fill}{\textwidth}
553  \addtolength{\@tufte@caption@fill}{\marginparsep}
554}
555
556\AtBeginDocument{\TufteRecalculate}
557
558%%
559% Modified \title, \author, and \date commands.  These store the
560% (footnote-less) values in \plaintitle, \plainauthor, and \thedate, respectively.
561
562\newcommand{\plaintitle}{}%     plain-text-only title
563\newcommand{\plainauthor}{}%    plain-text-only author
564\newcommand{\plainpublisher}{}% plain-text-only publisher
565
566\newcommand{\thanklesstitle}{}%     full title text minus \thanks{}
567\newcommand{\thanklessauthor}{}%    full author text minus \thanks{}
568\newcommand{\thanklesspublisher}{}% full publisher minus \thanks{}
569
570\newcommand{\@publisher}{}% full publisher with \thanks{}
571\newcommand{\thedate}{\today}
572
573% TODO Fix it so that \thanks is not spaced out (with `soul') and can be
574% used in \maketitle when the `sfsidenotes' option is provided.
575\renewcommand{\thanks}[1]{\NoCaseChange{\footnote{#1}}}
576
577\renewcommand{\title}[2][]{%
578  \gdef\@title{#2}%
579  \begingroup%
580    % TODO store contents of \thanks command
581    \renewcommand{\thanks}[1]{}% swallow \thanks contents
582    \protected@xdef\thanklesstitle{#2}%
583  \endgroup%
584  \ifthenelse{\isempty{#1}}%
585    {\renewcommand{\plaintitle}{\thanklesstitle}}% use thankless title
586    {\renewcommand{\plaintitle}{#1}}% use provided plain-text title
587  \ifthenelse{\isundefined{\hypersetup}}%
588    {}% hyperref is not loaded; do nothing
589    {\hypersetup{pdftitle={\plaintitle}}}% set the PDF metadata title
590}
591
592\let\@author\@empty% suppress default latex.ltx ``no author'' warning
593\renewcommand{\author}[2][]{%
594  \ifthenelse{\isempty{#2}}{}{\gdef\@author{#2}}%
595  \begingroup%
596    % TODO store contents of \thanks command
597    \renewcommand{\thanks}[1]{}% swallow \thanks contents
598    \protected@xdef\thanklessauthor{#2}%
599  \endgroup%
600  \ifthenelse{\isempty{#1}}%
601    {\renewcommand{\plainauthor}{\thanklessauthor}}% use thankless author
602    {\renewcommand{\plainauthor}{#1}}% use provided plain-text author
603  \ifthenelse{\isundefined{\hypersetup}}%
604    {}% hyperref is not loaded; do nothing
605    {\hypersetup{pdfauthor={\plainauthor}}}% set the PDF metadata author
606}
607
608\renewcommand{\date}[1]{%
609  \gdef\@date{#1}%
610  \begingroup%
611    % TODO store contents of \thanks command
612    \renewcommand{\thanks}[1]{}% swallow \thanks contents
613    \protected@xdef\thedate{#1}%
614  \endgroup%
615}
616
617%%
618% Provides a \publisher command to set the publisher
619
620\newcommand{\publisher}[2][]{%
621  \gdef\@publisher{#2}%
622  \begingroup%
623    \renewcommand{\thanks}[1]{}% swallow \thanks contents
624    \protected@xdef\thanklesspublisher{#2}%
625  \endgroup%
626  \ifthenelse{\isempty{#1}}
627    {\renewcommand{\plainpublisher}{\thanklesspublisher}}% use thankless publisher
628    {\renewcommand{\plainpublisher}{#1}}% use provided plain-text publisher
629}
630
631% TODO: Test \hypersetup{pdfauthor,pdftitle} with DVI and XeTeX
632
633%%
634% Require paralist package for tighter lists
635
636\RequirePackage{paralist}
637
638% Add rightmargin to compactenum
639
640\def\@compactenum@{%
641  \expandafter\list\csname label\@enumctr\endcsname{%
642    \usecounter{\@enumctr}%
643    \rightmargin=2em% added this
644    \parsep\plparsep
645    \itemsep\plitemsep
646    \topsep\pltopsep
647    \partopsep\plpartopsep
648    \def\makelabel##1{\hss\llap{##1}}}}
649
650%%
651% Improved letterspacing of small caps and all-caps text.
652%
653% First, try to use the `microtype' package, if it's available.
654% Failing that, try to use the `soul' package, if it's available.
655% Failing that, well, I give up.
656
657\DeclareTextFontCommand{\textsmallcaps}{\scshape}
658
659\RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase
660\def\allcapsspacing{\@tufte@warning{Proper spacing of ALL-CAPS letters has not been set up.}}
661\def\smallcapsspacing{\@tufte@warning{Proper spacing of small-caps letters has not been set up.}}
662\newcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{#1}}}
663\newcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{#1}}}
664
665% If we're using pdfLaTeX v1.40+, use the letterspace package.
666% If we're using pdfLaTex < v1.40, use the soul package.
667% If we're using XeLaTeX, use XeLaTeX letterspacing options.
668% Otherwise fall back on the soul package.
669
670\ifthenelse{\boolean{@tufte@pdf}}
671  {\@tufte@debug@info@noline{ifpdf = true}}
672  {\@tufte@debug@info@noline{ifpdf = false}}
673
674\ifthenelse{\boolean{@tufte@xetex}}
675  {\@tufte@debug@info@noline{ifxetex = true}}
676  {\@tufte@debug@info@noline{ifxetex = false}}
677
678% Check pdfLaTeX version
679\def\@tufte@pdftexversion{0}
680\ifx\normalpdftexversion\@undefined \else
681  \let\pdftexversion \normalpdftexversion
682  \let\pdftexrevision\normalpdftexrevision
683  \let\pdfoutput     \normalpdfoutput
684\fi
685\ifx\pdftexversion\@undefined \else
686  \ifx\pdftexversion\relax \else
687    \def\@tufte@pdftexversion{6}
688    \ifnum\pdftexversion < 140
689      \def\@tufte@pdftexversion{5}
690    \fi
691  \fi
692\fi
693
694\newboolean{@tufte@letterspace@pkg@prereqs}
695\setboolean{@tufte@letterspace@pkg@prereqs}{true}
696\ifnum\@tufte@pdftexversion<6
697  \setboolean{@tufte@letterspace@pkg@prereqs}{false}
698\fi
699
700
701\newcommand{\@tufte@letterspacing@soul}{%
702  \RequirePackage{soul}%
703  \sodef\allcapsspacing{}{0.15em}{0.65em}{0.6em}%
704  \sodef\smallcapsspacing{}{0.075em}{0.5em}{0.6em}%
705  \sodef\sotextsc{\scshape}{0.075em}{0.5em}{0.6em}%
706  \renewcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{##1}}}%
707  \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}%
708  \renewcommand{\textsc}[1]{\sotextsc{##1}}%
709}
710
711\newcommand{\@tufte@letterspacing@letterspace}{%
712  \@tufte@debug@info@noline{Modern version of pdfTeX detected. Using `letterspace' package}%
713  \RequirePackage{letterspace}%
714  % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
715  \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}%
716  \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}%
717  \renewcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{##1}}}%
718  \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}%
719  \renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}%
720}
721
722\ifthenelse{\boolean{@tufte@letterspace}}{%
723  \ifthenelse{\boolean{@tufte@pdf}\AND\boolean{@tufte@letterspace@pkg@prereqs}\AND\NOT\boolean{@tufte@xetex}}{%
724    % load letterspace pkg
725    \IfFileExists{letterspace.sty}{%
726      \@tufte@letterspacing@letterspace
727    }{}%
728  }{}%
729  % load soul pkg
730  \@ifpackageloaded{letterspace}{}{%
731    \IfFileExists{soul.sty}{%
732      \@tufte@letterspacing@soul
733    }{%
734      \@tufte@warning@noline{Couldn't locate `soul' package}%
735    }% soul not installed... giving up.
736  }%
737}{}
738
739%\ifthenelse{\boolean{@tufte@letterspace}}{%
740  %\ifthenelse{\boolean{pdf}}{%
741    %\ifthenelse{\NOT\boolean{@tufte@letterspace@pkg@prereqs}}{%
742      %% pdfLaTeX version is too old or not using pdfLaTeX
743      %\ifthenelse{\boolean{@tufte@xetex}}{%
744        %% TODO use xetex letterspacing
745        %\@tufte@debug@info@noline{XeTeX detected. Reverting to `soul' package for letterspacing}%
746        %\@tufte@loadsoul%
747      %}{%
748        %% use `soul' package for letterspacing
749        %\@tufte@debug@info@noline{Old version of pdfTeX detected. Reverting to `soul' package for letterspacing}%
750        %\@tufte@loadsoul%
751      %}
752    %}{%
753      %\IfFileExists{letterspace.sty}{%
754        %\@tufte@debug@info@noline{Modern version of pdfTeX detected. Using `letterspace' package}
755        %\RequirePackage{letterspace}
756        %% Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
757        %\renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
758        %\renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
759        %\renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
760        %\renewcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{##1}}}
761        %\renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}
762      %}{% microtype failed, check for soul
763        %\@tufte@debug@info@noline{Modern version of pdfTeX detected, but `letterspace' package not installed.  Reverting to  `soul' package for letterspacing}
764        %\@tufte@loadsoul
765      %}%
766    %}%
767  %}{%
768    %\@tufte@debug@info@noline{Plain LaTeX detected. Using `soul' package for letterspacing}
769    %\@tufte@loadsoul
770  %}
771%}{%
772%% we're not to load letterspacing, so do nothing
773%}
774
775
776%%
777% An environment for paragraph-style section
778
779\providecommand\newthought[1]{%
780   \tuftebreak
781   \noindent\textsc{#1}%
782}
783
784%%
785% Redefine the display environments (quote, quotation, etc.)
786
787\renewenvironment{verse}
788               {\let\\\@centercr
789                \list{}{\itemsep      \z@
790                        \itemindent   -1pc%
791                        \listparindent\itemindent
792                        \rightmargin  \leftmargin
793                        \advance\leftmargin 1pc}%
794                \small%
795                \item\relax}
796               {\endlist}
797\renewenvironment{quotation}
798               {\list{}{\listparindent 1pc%
799                        \itemindent    \listparindent
800                        \rightmargin   \leftmargin
801                        \parsep        \z@ \@plus\p@}%
802                \small%
803                \item\relax\noindent\ignorespaces}
804               {\endlist}
805\renewenvironment{quote}
806               {\list{}{\rightmargin\leftmargin}%
807                \small%
808                \item\relax}
809               {\endlist}
810
811%%
812% Italicize description run-in headings (instead of the default bold)
813
814\renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\em #1}
815
816
817%%
818% Used for doublespacing, and other linespacing
819
820\RequirePackage{setspace}
821
822%%
823% Color
824\RequirePackage[dvipsnames,svgnames]{xcolor}% load before bidi
825
826%%
827% Load the bidi package if instructed to do so.  This package must be loaded
828% prior to our redefining the \footnote and \cite commands.
829
830\ifthenelse{\boolean{@tufte@loadbidi}}{%
831  \AtBeginDocument{%
832    \RequirePackage{bidi}
833    \@tufte@pkghook@post@bidi%
834  }%
835}{}
836
837
838%%
839% A function that removes leading and trailling spaces from the supplied macro.
840% Based on code written by Michael Downes (See ``Around the Bend'', #15.)
841% Executing \@tufte@trim@spaces\xyzzy will result in the contents of \xyzzy
842% being trimmed of leading and trailing white space.
843
844\catcode`\Q=3
845\def\@tufte@trim@spaces#1{%
846  % Use grouping to emulate a multi-token afterassignment queue
847  \begingroup%
848  % Put `\toks 0 {' into the afterassignment queue
849  \aftergroup\toks\aftergroup0\aftergroup{%
850  % Apply \trimb to the replacement text of #1, adding a leading
851  % \noexpand to prevent brace stripping and to serve another purpose
852  % later.
853  \expandafter\@tufte@trim@b\expandafter\noexpand#1Q Q}%
854  % Transfer the trimmed text back into #1.
855  \edef#1{\the\toks0}%
856}
857
858% \trimb removes a trailing space if present, then calls \@tufte@trim@c to
859% clean up any leftover bizarre Qs, and trim a leading space. In
860% order for \trimc to work properly we need to put back a Q first.
861\def\@tufte@trim@b#1 Q{\@tufte@trim@c#1Q}
862
863% Execute \vfuzz assignment to remove leading space; the \noexpand
864% will now prevent unwanted expansion of a macro or other expandable
865% token at the beginning of the trimmed text. The \endgroup will feed
866% in the \aftergroup tokens after the \vfuzz assignment is completed.
867\def\@tufte@trim@c#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1}
868\catcode`\Q=11
869
870%%
871% Citations should go in the margin as sidenotes
872
873\ifthenelse{\boolean{@tufte@loadnatbib}}{%
874  \RequirePackage{natbib}%
875  \RequirePackage{bibentry}% allows bibitems to be typeset outside thebibliography environment
876  % Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style
877  \renewcommand\BR@b@bibitem[2][]{%
878    \ifthenelse{\isempty{#1}}%
879      {\BR@bibitem{#2}}%
880      {\BR@bibitem[#1]{#2}}%
881    \BR@c@bibitem{#2}%
882  }%
883  \nobibliography*% pre-loads the bibliography keys
884  \providecommand{\doi}[1]{\textsc{doi:} #1}% pre-defining this so it may be used before the \bibliography command it issued
885}{}
886
887%%
888% Normal \cite behavior
889\newcounter{@tufte@num@bibkeys}%
890\newcommand{\@tufte@normal@cite}[2][0pt]{%
891  % Snag the last bibentry in the list for later comparison
892  \let\@temp@last@bibkey\@empty%
893  \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
894  \sidenote[][#1]{%
895    % Loop through all the bibentries, separating them with semicolons and spaces
896    \normalsize\normalfont\@tufte@citation@font%
897    \setcounter{@tufte@num@bibkeys}{0}%
898    \@for\@temp@bibkeyx:=#2\do{%
899      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
900        {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
901         \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
902         \bibentry{\@temp@bibkeyx}}%
903        {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
904         \bibentry{\@temp@bibkeyx};\ }%
905      \stepcounter{@tufte@num@bibkeys}%
906    }%
907  }%
908}
909
910
911%%
912% Macros for holding the list of cite keys until after the \sidenote
913
914\gdef\@tufte@citations{}% list of cite keys
915\newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
916  \ifx\@tufte@citations\@empty\else
917    \g@addto@macro\@tufte@citations{,}% separate by commas
918  \fi
919  \g@addto@macro\@tufte@citations{#1}
920}
921
922\newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note
923  % Snag the last bibentry in the list for later comparison
924  \let\@temp@last@bibkey\@empty%
925  \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
926  \marginpar{%
927    \hbox{}\vspace*{#1}%
928    \@tufte@citation@font%
929    \@tufte@citation@justification%
930    \@tufte@margin@par% use parindent and parskip settings for marginal text
931    \vspace*{-1\baselineskip}%
932    % Loop through all the bibentries, separating them with semicolons and spaces
933    \setcounter{@tufte@num@bibkeys}{0}%
934    \@for\@temp@bibkeyx:=\@tufte@citations\do{%
935      \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
936        {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
937         \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
938         \bibentry{\@temp@bibkeyx}}%
939        {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
940         \bibentry{\@temp@bibkeyx};\ }%
941      \stepcounter{@tufte@num@bibkeys}%
942    }%
943  }%
944}
945
946%%
947% \cite behavior when executed within a sidenote
948
949\newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote
950\newcommand{\@tufte@infootnote@cite}[1]{%
951  \@tufte@add@citation{#1}
952}
953
954%%
955% Set the default \cite style.  This is set and reset by the \sidenote command.
956
957\ifthenelse{\boolean{@tufte@loadnatbib}}{%
958  \let\cite\@tufte@normal@cite
959}{}
960
961%%
962% Transform existing \footnotes into \sidenotes
963% Sidenote: ``Where God meant footnotes to go.'' ---Tufte
964
965\RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
966
967\providecommand{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification}
968\renewcommand{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification}
969
970% Override footmisc's definition to set the sidenote marks (numbers) inside the
971% sidenote's text block.
972\long\def\@makefntext#1{\@textsuperscript{\@tufte@sidenote@font\tiny\@thefnmark}\,\footnotelayout#1}
973
974% Set the in-text footnote mark in the same typeface as the body text itself.
975\def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}}
976
977\providecommand*{\multiplefootnotemarker}{3sp}
978\providecommand*{\multfootsep}{,}
979
980\renewcommand{\@footnotemark}{%
981  \leavevmode%
982  \ifhmode%
983    \edef\@x@sf{\the\spacefactor}%
984    \@tufte@check@multiple@sidenotes%
985    \nobreak%
986  \fi%
987  \@makefnmark%
988  \ifhmode\spacefactor\@x@sf\fi%
989  \relax%
990}
991
992\newcommand{\@tufte@check@multiple@sidenotes}{%
993  \ifdim\lastkern=\multiplefootnotemarker\relax%
994    \edef\@x@sf{\the\spacefactor}%
995    \unkern%
996    \textsuperscript{\multfootsep}%
997    \spacefactor\@x@sf\relax%
998  \fi
999}
1000
1001\renewcommand\@footnotetext[2][0pt]{%
1002  \marginpar{%
1003    \hbox{}\vspace*{#1}%
1004    \def\baselinestretch {\setspace@singlespace}%
1005    \reset@font\footnotesize%
1006    \@tufte@margin@par% use parindent and parskip settings for marginal text
1007    \vspace*{-1\baselineskip}\noindent%
1008    \protected@edef\@currentlabel{%
1009       \csname p@footnote\endcsname\@thefnmark%
1010    }%
1011    \color@begingroup%
1012       \@makefntext{%
1013         \ignorespaces#2%
1014       }%
1015    \color@endgroup%
1016  }%
1017}%
1018
1019% Ensure this is run after the bidi package has been loaded
1020\def\@tufte@pkghook@post@bidi{}%
1021\g@addto@macro{\@tufte@pkghook@post@bidi}{%
1022  \renewcommand\@footnotetext[2][0pt]{%
1023    \marginpar{%
1024      \hbox{}\vspace*{#1}%
1025      \def\baselinestretch {\setspace@singlespace}%
1026      \if@rl@footnote\@rltrue\else\@rlfalse\fi%
1027      \reset@font\footnotesize%
1028      \@tufte@margin@par% use parindent and parskip settings for marginal text
1029      \vspace*{-1\baselineskip}\noindent%
1030      \protected@edef\@currentlabel{%
1031         \csname p@footnote\endcsname\@thefnmark%
1032      }%
1033      \color@begingroup%
1034         \@makefntext{%
1035           \ignorespaces#2%
1036         }%
1037      \color@endgroup%
1038    }%
1039  }%
1040}%
1041
1042%
1043% Define \sidenote command.  Can handle \cite.
1044
1045\newlength{\@tufte@sidenote@vertical@offset}
1046\setlength{\@tufte@sidenote@vertical@offset}{0pt}
1047
1048% #1 = footnote num, #2 = vertical offset, #3 = footnote text
1049\long\def\@tufte@sidenote[#1][#2]#3{%
1050  \ifthenelse{\boolean{@tufte@loadnatbib}}{%
1051    \let\cite\@tufte@infootnote@cite%   use the in-sidenote \cite command
1052  }{}%
1053  \gdef\@tufte@citations{}%           clear out any old citations
1054  \ifthenelse{\NOT\isempty{#2}}{%
1055    \gsetlength{\@tufte@sidenote@vertical@offset}{#2}%
1056  }{%
1057    \gsetlength{\@tufte@sidenote@vertical@offset}{0pt}%
1058  }%
1059  \ifthenelse{\isempty{#1}}{%
1060    % no specific footnote number provided
1061    \stepcounter\@mpfn%
1062    \protected@xdef\@thefnmark{\thempfn}%
1063    \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
1064  }{%
1065    % specific footnote number provided
1066    \begingroup%
1067      \csname c@\@mpfn\endcsname #1\relax%
1068      \unrestored@protected@xdef\@thefnmark{\thempfn}%
1069    \endgroup%
1070    \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
1071  }%
1072  \@tufte@print@citations%            print any citations
1073  \ifthenelse{\boolean{@tufte@loadnatbib}}{%
1074    \let\cite\@tufte@normal@cite%       go back to using normal in-text \cite command
1075  }{}%
1076  \unskip\ignorespaces%               remove extra white space
1077  \kern-\multiplefootnotemarker%      remove \kern left behind by sidenote
1078  \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
1079}
1080
1081\newcommand{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}}
1082\renewcommand{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}}
1083
1084%%
1085% Sidenote without the footnote mark
1086
1087\newcommand\marginnote[2][0pt]{%
1088  \ifthenelse{\boolean{@tufte@loadnatbib}}{%
1089    \let\cite\@tufte@infootnote@cite%   use the in-sidenote \cite command
1090  }{}%
1091  \gdef\@tufte@citations{}%           clear out any old citations
1092  \marginpar{\hbox{}\vspace*{#1}\@tufte@marginnote@font\@tufte@marginnote@justification\@tufte@margin@par\vspace*{-1\baselineskip}\noindent #2}%
1093  \@tufte@print@citations%            print any citations
1094  \ifthenelse{\boolean{@tufte@loadnatbib}}{%
1095    \let\cite\@tufte@normal@cite%       go back to using normal in-text \cite command
1096  }{}%
1097}
1098
1099
1100%%
1101% The placeins package provides the \FloatBarrier command.  This forces
1102% LaTeX to place all of the floats before proceeding.  We'll use this to
1103% keep the float (figure and table) numbers in sequence.
1104\RequirePackage{placeins}
1105
1106%%
1107% Margin float environment
1108
1109\newsavebox{\@tufte@margin@floatbox}
1110\newenvironment{@tufte@margin@float}[2][-1.2ex]%
1111  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
1112  \begin{lrbox}{\@tufte@margin@floatbox}%
1113  \begin{minipage}{\marginparwidth}%
1114    \@tufte@caption@font%
1115    \def\@captype{#2}%
1116    \hbox{}\vspace*{#1}%
1117    \@tufte@caption@justification%
1118    \@tufte@margin@par%
1119    \noindent%
1120  }
1121  {\end{minipage}%
1122  \end{lrbox}%
1123  \marginpar{\usebox{\@tufte@margin@floatbox}}%
1124  }
1125
1126
1127%%
1128% Margin figure environment
1129
1130\newenvironment{marginfigure}[1][-1.2ex]%
1131  {\begin{@tufte@margin@float}[#1]{figure}}
1132  {\end{@tufte@margin@float}}
1133
1134
1135%%
1136% Margin table environment
1137
1138\newenvironment{margintable}[1][-1.2ex]%
1139  {\begin{@tufte@margin@float}[#1]{table}}
1140  {\end{@tufte@margin@float}}
1141
1142
1143%%
1144% Auto-detects the proper text alignment based on the various class options
1145
1146\newcommand*{\@tufte@justification@autodetect}{%
1147  \ifthenelse{\boolean{@tufte@justified}}%
1148    {\justifying}%
1149    {\RaggedRight}%
1150}
1151
1152%%
1153% Forces the outer edge of the caption to be set ragged.
1154% Therefore, on verso pages it's ragged left, and on recto pages it's ragged right.
1155
1156\newcommand*{\@tufte@justification@caption@outer}{%
1157  \ifthenelse{\boolean{@tufte@float@recto}}%
1158    {\RaggedRight}%
1159    {\RaggedLeft}%
1160}
1161
1162\newcommand*{\@tufte@justification@outer}{%
1163  \@tufte@checkoddpage%
1164  \ifthenelse{\boolean{@tufte@odd@page}}%
1165    {\RaggedRight}%
1166    {\RaggedLeft}%
1167}
1168
1169
1170
1171%%
1172% A collection of macros to be used with the new Tufte-style float environments.
1173% \setfloatalignment forces the caption placement to be treated as top, bottom, etc.
1174% \forcerectofloat forces the float to be treated as if it were appearing on a recto page.
1175% \forceversofloat does the same, but for verso pages.
1176
1177\newcommand{\@tufte@float@debug@info}{}% contains debug info generated as the float is processed
1178\newcommand{\@tufte@float@debug}[1]{% adds debug info to the queue for output
1179  \ifthenelse{\equal{\@tufte@float@debug@info}{}}%
1180    {\def\@tufte@float@debug@info{#1}}%
1181    {\g@addto@macro\@tufte@float@debug@info{\MessageBreak#1}}%
1182}
1183
1184\newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p)
1185\newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}\@tufte@float@debug{Forcing position: [#1]}}% manually sets the float alignment
1186\newboolean{@tufte@float@recto}
1187\newcommand{\forcerectofloat}{\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Forcing page: [recto]}}
1188\newcommand{\forceversofloat}{\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Forcing page: [verso]}}
1189
1190% Boxes to temporarily store our float and caption
1191\newsavebox{\@tufte@figure@box}
1192\newsavebox{\@tufte@caption@box}
1193
1194% Save original LaTeX float environment
1195\let\@tufte@orig@float\@float
1196\let\@tufte@orig@endfloat\end@float
1197
1198% New length for tweaking float captions
1199\newlength{\@tufte@caption@vertical@offset}
1200\setlength{\@tufte@caption@vertical@offset}{0pt}
1201
1202% Store the caption and label contents
1203\newcommand{\@tufte@stored@shortcaption}{}
1204\newcommand{\@tufte@stored@caption}{}
1205\newcommand{\@tufte@stored@label}{}
1206
1207\long\def\@tufte@caption[#1][#2]#3{%
1208  \ifthenelse{\isempty{#1}}%
1209    {\gdef\@tufte@stored@shortcaption{#3}}%
1210    {\gdef\@tufte@stored@shortcaption{#1}}%
1211  \gsetlength{\@tufte@caption@vertical@offset}{-#2}% we want a positive offset to lower captions
1212  \gdef\@tufte@stored@caption{#3}%
1213}
1214
1215\newcommand{\@tufte@label}[1]{%
1216  \gdef\@tufte@stored@label{#1}%
1217}
1218
1219\newcommand{\@tufte@fps}{}
1220
1221\newboolean{@tufte@float@star}
1222\newlength{\@tufte@float@contents@width}
1223
1224%%
1225% Define a float environment to place the captions in the margin space
1226
1227\newenvironment{@tufte@float}[3][htbp]%
1228  {% begin @tufte@float
1229    % Should this float be full-width or just text-width?
1230    \ifthenelse{\equal{#3}{star}}%
1231      {\gsetboolean{@tufte@float@star}{true}}%
1232      {\gsetboolean{@tufte@float@star}{false}}%
1233    % Check page side (recto/verso) and store detected value -- can be overriden in environment contents
1234    \@tufte@checkoddpage%
1235    \ifthenelse{\boolean{@tufte@odd@page}}%
1236      {\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Detected page: [recto/odd]}}%
1237      {\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Detected page: [verso/even]}}%
1238    % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them.
1239    \renewcommand{\@tufte@fps}{#1}%
1240    \@tufte@float@debug{Allowed positions: [#1]}%
1241    \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}%
1242      {\renewcommand{\floatalignment}{b}\@tufte@float@debug{Presumed position: [bottom]}}%
1243      {\renewcommand{\floatalignment}{t}\@tufte@float@debug{Presumed position: [top]}}%
1244    % Capture the contents of the \caption and \label commands to use later
1245    \global\let\@tufte@orig@caption\caption%
1246    \global\let\@tufte@orig@label\label%
1247    \renewcommand{\caption}{\optparams{\@tufte@caption}{[][0pt]}}%
1248    \renewcommand{\label}[1]{\@tufte@label{##1}}%
1249    % Handle subfigure package compatibility
1250    \ifthenelse{\boolean{@tufte@packages@subfigure}}{%
1251      % don't move the label while inside a \subfigure or \subtable command
1252      \global\let\label\@tufte@orig@label%
1253    }{}% subfigure package is not loaded
1254    \@tufte@orig@float{#2}[#1]%
1255    \ifthenelse{\boolean{@tufte@float@star}}%
1256      {\setlength{\@tufte@float@contents@width}{\@tufte@fullwidth}}%
1257      {\setlength{\@tufte@float@contents@width}{\textwidth}}%
1258    \begin{lrbox}{\@tufte@figure@box}%
1259      \begin{minipage}[\floatalignment]{\@tufte@float@contents@width}\hbox{}%
1260  }{% end @tufte@float
1261      \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
1262      \end{minipage}%
1263    \end{lrbox}%
1264    % build the caption box
1265    \begin{lrbox}{\@tufte@caption@box}%
1266      \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
1267        \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
1268        \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
1269        \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
1270      \end{minipage}%
1271    \end{lrbox}%
1272    % now typeset the stored boxes
1273    \begin{fullwidth}%
1274      \begin{minipage}[\floatalignment]{\linewidth}%
1275        \ifthenelse{\boolean{@tufte@float@star}}%
1276          {\@tufte@float@fullwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
1277          {\@tufte@float@textwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
1278      \end{minipage}%
1279    \end{fullwidth}%
1280    \@tufte@orig@endfloat% end original LaTeX float environment
1281    % output debug info
1282    \ifthenelse{\boolean{@tufte@debug}}{%
1283      \typeout{^^J^^J----------- Tufte-LaTeX float information ----------}%
1284      \ifthenelse{\equal{\@tufte@stored@label}{}}%
1285        {\typeout{Warning: Float unlabeled!}}%
1286        {\typeout{Float label: [\@tufte@stored@label]}}%
1287      \typeout{Page number: [\thepage]}%
1288      \def\MessageBreak{^^J}%
1289      \typeout{\@tufte@float@debug@info}%
1290      \ifthenelse{\boolean{@tufte@symmetric}}%
1291        {\typeout{Symmetric: [true]}}%
1292        {\typeout{Symmetric: [false]}}%
1293      \typeout{----------------------------------------------------^^J^^J}%
1294    }{}%
1295    % reset commands and temp boxes and captions
1296    \gdef\@tufte@float@debug@info{}%
1297    \let\caption\@tufte@orig@caption%
1298    \let\label\@tufte@orig@label%
1299    \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}%
1300    \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}%
1301    \gdef\@tufte@stored@shortcaption{}%
1302    \gdef\@tufte@stored@caption{}%
1303    \gdef\@tufte@stored@label{}%
1304    \gsetlength{\@tufte@caption@vertical@offset}{0pt}% reset caption offset
1305  }
1306
1307\newcommand{\@tufte@float@textwidth}[3][0pt]{%
1308  \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}{%
1309    % asymmetric or page is odd, so caption is on the right
1310    \hbox{%
1311      \usebox{#2}%
1312      \hspace{\marginparsep}%
1313      \smash{\raisebox{#1}{\usebox{#3}}}%
1314    }%
1315    \@tufte@float@debug{Caption position: [right]}%
1316  }{% symmetric pages and page is even, so caption is on the left
1317    \hbox{%
1318      \smash{\raisebox{#1}{\usebox{#3}}}%
1319      \hspace{\marginparsep}%
1320      \usebox{#2}%
1321    }%
1322    \@tufte@float@debug{Caption position: [left]}%
1323  }%
1324}
1325
1326\newcommand{\@tufte@float@fullwidth}[3][0pt]{%
1327  \ifthenelse{\equal{\floatalignment}{b}}%
1328    {% place caption above figure
1329      \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
1330        {\hfill\smash{\raisebox{#1}{\usebox{#3}}}\par\usebox{#2}\@tufte@float@debug{Caption position: [above right]}}% caption on the right
1331        {\smash{\raisebox{#1}{\usebox{#3}}}\hfill\par\usebox{#2}\@tufte@float@debug{Caption position: [above left]}}% caption on the left
1332    }{% place caption below figure
1333      \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
1334        {\usebox{#2}\par\hfill\smash{\raisebox{#1}{\usebox{#3}}}\@tufte@float@debug{Caption position: [below right]}}% caption on the right
1335        {\usebox{#2}\par\smash{\raisebox{#1}{\usebox{#3}}}\hfill\@tufte@float@debug{Caption position: [below left]}}% caption on the left
1336    }%
1337}
1338
1339
1340%%
1341% Redefine the figure environment to place the captions in the margin space
1342
1343\renewenvironment{figure}[1][htbp]%
1344  {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{}}
1345  {\end{@tufte@float}}
1346
1347
1348%%
1349% Redefine the table environment to place the captions in the margin space
1350
1351\renewenvironment{table}[1][htbp]
1352  {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{}}
1353  {\end{@tufte@float}}
1354
1355
1356%%
1357% Full-width figure
1358
1359\renewenvironment{figure*}[1][htbp]%
1360  {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{figure}{star}}
1361  {\end{@tufte@float}}
1362
1363
1364%%
1365% Full-width table
1366
1367\renewenvironment{table*}[1][htbp]%
1368  {\ifvmode\else\unskip\fi\begin{@tufte@float}[#1]{table}{star}}
1369  {\end{@tufte@float}}
1370
1371
1372%%
1373% Full-page-width area
1374
1375\newenvironment{fullwidth}
1376  {\ifthenelse{\boolean{@tufte@symmetric}}%
1377     {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}%
1378     {\begin{adjustwidth}{}{-\@tufte@overhang}}%
1379  }%
1380  {\ifthenelse{\boolean{@tufte@symmetric}}%
1381    {\ifthenelse{\boolean{@tufte@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}%
1382    {\end{adjustwidth}}%
1383  }
1384
1385%%
1386% Format the captions in a style similar to the sidenotes
1387
1388\long\def\@caption#1[#2]#3{%
1389  \par%
1390  \addcontentsline{\csname ext@#1\endcsname}{#1}%
1391    {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
1392  \begingroup%
1393    \@parboxrestore%
1394    \if@minipage%
1395      \@setminipage%
1396    \fi%
1397    \@tufte@caption@font\@tufte@caption@justification%
1398    \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
1399    %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
1400  \endgroup}
1401
1402%%
1403% If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided,
1404% we should load the Palatino, Helvetica, and Bera Mono fonts (if they are
1405% installed.)
1406
1407\ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}\AND\NOT\boolean{@tufte@luatex}}{%
1408  \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
1409  \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.90]{helvet}}{}
1410  \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{}
1411  \RequirePackage[T1]{fontenc}
1412  \RequirePackage{textcomp}
1413}{}
1414
1415
1416%%
1417% Turns newlines into spaces.  Based on code from the `titlesec' package.
1418
1419\DeclareRobustCommand{\@tufte@newlinetospace}{%
1420  \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}%
1421}
1422
1423\def\@tufte@newlinetospace@i{%
1424  \ifdim\lastskip>\z@\else\space\fi
1425  \ignorespaces%
1426}
1427
1428\DeclareRobustCommand{\newlinetospace}[1]{%
1429  \let\@tufte@orig@cr\\% save the original meaning of \\
1430  \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space
1431  \let\newline\\% turn \newline into \space
1432  #1%
1433  \let\\\@tufte@orig@cr% revert to original meaning of \\
1434}
1435
1436
1437%%
1438% Sets up the running heads and folios.
1439
1440\RequirePackage{fancyhdr}
1441
1442% Set the default page style to 'fancy'
1443\pagestyle{fancy}
1444
1445% Set the header/footer width to be the body text block plus the margin
1446% note area.
1447\AtBeginDocument{%
1448  \ifthenelse{\boolean{@tufte@symmetric}}
1449    {\fancyhfoffset[LE,RO]{\@tufte@overhang}}
1450    {\fancyhfoffset[RE,RO]{\@tufte@overhang}}
1451}
1452
1453% The running heads/feet don't have rules
1454\renewcommand{\headrulewidth}{0pt}
1455\renewcommand{\footrulewidth}{0pt}
1456
1457% The 'fancy' page style is the default style for all pages.
1458\fancyhf{} % clear header and footer fields
1459\ifthenelse{\boolean{@tufte@twoside}}
1460  {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}%
1461    \fancyhead[RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
1462  {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
1463
1464
1465% The `plain' page style is used on chapter opening pages.
1466% In Tufte's /Beautiful Evidence/ he never puts page numbers at the
1467% bottom of pages -- the folios are unexpressed.
1468\fancypagestyle{plain}{
1469  \fancyhf{} % clear header and footer fields
1470  % Uncomment the following five lines of code if you want the opening page
1471  % of the chapter to express the folio in the lower outside corner.
1472  %\ifthenelse{\boolean{@tufte@twoside}}
1473  %  {\fancyfoot[LE,RO]{\thepage}}
1474  %  {\fancyfoot[RE,RO]{\thepage}}
1475}
1476
1477% The `empty' page style suppresses all headers and footers.
1478% It's used on title pages and `intentionally blank' pages.
1479\fancypagestyle{empty}{
1480  \fancyhf{} % clear header and footer fields
1481}
1482
1483
1484%%
1485% Set raggedright and paragraph indentation for document
1486
1487\AtBeginDocument{\@tufte@justification}
1488
1489
1490%%
1491% Prints the list of class options and their states.
1492
1493\newcommand{\typeoutbool}[2]{%
1494  \ifthenelse{\boolean{#2}}
1495    {\typeout{\space\space#1: true}}
1496    {\typeout{\space\space#1: false}}
1497}
1498
1499\newcommand{\typeoutstr}[2]{%
1500  \typeout{\space\space#1: #2}
1501}
1502
1503\newcommand{\PrintTufteSettings}{%
1504  \typeout{-------------------- Tufte-LaTeX settings ----------}
1505  \typeout{Class: \@tufte@pkgname}
1506  \typeout{}
1507  \typeout{Class options:}
1508  \typeoutbool{a4paper}{@tufte@afourpaper}
1509  \typeoutbool{b5paper}{@tufte@bfivepaper}
1510  \typeoutbool{load fonts}{@tufte@loadfonts}
1511  \typeoutbool{fully-justified}{@tufte@justified}
1512  \typeoutbool{letterspacing}{@tufte@letterspace}
1513  \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes}
1514  \typeoutbool{symmetric margins}{@tufte@symmetric}
1515  \typeoutbool{titlepage}{@tufte@titlepage}
1516  \typeoutbool{twoside}{@tufte@twoside}
1517  \typeoutbool{debug}{@tufte@debug}
1518  \typeout{}
1519  \typeout{Internal variables:}
1520  \typeoutbool{[twoside]}{@twoside}
1521  \typeoutbool{pdflatex}{@tufte@pdf}
1522  \typeoutbool{xelatex}{@tufte@xetex}
1523  \typeout{----------------------------------------------------}
1524}
1525
1526%%
1527% Amount of space to skip before \newthought or after title block
1528
1529\newskip\tufteskipamount
1530\tufteskipamount=1.0\baselineskip plus 0.5ex minus 0.2ex
1531
1532\newcommand{\tuftebreak}{\par\ifdim\lastskip<\tufteskipamount
1533  \removelastskip\penalty-100\tufteskip\fi}
1534
1535\newcommand{\tufteskip}{\vspace\tufteskipamount}
1536
1537
1538%%
1539% Produces a full title page
1540
1541\newcommand{\maketitlepage}[0]{%
1542  \cleardoublepage%
1543  {%
1544  \sffamily%
1545  \begin{fullwidth}%
1546  \fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}%
1547  \vspace{11.5pc}%
1548  \fontsize{36}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklesstitle}}%
1549  \vfill%
1550  \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}%
1551  \end{fullwidth}%
1552  }
1553  \thispagestyle{empty}%
1554  \clearpage%
1555}
1556
1557%%
1558% Title block
1559
1560\renewcommand{\maketitle}{%
1561  \newpage
1562  \global\@topnum\z@% prevent floats from being placed at the top of the page
1563  \begingroup
1564    \setlength{\parindent}{0pt}%
1565    \setlength{\parskip}{4pt}%
1566    \let\@@title\@empty
1567    \let\@@author\@empty
1568    \let\@@date\@empty
1569    \ifthenelse{\boolean{@tufte@sfsidenotes}}{%
1570      \gdef\@@title{\sffamily\LARGE\allcaps{\@title}\par}%
1571      \gdef\@@author{\sffamily\Large\allcaps{\@author}\par}%
1572      \gdef\@@date{\sffamily\Large\allcaps{\@date}\par}%
1573    }{%
1574      \gdef\@@title{\LARGE\itshape\@title\par}%
1575      \gdef\@@author{\Large\itshape\@author\par}%
1576      \gdef\@@date{\Large\itshape\@date\par}%
1577    }%
1578    \@@title
1579    \@@author
1580    \@@date
1581  \endgroup
1582  \thispagestyle{plain}% suppress the running head
1583  \tuftebreak% add some space before the text begins
1584  \@afterindentfalse\@afterheading% suppress indentation of the next paragraph
1585}
1586
1587
1588%%
1589% Title page (if the `titlepage' option was passed to the tufte-handout
1590% class.)
1591
1592\ifthenelse{\boolean{@tufte@titlepage}}
1593  {\renewcommand{\maketitle}{\maketitlepage}}
1594  {}
1595
1596%%
1597% When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
1598% without headers and footers
1599\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
1600  \hbox{}
1601  %\vspace*{\fill}
1602  %\begin{center}
1603  %  This page intentionally contains only this sentence.
1604  %\end{center}
1605  %\vspace{\fill}
1606  \thispagestyle{empty}
1607  \newpage
1608  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
1609
1610%%
1611% Make Tuftian-style section headings and TOC formatting
1612
1613\titleformat{\chapter}%
1614  [display]% shape
1615  {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
1616  {\itshape\huge\thechapter}% label
1617  {0pt}% horizontal separation between label and title body
1618  {\huge\rmfamily\itshape}% before the title body
1619  [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body
1620
1621\titleformat{\section}%
1622  [hang]% shape
1623  {\normalfont\Large\itshape}% format applied to label+text
1624  {\thesection}% label
1625  {1em}% horizontal separation between label and title body
1626  {}% before the title body
1627  []% after the title body
1628
1629\titleformat{\subsection}%
1630  [hang]% shape
1631  {\normalfont\large\itshape}% format applied to label+text
1632  {\thesubsection}% label
1633  {1em}% horizontal separation between label and title body
1634  {}% before the title body
1635  []% after the title body
1636
1637\titleformat{\paragraph}%
1638  [runin]% shape
1639  {\normalfont\itshape}% format applied to label+text
1640  {\theparagraph}% label
1641  {1em}% horizontal separation between label and title body
1642  {}% before the title body
1643  []% after the title body
1644
1645\titlespacing*{\chapter}{0pt}{50pt}{40pt}
1646\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
1647\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus.2ex}
1648
1649% Subsubsection and following section headings shouldn't be used.
1650% See Bringhurst's _The Elements of Typography_, section 4.2.2.
1651\renewcommand\subsubsection{%
1652  \@tufte@error{\string\subsubsection is undefined by this class.
1653    See Robert Bringhurst's _The Elements of
1654    Typographic Style_, section 4.2.2.
1655    \string\subsubsection was used}
1656    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
1657    many levels of headings as you need, no more and no fewer.  Also see the many
1658    related threads on Ask E.T. at http://www.edwardtufte.com/.}
1659}
1660
1661\renewcommand\subparagraph{%
1662  \@tufte@error{\string\subparagraph is undefined by this class.%
1663    See Robert Bringhurst's _The Elements of
1664    Typographic Style_, section 4.2.2.
1665    \string\subparagraph was used}
1666    {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
1667    many levels of headings as you need, no more and no fewer.  Also see the many
1668    related threads on Ask E.T. at http://www.edwardtufte.com/.}
1669}
1670
1671
1672% Formatting for main TOC (printed in front matter)
1673% {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
1674\ifthenelse{\boolean{@tufte@toc}}{%
1675  \titlecontents{part}% FIXME
1676    [0em] % distance from left margin
1677    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
1678    {\contentslabel{2em}} % before w/label (label = ``II'')
1679    {} % before w/o label
1680    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
1681    [\end{fullwidth}] % after
1682  \titlecontents{chapter}%
1683    [0em] % distance from left margin
1684    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
1685    {\hspace*{0em}\contentslabel{2em}} % before w/label (label = ``2'')
1686    {\hspace*{0em}} % before w/o label
1687    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
1688    [\end{fullwidth}] % after
1689  \titlecontents{section}% FIXME
1690    [0em] % distance from left margin
1691    {\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape} % above (global formatting of entry)
1692    {\hspace*{2em}\contentslabel{2em}} % before w/label (label = ``2.6'')
1693    {\hspace*{2em}} % before w/o label
1694    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
1695    [\end{fullwidth}] % after
1696  \titlecontents{subsection}% FIXME
1697    [0em] % distance from left margin
1698    {\vspace{0\baselineskip}\begin{fullwidth}\large\rmfamily\itshape} % above (global formatting of entry)
1699    {\hspace*{4em}\contentslabel{4em}} % before w/label (label = ``2.6.1'')
1700    {\hspace*{4em}} % before w/o label
1701    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
1702    [\end{fullwidth}] % after
1703  \titlecontents{paragraph}% FIXME
1704    [0em] % distance from left margin
1705    {\vspace{0\baselineskip}\begin{fullwidth}\normalsize\rmfamily\itshape} % above (global formatting of entry)
1706    {\hspace*{6em}\contentslabel{2em}} % before w/label (label = ``2.6.0.0.1'')
1707    {\hspace*{6em}} % before w/o label
1708    {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
1709    [\end{fullwidth}] % after
1710}{}
1711
1712%%
1713% Format lists of figures/tables
1714
1715\renewcommand\listoffigures{%
1716  \ifthenelse{\equal{\@tufte@class}{book}}%
1717    {\chapter*{\listfigurename}}%
1718    {\section*{\listfigurename}}%
1719%  \begin{fullwidth}%
1720    \@starttoc{lof}%
1721%  \end{fullwidth}%
1722}
1723
1724\renewcommand\listoftables{%
1725  \ifthenelse{\equal{\@tufte@class}{book}}%
1726    {\chapter*{\listtablename}}%
1727    {\section*{\listtablename}}%
1728%  \begin{fullwidth}%
1729    \@starttoc{lot}%
1730%  \end{fullwidth}%
1731}
1732
1733\newcommand{\@tufte@lof@line}[2]{%
1734  % #1 is the figure/table number and its caption text
1735  % #2 is the page number on which the figure/table appears
1736  \leftskip 0.0em
1737  \rightskip 0em
1738  \parfillskip 0em plus 1fil
1739  \parindent 0.0em
1740  \@afterindenttrue
1741  \interlinepenalty\@M
1742  \leavevmode
1743  \@tempdima 2.0em
1744  \advance\leftskip\@tempdima
1745  \null\nobreak\hskip -\leftskip
1746  {#1}\nobreak\qquad\nobreak#2%
1747  \par%
1748}
1749
1750\renewcommand*\l@figure{\@tufte@lof@line}
1751\let\l@table\l@figure
1752
1753
1754%%
1755% A handy command to disable hyphenation for short bits of text.
1756% Borrowed from Peter Wilson's `hyphenat' package.
1757
1758\AtBeginDocument{%
1759  \@ifpackageloaded{hyphenat}{}{%
1760    \newlanguage\langwohyphens% define a language without hyphenation rules
1761    \providecommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text
1762    \providecommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text
1763  }%
1764}
1765
1766%%
1767% Redefine \bibsection to not mark the running heads.
1768% (Code modified from natbib.sty.)
1769
1770\ifthenelse{\boolean{@tufte@loadnatbib}}{%
1771  \@ifundefined{chapter}{%
1772    \renewcommand\bibsection{\section*{\refname}}%
1773  }{%
1774    \@ifundefined{NAT@sectionbib}{%
1775      \renewcommand\bibsection{\chapter{\bibname}}%
1776    }{%
1777      \renewcommand\bibsection{\section*{\bibname}}%
1778    }%
1779  }%
1780}
1781
1782%%
1783% An index environment to mimic Tufte's indexes
1784
1785\RequirePackage{multicol}
1786\renewenvironment{theindex}{%
1787  \ifthenelse{\equal{\@tufte@class}{book}}%
1788    {\chapter{\indexname}}%
1789    {\section*{\indexname}}%
1790  \begin{fullwidth}%
1791  \small%
1792  \parskip0pt%
1793  \parindent0pt%
1794  \let\item\@idxitem%
1795  \begin{multicols}{3}%
1796}{%
1797  \end{multicols}%
1798  \end{fullwidth}%
1799}
1800\renewcommand\@idxitem{\par\hangindent 2em}
1801\renewcommand\subitem{\par\hangindent 3em\hspace*{1em}}
1802\renewcommand\subsubitem{\par\hangindent 4em\hspace*{2em}}
1803\renewcommand\indexspace{\par\addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}\relax}%
1804\newcommand{\lettergroup}[1]{}% swallow the letter heading in the index
1805
1806
1807%%
1808% A couple commands to incresae the number of floats you can use at a time.
1809
1810\def\morefloats{% provides a total of 52 floats
1811  \ifthenelse{\isundefined{\bx@S}}{%
1812    \@tufte@debug@info@noline{Adding 34 more float slots.}
1813    \newinsert\bx@S
1814    \newinsert\bx@T
1815    \newinsert\bx@U
1816    \newinsert\bx@V
1817    \newinsert\bx@W
1818    \newinsert\bx@X
1819    \newinsert\bx@Y
1820    \newinsert\bx@Z
1821    \newinsert\bx@a
1822    \newinsert\bx@b
1823    \newinsert\bx@c
1824    \newinsert\bx@d
1825    \newinsert\bx@e
1826    \newinsert\bx@f
1827    \newinsert\bx@g
1828    \newinsert\bx@h
1829    \newinsert\bx@i
1830    \newinsert\bx@j
1831    \newinsert\bx@k
1832    \newinsert\bx@l
1833    \newinsert\bx@m
1834    \newinsert\bx@n
1835    \newinsert\bx@o
1836    \newinsert\bx@p
1837    \newinsert\bx@q
1838    \newinsert\bx@r
1839    \newinsert\bx@s
1840    \newinsert\bx@t
1841    \newinsert\bx@u
1842    \newinsert\bx@v
1843    \newinsert\bx@w
1844    \newinsert\bx@x
1845    \newinsert\bx@y
1846    \newinsert\bx@z
1847    \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
1848                    \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
1849                    \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
1850                    \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
1851                    \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
1852                    \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
1853                    \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
1854                    \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
1855                    \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
1856                    \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
1857                    \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
1858                    \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z}%
1859  }{% we've already added another 34 floats, so we'll add 26 more, but that's it!
1860    \ifthenelse{\isundefined{\bx@AA}}{%
1861      \@tufte@debug@info@noline{Adding 26 more float slots.}
1862      \newinsert\bx@AA
1863      \newinsert\bx@BB
1864      \newinsert\bx@CC
1865      \newinsert\bx@DD
1866      \newinsert\bx@EE
1867      \newinsert\bx@FF
1868      \newinsert\bx@GG
1869      \newinsert\bx@HH
1870      \newinsert\bx@II
1871      \newinsert\bx@JJ
1872      \newinsert\bx@KK
1873      \newinsert\bx@LL
1874      \newinsert\bx@MM
1875      \newinsert\bx@NN
1876      \newinsert\bx@OO
1877      \newinsert\bx@PP
1878      \newinsert\bx@QQ
1879      \newinsert\bx@RR
1880      \newinsert\bx@SS
1881      \newinsert\bx@TT
1882      \newinsert\bx@UU
1883      \newinsert\bx@VV
1884      \newinsert\bx@WW
1885      \newinsert\bx@XX
1886      \newinsert\bx@YY
1887      \newinsert\bx@ZZ
1888      \gdef\@freelist{\@elt\bx@A\@elt\bx@B\@elt\bx@C\@elt\bx@D\@elt\bx@E
1889                      \@elt\bx@F\@elt\bx@G\@elt\bx@H\@elt\bx@I\@elt\bx@J
1890                      \@elt\bx@K\@elt\bx@L\@elt\bx@M\@elt\bx@N
1891                      \@elt\bx@O\@elt\bx@P\@elt\bx@Q\@elt\bx@R
1892                      \@elt\bx@S\@elt\bx@T\@elt\bx@U\@elt\bx@V
1893                      \@elt\bx@W\@elt\bx@X\@elt\bx@Y\@elt\bx@Z
1894                      \@elt\bx@a\@elt\bx@b\@elt\bx@c\@elt\bx@d\@elt\bx@e
1895                      \@elt\bx@f\@elt\bx@g\@elt\bx@h\@elt\bx@i\@elt\bx@j
1896                      \@elt\bx@k\@elt\bx@l\@elt\bx@m\@elt\bx@n
1897                      \@elt\bx@o\@elt\bx@p\@elt\bx@q\@elt\bx@r
1898                      \@elt\bx@s\@elt\bx@t\@elt\bx@u\@elt\bx@v
1899                      \@elt\bx@w\@elt\bx@x\@elt\bx@y\@elt\bx@z
1900                      \@elt\bx@AA\@elt\bx@BB\@elt\bx@CC\@elt\bx@DD\@elt\bx@EE
1901                      \@elt\bx@FF\@elt\bx@GG\@elt\bx@HH\@elt\bx@II\@elt\bx@JJ
1902                      \@elt\bx@KK\@elt\bx@LL\@elt\bx@MM\@elt\bx@NN
1903                      \@elt\bx@OO\@elt\bx@PP\@elt\bx@QQ\@elt\bx@RR
1904                      \@elt\bx@SS\@elt\bx@TT\@elt\bx@UU\@elt\bx@VV
1905                      \@elt\bx@WW\@elt\bx@XX\@elt\bx@YY\@elt\bx@ZZ}%
1906    }{%
1907      \@tufte@error{You may only call \string\morefloats\space twice. See the Tufte-LaTeX documentation for other workarounds}
1908        {There are already 78 float slots allocated. Try using \string\FloatBarrier\space or \string\clearpage\space to place some floats before creating more.}
1909    }%
1910  }%
1911}
1912
1913
1914%%
1915% Detect if the subfigure package has been loaded
1916
1917\newboolean{@tufte@packages@subfigure}
1918\setboolean{@tufte@packages@subfigure}{false}
1919\AtBeginDocument{%
1920  \@ifpackageloaded{subfigure}
1921    {\gsetboolean{@tufte@packages@subfigure}{true}}
1922    {\gsetboolean{@tufte@packages@subfigure}{false}}%
1923}
1924
1925
1926%%
1927% Detect of the float package has been loaded
1928
1929\AtBeginDocument{%
1930  \@ifpackageloaded{float}{%
1931    % Save the redefined float environment (instead of the LaTeX float environment)
1932    \let\@tufte@orig@float\@float
1933    \let\@tufte@orig@endfloat\end@float
1934
1935    % Define Tuftian float styles (with the caption in the margin)
1936    \newcommand{\floatc@tufteplain}[2]{%
1937      \begin{lrbox}{\@tufte@caption@box}%
1938        \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
1939          \@tufte@caption@font{\@fs@cfont #1:} #2\par%
1940        \end{minipage}%
1941      \end{lrbox}%
1942      \smash{\hspace{\@tufte@caption@fill}\usebox{\@tufte@caption@box}}%
1943    }
1944    \newcommand{\fs@tufteplain}{%
1945      \def\@fs@cfont{\@tufte@caption@font}%
1946      \let\@fs@capt\floatc@tufteplain%
1947      \def\@fs@pre{}%
1948      \def\@fs@post{}%
1949      \def\@fs@mid{}%
1950      \let\@fs@iftopcapt\iftrue%
1951    }
1952    \let\fs@tufteplaintop=\fs@tufteplain
1953    \let\floatc@tufteplaintop=\floatc@tufteplain
1954    \newcommand\floatc@tufteruled[2]{%
1955      {\@fs@cfont #1} #2\par%
1956    }
1957    \newcommand\fs@tufteruled{%
1958      \def\@fs@cfont{\@tufte@caption@font}%
1959      \let\@fs@capt\floatc@tufteplain%
1960      \def\@fs@pre{\hrule height.8pt depth0pt width\textwidth \kern2pt}%
1961      \def\@fs@post{\kern2pt\hrule width\textwidth\relax}%
1962      \def\@fs@mid{}%
1963      \let\@fs@iftopcapt\iftrue%
1964    }
1965    \newcommand\fs@tufteboxed{%
1966      \def\@fs@cfont{}%
1967      \let\@fs@capt\floatc@tufteplain%
1968      \def\@fs@pre{%
1969        \setbox\@currbox\vbox{\hbadness10000
1970        \moveleft3.4pt\vbox{\advance\hsize by6.8pt
1971          \hrule \hbox to\hsize{\vrule\kern3pt
1972            \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}}
1973      }%
1974      \def\@fs@mid{\kern2pt}%
1975      \def\@fs@post{}%
1976      \let\@fs@iftopcapt\iftrue%
1977    }
1978  }{%
1979    % Nothing to do
1980  }
1981}
1982
1983\AtBeginDocument{%
1984  \@ifpackageloaded{algorithm}{%
1985    % Set the float style to the Tuftian version
1986    \ifthenelse{\equal{\ALG@floatstyle}{plain}\OR\equal{\ALG@floatstyle}{ruled}\OR\equal{\ALG@floatstyle}{boxed}}{%
1987      \@tufte@info@noline{Switching algorithm float style from \ALG@floatstyle\space to tufte\ALG@floatstyle}%
1988      \floatstyle{tufte\ALG@floatstyle}%
1989      \restylefloat{algorithm}%
1990    }{}%
1991  }{%
1992    % Nothing to do
1993  }
1994}
1995
1996
1997%%
1998% For compatibility with the subfig package, we'll set captions=false so that
1999% it doesn't load the caption package (which modifies our own caption
2000% formatting).
2001
2002\PassOptionsToPackage{caption=false}{subfig}
2003
2004
2005%%
2006% If debugging is enabled, print the Tufte-LaTeX options and the list of
2007% files.
2008
2009\ifthenelse{\boolean{@tufte@debug}}
2010  {\PrintTufteSettings\listfiles}
2011  {}
2012
2013
2014%%
2015% If there is a `tufte-common-local.tex' file, load it up.
2016
2017\IfFileExists{tufte-common-local.tex}
2018  {\input{tufte-common-local.tex}%
2019   \@tufte@info@noline{Loading tufte-common-local.tex}}
2020  {}
2021
2022
2023%%
2024% End of file
2025\endinput
2026
2027