Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1835 lines
63KB

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