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.

912 line
28KB

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