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.

1015 line
31KB

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