Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1100 řádky
34KB

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