您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1428 行
46KB

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