25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

2027 satır
69KB

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