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.

1416 lines
45KB

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