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.

1707 lines
59KB

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