You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1510 lines
48KB

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