25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1839 lines
64KB

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