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

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