Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1441 lines
46KB

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