您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1004 行
31KB

  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. \newcounter{@tufte@num@bibkeys}%
  334. \newcommand{\@tufte@normal@cite}[2][0pt]{%
  335. % Snag the last bibentry in the list for later comparison
  336. \let\@temp@last@bibkey\@empty%
  337. \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  338. \sidenote[][#1]{%
  339. % Loop through all the bibentries, separating them with semicolons and spaces
  340. \setcounter{@tufte@num@bibkeys}{0}%
  341. \@for\@temp@bibkeyx:=#2\do{%
  342. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  343. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  344. \bibentry{\@temp@bibkeyx}}%
  345. {\bibentry{\@temp@bibkeyx};\ }%
  346. \stepcounter{@tufte@num@bibkeys}%
  347. }%
  348. }%
  349. }
  350. %%
  351. % Macros for holding the list of cite keys until after the \sidenote
  352. \gdef\@tufte@citations{}% list of cite keys
  353. \newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
  354. \ifx\@tufte@citations\@empty\else
  355. \g@addto@macro\@tufte@citations{,}% separate by commas
  356. \fi
  357. \g@addto@macro\@tufte@citations{#1}
  358. }
  359. \newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note
  360. % Snag the last bibentry in the list for later comparison
  361. \let\@temp@last@bibkey\@empty%
  362. \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
  363. \marginpar{%
  364. \vspace*{#1}%
  365. \@tufte@marginfont%
  366. \@tufte@justification%
  367. % Loop through all the bibentries, separating them with semicolons and spaces
  368. \setcounter{@tufte@num@bibkeys}{0}%
  369. \@for\@temp@bibkeyx:=\@tufte@citations\do{%
  370. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  371. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  372. \bibentry{\@temp@bibkeyx}}%
  373. {\bibentry{\@temp@bibkeyx};\ }%
  374. \stepcounter{@tufte@num@bibkeys}%
  375. }%
  376. }%
  377. }
  378. %%
  379. % \cite behavior when executed within a sidenote
  380. \newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote
  381. \newcommand{\@tufte@infootnote@cite}[1]{%
  382. \@tufte@add@citation{#1}
  383. }
  384. %%
  385. % Set the default \cite style. This is set and reset by the \sidenote command.
  386. \let\cite\@tufte@normal@cite
  387. %%
  388. % Transform existing \footnotes into \sidenotes
  389. % Sidenote: ``Where God meant footnotes to go.'' ---Tufte
  390. \RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
  391. \providecommand*{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  392. \renewcommand{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  393. % Override footmisc's definition to set the sidenote marks (numbers) inside the
  394. % sidenote's text block.
  395. \long\def\@makefntext#1{\@textsuperscript{\@tufte@marginfont\tiny\@thefnmark}\,\footnotelayout#1}
  396. % Set the in-text footnote mark in the same typeface as the body text itself.
  397. \def\@makefnmark{\hbox{\@textsuperscript{\normalfont\scriptsize\@thefnmark}}}
  398. \providecommand*{\multiplefootnotemarker}{3sp}
  399. \providecommand*{\multfootsep}{,}
  400. \renewcommand*\@footnotemark{%
  401. \leavevmode%
  402. \ifhmode%
  403. \edef\@x@sf{\the\spacefactor}%
  404. \@tufte@check@multiple@sidenotes%
  405. \nobreak%
  406. \fi%
  407. \@makefnmark%
  408. \ifhmode\spacefactor\@x@sf\fi%
  409. \relax%
  410. }
  411. \newcommand{\@tufte@check@multiple@sidenotes}{%
  412. \ifdim\lastkern=\multiplefootnotemarker\relax
  413. \edef\@x@sf{\the\spacefactor}%
  414. \unkern
  415. \textsuperscript{\multfootsep}%
  416. \spacefactor\@x@sf\relax
  417. \fi
  418. }
  419. \renewcommand\@footnotetext[2][0pt]{%
  420. \marginpar{%
  421. \vspace*{#1}%
  422. \def\baselinestretch {\setspace@singlespace}%
  423. \reset@font\footnotesize%
  424. \protected@edef\@currentlabel{%
  425. \csname p@footnote\endcsname\@thefnmark%
  426. }%
  427. \color@begingroup%
  428. \@makefntext{%
  429. \ignorespaces#2%
  430. }%
  431. \color@endgroup%
  432. }%
  433. }%
  434. %
  435. % Define \sidenote command. Can handle \cite.
  436. \newcommand{\@tufte@sidenote@vertical@offset}{0pt}
  437. % #1 = footnote num, #2 = vertical offset, #3 = footnote text
  438. \def\@tufte@sidenote[#1][#2]#3{%
  439. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  440. \gdef\@tufte@citations{}% clear out any old citations
  441. \ifthenelse{\NOT\isempty{#2}}{\renewcommand{\@tufte@sidenote@vertical@offset}{#2}}{}%
  442. \ifthenelse{\isempty{#1}}{%
  443. % % no footnote number
  444. \stepcounter\@mpfn%
  445. \protected@xdef\@thefnmark{\thempfn}%
  446. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  447. }{%
  448. % % footnote number
  449. \begingroup%
  450. \csname c@\@mpfn\endcsname #1\relax%
  451. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  452. \endgroup%
  453. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  454. }%
  455. \@tufte@print@citations% print any citations
  456. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  457. \unskip\ignorespaces% remove extra white space
  458. \kern-\multiplefootnotemarker% remove \kern left behind by sidenote
  459. \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
  460. }
  461. \newcommand*{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  462. \renewcommand*{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  463. %%
  464. % Sidenote without the footnote mark
  465. \newcommand\marginnote[2][0pt]{%
  466. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  467. \gdef\@tufte@citations{}% clear out any old citations
  468. \marginpar{\vspace*{#1}\@tufte@marginfont\@tufte@justification #2}%
  469. \@tufte@print@citations% print any citations
  470. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  471. }
  472. % TODO: Combine sequences of citations so that 2,3,4,6 becomes 2--4,6
  473. % but be careful of hyperref interaction
  474. %%
  475. % The placeins package provides the \FloatBarrier command. This forces
  476. % LaTeX to place all of the floats before proceeding. We'll use this to
  477. % keep the float (figure and table) numbers in sequence.
  478. \RequirePackage{placeins}
  479. %%
  480. % Margin figure environment
  481. \newsavebox{\@tufte@marginfigbox}
  482. \newenvironment{marginfigure}[1]
  483. [-1.2ex]
  484. {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
  485. \begin{lrbox}{\@tufte@marginfigbox}
  486. \begin{minipage}{\marginparwidth}
  487. \@tufte@marginfont
  488. \def\@captype{figure}
  489. \vspace*{#1}
  490. \@tufte@justification
  491. }
  492. {\end{minipage}%
  493. \end{lrbox}%
  494. \marginpar{\usebox{\@tufte@marginfigbox}}}
  495. %%
  496. % Margin table environment
  497. \newsavebox{\@tufte@margintablebox}
  498. \newenvironment{margintable}[1]
  499. [-1.2ex]
  500. {\FloatBarrier% process all floats before this point so the figure numbers stay in order.
  501. \begin{lrbox}{\@tufte@margintablebox}
  502. \begin{minipage}{\marginparwidth}
  503. \@tufte@marginfont
  504. \def\@captype{table}
  505. \vspace*{#1}
  506. \@tufte@justification
  507. }
  508. {\end{minipage}%
  509. \end{lrbox}%
  510. \marginpar{\usebox{\@tufte@margintablebox}}}
  511. %%
  512. % Full-width figure
  513. \renewenvironment{figure*}[1]%
  514. [htbp]%
  515. {\@float{figure}[#1]%
  516. \ifthenelse{\boolean{@tufte@symmetric}}
  517. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  518. {\begin{adjustwidth}{}{-\@tufte@overhang}}
  519. \begin{minipage}{\linewidth}}%
  520. {\end{minipage}%
  521. \end{adjustwidth}%
  522. \end@float}
  523. %%
  524. % Full-width table
  525. \renewenvironment{table*}[1]
  526. [htbp]%
  527. {\@float{table}[#1]%
  528. \ifthenelse{\boolean{@tufte@symmetric}}
  529. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  530. {\begin{adjustwidth}{}{-\@tufte@overhang}}
  531. \begin{minipage}{\linewidth}}%
  532. {\end{minipage}%
  533. \end{adjustwidth}%
  534. \end@float}
  535. %%
  536. % Full-page-width area
  537. \newenvironment{fullwidth}
  538. {\ifthenelse{\boolean{@tufte@symmetric}}
  539. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}
  540. {\begin{adjustwidth}{}{-\@tufte@overhang}}
  541. }
  542. {\end{adjustwidth}}
  543. %%
  544. % Format the captions in a style similar to the sidenotes
  545. \RequirePackage[format=default,font={rm,scriptsize},justification=raggedright,singlelinecheck=false]{caption}
  546. % if the `sfsidenotes' option is specified, set the captions in sf, too.
  547. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  548. {\captionsetup{font={sf,scriptsize}}}
  549. {\captionsetup{font={rm,scriptsize}}}
  550. % if the `justified' option is specified, set the captions in flush left
  551. % and flush right
  552. \ifthenelse{\boolean{@tufte@justified}}
  553. {\captionsetup{justification=justified}}
  554. {\captionsetup{justification=raggedright}}
  555. %%
  556. % If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided,
  557. % we should load the Palatino, Helvetica, and Bera Mono fonts (if they are
  558. % installed.)
  559. \ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  560. \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
  561. \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.95]{helvet}}{}
  562. \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{}
  563. \RequirePackage[T1]{fontenc}
  564. \RequirePackage{textcomp}
  565. }{}
  566. %%
  567. % Turns newlines into spaces. Based on code from the `titlesec' package.
  568. \DeclareRobustCommand{\@tufte@newlinetospace}{%
  569. \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}%
  570. }
  571. \def\@tufte@newlinetospace@i{%
  572. \ifdim\lastskip>\z@\else\space\fi
  573. \ignorespaces%
  574. }
  575. \DeclareRobustCommand{\newlinetospace}[1]{%
  576. \let\@tufte@orig@cr\\% save the original meaning of \\
  577. \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space
  578. \let\newline\\% turn \newline into \space
  579. #1
  580. \let\\\@tufte@orig@cr% revert to original meaning of \\
  581. }
  582. %%
  583. % Sets up the running heads and folios.
  584. \RequirePackage{fancyhdr}
  585. % Set the default page style to 'fancy'
  586. \pagestyle{fancy}
  587. % Set the header/footer width to be the body text block plus the margin
  588. % note area.
  589. \ifthenelse{\boolean{@tufte@symmetric}}
  590. {\fancyhfoffset[LE,RO]{\@tufte@overhang}}
  591. {\fancyhfoffset[RE,RO]{\@tufte@overhang}}
  592. % The running heads/feet don't have rules
  593. \renewcommand{\headrulewidth}{0pt}
  594. \renewcommand{\footrulewidth}{0pt}
  595. % The 'fancy' page style is the default style for all pages.
  596. \fancyhf{} % clear header and footer fields
  597. \ifthenelse{\boolean{@tufte@twoside}}
  598. {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\theauthor}}}%
  599. \fancyhead[RO]{\smallcaps{\newlinetospace{\thetitle}}\quad\thepage}}
  600. {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\thetitle}}\quad\thepage}}
  601. % The `plain' page style is used on chapter opening pages.
  602. % In Tufte's /Beautiful Evidence/ he never puts page numbers at the
  603. % bottom of pages -- the folios are unexpressed.
  604. \fancypagestyle{plain}{
  605. \fancyhf{} % clear header and footer fields
  606. % Uncomment the following five lines of code if you want the opening page
  607. % of the chapter to express the folio in the lower outside corner.
  608. %\ifthenelse{\boolean{@tufte@twoside}}
  609. % {\fancyfoot[LE,RO]{\thepage}}
  610. % {\fancyfoot[RE,RO]{\thepage}}
  611. }
  612. % The `empty' page style suppresses all headers and footers.
  613. % It's used on title pages and `intentionally blank' pages.
  614. \fancypagestyle{empty}{
  615. \fancyhf{} % clear header and footer fields
  616. }
  617. %%
  618. % Set raggedright and paragraph indentation for document
  619. \AtBeginDocument{\@tufte@justification\setlength\parindent{1em}}
  620. %%
  621. % Prints the list of class options and their states.
  622. \newcommand{\typeoutbool}[2]{%
  623. \ifthenelse{\boolean{#2}}
  624. {\typeout{\space\space#1: true}}
  625. {\typeout{\space\space#1: false}}
  626. }
  627. \newcommand{\typeoutstr}[2]{%
  628. \typeout{\space\space#1: #2}
  629. }
  630. \newcommand{\PrintTufteSettings}{%
  631. \typeout{-------------------- Tufte-LaTeX settings ----------}
  632. \typeout{Class: \@tufte@pkgname}
  633. \typeout{}
  634. \typeout{Class options:}
  635. \typeoutbool{a4paper}{@tufte@afourpaper}
  636. \typeoutbool{load fonts}{@tufte@loadfonts}
  637. \typeoutbool{fully-justified}{@tufte@justified}
  638. \typeoutbool{letterspacing}{@tufte@letterspace}
  639. \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes}
  640. \typeoutbool{symmetric margins}{@tufte@symmetric}
  641. \typeoutbool{titlepage}{@tufte@titlepage}
  642. \typeoutbool{twoside}{@tufte@twoside}
  643. \typeoutbool{debug}{@tufte@debug}
  644. \typeout{}
  645. \typeout{Internal variables:}
  646. \typeoutbool{[twoside]}{@twoside}
  647. \typeoutbool{pdflatex}{@tufte@pdf}
  648. \typeoutbool{xelatex}{@tufte@xetex}
  649. \typeout{----------------------------------------------------}
  650. }
  651. %%
  652. % Color
  653. \RequirePackage{xcolor}
  654. %%
  655. % Produces a full title page
  656. \newcommand{\maketitlepage}[0]{%
  657. \cleardoublepage
  658. {
  659. \sffamily
  660. \begin{fullwidth}
  661. \par\noindent\fontsize{18}{18}\selectfont\textcolor{darkgray}{\allcaps{\thanklessauthor}}
  662. \end{fullwidth}
  663. \vspace{11.5pc}
  664. \begin{fullwidth}
  665. \par\noindent\fontsize{36}{36}\selectfont\textcolor{darkgray}{\allcaps{\thanklesstitle}}
  666. \end{fullwidth}
  667. \vfill
  668. \begin{fullwidth}
  669. \par\noindent\fontsize{14}{14}\selectfont\allcaps{\thanklesspublisher}
  670. \end{fullwidth}
  671. }
  672. \thispagestyle{empty}
  673. \clearpage
  674. }
  675. %%
  676. % Title block
  677. \renewcommand{\maketitle}{%
  678. \newpage
  679. \global\@topnum\z@% prevent floats from being placed at the top of the page
  680. \begingroup
  681. \setlength{\parindent}{0pt}
  682. \setlength{\parskip}{4pt}
  683. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  684. {\begingroup
  685. % FIXME fails with \thanks
  686. \sffamily
  687. \par{\Large\allcaps{\@title}}
  688. \ifthenelse{\equal{\@author}{}}{}{\par{\large\allcaps{\@author}}}
  689. \ifthenelse{\equal{\@date}{}}{}{\par{\large\allcaps{\@date}}}
  690. \endgroup}
  691. {\begingroup
  692. \par{\Large\textit{\@title}}
  693. \ifthenelse{\equal{\@author}{}}{}{\par{\large\textit{\@author}}}
  694. \ifthenelse{\equal{\@date}{}}{}{\par{\large\textit{\@date}}}
  695. \endgroup}
  696. \par
  697. \endgroup
  698. \thispagestyle{plain}% suppress the running head
  699. }
  700. %%
  701. % Title page (if the `titlepage' option was passed to the tufte-handout
  702. % class.)
  703. \ifthenelse{\boolean{@tufte@titlepage}}
  704. {\renewcommand{\maketitle}{\maketitlepage}}
  705. {}
  706. %%
  707. % When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
  708. % without headers and footers
  709. \def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
  710. \hbox{}
  711. %\vspace*{\fill}
  712. %\begin{center}
  713. % This page intentionally contains only this sentence.
  714. %\end{center}
  715. %\vspace{\fill}
  716. \thispagestyle{empty}
  717. \newpage
  718. \if@twocolumn\hbox{}\newpage\fi\fi\fi}
  719. %%
  720. % Make Tuftian-style section headings and TOC formatting
  721. \RequirePackage{titlesec,titletoc}
  722. % TODO: I'd prefer to use the 'titlesec' package for this formatting, but
  723. % I'll do it old-style for now. --Kevin
  724. \renewcommand\section{\@startsection {section}{1}{\z@}%
  725. {-3.5ex \@plus -1ex \@minus -.2ex}%
  726. {2.3ex \@plus.2ex}%
  727. {\normalfont\large\it}}
  728. \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  729. {-3.25ex\@plus -1ex \@minus -.2ex}%
  730. {1.5ex \@plus .2ex}%
  731. {\normalfont\normalsize\it}}
  732. % Subsubsection and following section headings shouldn't be used.
  733. % See Bringhurst's _The Elements of Typography_, section 4.2.2.
  734. \renewcommand\subsubsection{%
  735. \PackageError{\@tufte@pkgname}{\noexpand\subsubsection is undefined by this class.%
  736. \MessageBreak See Robert Bringhurst's _The Elements of
  737. \MessageBreak Typographic Style_, section 4.2.2.
  738. \MessageBreak \noexpand\subsubsection was used}
  739. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  740. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  741. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  742. }
  743. \renewcommand\paragraph{%
  744. \PackageError{\@tufte@pkgname}{\noexpand\paragraph is undefined by this class.%
  745. \MessageBreak See Robert Bringhurst's _The Elements of
  746. \MessageBreak Typographic Style_, section 4.2.2.
  747. \MessageBreak \noexpand\paragraph was used}
  748. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  749. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  750. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  751. }
  752. \renewcommand\subparagraph{%
  753. \PackageError{\@tufte@pkgname}{\noexpand\subparagraph is undefined by this class.%
  754. \MessageBreak See Robert Bringhurst's _The Elements of
  755. \MessageBreak Typographic Style_, section 4.2.2.
  756. \MessageBreak \noexpand\subparagraph was used}
  757. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  758. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  759. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  760. }
  761. % Formatting for main TOC (printed in front matter)
  762. % {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
  763. \ifthenelse{\boolean{@tufte@toc}}
  764. {\titlecontents{chapter}%
  765. [0em] % distance from left margin
  766. {\begin{fullwidth}\fontsize{13pt}{18pt}\selectfont} % above (global formatting of entry)
  767. {\contentslabel{2em}\rm\itshape} % before w/label (label = ``Chapter 1'')
  768. {\rm\itshape} % before w/o label
  769. {\rm\qquad\thecontentspage} % filler + page (leaders and page num)
  770. [\vspace{1.5\baselineskip}\end{fullwidth}] % after
  771. }
  772. {}
  773. %\titlecontents{chapter}%
  774. % [0em]% distance from left margin
  775. % {\fontsize{12pt}{18pt}\selectfont}% above (global formatting of entry)
  776. % {\textit}% before w/ label (label = ``Chapter 1'')
  777. % {\textit}% before w/o label
  778. % {\qquad\thecontentspage}% filler and page (leaders and page num)
  779. % [\vspace{1.5\baselineskip}]% after
  780. \titleformat{\chapter}%
  781. [display]% shape
  782. {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
  783. {\itshape\fontsize{22}{24}\selectfont\thechapter}% label
  784. {0pt}% horizontal separation between label and title body
  785. {\fontsize{22}{24}\rm\itshape}% before the title body
  786. [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body
  787. %%
  788. % A handy command to disable hyphenation for short bits of text.
  789. % Borrowed from Peter Wilson's `hyphenat' package.
  790. \newlanguage\langwohyphens% define a language without hyphenation rules
  791. \newcommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text
  792. \newcommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text
  793. %%
  794. % If debugging is enabled, print the Tufte-LaTeX options and the list of
  795. % files.
  796. \ifthenelse{\boolean{@tufte@debug}}
  797. {\PrintTufteSettings\listfiles}
  798. {}
  799. %%
  800. % If there is a `tufte-common-local.tex' file, load it up.
  801. \IfFileExists{tufte-common-local.tex}
  802. {\input{tufte-common-local}}
  803. {}
  804. %%
  805. % End of file
  806. \endinput