You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2004 lines
69KB

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