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

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