選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

1128 行
35KB

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