PageRenderTime 30ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/website/texlive/texmf-dist/tex/latex/hvfloat/tufte-common.def

https://github.com/JohnMcLear/texlive.js
Module-Definition | 1872 lines | 1584 code | 288 blank | 0 comment | 57 complexity | b7511c5946078b0c502b75317c740631 MD5 | raw file
Possible License(s): AGPL-3.0, Unlicense

Large files files are truncated, but you can click here to view the full file

  1. %%
  2. %% This file contains the code that's common to the Tufte-LaTeX document classes.
  3. %%
  4. \ProvidesFile{tufte-common.def}[2009/12/11 v3.5.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. \DeclareTextFontCommand{\textsmallcaps}{\scshape}
  514. \RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase
  515. \def\allcapsspacing{\TufteWarning{Proper spacing of ALL-CAPS letters has not been set up.}}
  516. \def\smallcapsspacing{\TufteWarning{Proper spacing of small-caps letters has not been set up.}}
  517. \newcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{#1}}}
  518. \newcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{#1}}}
  519. % If we're using pdfLaTeX v1.40+, use the letterspace package.
  520. % If we're using pdfLaTex < v1.40, use the soul package.
  521. % If we're using XeLaTeX, use XeLaTeX letterspacing options.
  522. % Otherwise fall back on the soul package.
  523. \ifthenelse{\boolean{@tufte@pdf}}
  524. {\TufteDebugInfoNL{ifpdf = true}}
  525. {\TufteDebugInfoNL{ifpdf = false}}
  526. \ifthenelse{\boolean{@tufte@xetex}}
  527. {\TufteDebugInfoNL{ifxetex = true}}
  528. {\TufteDebugInfoNL{ifxetex = false}}
  529. % Check pdfLaTeX version
  530. \def\@tufte@pdftexversion{0}
  531. \ifx\normalpdftexversion\@undefined \else
  532. \let\pdftexversion \normalpdftexversion
  533. \let\pdftexrevision\normalpdftexrevision
  534. \let\pdfoutput \normalpdfoutput
  535. \fi
  536. \ifx\pdftexversion\@undefined \else
  537. \ifx\pdftexversion\relax \else
  538. \def\@tufte@pdftexversion{6}
  539. \ifnum\pdftexversion < 140
  540. \def\@tufte@pdftexversion{5}
  541. \fi
  542. \fi
  543. \fi
  544. \newboolean{@tufte@letterspace@pkg@prereqs}
  545. \setboolean{@tufte@letterspace@pkg@prereqs}{true}
  546. \ifnum\@tufte@pdftexversion<6
  547. \setboolean{@tufte@letterspace@pkg@prereqs}{false}
  548. \fi
  549. \ifthenelse{\boolean{@tufte@letterspace}}{%
  550. \ifthenelse{\boolean{@tufte@pdf}\AND\boolean{@tufte@letterspace@pkg@prereqs}\AND\NOT\boolean{@tufte@xetex}}{%
  551. % load letterspace pkg
  552. \IfFileExists{letterspace.sty}{%
  553. \TufteDebugInfoNL{Modern version of pdfTeX detected. \MessageBreak Using `letterspace' package}
  554. \RequirePackage{letterspace}
  555. % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
  556. \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
  557. \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
  558. \renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
  559. \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}
  560. \renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}
  561. }{}%
  562. }{}%
  563. % load soul pkg
  564. \@ifpackageloaded{letterspace}{}{%
  565. \IfFileExists{soul.sty}{%
  566. \RequirePackage{soul}
  567. \sodef\allcapsspacing{}{0.15em}{0.65em}{0.6em}
  568. \sodef\smallcapsspacing{}{0.075em}{0.5em}{0.6em}
  569. \sodef\sotextsc{\scshape}{0.075em}{0.5em}{0.6em}
  570. \renewcommand{\allcaps}[1]{\allcapsspacing{\MakeTextUppercase{##1}}}
  571. \renewcommand{\smallcaps}[1]{\smallcapsspacing{\scshape\MakeTextLowercase{##1}}}
  572. \renewcommand{\textsc}[1]{\sotextsc{##1}}
  573. }{
  574. \TufteWarningNL{Couldn't locate `soul' package}
  575. }% soul not installed... giving up.
  576. }%
  577. }{}
  578. %\ifthenelse{\boolean{@tufte@letterspace}}{%
  579. %\ifthenelse{\boolean{pdf}}{%
  580. %\ifthenelse{\NOT\boolean{@tufte@letterspace@pkg@prereqs}}{%
  581. %% pdfLaTeX version is too old or not using pdfLaTeX
  582. %\ifthenelse{\boolean{@tufte@xetex}}{%
  583. %% TODO use xetex letterspacing
  584. %\TufteDebugInfoNL{XeTeX detected. \MessageBreak Reverting to `soul' package for letterspacing}%
  585. %\@tufte@loadsoul%
  586. %}{%
  587. %% use `soul' package for letterspacing
  588. %\TufteDebugInfoNL{Old version of pdfTeX detected. \MessageBreak Reverting to `soul' package for letterspacing}%
  589. %\@tufte@loadsoul%
  590. %}
  591. %}{%
  592. %\IfFileExists{letterspace.sty}{%
  593. %\TufteDebugInfoNL{Modern version of pdfTeX detected. \MessageBreak Using `letterspace' package}
  594. %\RequirePackage{letterspace}
  595. %% Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
  596. %\renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
  597. %\renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
  598. %\renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
  599. %\renewcommand{\smallcaps}[1]{\smallcapsspacing{\MakeTextLowercase{##1}}}
  600. %\renewcommand{\textsc}[1]{\smallcapsspacing{\textsmallcaps{##1}}}
  601. %}{% microtype failed, check for soul
  602. %\TufteDebugInfoNL{Modern version of pdfTeX detected, but `letterspace' \MessageBreak package not installed. \MessageBreak Reverting to `soul' package for letterspacing}
  603. %\@tufte@loadsoul
  604. %}%
  605. %}%
  606. %}{%
  607. %\TufteDebugInfoNL{Plain LaTeX detected. \MessageBreak Using `soul' package for letterspacing}
  608. %\@tufte@loadsoul
  609. %}
  610. %}{%
  611. %% we're not to load letterspacing, so do nothing
  612. %}
  613. %%
  614. % An environment for paragraph-style section
  615. \providecommand\newthought[1]{%
  616. \addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}%
  617. \noindent\textsc{#1}%
  618. }
  619. %%
  620. % Redefine the display environments (quote, quotation, etc.)
  621. \renewenvironment{verse}
  622. {\let\\\@centercr
  623. \list{}{\itemsep \z@
  624. \itemindent -1pc%
  625. \listparindent\itemindent
  626. \rightmargin \leftmargin
  627. \advance\leftmargin 1pc}%
  628. \small%
  629. \item\relax}
  630. {\endlist}
  631. \renewenvironment{quotation}
  632. {\list{}{\listparindent 1pc%
  633. \itemindent \listparindent
  634. \rightmargin \leftmargin
  635. \parsep \z@ \@plus\p@}%
  636. \small%
  637. \item\relax\noindent\ignorespaces}
  638. {\endlist}
  639. \renewenvironment{quote}
  640. {\list{}{\rightmargin\leftmargin}%
  641. \small%
  642. \item\relax}
  643. {\endlist}
  644. %%
  645. % Italicize description run-in headings (instead of the default bold)
  646. \renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\em #1}
  647. %%
  648. % Used for doublespacing, and other linespacing
  649. \RequirePackage{setspace}
  650. %%
  651. % Load the bidi package if instructed to do so. This package must be loaded
  652. % prior to our redefining the \footnote and \cite commands.
  653. \ifthenelse{\boolean{@tufte@loadbidi}}{\RequirePackage{bidi}}{}
  654. %%
  655. % A function that removes leading and trailling spaces from the supplied macro.
  656. % Based on code written by Michael Downes (See ``Around the Bend'', #15.)
  657. % Executing \@tufte@trim@spaces\xyzzy will result in the contents of \xyzzy
  658. % being trimmed of leading and trailing white space.
  659. \catcode`\Q=3
  660. \def\@tufte@trim@spaces#1{%
  661. % Use grouping to emulate a multi-token afterassignment queue
  662. \begingroup%
  663. % Put `\toks 0 {' into the afterassignment queue
  664. \aftergroup\toks\aftergroup0\aftergroup{%
  665. % Apply \trimb to the replacement text of #1, adding a leading
  666. % \noexpand to prevent brace stripping and to serve another purpose
  667. % later.
  668. \expandafter\@tufte@trim@b\expandafter\noexpand#1Q Q}%
  669. % Transfer the trimmed text back into #1.
  670. \edef#1{\the\toks0}%
  671. }
  672. % \trimb removes a trailing space if present, then calls \@tufte@trim@c to
  673. % clean up any leftover bizarre Qs, and trim a leading space. In
  674. % order for \trimc to work properly we need to put back a Q first.
  675. \def\@tufte@trim@b#1 Q{\@tufte@trim@c#1Q}
  676. % Execute \vfuzz assignment to remove leading space; the \noexpand
  677. % will now prevent unwanted expansion of a macro or other expandable
  678. % token at the beginning of the trimmed text. The \endgroup will feed
  679. % in the \aftergroup tokens after the \vfuzz assignment is completed.
  680. \def\@tufte@trim@c#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1}
  681. \catcode`\Q=11
  682. %%
  683. % Citations should go in the margin as sidenotes
  684. \RequirePackage{natbib}
  685. \RequirePackage{bibentry} % allows bibitems to be typeset outside thebibliography environment
  686. % Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style
  687. \renewcommand\BR@b@bibitem[2][]{%
  688. \ifthenelse{\isempty{#1}}%
  689. {\BR@bibitem{#2}}%
  690. {\BR@bibitem[#1]{#2}}%
  691. \BR@c@bibitem{#2}%
  692. }
  693. \nobibliography* % pre-loads the bibliography keys
  694. \providecommand{\doi}[1]{\textsc{doi:} #1}% pre-defining this so it may be used before the \bibliography command it issued
  695. %%
  696. % Normal \cite behavior
  697. \newcounter{@tufte@num@bibkeys}%
  698. \newcommand{\@tufte@normal@cite}[2][0pt]{%
  699. % Snag the last bibentry in the list for later comparison
  700. \let\@temp@last@bibkey\@empty%
  701. \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  702. \sidenote[][#1]{%
  703. % Loop through all the bibentries, separating them with semicolons and spaces
  704. \normalsize\normalfont\@tufte@citation@font%
  705. \setcounter{@tufte@num@bibkeys}{0}%
  706. \@for\@temp@bibkeyx:=#2\do{%
  707. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  708. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  709. \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  710. \bibentry{\@temp@bibkeyx}}%
  711. {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  712. \bibentry{\@temp@bibkeyx};\ }%
  713. \stepcounter{@tufte@num@bibkeys}%
  714. }%
  715. }%
  716. }
  717. %%
  718. % Macros for holding the list of cite keys until after the \sidenote
  719. \gdef\@tufte@citations{}% list of cite keys
  720. \newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
  721. \ifx\@tufte@citations\@empty\else
  722. \g@addto@macro\@tufte@citations{,}% separate by commas
  723. \fi
  724. \g@addto@macro\@tufte@citations{#1}
  725. }
  726. \newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note
  727. % Snag the last bibentry in the list for later comparison
  728. \let\@temp@last@bibkey\@empty%
  729. \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
  730. \marginpar{%
  731. \hbox{}\vspace*{#1}%
  732. \@tufte@citation@font%
  733. \@tufte@citation@justification%
  734. \@tufte@margin@par% use parindent and parskip settings for marginal text
  735. \vspace*{-1\baselineskip}%
  736. % Loop through all the bibentries, separating them with semicolons and spaces
  737. \setcounter{@tufte@num@bibkeys}{0}%
  738. \@for\@temp@bibkeyx:=\@tufte@citations\do{%
  739. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  740. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  741. \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  742. \bibentry{\@temp@bibkeyx}}%
  743. {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  744. \bibentry{\@temp@bibkeyx};\ }%
  745. \stepcounter{@tufte@num@bibkeys}%
  746. }%
  747. \@tufte@reset@par% use parindent and parskip settings for body text
  748. }%
  749. }
  750. %%
  751. % \cite behavior when executed within a sidenote
  752. \newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote
  753. \newcommand{\@tufte@infootnote@cite}[1]{%
  754. \@tufte@add@citation{#1}
  755. }
  756. %%
  757. % Set the default \cite style. This is set and reset by the \sidenote command.
  758. \let\cite\@tufte@normal@cite
  759. %%
  760. % Transform existing \footnotes into \sidenotes
  761. % Sidenote: ``Where God meant footnotes to go.'' ---Tufte
  762. \RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
  763. \providecommand*{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification}
  764. \renewcommand{\footnotelayout}{\@tufte@sidenote@font\@tufte@sidenote@justification}
  765. % Override footmisc's definition to set the sidenote marks (numbers) inside the
  766. % sidenote's text block.
  767. \long\def\@makefntext#1{\@textsuperscript{\@tufte@sidenote@font\tiny\@thefnmark}\,\footnotelayout#1}
  768. % Set the in-text footnote mark in the same typeface as the body text itself.
  769. \def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}}
  770. \providecommand*{\multiplefootnotemarker}{3sp}
  771. \providecommand*{\multfootsep}{,}
  772. \renewcommand*\@footnotemark{%
  773. \leavevmode%
  774. \ifhmode%
  775. \edef\@x@sf{\the\spacefactor}%
  776. \@tufte@check@multiple@sidenotes%
  777. \nobreak%
  778. \fi%
  779. \@makefnmark%
  780. \ifhmode\spacefactor\@x@sf\fi%
  781. \relax%
  782. }
  783. \newcommand{\@tufte@check@multiple@sidenotes}{%
  784. \ifdim\lastkern=\multiplefootnotemarker\relax%
  785. \edef\@x@sf{\the\spacefactor}%
  786. \unkern%
  787. \textsuperscript{\multfootsep}%
  788. \spacefactor\@x@sf\relax%
  789. \fi
  790. }
  791. \renewcommand\@footnotetext[2][0pt]{%
  792. \marginpar{%
  793. \hbox{}\vspace*{#1}%
  794. \def\baselinestretch {\setspace@singlespace}%
  795. \ifthenelse{\boolean{@tufte@loadbidi}}{\if@rl@footnote\@rltrue\else\@rlfalse\fi}{}%
  796. \reset@font\footnotesize%
  797. \@tufte@margin@par% use parindent and parskip settings for marginal text
  798. \vspace*{-1\baselineskip}\noindent%
  799. \protected@edef\@currentlabel{%
  800. \csname p@footnote\endcsname\@thefnmark%
  801. }%
  802. \color@begingroup%
  803. \@makefntext{%
  804. \ignorespaces#2%
  805. }%
  806. \color@endgroup%
  807. }%
  808. \@tufte@reset@par% use parindent and parskip settings for body text
  809. }%
  810. %
  811. % Define \sidenote command. Can handle \cite.
  812. \newlength{\@tufte@sidenote@vertical@offset}
  813. \setlength{\@tufte@sidenote@vertical@offset}{0pt}
  814. % #1 = footnote num, #2 = vertical offset, #3 = footnote text
  815. \long\def\@tufte@sidenote[#1][#2]#3{%
  816. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  817. \gdef\@tufte@citations{}% clear out any old citations
  818. \ifthenelse{\NOT\isempty{#2}}{%
  819. \gsetlength{\@tufte@sidenote@vertical@offset}{#2}%
  820. }{%
  821. \gsetlength{\@tufte@sidenote@vertical@offset}{0pt}%
  822. }%
  823. \ifthenelse{\isempty{#1}}{%
  824. % no specific footnote number provided
  825. \stepcounter\@mpfn%
  826. \protected@xdef\@thefnmark{\thempfn}%
  827. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  828. }{%
  829. % specific footnote number provided
  830. \begingroup%
  831. \csname c@\@mpfn\endcsname #1\relax%
  832. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  833. \endgroup%
  834. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  835. }%
  836. \@tufte@print@citations% print any citations
  837. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  838. \unskip\ignorespaces% remove extra white space
  839. \kern-\multiplefootnotemarker% remove \kern left behind by sidenote
  840. \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
  841. }
  842. \newcommand*{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  843. \renewcommand*{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  844. %%
  845. % Sidenote without the footnote mark
  846. \newcommand\marginnote[2][0pt]{%
  847. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  848. \gdef\@tufte@citations{}% clear out any old citations
  849. \@tufte@margin@par% use parindent and parskip settings for marginal text
  850. \marginpar{\hbox{}\vspace*{#1}\@tufte@marginnote@font\@tufte@marginnote@justification\vspace*{-1\baselineskip}\noindent #2}%
  851. \@tufte@reset@par% use parindent and parskip settings for body text
  852. \@tufte@print@citations% print any citations
  853. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  854. }
  855. %%
  856. % The placeins package provides the \FloatBarrier command. This forces
  857. % LaTeX to place all of the floats before proceeding. We'll use this to
  858. % keep the float (figure and table) numbers in sequence.
  859. \RequirePackage{placeins}
  860. %%
  861. % Margin float environment
  862. \newsavebox{\@tufte@margin@floatbox}
  863. \newenvironment{@tufte@margin@float}[2][-1.2ex]%
  864. {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  865. \begin{lrbox}{\@tufte@margin@floatbox}%
  866. \begin{minipage}{\marginparwidth}%
  867. \@tufte@caption@font%
  868. \def\@captype{#2}%
  869. \hbox{}\vspace*{#1}%
  870. \@tufte@caption@justification%
  871. \@tufte@margin@par%
  872. \noindent%
  873. }
  874. {\end{minipage}%
  875. \end{lrbox}%
  876. \marginpar{\usebox{\@tufte@margin@floatbox}}%
  877. \@tufte@reset@par%
  878. }
  879. %%
  880. % Margin figure environment
  881. \newenvironment{marginfigure}[1][-1.2ex]%
  882. {\begin{@tufte@margin@float}[#1]{figure}}
  883. {\end{@tufte@margin@float}}
  884. %%
  885. % Margin table environment
  886. \newenvironment{margintable}[1][-1.2ex]%
  887. {\begin{@tufte@margin@float}[#1]{table}}
  888. {\end{@tufte@margin@float}}
  889. %%
  890. % Auto-detects the proper text alignment based on the various class options
  891. \newcommand*{\@tufte@justification@autodetect}{%
  892. \ifthenelse{\boolean{@tufte@justified}}%
  893. {\justifying}%
  894. {\RaggedRight}%
  895. }
  896. %%
  897. % Forces the outer edge of the caption to be set ragged.
  898. % Therefore, on verso pages it's ragged left, and on recto pages it's ragged right.
  899. \newcommand*{\@tufte@justification@caption@outer}{%
  900. \ifthenelse{\boolean{@tufte@float@recto}}%
  901. {\RaggedRight}%
  902. {\RaggedLeft}%
  903. }
  904. \newcommand*{\@tufte@justification@outer}{%
  905. \@tufte@checkoddpage%
  906. \ifthenelse{\boolean{@tufte@odd@page}}%
  907. {\RaggedRight}%
  908. {\RaggedLeft}%
  909. }
  910. %%
  911. % A collection of macros to be used with the new Tufte-style float environments.
  912. % \setfloatalignment forces the caption placement to be treated as top, bottom, etc.
  913. % \forcerectofloat forces the float to be treated as if it were appearing on a recto page.
  914. % \forceversofloat does the same, but for verso pages.
  915. \newcommand{\@tufte@float@debug@info}{}% contains debug info generated as the float is processed
  916. \newcommand{\@tufte@float@debug}[1]{% adds debug info to the queue for output
  917. \ifthenelse{\equal{\@tufte@float@debug@info}{}}%
  918. {\def\@tufte@float@debug@info{#1}}%
  919. {\g@addto@macro\@tufte@float@debug@info{\MessageBreak#1}}
  920. }
  921. \newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p)
  922. \newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}\@tufte@float@debug{Forcing position: [#1]}}% manually sets the float alignment
  923. \newboolean{@tufte@float@recto}
  924. \newcommand{\forcerectofloat}{\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Forcing page: [recto]}}
  925. \newcommand{\forceversofloat}{\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Forcing page: [verso]}}
  926. % Boxes to temporarily store our float and caption
  927. \newsavebox{\@tufte@figure@box}
  928. \newsavebox{\@tufte@caption@box}
  929. % Save original LaTeX float environment
  930. \let\@tufte@orig@float\@float
  931. \let\@tufte@orig@endfloat\end@float
  932. % New length for tweaking float captions
  933. \newlength{\@tufte@caption@vertical@offset}
  934. \setlength{\@tufte@caption@vertical@offset}{0pt}
  935. % Store the caption and label contents
  936. \newcommand{\@tufte@stored@shortcaption}{}
  937. \newcommand{\@tufte@stored@caption}{}
  938. \newcommand{\@tufte@stored@label}{}
  939. \long\def\@tufte@caption[#1][#2]#3{%
  940. \ifthenelse{\isempty{#1}}%
  941. {\gdef\@tufte@stored@shortcaption{#3}}%
  942. {\gdef\@tufte@stored@shortcaption{#1}}%
  943. \gsetlength{\@tufte@caption@vertical@offset}{-#2}% we want a positive offset to lower captions
  944. \gdef\@tufte@stored@caption{#3}%
  945. }
  946. \newcommand{\@tufte@label}[1]{%
  947. \gdef\@tufte@stored@label{#1}%
  948. }
  949. \newcommand{\@tufte@fps}{}
  950. \newboolean{@tufte@float@star}
  951. \newlength{\@tufte@float@contents@width}
  952. %%
  953. % Define a float environment to place the captions in the margin space
  954. \newenvironment{@tufte@float}[3][htbp]%
  955. {% begin @tufte@float
  956. % Should this float be full-width or just text-width?
  957. \ifthenelse{\equal{#3}{star}}%
  958. {\gsetboolean{@tufte@float@star}{true}}%
  959. {\gsetboolean{@tufte@float@star}{false}}%
  960. % Check page side (recto/verso) and store detected value -- can be overriden in environment contents
  961. \@tufte@checkoddpage%
  962. \ifthenelse{\boolean{@tufte@odd@page}}%
  963. {\gsetboolean{@tufte@float@recto}{true}\@tufte@float@debug{Detected page: [recto/odd]}}%
  964. {\gsetboolean{@tufte@float@recto}{false}\@tufte@float@debug{Detected page: [verso/even]}}%
  965. % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them.
  966. \renewcommand{\@tufte@fps}{#1}%
  967. \@tufte@float@debug{Allowed positions: [#1]}
  968. \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}%
  969. {\renewcommand{\floatalignment}{b}\@tufte@float@debug{Presumed position: [bottom]}}%
  970. {\renewcommand{\floatalignment}{t}\@tufte@float@debug{Presumed position: [top]}}%
  971. % Capture the contents of the \caption and \label commands to use later
  972. \global\let\@tufte@orig@caption\caption%
  973. \global\let\@tufte@orig@label\label%
  974. \renewcommand{\caption}{\optparams{\@tufte@caption}{[][0pt]}}%
  975. \renewcommand{\label}[1]{\@tufte@label{##1}}%
  976. % Handle subfigure package compatibility
  977. \ifthenelse{\boolean{@tufte@packages@subfigure}}{%
  978. % don't move the label while inside a \subfigure or \subtable command
  979. \global\let\label\@tufte@orig@label%
  980. }{}% subfigure package is not loaded
  981. \@tufte@orig@float{#2}[#1]%
  982. \ifthenelse{\boolean{@tufte@float@star}}%
  983. {\setlength{\@tufte@float@contents@width}{\@tufte@fullwidth}}%
  984. {\setlength{\@tufte@float@contents@width}{\textwidth}}%
  985. \begin{lrbox}{\@tufte@figure@box}%
  986. \begin{minipage}[\floatalignment]{\@tufte@float@contents@width}\hbox{}%
  987. }{% end @tufte@float
  988. \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
  989. \end{minipage}%
  990. \end{lrbox}%
  991. % build the caption box
  992. \begin{lrbox}{\@tufte@caption@box}%
  993. \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
  994. \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
  995. \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
  996. \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
  997. \end{minipage}%
  998. \end{lrbox}%
  999. % now typeset the stored boxes
  1000. \begin{fullwidth}%
  1001. \begin{minipage}[\floatalignment]{\linewidth}%
  1002. \ifthenelse{\boolean{@tufte@float@star}}%
  1003. {\@tufte@float@fullwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
  1004. {\@tufte@float@textwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
  1005. \end{minipage}%
  1006. \end{fullwidth}%
  1007. \@tufte@orig@endfloat% end original LaTeX float environment
  1008. % output debug info
  1009. \ifthenelse{\boolean{@tufte@debug}}{%
  1010. \typeout{^^J^^J----------- Tufte-LaTeX float information ----------}%
  1011. \ifthenelse{\equal{\@tufte@stored@label}{}}%
  1012. {\typeout{Warning: Float unlabeled!}}%
  1013. {\typeout{Float label: [\@tufte@stored@label]}}%
  1014. \typeout{Page number: [\thepage]}%
  1015. \def\MessageBreak{^^J}%
  1016. \typeout{\@tufte@float@debug@info}%
  1017. \ifthenelse{\boolean{@tufte@symmetric}}%
  1018. {\typeout{Symmetric: [true]}}%
  1019. {\typeout{Symmetric: [false]}}%
  1020. \typeout{----------------------------------------------------^^J^^J}%
  1021. }{}%
  1022. % reset commands and temp boxes and captions
  1023. \gdef\@tufte@float@debug@info{}%
  1024. \let\caption\@tufte@orig@caption%
  1025. \let\label\@tufte@orig@label%
  1026. \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}%
  1027. \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}%
  1028. \gdef\@tufte@stored@shortcaption{}%
  1029. \gdef\@tufte@stored@caption{}%
  1030. \gdef\@tufte@stored@label{}%
  1031. \gsetlength{\@tufte@caption@vertical@offset}{0pt}% reset caption offset
  1032. }
  1033. \newcommand{\@tufte@float@textwidth}[3][0pt]{%
  1034. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}{%
  1035. % asymmetric or page is odd, so caption is on the right
  1036. \hbox{%
  1037. \usebox{#2}%
  1038. \hspace{\marginparsep}%
  1039. \smash{\raisebox{#1}{\usebox{#3}}}%
  1040. }%
  1041. \@tufte@float@debug{Caption position: [right]}%
  1042. }{% symmetric pages and page is even, so caption is on the left
  1043. \hbox{%
  1044. \smash{\raisebox{#1}{\usebox{#3}}}%
  1045. \hspace{\marginparsep}%
  1046. \usebox{#2}%
  1047. }%
  1048. \@tufte@float@debug{Caption position: [left]}%
  1049. }%
  1050. }
  1051. \newcommand{\@tufte@float@fullwidth}[3][0pt]{%
  1052. \ifthenelse{\equal{\floatalignment}{b}}%
  1053. {% place caption above figure
  1054. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
  1055. {\hfill\smash{\raisebox{#1}{\usebox{#3}}}\par\usebox{#2}\@tufte@float@debug{Caption position: [above right]}}% caption on the right
  1056. {\smash{\raisebox{#1}{\usebox{#3}}}\hfill\par\usebox{#2}\@tufte@float@debug{Caption position: [above left]}}% caption on the left
  1057. }{% place caption below figure
  1058. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
  1059. {\usebox{#2}\par\hfill\smash{\raisebox{#1}{\usebox{#3}}}\@tufte@float@debug{Caption position: [below right]}}% caption on the right
  1060. {\usebox{#2}\par\smash{\raisebox{#1}{\usebox{#3}}}\hfill\@tufte@float@debug{Caption position: [below left]}}% caption on the left
  1061. }%
  1062. }
  1063. %%
  1064. % Redefine the figure environment to place the captions in the margin space
  1065. \renewenvironment{figure}[1][htbp]
  1066. {\begin{@tufte@float}[#1]{figure}{}}
  1067. {\end{@tufte@float}}
  1068. %%
  1069. % Redefine the table environment to place the captions in the margin space
  1070. \renewenvironment{table}[1][htbp]
  1071. {\begin{@tufte@float}[#1]{table}{}}
  1072. {\end{@tufte@float}}
  1073. %%
  1074. % Full-width figure
  1075. \renewenvironment{figure*}[1][htbp]%
  1076. {\begin{@tufte@float}[#1]{figure}{star}}
  1077. {\end{@tufte@float}}
  1078. %%
  1079. % Full-width table
  1080. \renewenvironment{table*}[1][htbp]%
  1081. {\begin{@tufte@float}[#1]{table}{star}}
  1082. {\end{@tufte@float}}
  1083. %%
  1084. % Full-page-width area
  1085. \newenvironment{fullwidth}
  1086. {\ifthenelse{\boolean{@tufte@symmetric}}%
  1087. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}%
  1088. {\begin{adjustwidth}{}{-\@tufte@overhang}}%
  1089. }%
  1090. {\ifthenelse{\boolean{@tufte@symmetric}}%
  1091. {\ifthenelse{\boolean{@tufte@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}%
  1092. {\end{adjustwidth}}%
  1093. }
  1094. %%
  1095. % Format the captions in a style similar to the sidenotes
  1096. \long\def\@caption#1[#2]#3{%
  1097. \par%
  1098. \addcontentsline{\csname ext@#1\endcsname}{#1}%
  1099. {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  1100. \begingroup%
  1101. \@parboxrestore%
  1102. \if@minipage%
  1103. \@setminipage%
  1104. \fi%
  1105. \@tufte@caption@font\@tufte@caption@justification%
  1106. \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
  1107. %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  1108. \endgroup}
  1109. %%
  1110. % If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided,
  1111. % we should load the Palatino, Helvetica, and Bera Mono fonts (if they are
  1112. % installed.)
  1113. \ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  1114. \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
  1115. \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.90]{helvet}}{}
  1116. \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{}
  1117. \RequirePackage[T1]{fontenc}
  1118. \RequirePackage{textcomp}
  1119. }{}
  1120. %%
  1121. % Turns newlines into spaces. Based on code from the `titlesec' package.
  1122. \DeclareRobustCommand{\@tufte@newlinetospace}{%
  1123. \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}%
  1124. }
  1125. \def\@tufte@newlinetospace@i{%
  1126. \ifdim\lastskip>\z@\else\space\fi
  1127. \ignorespaces%
  1128. }
  1129. \DeclareRobustCommand{\newlinetospace}[1]{%
  1130. \let\@tufte@orig@cr\\% save the original meaning of \\
  1131. \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space
  1132. \let\newline\\% turn \newline into \space
  1133. #1%
  1134. \let\\\@tufte@orig@cr% revert to original meaning of \\
  1135. }
  1136. %%
  1137. % Sets up the running heads and folios.
  1138. \RequirePackage{fancyhdr}
  1139. % Set the default page style to 'fancy'
  1140. \pagestyle{fancy}
  1141. % S…

Large files files are truncated, but you can click here to view the full file