Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1410 linhas
45KB

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