Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

980 рядки
30KB

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