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.

1101 line
34KB

  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\@xiipt{14}}
  161. \renewcommand\Large{\@setfontsize\Large\@xivpt{18}}
  162. \renewcommand\LARGE{\@setfontsize\LARGE\@xviipt{22}}
  163. \renewcommand\huge{\@setfontsize\huge\@xxpt{25}}
  164. \renewcommand\Huge{\@setfontsize\Huge\@xxvpt{30}}
  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. \setlength{\parindent}{1pc}
  175. \setlength{\parskip}{0pt}
  176. %%
  177. % Set page layout geometry
  178. \RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
  179. \ifthenelse{\boolean{@tufte@afourpaper}}
  180. {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  181. {}
  182. \ifthenelse{\boolean{@tufte@symmetric}}
  183. {}
  184. {\geometry{asymmetric}}% forces internal LaTeX `twoside'
  185. %%
  186. % Separation marginpars by a line's worth of space.
  187. \setlength\marginparpush{10pt}
  188. %%
  189. % Font for margin items
  190. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  191. {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize\sffamily}}
  192. {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize}}
  193. %%
  194. % \RaggedRight allows hyphenation
  195. \RequirePackage{ragged2e}
  196. \setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize}
  197. %%
  198. % Set the justification baesed on the `justified' class option
  199. \newcommand{\@tufte@justification}{%
  200. \ifthenelse{\boolean{@tufte@justified}}
  201. {\justifying}
  202. {\RaggedRight}
  203. }
  204. %%
  205. % Turn off section numbering
  206. \setcounter{secnumdepth}{-1}
  207. %%
  208. % Tighten up space between displays (e.g., a figure or table) and make symmetric
  209. \setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
  210. \setlength\belowdisplayskip{6pt plus 2pt minus 4pt}
  211. %%
  212. % To implement full-width display environments
  213. \newboolean{@tufte@changepage}
  214. \IfFileExists{changepage.sty}{%
  215. \RequirePackage[strict]{changepage}
  216. \setboolean{@tufte@changepage}{true}
  217. }{%
  218. \RequirePackage[strict]{chngpage}
  219. \setboolean{@tufte@changepage}{false}
  220. }
  221. % Compute length used for full-width displays
  222. \newlength{\@tufte@overhang}
  223. \setlength{\@tufte@overhang}{\marginparwidth}
  224. \addtolength{\@tufte@overhang}{\marginparsep}
  225. %%
  226. % Modified \title, \author, and \date commands. These store the
  227. % (footnote-less) values in \thetitle, \theauthor, and \thedate, respectively.
  228. \newcommand{\thetitle}{}% plain-text-only title
  229. \newcommand{\theauthor}{}% plain-text-only author
  230. \newcommand{\thepublisher}{}% plain-text-only publisher
  231. \newcommand{\thanklesstitle}{}% full title text minus \thanks{}
  232. \newcommand{\thanklessauthor}{}% full author text minus \thanks{}
  233. \newcommand{\thanklesspublisher}{}% full publisher minus \thanks{}
  234. \newcommand{\@publisher}{}% full publisher with \thanks{}
  235. \newcommand{\thedate}{\today}
  236. % TODO Fix it so that \thanks is not spaced out (with `soul') and can be
  237. % used in \maketitle when the `sfsidenotes' option is provided.
  238. \renewcommand{\thanks}[1]{\NoCaseChange{\footnote{#1}}}
  239. \renewcommand{\title}[2][]{%
  240. \gdef\@title{#2}%
  241. \begingroup%
  242. % TODO store contents of \thanks command
  243. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  244. \protected@xdef\thanklesstitle{#2}%
  245. \endgroup%
  246. \ifthenelse{\isempty{#1}}%
  247. {\renewcommand{\thetitle}{\thanklesstitle}}% use thankless title
  248. {\renewcommand{\thetitle}{#1}}% use provided plain-text title
  249. \hypersetup{pdftitle={\thetitle}}% set the PDF metadata title
  250. }
  251. \def\@author{}% default author is empty (suppresses LaTeX's ``no author'' warning)
  252. \renewcommand*{\author}[2][]{%
  253. \gdef\@author{#2}%
  254. \begingroup%
  255. % TODO store contents of \thanks command
  256. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  257. \protected@xdef\thanklessauthor{#2}%
  258. \endgroup%
  259. \ifthenelse{\isempty{#1}}
  260. {\renewcommand{\theauthor}{\thanklessauthor}}% use thankless author
  261. {\renewcommand{\theauthor}{#1}}% use provided plain-text author
  262. \hypersetup{pdfauthor={\theauthor}}% set the PDF metadata author
  263. }
  264. \renewcommand*{\date}[1]{%
  265. \gdef\@date{#1}%
  266. \begingroup%
  267. % TODO store contents of \thanks command
  268. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  269. \protected@xdef\thedate{#1}%
  270. \endgroup%
  271. }
  272. %%
  273. % Provides a \publisher command to set the publisher
  274. \newcommand{\publisher}[2][]{%
  275. \gdef\@publisher{#2}%
  276. \begingroup%
  277. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  278. \protected@xdef\thanklesspublisher{#2}%
  279. \endgroup%
  280. \ifthenelse{\isempty{#1}}
  281. {\renewcommand{\thepublisher}{\thanklesspublisher}}% use thankless publisher
  282. {\renewcommand{\thepublisher}{#1}}% use provided plain-text publisher
  283. }
  284. % TODO: Test \hypersetup{pdfauthor,pdftitle} with DVI and XeTeX
  285. %%
  286. % Require paralist package for tighter lists
  287. \RequirePackage{paralist}
  288. % Add rightmargin to compactenum
  289. \def\@compactenum@{%
  290. \expandafter\list\csname label\@enumctr\endcsname{%
  291. \usecounter{\@enumctr}%
  292. \rightmargin=2em% added this
  293. \parsep\plparsep
  294. \itemsep\plitemsep
  295. \topsep\pltopsep
  296. \partopsep\plpartopsep
  297. \def\makelabel##1{\hss\llap{##1}}}}
  298. %%
  299. % Improved letterspacing of small caps and all-caps text.
  300. %
  301. % First, try to use the `microtype' package, if it's available.
  302. % Failing that, try to use the `soul' package, if it's available.
  303. % Failing that, well, I give up.
  304. \RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase
  305. \def\allcapsspacing{\relax}
  306. \def\smallcapsspacing{\relax}
  307. \newcommand{\allcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}}
  308. \newcommand{\smallcaps}[1]{\MakeTextLowercase{\textsc{#1}}}
  309. \newcommand{\@tufte@loadsoul}{%
  310. \IfFileExists{soul.sty}{%
  311. \RequirePackage{soul}
  312. \sodef\allcapsspacing{\upshape}{0.15em}{0.65em}{0.6em}
  313. \sodef\smallcapsspacing{\scshape}{0.075em}{0.5em}{0.6em}
  314. }{
  315. \PackageWarningNoLine{\@tufte@pkgname}{Couldn't locate `soul' package.}
  316. }% soul not installed... giving up.
  317. }
  318. % If we're using pdfLaTeX v1.40+, use the letterspace package.
  319. % If we're using pdfLaTex < v1.40, use the soul package.
  320. % If we're using XeLaTeX, use XeLaTeX letterspacing options.
  321. % Otherwise fall back on the soul package.
  322. \ifthenelse{\boolean{@tufte@pdf}}
  323. {\PackageInfo{\@tufte@pkgname}{ifpdf = true}}
  324. {\PackageInfo{\@tufte@pkgname}{ifpdf = false}}
  325. \ifthenelse{\boolean{@tufte@xetex}}
  326. {\PackageInfo{\@tufte@pkgname}{ifxetex = true}}
  327. {\PackageInfo{\@tufte@pkgname}{ifxetex = false}}
  328. % Check pdfLaTeX version
  329. \def\@tufte@pdftexversion{0}
  330. \ifx\normalpdftexversion\@undefined \else
  331. \let\pdftexversion \normalpdftexversion
  332. \let\pdftexrevision\normalpdftexrevision
  333. \let\pdfoutput \normalpdfoutput
  334. \fi
  335. \ifx\pdftexversion\@undefined \else
  336. \ifx\pdftexversion\relax \else
  337. \def\@tufte@pdftexversion{6}
  338. \ifnum\pdftexversion < 140
  339. \def\@tufte@pdftexversion{5}
  340. \fi
  341. \fi
  342. \fi
  343. \ifthenelse{\boolean{@tufte@letterspace}}
  344. {%
  345. \ifnum\@tufte@pdftexversion<6
  346. % pdfLaTeX version is too old or not using pdfLaTeX
  347. \ifthenelse{\boolean{@tufte@xetex}}
  348. {% TODO use xetex letterspacing
  349. \PackageInfo{\@tufte@pkgname}{XeTeX detected. Reverting to `soul' package for letterspacing.}
  350. \@tufte@loadsoul}
  351. {% use `soul' package for letterspacing
  352. \PackageInfo{\@tufte@pkgname}{Old version of pdfTeX detected. Reverting to `soul' package for letterspacing.}
  353. \@tufte@loadsoul}
  354. \else
  355. \IfFileExists{letterspace.sty}{%
  356. \PackageInfo{\@tufte@pkgname}{Modern version of pdfTeX detected. Using `letterspace' package.}
  357. \RequirePackage{letterspace}
  358. % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
  359. \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
  360. \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
  361. \renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
  362. \renewcommand{\smallcaps}[1]{\textsc{\MakeTextLowercase{##1}}}
  363. }{% microtype failed, check for soul
  364. \PackageInfo{\@tufte@pkgname}{Modern version of pdfTeX detected, but `letterspace' package not installed. Reverting to `soul' package for letterspacing.}
  365. \@tufte@loadsoul
  366. }
  367. \fi}
  368. {}
  369. \DeclareTextFontCommand{\textsmallcaps}{\scshape}
  370. \renewcommand{\textsc}[1]{\textsmallcaps{\smallcapsspacing{#1}}}
  371. %%
  372. % An environment for paragraph-style section
  373. \providecommand\newthought[1]{%
  374. \addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}%
  375. \noindent\textsc{#1}%
  376. }
  377. %%
  378. % Redefine the display environments (quote, quotation, etc.)
  379. \renewenvironment{verse}
  380. {\let\\\@centercr
  381. \list{}{\itemsep \z@
  382. \itemindent -1pc%
  383. \listparindent\itemindent
  384. \rightmargin \leftmargin
  385. \advance\leftmargin 1pc}%
  386. \small%
  387. \item\relax}
  388. {\endlist}
  389. \renewenvironment{quotation}
  390. {\list{}{\listparindent 1pc%
  391. \itemindent \listparindent
  392. \rightmargin \leftmargin
  393. \parsep \z@ \@plus\p@}%
  394. \small%
  395. \item\relax\noindent\ignorespaces}
  396. {\endlist}
  397. \renewenvironment{quote}
  398. {\list{}{\rightmargin\leftmargin}%
  399. \small%
  400. \item\relax}
  401. {\endlist}
  402. %%
  403. % Used for doublespacing, and other linespacing
  404. \RequirePackage{setspace}
  405. %%
  406. % Load the bidi package if instructed to do so. This package must be loaded
  407. % prior to our redefining the \footnote and \cite commands.
  408. \ifthenelse{\boolean{@tufte@loadbidi}}{\RequirePackage{bidi}}{}
  409. %%
  410. % Citations should go in the margin as sidenotes
  411. \RequirePackage[numbers]{natbib}
  412. \RequirePackage{bibentry} % allows bibitems to be typeset outside thebibliography environment
  413. % Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style
  414. \renewcommand\BR@b@bibitem[2][]{%
  415. \ifthenelse{\isempty{#1}}%
  416. {\BR@bibitem{#2}}%
  417. {\BR@bibitem[#1]{#2}}%
  418. \BR@c@bibitem{#2}%
  419. }
  420. \nobibliography* % pre-loads the bibliography keys
  421. \providecommand{\doi}[1]{\textsc{doi:} #1} % pre-defining this so it may be used before the \bibliography command it issued
  422. %%
  423. % Normal \cite behavior
  424. \newcounter{@tufte@num@bibkeys}%
  425. \newcommand{\@tufte@normal@cite}[2][0pt]{%
  426. % Snag the last bibentry in the list for later comparison
  427. \let\@temp@last@bibkey\@empty%
  428. \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  429. \sidenote[][#1]{%
  430. % Loop through all the bibentries, separating them with semicolons and spaces
  431. \setcounter{@tufte@num@bibkeys}{0}%
  432. \@for\@temp@bibkeyx:=#2\do{%
  433. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  434. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  435. \bibentry{\@temp@bibkeyx}}%
  436. {\bibentry{\@temp@bibkeyx};\ }%
  437. \stepcounter{@tufte@num@bibkeys}%
  438. }%
  439. }%
  440. }
  441. %%
  442. % Macros for holding the list of cite keys until after the \sidenote
  443. \gdef\@tufte@citations{}% list of cite keys
  444. \newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
  445. \ifx\@tufte@citations\@empty\else
  446. \g@addto@macro\@tufte@citations{,}% separate by commas
  447. \fi
  448. \g@addto@macro\@tufte@citations{#1}
  449. }
  450. \newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note
  451. % Snag the last bibentry in the list for later comparison
  452. \let\@temp@last@bibkey\@empty%
  453. \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
  454. \marginpar{%
  455. \vspace*{#1}%
  456. \@tufte@marginfont%
  457. \@tufte@justification%
  458. % Loop through all the bibentries, separating them with semicolons and spaces
  459. \setcounter{@tufte@num@bibkeys}{0}%
  460. \@for\@temp@bibkeyx:=\@tufte@citations\do{%
  461. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  462. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  463. \bibentry{\@temp@bibkeyx}}%
  464. {\bibentry{\@temp@bibkeyx};\ }%
  465. \stepcounter{@tufte@num@bibkeys}%
  466. }%
  467. }%
  468. }
  469. %%
  470. % \cite behavior when executed within a sidenote
  471. \newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote
  472. \newcommand{\@tufte@infootnote@cite}[1]{%
  473. \@tufte@add@citation{#1}
  474. }
  475. %%
  476. % Set the default \cite style. This is set and reset by the \sidenote command.
  477. \let\cite\@tufte@normal@cite
  478. %%
  479. % Transform existing \footnotes into \sidenotes
  480. % Sidenote: ``Where God meant footnotes to go.'' ---Tufte
  481. \RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
  482. \providecommand*{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  483. \renewcommand{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  484. % Override footmisc's definition to set the sidenote marks (numbers) inside the
  485. % sidenote's text block.
  486. \long\def\@makefntext#1{\@textsuperscript{\@tufte@marginfont\tiny\@thefnmark}\,\footnotelayout#1}
  487. % Set the in-text footnote mark in the same typeface as the body text itself.
  488. \def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}}
  489. \providecommand*{\multiplefootnotemarker}{3sp}
  490. \providecommand*{\multfootsep}{,}
  491. \renewcommand*\@footnotemark{%
  492. \leavevmode%
  493. \ifhmode%
  494. \edef\@x@sf{\the\spacefactor}%
  495. \@tufte@check@multiple@sidenotes%
  496. \nobreak%
  497. \fi%
  498. \@makefnmark%
  499. \ifhmode\spacefactor\@x@sf\fi%
  500. \relax%
  501. }
  502. \newcommand{\@tufte@check@multiple@sidenotes}{%
  503. \ifdim\lastkern=\multiplefootnotemarker\relax
  504. \edef\@x@sf{\the\spacefactor}%
  505. \unkern
  506. \textsuperscript{\multfootsep}%
  507. \spacefactor\@x@sf\relax
  508. \fi
  509. }
  510. \renewcommand\@footnotetext[2][0pt]{%
  511. \marginpar{%
  512. \vspace*{#1}%
  513. \def\baselinestretch {\setspace@singlespace}%
  514. \ifthenelse{\boolean{@tufte@loadbidi}}{\if@rl@footnote\@rltrue\else\@rlfalse\fi}{}%
  515. \reset@font\footnotesize%
  516. \protected@edef\@currentlabel{%
  517. \csname p@footnote\endcsname\@thefnmark%
  518. }%
  519. \color@begingroup%
  520. \@makefntext{%
  521. \ignorespaces#2%
  522. }%
  523. \color@endgroup%
  524. }%
  525. }%
  526. %
  527. % Define \sidenote command. Can handle \cite.
  528. \newcommand{\@tufte@sidenote@vertical@offset}{0pt}
  529. % #1 = footnote num, #2 = vertical offset, #3 = footnote text
  530. \long\def\@tufte@sidenote[#1][#2]#3{%
  531. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  532. \gdef\@tufte@citations{}% clear out any old citations
  533. \ifthenelse{\NOT\isempty{#2}}{\renewcommand{\@tufte@sidenote@vertical@offset}{#2}}{}%
  534. \ifthenelse{\isempty{#1}}{%
  535. % % no footnote number
  536. \stepcounter\@mpfn%
  537. \protected@xdef\@thefnmark{\thempfn}%
  538. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  539. }{%
  540. % % footnote number
  541. \begingroup%
  542. \csname c@\@mpfn\endcsname #1\relax%
  543. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  544. \endgroup%
  545. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  546. }%
  547. \@tufte@print@citations% print any citations
  548. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  549. \unskip\ignorespaces% remove extra white space
  550. \kern-\multiplefootnotemarker% remove \kern left behind by sidenote
  551. \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
  552. }
  553. \newcommand*{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  554. \renewcommand*{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  555. %%
  556. % Sidenote without the footnote mark
  557. \newcommand\marginnote[2][0pt]{%
  558. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  559. \gdef\@tufte@citations{}% clear out any old citations
  560. \marginpar{\vspace*{#1}\@tufte@marginfont\@tufte@justification #2}%
  561. \@tufte@print@citations% print any citations
  562. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  563. }
  564. %%
  565. % The placeins package provides the \FloatBarrier command. This forces
  566. % LaTeX to place all of the floats before proceeding. We'll use this to
  567. % keep the float (figure and table) numbers in sequence.
  568. \RequirePackage{placeins}
  569. %%
  570. % Margin figure environment
  571. \newsavebox{\@tufte@marginfigbox}
  572. \newenvironment{marginfigure}[1][-1.2ex]
  573. {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
  574. \begin{lrbox}{\@tufte@marginfigbox}%
  575. \begin{minipage}{\marginparwidth}%
  576. \captionsetup{type=figure}%
  577. \@tufte@marginfont%
  578. \def\@captype{figure}%
  579. \vspace*{#1}%
  580. \@tufte@justification%
  581. }
  582. {\end{minipage}%
  583. \end{lrbox}%
  584. \marginpar{\usebox{\@tufte@marginfigbox}}}
  585. %%
  586. % Margin table environment
  587. \newsavebox{\@tufte@margintablebox}
  588. \newenvironment{margintable}[1][-1.2ex]
  589. {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
  590. \begin{lrbox}{\@tufte@margintablebox}%
  591. \begin{minipage}{\marginparwidth}%
  592. \captionsetup{type=table}%
  593. \@tufte@marginfont%
  594. \def\@captype{table}%
  595. \vspace*{#1}%
  596. \@tufte@justification%
  597. }
  598. {\end{minipage}%
  599. \end{lrbox}%
  600. \marginpar{\usebox{\@tufte@margintablebox}}}
  601. %%
  602. % Full-width figure
  603. \renewenvironment{figure*}[1]%
  604. [htbp]%
  605. {\@float{figure}[#1]%
  606. \ifthenelse{\boolean{@tufte@symmetric}}
  607. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  608. {\begin{adjustwidth}{}{-\@tufte@overhang}}
  609. \begin{minipage}{\linewidth}%
  610. }%
  611. {\end{minipage}%
  612. \end{adjustwidth}%
  613. \end@float}
  614. %%
  615. % Full-width table
  616. \renewenvironment{table*}[1]
  617. [htbp]%
  618. {\@float{table}[#1]%
  619. \ifthenelse{\boolean{@tufte@symmetric}}
  620. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  621. {\begin{adjustwidth}{}{-\@tufte@overhang}}
  622. \begin{minipage}{\linewidth}%
  623. }%
  624. {\end{minipage}%
  625. \end{adjustwidth}%
  626. \end@float}
  627. %%
  628. % Full-page-width area
  629. \newenvironment{fullwidth}
  630. {\ifthenelse{\boolean{@tufte@symmetric}}
  631. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  632. {\begin{adjustwidth}{}{-\@tufte@overhang}}%
  633. }
  634. {\end{adjustwidth}}
  635. %%
  636. % Format the captions in a style similar to the sidenotes
  637. \RequirePackage[format=default,font={rm,footnotesize},justification=raggedright,singlelinecheck=false]{caption}
  638. % if the `sfsidenotes' option is specified, set the captions in sf, too.
  639. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  640. {\captionsetup{font={sf,footnotesize}}}
  641. {\captionsetup{font={rm,footnotesize}}}
  642. % if the `justified' option is specified, set the captions in flush left
  643. % and flush right
  644. \ifthenelse{\boolean{@tufte@justified}}
  645. {\captionsetup{justification=justified}}
  646. {\captionsetup{justification=raggedright}}
  647. %%
  648. % If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided,
  649. % we should load the Palatino, Helvetica, and Bera Mono fonts (if they are
  650. % installed.)
  651. \ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  652. \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
  653. \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.90]{helvet}}{}
  654. \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{}
  655. \RequirePackage[T1]{fontenc}
  656. \RequirePackage{textcomp}
  657. }{}
  658. %%
  659. % Turns newlines into spaces. Based on code from the `titlesec' package.
  660. \DeclareRobustCommand{\@tufte@newlinetospace}{%
  661. \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}%
  662. }
  663. \def\@tufte@newlinetospace@i{%
  664. \ifdim\lastskip>\z@\else\space\fi
  665. \ignorespaces%
  666. }
  667. \DeclareRobustCommand{\newlinetospace}[1]{%
  668. \let\@tufte@orig@cr\\% save the original meaning of \\
  669. \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space
  670. \let\newline\\% turn \newline into \space
  671. #1%
  672. \let\\\@tufte@orig@cr% revert to original meaning of \\
  673. }
  674. %%
  675. % Sets up the running heads and folios.
  676. \RequirePackage{fancyhdr}
  677. % Set the default page style to 'fancy'
  678. \pagestyle{fancy}
  679. % Set the header/footer width to be the body text block plus the margin
  680. % note area.
  681. \ifthenelse{\boolean{@tufte@symmetric}}
  682. {\fancyhfoffset[LE,RO]{\@tufte@overhang}}
  683. {\fancyhfoffset[RE,RO]{\@tufte@overhang}}
  684. % The running heads/feet don't have rules
  685. \renewcommand{\headrulewidth}{0pt}
  686. \renewcommand{\footrulewidth}{0pt}
  687. % The 'fancy' page style is the default style for all pages.
  688. \fancyhf{} % clear header and footer fields
  689. \ifthenelse{\boolean{@tufte@twoside}}
  690. {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\theauthor}}}%
  691. \fancyhead[RO]{\smallcaps{\newlinetospace{\thetitle}}\quad\thepage}}
  692. {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\thetitle}}\quad\thepage}}
  693. % The `plain' page style is used on chapter opening pages.
  694. % In Tufte's /Beautiful Evidence/ he never puts page numbers at the
  695. % bottom of pages -- the folios are unexpressed.
  696. \fancypagestyle{plain}{
  697. \fancyhf{} % clear header and footer fields
  698. % Uncomment the following five lines of code if you want the opening page
  699. % of the chapter to express the folio in the lower outside corner.
  700. %\ifthenelse{\boolean{@tufte@twoside}}
  701. % {\fancyfoot[LE,RO]{\thepage}}
  702. % {\fancyfoot[RE,RO]{\thepage}}
  703. }
  704. % The `empty' page style suppresses all headers and footers.
  705. % It's used on title pages and `intentionally blank' pages.
  706. \fancypagestyle{empty}{
  707. \fancyhf{} % clear header and footer fields
  708. }
  709. %%
  710. % Set raggedright and paragraph indentation for document
  711. \AtBeginDocument{\@tufte@justification}
  712. %%
  713. % Prints the list of class options and their states.
  714. \newcommand{\typeoutbool}[2]{%
  715. \ifthenelse{\boolean{#2}}
  716. {\typeout{\space\space#1: true}}
  717. {\typeout{\space\space#1: false}}
  718. }
  719. \newcommand{\typeoutstr}[2]{%
  720. \typeout{\space\space#1: #2}
  721. }
  722. \newcommand{\PrintTufteSettings}{%
  723. \typeout{-------------------- Tufte-LaTeX settings ----------}
  724. \typeout{Class: \@tufte@pkgname}
  725. \typeout{}
  726. \typeout{Class options:}
  727. \typeoutbool{a4paper}{@tufte@afourpaper}
  728. \typeoutbool{load fonts}{@tufte@loadfonts}
  729. \typeoutbool{fully-justified}{@tufte@justified}
  730. \typeoutbool{letterspacing}{@tufte@letterspace}
  731. \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes}
  732. \typeoutbool{symmetric margins}{@tufte@symmetric}
  733. \typeoutbool{titlepage}{@tufte@titlepage}
  734. \typeoutbool{twoside}{@tufte@twoside}
  735. \typeoutbool{debug}{@tufte@debug}
  736. \typeout{}
  737. \typeout{Internal variables:}
  738. \typeoutbool{[twoside]}{@twoside}
  739. \typeoutbool{pdflatex}{@tufte@pdf}
  740. \typeoutbool{xelatex}{@tufte@xetex}
  741. \typeout{----------------------------------------------------}
  742. }
  743. %%
  744. % Color
  745. \RequirePackage{xcolor}
  746. %%
  747. % Produces a full title page
  748. \newcommand{\maketitlepage}[0]{%
  749. \cleardoublepage%
  750. {%
  751. \sffamily%
  752. \begin{fullwidth}%
  753. \fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}%
  754. \vspace{11.5pc}%
  755. \fontsize{36}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklesstitle}}%
  756. \vfill%
  757. \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}%
  758. \end{fullwidth}%
  759. }
  760. \thispagestyle{empty}%
  761. \clearpage%
  762. }
  763. %%
  764. % Title block
  765. \renewcommand{\maketitle}{%
  766. \newpage
  767. \global\@topnum\z@% prevent floats from being placed at the top of the page
  768. \begingroup
  769. \setlength{\parindent}{0pt}
  770. \setlength{\parskip}{4pt}
  771. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  772. {\begingroup
  773. % FIXME fails with \thanks
  774. \sffamily
  775. \par{\Large\allcaps{\@title}}
  776. \ifthenelse{\equal{\@author}{}}{}{\par{\large\allcaps{\@author}}}
  777. \ifthenelse{\equal{\@date}{}}{}{\par{\large\allcaps{\@date}}}
  778. \endgroup}
  779. {\begingroup
  780. \par{\Large\textit{\@title}}
  781. \ifthenelse{\equal{\@author}{}}{}{\par{\large\textit{\@author}}}
  782. \ifthenelse{\equal{\@date}{}}{}{\par{\large\textit{\@date}}}
  783. \endgroup}
  784. \par
  785. \endgroup
  786. \setlength{\parindent}{1pc}
  787. \setlength{\parskip}{0pt}
  788. \thispagestyle{plain}% suppress the running head
  789. }
  790. %%
  791. % Title page (if the `titlepage' option was passed to the tufte-handout
  792. % class.)
  793. \ifthenelse{\boolean{@tufte@titlepage}}
  794. {\renewcommand{\maketitle}{\maketitlepage}}
  795. {}
  796. %%
  797. % When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
  798. % without headers and footers
  799. \def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
  800. \hbox{}
  801. %\vspace*{\fill}
  802. %\begin{center}
  803. % This page intentionally contains only this sentence.
  804. %\end{center}
  805. %\vspace{\fill}
  806. \thispagestyle{empty}
  807. \newpage
  808. \if@twocolumn\hbox{}\newpage\fi\fi\fi}
  809. %%
  810. % Make Tuftian-style section headings and TOC formatting
  811. \RequirePackage{titlesec,titletoc}
  812. % TODO: I'd prefer to use the 'titlesec' package for this formatting, but
  813. % I'll do it old-style for now. --Kevin
  814. \renewcommand\section{\@startsection {section}{1}{\z@}%
  815. {-3.5ex \@plus -1ex \@minus -.2ex}%
  816. {2.3ex \@plus.2ex}%
  817. {\normalfont\large\it}}
  818. \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  819. {-3.25ex\@plus -1ex \@minus -.2ex}%
  820. {1.5ex \@plus .2ex}%
  821. {\normalfont\normalsize\it}}
  822. % Subsubsection and following section headings shouldn't be used.
  823. % See Bringhurst's _The Elements of Typography_, section 4.2.2.
  824. \renewcommand\subsubsection{%
  825. \PackageError{\@tufte@pkgname}{\noexpand\subsubsection is undefined by this class.%
  826. \MessageBreak See Robert Bringhurst's _The Elements of
  827. \MessageBreak Typographic Style_, section 4.2.2.
  828. \MessageBreak \noexpand\subsubsection was used}
  829. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  830. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  831. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  832. }
  833. \renewcommand\paragraph{%
  834. \PackageError{\@tufte@pkgname}{\noexpand\paragraph is undefined by this class.%
  835. \MessageBreak See Robert Bringhurst's _The Elements of
  836. \MessageBreak Typographic Style_, section 4.2.2.
  837. \MessageBreak \noexpand\paragraph was used}
  838. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  839. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  840. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  841. }
  842. \renewcommand\subparagraph{%
  843. \PackageError{\@tufte@pkgname}{\noexpand\subparagraph is undefined by this class.%
  844. \MessageBreak See Robert Bringhurst's _The Elements of
  845. \MessageBreak Typographic Style_, section 4.2.2.
  846. \MessageBreak \noexpand\subparagraph was used}
  847. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  848. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  849. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  850. }
  851. % Formatting for main TOC (printed in front matter)
  852. % {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
  853. \ifthenelse{\boolean{@tufte@toc}}
  854. {\titlecontents{chapter}%
  855. [0em] % distance from left margin
  856. {\begin{fullwidth}\fontsize{13pt}{18pt}\selectfont} % above (global formatting of entry)
  857. {\contentslabel{2em}\rm\itshape} % before w/label (label = ``Chapter 1'')
  858. {\rm\itshape} % before w/o label
  859. {\rm\qquad\thecontentspage} % filler + page (leaders and page num)
  860. [\vspace{1.5\baselineskip}\end{fullwidth}] % after
  861. }
  862. {}
  863. %\titlecontents{chapter}%
  864. % [0em]% distance from left margin
  865. % {\fontsize{12pt}{18pt}\selectfont}% above (global formatting of entry)
  866. % {\textit}% before w/ label (label = ``Chapter 1'')
  867. % {\textit}% before w/o label
  868. % {\qquad\thecontentspage}% filler and page (leaders and page num)
  869. % [\vspace{1.5\baselineskip}]% after
  870. \titleformat{\chapter}%
  871. [display]% shape
  872. {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
  873. {\itshape\fontsize{22}{24}\selectfont\thechapter}% label
  874. {0pt}% horizontal separation between label and title body
  875. {\fontsize{22}{24}\rm\itshape}% before the title body
  876. [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body
  877. %%
  878. % A handy command to disable hyphenation for short bits of text.
  879. % Borrowed from Peter Wilson's `hyphenat' package.
  880. \newlanguage\langwohyphens% define a language without hyphenation rules
  881. \newcommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text
  882. \newcommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text
  883. %%
  884. % If debugging is enabled, print the Tufte-LaTeX options and the list of
  885. % files.
  886. \ifthenelse{\boolean{@tufte@debug}}
  887. {\PrintTufteSettings\listfiles}
  888. {}
  889. %%
  890. % If there is a `tufte-common-local.tex' file, load it up.
  891. \IfFileExists{tufte-common-local.tex}
  892. {\input{tufte-common-local}}
  893. {}
  894. %%
  895. % End of file
  896. \endinput