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

1498 рядки
48KB

  1. %\NeedsTeXFormat{LaTeX2e}[1994/06/01]
  2. %\ProvidesPackage{tufte-common}[2009/05/17 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. % `titlepage' option -- creates a full title page with \maketitle
  25. \newboolean{@tufte@titlepage}
  26. \DeclareOption{titlepage}{\setboolean{@tufte@titlepage}{true}}
  27. \DeclareOption{notitlepage}{\setboolean{@tufte@titlepage}{false}}
  28. %%
  29. % `a4paper' option
  30. \newboolean{@tufte@afourpaper}
  31. \DeclareOption{a4paper}{\setboolean{@tufte@afourpaper}{true}}
  32. %%
  33. % `b4paper' option
  34. \newboolean{@tufte@bfivepaper}
  35. \DeclareOption{b5paper}{\setboolean{@tufte@bfivepaper}{true}}
  36. %%
  37. % `sfsidenotes' option -- typesets sidenotes in sans serif typeface
  38. \newboolean{@tufte@sfsidenotes}
  39. \DeclareOption{sfsidenotes}{\setboolean{@tufte@sfsidenotes}{true}}
  40. %%
  41. % `symmetric' option -- puts marginpar space to the outside edge of the page
  42. % Note: this option forces the twoside option (see the .cls files)
  43. \newboolean{@tufte@symmetric}
  44. \DeclareOption{symmetric}{
  45. \setboolean{@tufte@symmetric}{true}
  46. \ClassInfo{\@tufte@pkgname}{The `symmetric' option implies `twoside'}
  47. \ExecuteOptions{twoside}
  48. }
  49. %%
  50. % `twoside' option -- alternates running heads
  51. \newboolean{@tufte@twoside}
  52. \DeclareOption{twoside}{%
  53. \setboolean{@tufte@twoside}{true}
  54. \ClassInfo{\@tufte@pkgname}{Passing the `\CurrentOption' option to the `\@tufte@class' class}
  55. \PassOptionsToClass{\CurrentOption}{\@tufte@class}
  56. }
  57. %%
  58. % `notoc' option -- suppresses the Tufte-style table of contents
  59. \newboolean{@tufte@toc}
  60. \setboolean{@tufte@toc}{true}
  61. \DeclareOption{notoc}{\setboolean{@tufte@toc}{false}}
  62. \DeclareOption{toc}{\setboolean{@tufte@toc}{true}}
  63. %%
  64. % `justified' option -- uses fully justified text (flush left and flush
  65. % right) instead of ragged right.
  66. \newboolean{@tufte@justified}
  67. \DeclareOption{justified}{\setboolean{@tufte@justified}{true}}
  68. %%
  69. % `bidi' option -- loads the bidi package for bi-directional text
  70. \newboolean{@tufte@loadbidi}
  71. \DeclareOption{bidi}{\setboolean{@tufte@loadbidi}{true}}
  72. \DeclareOption{nobidi}{\setboolean{@tufte@loadbibi}{false}}
  73. %%
  74. % `nohyper' option -- suppresses loading of the hyperref package
  75. \newboolean{@tufte@loadhyper}
  76. \setboolean{@tufte@loadhyper}{true}
  77. \DeclareOption{hyper}{\setboolean{@tufte@loadhyper}{true}}
  78. \DeclareOption{nohyper}{\setboolean{@tufte@loadhyper}{false}}
  79. %%
  80. % Unsupported options
  81. \newcommand{\@tufte@unsupported@option}[1]{\ClassWarningNoLine{\@tufte@pkgname}{Option `#1' is not supported -- \MessageBreak ignoring option}\OptionNotUsed}
  82. \DeclareOption{10pt}{\@tufte@unsupported@option{\CurrentOption}}
  83. \DeclareOption{11pt}{\@tufte@unsupported@option{\CurrentOption}}
  84. \DeclareOption{12pt}{\@tufte@unsupported@option{\CurrentOption}}
  85. \DeclareOption{a5paper}{\@tufte@unsupported@option{\CurrentOption}}
  86. \DeclareOption{executivepaper}{\@tufte@unsupported@option{\CurrentOption}}
  87. \DeclareOption{legalpaper}{\@tufte@unsupported@option{\CurrentOption}}
  88. \DeclareOption{landscape}{\@tufte@unsupported@option{\CurrentOption}}
  89. \DeclareOption{onecolumn}{\@tufte@unsupported@option{\CurrentOption}}
  90. \DeclareOption{twocolumn}{\@tufte@unsupported@option{\CurrentOption}}
  91. %%
  92. % Default `book' and `handout' options
  93. \ifthenelse{\equal{\@tufte@pkgname}{tufte-book}}
  94. {\ExecuteOptions{titlepage}}
  95. {\ExecuteOptions{notitlepage}}
  96. \DeclareOption*{%
  97. \ClassInfo{\@tufte@pkgname}{Passing \CurrentOption\space to the `\@tufte@class' class}%
  98. \PassOptionsToClass{\CurrentOption}{\@tufte@class}%
  99. }
  100. \ProcessOptions\relax
  101. %%
  102. % Load the appropriate base class
  103. \ClassInfo{\@tufte@pkgname}{Loading the base class `\@tufte@class'}
  104. \LoadClass{\@tufte@class}
  105. %%
  106. % Detect whether we're in two-side mode or not. (Used to set up running
  107. % heads later.)
  108. \ifthenelse{\boolean{@twoside}}
  109. {\setboolean{@tufte@twoside}{true}}
  110. {}
  111. %%
  112. % Detect if we're using pdfLaTeX
  113. \newboolean{@tufte@pdf}
  114. \IfFileExists{ifpdf.sty}{%
  115. \RequirePackage{ifpdf}
  116. \ifthenelse{\boolean{pdf}}
  117. {\setboolean{@tufte@pdf}{true}}
  118. {\setboolean{@tufte@pdf}{false}}
  119. }{% assume we're not using pdfTex?
  120. \setboolean{@tufte@pdf}{false}
  121. }
  122. %%
  123. % Detect if we're using XeLaTeX
  124. \newboolean{@tufte@xetex}
  125. \IfFileExists{ifxetex.sty}{%
  126. \RequirePackage{ifxetex}
  127. \ifthenelse{\boolean{xetex}}
  128. {\setboolean{@tufte@xetex}{true}}
  129. {\setboolean{@tufte@xetex}{false}}
  130. }{% not using xelatex
  131. \setboolean{@tufte@xetex}{false}
  132. }
  133. %%
  134. % Load the `hyperref' package. We will set more options later.
  135. % TODO Set nice defaults for hyperref options
  136. \ifthenelse{\boolean{@tufte@loadhyper}}{%
  137. \ifthenelse{\boolean{@tufte@xetex}}
  138. {\RequirePackage[xetex]{hyperref}}
  139. {\RequirePackage{hyperref}}
  140. \hypersetup{%
  141. pdfborder = {0 0 0},
  142. bookmarksdepth = section,
  143. hyperfootnotes = false,
  144. citecolor = DarkGreen,
  145. linkcolor = DarkBlue,
  146. pagecolor = DarkBlue,
  147. urlcolor = DarkGreen,
  148. }%
  149. }{%
  150. }
  151. %%
  152. % Set the font sizes and baselines to match Tufte's books
  153. \renewcommand\normalsize{%
  154. \@setfontsize\normalsize\@xpt{14}%
  155. \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
  156. \abovedisplayshortskip \z@ \@plus3\p@
  157. \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
  158. \belowdisplayskip \abovedisplayskip
  159. \let\@listi\@listI}
  160. \normalbaselineskip=14pt
  161. \normalsize
  162. \renewcommand\small{%
  163. \@setfontsize\small\@ixpt{12}%
  164. \abovedisplayskip 8.5\p@ \@plus3\p@ \@minus4\p@
  165. \abovedisplayshortskip \z@ \@plus2\p@
  166. \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
  167. \def\@listi{\leftmargin\leftmargini
  168. \topsep 4\p@ \@plus2\p@ \@minus2\p@
  169. \parsep 2\p@ \@plus\p@ \@minus\p@
  170. \itemsep \parsep}%
  171. \belowdisplayskip \abovedisplayskip
  172. }
  173. \renewcommand\footnotesize{%
  174. \@setfontsize\footnotesize\@viiipt{10}%
  175. \abovedisplayskip 6\p@ \@plus2\p@ \@minus4\p@
  176. \abovedisplayshortskip \z@ \@plus\p@
  177. \belowdisplayshortskip 3\p@ \@plus\p@ \@minus2\p@
  178. \def\@listi{\leftmargin\leftmargini
  179. \topsep 3\p@ \@plus\p@ \@minus\p@
  180. \parsep 2\p@ \@plus\p@ \@minus\p@
  181. \itemsep \parsep}%
  182. \belowdisplayskip \abovedisplayskip
  183. }
  184. \renewcommand\scriptsize{\@setfontsize\scriptsize\@viipt\@viiipt}
  185. \renewcommand\tiny{\@setfontsize\tiny\@vpt\@vipt}
  186. \renewcommand\large{\@setfontsize\large\@xipt{15}}
  187. \renewcommand\Large{\@setfontsize\Large\@xiipt{16}}
  188. \renewcommand\LARGE{\@setfontsize\LARGE\@xivpt{18}}
  189. \renewcommand\huge{\@setfontsize\huge\@xxpt{30}}
  190. \renewcommand\Huge{\@setfontsize\Huge{24}{36}}
  191. \setlength\leftmargini {1pc}
  192. \setlength\leftmarginii {1pc}
  193. \setlength\leftmarginiii {1pc}
  194. \setlength\leftmarginiv {1pc}
  195. \setlength\leftmarginv {1pc}
  196. \setlength\leftmarginvi {1pc}
  197. \setlength\labelsep {.5pc}
  198. \setlength\labelwidth {\leftmargini}
  199. \addtolength\labelwidth{-\labelsep}
  200. %%
  201. % \RaggedRight allows hyphenation
  202. \RequirePackage{ragged2e}
  203. \setlength{\RaggedRightRightskip}{\z@ plus 0.08\hsize}
  204. \setlength{\RaggedRightParindent}{1pc}
  205. % Paragraph indentation and separation for normal text
  206. \newcommand{\@tufte@reset@par}{%
  207. \setlength{\RaggedRightParindent}{1.0pc}%
  208. \setlength{\parindent}{1pc}%
  209. \setlength{\parskip}{0pt}%
  210. }
  211. \@tufte@reset@par
  212. % Paragraph indentation and separation for marginal text
  213. \newcommand{\@tufte@margin@par}{%
  214. \setlength{\RaggedRightParindent}{0.5pc}%
  215. \setlength{\parindent}{0.5pc}%
  216. \setlength{\parskip}{0pt}%
  217. }
  218. %%
  219. % Set page layout geometry
  220. \RequirePackage[letterpaper,left=1in,top=1in,headsep=2\baselineskip,textwidth=26pc,marginparsep=2pc,marginparwidth=12pc,textheight=44\baselineskip,headheight=\baselineskip]{geometry}
  221. \ifthenelse{\boolean{@tufte@afourpaper}}
  222. {\geometry{a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,textheight=49\baselineskip,headheight=\baselineskip}}
  223. {}
  224. \ifthenelse{\boolean{@tufte@bfivepaper}}
  225. {\geometry{paperwidth=176mm,paperheight=250mm,left=14.66mm,top=13.88mm,textwidth=102.66mm,marginparsep=7.33mm,marginparwidth=36.66mm,textheight=38\baselineskip,includehead}}
  226. {}
  227. \ifthenelse{\boolean{@tufte@symmetric}}
  228. {}
  229. {\geometry{asymmetric}}% forces internal LaTeX `twoside'
  230. %%
  231. % Separation marginpars by a line's worth of space.
  232. \setlength\marginparpush{10pt}
  233. %%
  234. % Font for margin items
  235. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  236. {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize\sffamily}}
  237. {\newcommand{\@tufte@marginfont}{\normalfont\footnotesize}}
  238. %%
  239. % Set the justification baesed on the `justified' class option
  240. \newcommand{\@tufte@justification}{%
  241. \ifthenelse{\boolean{@tufte@justified}}%
  242. {\justifying}%
  243. {\RaggedRight}%
  244. }
  245. %%
  246. % Turn off section numbering
  247. \setcounter{secnumdepth}{-1}
  248. %%
  249. % Tighten up space between displays (e.g., a figure or table) and make symmetric
  250. \setlength\abovedisplayskip{6pt plus 2pt minus 4pt}
  251. \setlength\belowdisplayskip{6pt plus 2pt minus 4pt}
  252. %%
  253. % To implement full-width display environments
  254. \newboolean{@tufte@changepage}
  255. \IfFileExists{changepage.sty}{%
  256. \ClassInfo{\@tufte@pkgname}{Found changepage.sty}
  257. \RequirePackage[strict]{changepage}
  258. \setboolean{@tufte@changepage}{true}
  259. }{%
  260. \ClassInfo{\@tufte@pkgname}{Found chngpage.sty}
  261. \RequirePackage[strict]{chngpage}
  262. \setboolean{@tufte@changepage}{false}
  263. }
  264. % Write our own aliases for the \checkoddpage and \ifoddpage or \ifcpoddpage commands
  265. \newboolean{@tufte@odd@page}
  266. \setboolean{@tufte@odd@page}{true}
  267. \newcommand*{\@tufte@checkoddpage}{%
  268. \checkoddpage%
  269. \ifthenelse{\boolean{@tufte@changepage}}{%
  270. \ifoddpage%
  271. \setboolean{@tufte@odd@page}{true}%
  272. \else%
  273. \setboolean{@tufte@odd@page}{false}%
  274. \fi%
  275. }{%
  276. \ifcpoddpage%
  277. \setboolean{@tufte@odd@page}{true}%
  278. \else%
  279. \setboolean{@tufte@odd@page}{false}%
  280. \fi%
  281. }%
  282. }
  283. %%
  284. % Compute lengths used for full-width displays
  285. \newlength{\@tufte@overhang}% used by the fullwidth environment and the running heads
  286. \newlength{\@tufte@fullwidth}
  287. \newlength{\@tufte@caption@fill}
  288. \newcommand{\TufteRecalculate}{%
  289. \setlength{\@tufte@overhang}{\marginparwidth}
  290. \addtolength{\@tufte@overhang}{\marginparsep}
  291. \setlength{\@tufte@fullwidth}{\textwidth}
  292. \addtolength{\@tufte@fullwidth}{\marginparsep}
  293. \addtolength{\@tufte@fullwidth}{\marginparwidth}
  294. \setlength{\@tufte@caption@fill}{\textwidth}
  295. \addtolength{\@tufte@caption@fill}{\marginparsep}
  296. }
  297. \AtBeginDocument{\TufteRecalculate}
  298. %%
  299. % Modified \title, \author, and \date commands. These store the
  300. % (footnote-less) values in \plaintitle, \plainauthor, and \thedate, respectively.
  301. \newcommand{\plaintitle}{}% plain-text-only title
  302. \newcommand{\plainauthor}{}% plain-text-only author
  303. \newcommand{\plainpublisher}{}% plain-text-only publisher
  304. \newcommand{\thanklesstitle}{}% full title text minus \thanks{}
  305. \newcommand{\thanklessauthor}{}% full author text minus \thanks{}
  306. \newcommand{\thanklesspublisher}{}% full publisher minus \thanks{}
  307. \newcommand{\@publisher}{}% full publisher with \thanks{}
  308. \newcommand{\thedate}{\today}
  309. % TODO Fix it so that \thanks is not spaced out (with `soul') and can be
  310. % used in \maketitle when the `sfsidenotes' option is provided.
  311. \renewcommand{\thanks}[1]{\NoCaseChange{\footnote{#1}}}
  312. \renewcommand{\title}[2][]{%
  313. \gdef\@title{#2}%
  314. \begingroup%
  315. % TODO store contents of \thanks command
  316. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  317. \protected@xdef\thanklesstitle{#2}%
  318. \endgroup%
  319. \ifthenelse{\isempty{#1}}%
  320. {\renewcommand{\plaintitle}{\thanklesstitle}}% use thankless title
  321. {\renewcommand{\plaintitle}{#1}}% use provided plain-text title
  322. \ifthenelse{\boolean{@tufte@loadhyper}}{\hypersetup{pdftitle={\plaintitle}}}{}% set the PDF metadata title
  323. }
  324. \def\@author{}% default author is empty (suppresses LaTeX's ``no author'' warning)
  325. \renewcommand*{\author}[2][]{%
  326. \gdef\@author{#2}%
  327. \begingroup%
  328. % TODO store contents of \thanks command
  329. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  330. \protected@xdef\thanklessauthor{#2}%
  331. \endgroup%
  332. \ifthenelse{\isempty{#1}}
  333. {\renewcommand{\plainauthor}{\thanklessauthor}}% use thankless author
  334. {\renewcommand{\plainauthor}{#1}}% use provided plain-text author
  335. \ifthenelse{\boolean{@tufte@loadhyper}}{\hypersetup{pdfauthor={\plainauthor}}}{}% set the PDF metadata author
  336. }
  337. \renewcommand*{\date}[1]{%
  338. \gdef\@date{#1}%
  339. \begingroup%
  340. % TODO store contents of \thanks command
  341. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  342. \protected@xdef\thedate{#1}%
  343. \endgroup%
  344. }
  345. %%
  346. % Provides a \publisher command to set the publisher
  347. \newcommand{\publisher}[2][]{%
  348. \gdef\@publisher{#2}%
  349. \begingroup%
  350. \renewcommand{\thanks}[1]{}% swallow \thanks contents
  351. \protected@xdef\thanklesspublisher{#2}%
  352. \endgroup%
  353. \ifthenelse{\isempty{#1}}
  354. {\renewcommand{\plainpublisher}{\thanklesspublisher}}% use thankless publisher
  355. {\renewcommand{\plainpublisher}{#1}}% use provided plain-text publisher
  356. }
  357. % TODO: Test \hypersetup{pdfauthor,pdftitle} with DVI and XeTeX
  358. %%
  359. % Require paralist package for tighter lists
  360. \RequirePackage{paralist}
  361. % Add rightmargin to compactenum
  362. \def\@compactenum@{%
  363. \expandafter\list\csname label\@enumctr\endcsname{%
  364. \usecounter{\@enumctr}%
  365. \rightmargin=2em% added this
  366. \parsep\plparsep
  367. \itemsep\plitemsep
  368. \topsep\pltopsep
  369. \partopsep\plpartopsep
  370. \def\makelabel##1{\hss\llap{##1}}}}
  371. %%
  372. % Improved letterspacing of small caps and all-caps text.
  373. %
  374. % First, try to use the `microtype' package, if it's available.
  375. % Failing that, try to use the `soul' package, if it's available.
  376. % Failing that, well, I give up.
  377. \RequirePackage{textcase} % provides \MakeTextUppercase and \MakeTextLowercase
  378. \def\allcapsspacing{\relax}
  379. \def\smallcapsspacing{\relax}
  380. \newcommand{\allcaps}[1]{\MakeTextUppercase{\allcapsspacing{#1}}}
  381. \newcommand{\smallcaps}[1]{\MakeTextLowercase{\textsc{#1}}}
  382. \newcommand{\@tufte@loadsoul}{%
  383. \IfFileExists{soul.sty}{%
  384. \RequirePackage{soul}
  385. \sodef\allcapsspacing{\upshape}{0.15em}{0.65em}{0.6em}
  386. \sodef\smallcapsspacing{\scshape}{0.075em}{0.5em}{0.6em}
  387. }{
  388. \ClassWarningNoLine{\@tufte@pkgname}{Couldn't locate `soul' package.}
  389. }% soul not installed... giving up.
  390. }
  391. % If we're using pdfLaTeX v1.40+, use the letterspace package.
  392. % If we're using pdfLaTex < v1.40, use the soul package.
  393. % If we're using XeLaTeX, use XeLaTeX letterspacing options.
  394. % Otherwise fall back on the soul package.
  395. \ifthenelse{\boolean{@tufte@pdf}}
  396. {\ClassInfo{\@tufte@pkgname}{ifpdf = true}}
  397. {\ClassInfo{\@tufte@pkgname}{ifpdf = false}}
  398. \ifthenelse{\boolean{@tufte@xetex}}
  399. {\ClassInfo{\@tufte@pkgname}{ifxetex = true}}
  400. {\ClassInfo{\@tufte@pkgname}{ifxetex = false}}
  401. % Check pdfLaTeX version
  402. \def\@tufte@pdftexversion{0}
  403. \ifx\normalpdftexversion\@undefined \else
  404. \let\pdftexversion \normalpdftexversion
  405. \let\pdftexrevision\normalpdftexrevision
  406. \let\pdfoutput \normalpdfoutput
  407. \fi
  408. \ifx\pdftexversion\@undefined \else
  409. \ifx\pdftexversion\relax \else
  410. \def\@tufte@pdftexversion{6}
  411. \ifnum\pdftexversion < 140
  412. \def\@tufte@pdftexversion{5}
  413. \fi
  414. \fi
  415. \fi
  416. \ifthenelse{\boolean{@tufte@letterspace}}
  417. {%
  418. \ifnum\@tufte@pdftexversion<6
  419. % pdfLaTeX version is too old or not using pdfLaTeX
  420. \ifthenelse{\boolean{@tufte@xetex}}
  421. {% TODO use xetex letterspacing
  422. \ClassInfo{\@tufte@pkgname}{XeTeX detected. Reverting to `soul' package for letterspacing.}
  423. \@tufte@loadsoul}
  424. {% use `soul' package for letterspacing
  425. \ClassInfo{\@tufte@pkgname}{Old version of pdfTeX detected. Reverting to `soul' package for letterspacing.}
  426. \@tufte@loadsoul}
  427. \else
  428. \IfFileExists{letterspace.sty}{%
  429. \ClassInfo{\@tufte@pkgname}{Modern version of pdfTeX detected. Using `letterspace' package.}
  430. \RequirePackage{letterspace}
  431. % Set up letterspacing (using microtype package) -- requires pdfTeX v1.40+
  432. \renewcommand{\allcapsspacing}[1]{\textls[200]{##1}}
  433. \renewcommand{\smallcapsspacing}[1]{\textls[50]{##1}}
  434. \renewcommand{\allcaps}[1]{\textls[200]{\MakeTextUppercase{##1}}}
  435. \renewcommand{\smallcaps}[1]{\textsc{\MakeTextLowercase{##1}}}
  436. }{% microtype failed, check for soul
  437. \ClassInfo{\@tufte@pkgname}{Modern version of pdfTeX detected, but `letterspace' package not installed. Reverting to `soul' package for letterspacing.}
  438. \@tufte@loadsoul
  439. }
  440. \fi}
  441. {}
  442. \DeclareTextFontCommand{\textsmallcaps}{\scshape}
  443. \renewcommand{\textsc}[1]{\textsmallcaps{\smallcapsspacing{#1}}}
  444. %%
  445. % An environment for paragraph-style section
  446. \providecommand\newthought[1]{%
  447. \addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}%
  448. \noindent\textsc{#1}%
  449. }
  450. %%
  451. % Redefine the display environments (quote, quotation, etc.)
  452. \renewenvironment{verse}
  453. {\let\\\@centercr
  454. \list{}{\itemsep \z@
  455. \itemindent -1pc%
  456. \listparindent\itemindent
  457. \rightmargin \leftmargin
  458. \advance\leftmargin 1pc}%
  459. \small%
  460. \item\relax}
  461. {\endlist}
  462. \renewenvironment{quotation}
  463. {\list{}{\listparindent 1pc%
  464. \itemindent \listparindent
  465. \rightmargin \leftmargin
  466. \parsep \z@ \@plus\p@}%
  467. \small%
  468. \item\relax\noindent\ignorespaces}
  469. {\endlist}
  470. \renewenvironment{quote}
  471. {\list{}{\rightmargin\leftmargin}%
  472. \small%
  473. \item\relax}
  474. {\endlist}
  475. %%
  476. % Italicize description run-in headings (instead of the default bold)
  477. \renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\em #1}
  478. %%
  479. % Used for doublespacing, and other linespacing
  480. \RequirePackage{setspace}
  481. %%
  482. % Load the bidi package if instructed to do so. This package must be loaded
  483. % prior to our redefining the \footnote and \cite commands.
  484. \ifthenelse{\boolean{@tufte@loadbidi}}{\RequirePackage{bidi}}{}
  485. %%
  486. % A function that removes leading and trailling spaces from the supplied macro.
  487. % Based on code written by Michael Downes (See ``Around the Bend'', #15.)
  488. % Executing \@tufte@trim@spaces\xyzzy will result in the contents of \xyzzy
  489. % being trimmed of leading and trailing white space.
  490. \catcode`\Q=3
  491. \def\@tufte@trim@spaces#1{%
  492. % Use grouping to emulate a multi-token afterassignment queue
  493. \begingroup%
  494. % Put `\toks 0 {' into the afterassignment queue
  495. \aftergroup\toks\aftergroup0\aftergroup{%
  496. % Apply \trimb to the replacement text of #1, adding a leading
  497. % \noexpand to prevent brace stripping and to serve another purpose
  498. % later.
  499. \expandafter\@tufte@trim@b\expandafter\noexpand#1Q Q}%
  500. % Transfer the trimmed text back into #1.
  501. \edef#1{\the\toks0}%
  502. }
  503. % \trimb removes a trailing space if present, then calls \@tufte@trim@c to
  504. % clean up any leftover bizarre Qs, and trim a leading space. In
  505. % order for \trimc to work properly we need to put back a Q first.
  506. \def\@tufte@trim@b#1 Q{\@tufte@trim@c#1Q}
  507. % Execute \vfuzz assignment to remove leading space; the \noexpand
  508. % will now prevent unwanted expansion of a macro or other expandable
  509. % token at the beginning of the trimmed text. The \endgroup will feed
  510. % in the \aftergroup tokens after the \vfuzz assignment is completed.
  511. \def\@tufte@trim@c#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1}
  512. \catcode`\Q=11
  513. %%
  514. % Citations should go in the margin as sidenotes
  515. \RequirePackage{natbib}
  516. \RequirePackage{bibentry} % allows bibitems to be typeset outside thebibliography environment
  517. % Redefine the \BR@b@bibitem command to fix a bug with bibentry+chicago style
  518. \renewcommand\BR@b@bibitem[2][]{%
  519. \ifthenelse{\isempty{#1}}%
  520. {\BR@bibitem{#2}}%
  521. {\BR@bibitem[#1]{#2}}%
  522. \BR@c@bibitem{#2}%
  523. }
  524. \nobibliography* % pre-loads the bibliography keys
  525. \providecommand{\doi}[1]{\textsc{doi:} #1}% pre-defining this so it may be used before the \bibliography command it issued
  526. %%
  527. % Normal \cite behavior
  528. \newcounter{@tufte@num@bibkeys}%
  529. \newcommand{\@tufte@normal@cite}[2][0pt]{%
  530. % Snag the last bibentry in the list for later comparison
  531. \let\@temp@last@bibkey\@empty%
  532. \@for\@temp@bibkey:=#2\do{\let\@temp@last@bibkey\@temp@bibkey}%
  533. \sidenote[][#1]{%
  534. % Loop through all the bibentries, separating them with semicolons and spaces
  535. \setcounter{@tufte@num@bibkeys}{0}%
  536. \@for\@temp@bibkeyx:=#2\do{%
  537. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  538. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  539. \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  540. \bibentry{\@temp@bibkeyx}}%
  541. {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  542. \bibentry{\@temp@bibkeyx};\ }%
  543. \stepcounter{@tufte@num@bibkeys}%
  544. }%
  545. }%
  546. }
  547. %%
  548. % Macros for holding the list of cite keys until after the \sidenote
  549. \gdef\@tufte@citations{}% list of cite keys
  550. \newcommand\@tufte@add@citation[1]{\relax% adds a new bibkey to the list of cite keys
  551. \ifx\@tufte@citations\@empty\else
  552. \g@addto@macro\@tufte@citations{,}% separate by commas
  553. \fi
  554. \g@addto@macro\@tufte@citations{#1}
  555. }
  556. \newcommand{\@tufte@print@citations}[1][0pt]{% puts the citations in a margin note
  557. % Snag the last bibentry in the list for later comparison
  558. \let\@temp@last@bibkey\@empty%
  559. \@for\@temp@bibkey:=\@tufte@citations\do{\let\@temp@last@bibkey\@temp@bibkey}%
  560. \marginpar{%
  561. \hbox{}\vspace*{#1}%
  562. \@tufte@marginfont%
  563. \@tufte@justification%
  564. \@tufte@margin@par% use parindent and parskip settings for marginal text
  565. \vspace*{-1\baselineskip}%
  566. % Loop through all the bibentries, separating them with semicolons and spaces
  567. \setcounter{@tufte@num@bibkeys}{0}%
  568. \@for\@temp@bibkeyx:=\@tufte@citations\do{%
  569. \ifthenelse{\equal{\@temp@last@bibkey}{\@temp@bibkeyx}}%
  570. {\ifthenelse{\equal{\value{@tufte@num@bibkeys}}{0}}{}{and\ }%
  571. \@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  572. \bibentry{\@temp@bibkeyx}}%
  573. {\@tufte@trim@spaces\@temp@bibkeyx% trim spaces around bibkey
  574. \bibentry{\@temp@bibkeyx};\ }%
  575. \stepcounter{@tufte@num@bibkeys}%
  576. }%
  577. \@tufte@reset@par% use parindent and parskip settings for body text
  578. }%
  579. }
  580. %%
  581. % \cite behavior when executed within a sidenote
  582. \newcommand{\@tufte@sidenote@citations}{}% contains list of \cites in sidenote
  583. \newcommand{\@tufte@infootnote@cite}[1]{%
  584. \@tufte@add@citation{#1}
  585. }
  586. %%
  587. % Set the default \cite style. This is set and reset by the \sidenote command.
  588. \let\cite\@tufte@normal@cite
  589. %%
  590. % Transform existing \footnotes into \sidenotes
  591. % Sidenote: ``Where God meant footnotes to go.'' ---Tufte
  592. \RequirePackage{optparams}% for our new sidenote commands -- provides multiple optional arguments for commands
  593. \providecommand*{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  594. \renewcommand{\footnotelayout}{\@tufte@marginfont\@tufte@justification}
  595. % Override footmisc's definition to set the sidenote marks (numbers) inside the
  596. % sidenote's text block.
  597. \long\def\@makefntext#1{\@textsuperscript{\@tufte@marginfont\tiny\@thefnmark}\,\footnotelayout#1}
  598. % Set the in-text footnote mark in the same typeface as the body text itself.
  599. \def\@makefnmark{\hbox{\@textsuperscript{\normalfont\footnotesize\@thefnmark}}}
  600. \providecommand*{\multiplefootnotemarker}{3sp}
  601. \providecommand*{\multfootsep}{,}
  602. \renewcommand*\@footnotemark{%
  603. \leavevmode%
  604. \ifhmode%
  605. \edef\@x@sf{\the\spacefactor}%
  606. \@tufte@check@multiple@sidenotes%
  607. \nobreak%
  608. \fi%
  609. \@makefnmark%
  610. \ifhmode\spacefactor\@x@sf\fi%
  611. \relax%
  612. }
  613. \newcommand{\@tufte@check@multiple@sidenotes}{%
  614. \ifdim\lastkern=\multiplefootnotemarker\relax%
  615. \edef\@x@sf{\the\spacefactor}%
  616. \unkern%
  617. \textsuperscript{\multfootsep}%
  618. \spacefactor\@x@sf\relax%
  619. \fi
  620. }
  621. \renewcommand\@footnotetext[2][0pt]{%
  622. \marginpar{%
  623. \hbox{}\vspace*{#1}%
  624. \def\baselinestretch {\setspace@singlespace}%
  625. \ifthenelse{\boolean{@tufte@loadbidi}}{\if@rl@footnote\@rltrue\else\@rlfalse\fi}{}%
  626. \reset@font\footnotesize%
  627. \@tufte@margin@par% use parindent and parskip settings for marginal text
  628. \vspace*{-1\baselineskip}\noindent%
  629. \protected@edef\@currentlabel{%
  630. \csname p@footnote\endcsname\@thefnmark%
  631. }%
  632. \color@begingroup%
  633. \@makefntext{%
  634. \ignorespaces#2%
  635. }%
  636. \color@endgroup%
  637. }%
  638. \@tufte@reset@par% use parindent and parskip settings for body text
  639. }%
  640. %
  641. % Define \sidenote command. Can handle \cite.
  642. \newcommand{\@tufte@sidenote@vertical@offset}{0pt}
  643. % #1 = footnote num, #2 = vertical offset, #3 = footnote text
  644. \long\def\@tufte@sidenote[#1][#2]#3{%
  645. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  646. \gdef\@tufte@citations{}% clear out any old citations
  647. \ifthenelse{\NOT\isempty{#2}}{\renewcommand{\@tufte@sidenote@vertical@offset}{#2}}{}%
  648. \ifthenelse{\isempty{#1}}{%
  649. % no specific footnote number provided
  650. \stepcounter\@mpfn%
  651. \protected@xdef\@thefnmark{\thempfn}%
  652. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  653. }{%
  654. % specific footnote number provided
  655. \begingroup%
  656. \csname c@\@mpfn\endcsname #1\relax%
  657. \unrestored@protected@xdef\@thefnmark{\thempfn}%
  658. \endgroup%
  659. \@footnotemark\@footnotetext[\@tufte@sidenote@vertical@offset]{#3}%
  660. }%
  661. \@tufte@print@citations% print any citations
  662. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  663. \unskip\ignorespaces% remove extra white space
  664. \kern-\multiplefootnotemarker% remove \kern left behind by sidenote
  665. \kern\multiplefootnotemarker\relax% add new \kern here to replace the one we yanked
  666. }
  667. \newcommand*{\sidenote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  668. \renewcommand*{\footnote}{\optparams{\@tufte@sidenote}{[][0pt]}}
  669. %%
  670. % Sidenote without the footnote mark
  671. \newcommand\marginnote[2][0pt]{%
  672. \let\cite\@tufte@infootnote@cite% use the in-sidenote \cite command
  673. \gdef\@tufte@citations{}% clear out any old citations
  674. \@tufte@margin@par% use parindent and parskip settings for marginal text
  675. \marginpar{\hbox{}\vspace*{#1}\@tufte@marginfont\@tufte@justification\vspace*{-1\baselineskip}\noindent #2}%
  676. \@tufte@reset@par% use parindent and parskip settings for body text
  677. \@tufte@print@citations% print any citations
  678. \let\cite\@tufte@normal@cite% go back to using normal in-text \cite command
  679. }
  680. %%
  681. % The placeins package provides the \FloatBarrier command. This forces
  682. % LaTeX to place all of the floats before proceeding. We'll use this to
  683. % keep the float (figure and table) numbers in sequence.
  684. \RequirePackage{placeins}
  685. %%
  686. % Margin float environment
  687. \newsavebox{\@tufte@margin@floatbox}
  688. \newenvironment{@tufte@margin@float}[2][-1.2ex]%
  689. {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  690. \begin{lrbox}{\@tufte@margin@floatbox}%
  691. \begin{minipage}{\marginparwidth}%
  692. \@tufte@marginfont%
  693. \def\@captype{#2}%
  694. \hbox{}\vspace*{#1}%
  695. \@tufte@justification%
  696. \@tufte@margin@par%
  697. \noindent%
  698. }
  699. {\end{minipage}%
  700. \end{lrbox}%
  701. \marginpar{\usebox{\@tufte@margin@floatbox}}%
  702. \@tufte@reset@par%
  703. }
  704. %%
  705. % Margin figure environment
  706. \newenvironment{marginfigure}[1][-1.2ex]%
  707. {\begin{@tufte@margin@float}[#1]{figure}}
  708. {\end{@tufte@margin@float}}
  709. %%
  710. % Margin table environment
  711. \newenvironment{margintable}[1][-1.2ex]%
  712. {\begin{@tufte@margin@float}[#1]{table}}
  713. {\end{@tufte@margin@float}}
  714. %%
  715. % A collection of macros to be used with the new Tufte-style float environments.
  716. % \setfloatalignment forces the caption placement to be treated as top, bottom, etc.
  717. % \forcerectofloat forces the float to be treated as if it were appearing on a recto page.
  718. % \forceversofloat does the same, but for verso pages.
  719. \newcommand{\floatalignment}{x}% holds the current float alignment (t, b, h, p)
  720. \newcommand{\setfloatalignment}[1]{\global\def\floatalignment{#1}}% manually sets the float alignment
  721. \newboolean{@tufte@float@recto}
  722. \newcommand{\forcerectofloat}{\global\@tufte@float@rectotrue}
  723. \newcommand{\forceversofloat}{\global\@tufte@float@rectofalse}
  724. % Boxes to temporarily store our float and caption
  725. \newsavebox{\@tufte@figure@box}
  726. \newsavebox{\@tufte@caption@box}
  727. % Save original LaTeX float environment
  728. \let\@tufte@orig@float\@float
  729. \let\@tufte@orig@endfloat\end@float
  730. % Save original LaTeX \caption and \label commands
  731. \AtBeginDocument{%
  732. \let\@tufte@orig@caption\caption%
  733. \let\@tufte@orig@label\label%
  734. }
  735. % Store the caption and label contents
  736. \newcommand{\@tufte@stored@shortcaption}{}
  737. \newcommand{\@tufte@stored@caption}{}
  738. \newcommand{\@tufte@stored@label}{}
  739. \newcommand{\@tufte@caption}[2][]{%
  740. \ifthenelse{\isempty{#1}}%
  741. {\gdef\@tufte@stored@shortcaption{#2}}%
  742. {\gdef\@tufte@stored@shortcaption{#1}}%
  743. \gdef\@tufte@stored@caption{#2}%
  744. }
  745. \newcommand{\@tufte@label}[1]{%
  746. \gdef\@tufte@stored@label{#1}%
  747. }
  748. \newcommand{\@tufte@fps}{}
  749. \newboolean{@tufte@float@star}
  750. \newlength{\@tufte@float@contents@width}
  751. %%
  752. % Define a float environment to place the captions in the margin space
  753. \newenvironment{@tufte@float}[3][htbp]%
  754. {% begin @tufte@float
  755. % Should this float be full-width or just text-width?
  756. \ifthenelse{\equal{#3}{star}}%
  757. {\setboolean{@tufte@float@star}{true}}%
  758. {\setboolean{@tufte@float@star}{false}}%
  759. % Check page side (recto/verso) and store detected value -- can be overriden in environment contents
  760. \@tufte@checkoddpage%
  761. \ifthenelse{\boolean{@tufte@odd@page}}%
  762. {\global\@tufte@float@rectotrue}%
  763. {\global\@tufte@float@rectofalse}%
  764. % If the float placement specifier is 'b' and only 'b', then bottom-align the mini-pages, otherwise top-align them.
  765. \renewcommand{\@tufte@fps}{#1}%
  766. \ifthenelse{\equal{#1}{b}\OR\equal{#1}{B}}%
  767. {\renewcommand{\floatalignment}{b}}%
  768. {\renewcommand{\floatalignment}{t}}%
  769. % Caption the contents of the \caption and \label commands to use later
  770. \renewcommand{\caption}[2][]{\@tufte@caption[##1]{##2}}%
  771. \renewcommand{\label}[1]{\@tufte@label{##1}}%
  772. \@tufte@orig@float{#2}[#1]%
  773. \ifthenelse{\boolean{@tufte@float@star}}%
  774. {\setlength{\@tufte@float@contents@width}{\@tufte@fullwidth}}%
  775. {\setlength{\@tufte@float@contents@width}{\textwidth}}%
  776. \begin{lrbox}{\@tufte@figure@box}%
  777. \begin{minipage}[\floatalignment]{\@tufte@float@contents@width}\hbox{}%
  778. }{% end @tufte@float
  779. \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
  780. \end{minipage}%
  781. \end{lrbox}%
  782. % build the caption box
  783. \begin{lrbox}{\@tufte@caption@box}%
  784. \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
  785. \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
  786. \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
  787. \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
  788. \end{minipage}%
  789. \end{lrbox}%
  790. % now typeset the stored boxes
  791. \begin{fullwidth}%
  792. \begin{minipage}[\floatalignment]{\linewidth}%
  793. \ifthenelse{\boolean{@tufte@float@star}}%
  794. {\@tufte@float@fullwidth{\@tufte@figure@box}{\@tufte@caption@box}}%
  795. {\@tufte@float@textwidth{\@tufte@figure@box}{\@tufte@caption@box}}%
  796. \end{minipage}%
  797. \end{fullwidth}%
  798. \@tufte@orig@endfloat%
  799. % reset commands and temp boxes and captions
  800. \let\caption\@tufte@orig@caption%
  801. \let\label\@tufte@orig@label%
  802. \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}%
  803. \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}%
  804. \gdef\@tufte@stored@shortcaption{}%
  805. \gdef\@tufte@stored@caption{}%
  806. }
  807. \newcommand{\@tufte@float@textwidth}[2]{%
  808. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}{%
  809. % asymmetric or page is odd, so caption is on the right
  810. \usebox{#1}%
  811. \hspace{\marginparsep}%
  812. \smash{\usebox{#2}}%
  813. }{%
  814. % symmetric pages and page is even, so caption is on the left
  815. \strut\smash{\usebox{#2}}%
  816. \hspace{\marginparsep}%
  817. \usebox{#1}%
  818. }%
  819. }
  820. \newcommand{\@tufte@float@fullwidth}[2]{%
  821. \ifthenelse{\equal{\floatalignment}{b}}%
  822. {% place caption above figure
  823. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
  824. {\hfill\smash{\usebox{#2}}\par\usebox{#1}}% caption on the right
  825. {\smash{\usebox{#2}\hfill}\par\usebox{#1}}% caption on the left
  826. }%
  827. {% place caption below figure
  828. \ifthenelse{\NOT\boolean{@tufte@symmetric}\OR\boolean{@tufte@float@recto}}%
  829. {\usebox{#1}\par\hfill\smash{\usebox{#2}}}% caption on the right
  830. {\usebox{#1}\par\smash{\usebox{#2}\hfill}}% caption on the left
  831. }%
  832. }
  833. %%
  834. % Redefine the figure environment to place the captions in the margin space
  835. \renewenvironment{figure}[1][htbp]
  836. {\begin{@tufte@float}[#1]{figure}{}}
  837. {\end{@tufte@float}}
  838. %%
  839. % Redefine the table environment to place the captions in the margin space
  840. \renewenvironment{table}[1][htbp]
  841. {\begin{@tufte@float}[#1]{table}{}}
  842. {\end{@tufte@float}}
  843. %%
  844. % Full-width figure
  845. \renewenvironment{figure*}[1][htbp]%
  846. {\begin{@tufte@float}[#1]{figure}{star}}
  847. {\end{@tufte@float}}
  848. %%
  849. % Full-width table
  850. \renewenvironment{table*}[1][htbp]%
  851. {\begin{@tufte@float}[#1]{table}{star}}
  852. {\end{@tufte@float}}
  853. %%
  854. % Full-page-width area
  855. \newenvironment{fullwidth}
  856. {\ifthenelse{\boolean{@tufte@symmetric}}%
  857. {\ifthenelse{\boolean{@tufte@changepage}}{\begin{adjustwidth*}{}{-\@tufte@overhang}}{\begin{adjustwidth}[]{}{-\@tufte@overhang}}}%
  858. {\begin{adjustwidth}{}{-\@tufte@overhang}}%
  859. }%
  860. {\ifthenelse{\boolean{@tufte@symmetric}}%
  861. {\ifthenelse{\boolean{@tufte@changepage}}{\end{adjustwidth*}}{\end{adjustwidth}}}%
  862. {\end{adjustwidth}}%
  863. }
  864. %%
  865. % Format the captions in a style similar to the sidenotes
  866. \long\def\@caption#1[#2]#3{%
  867. \par%
  868. \addcontentsline{\csname ext@#1\endcsname}{#1}%
  869. {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  870. \begingroup%
  871. \@parboxrestore%
  872. \if@minipage%
  873. \@setminipage%
  874. \fi%
  875. \@tufte@marginfont\@tufte@justification%
  876. \noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
  877. %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  878. \endgroup}
  879. %%
  880. % If we're NOT using XeLaTeX and the `nofonts' class option was NOT provided,
  881. % we should load the Palatino, Helvetica, and Bera Mono fonts (if they are
  882. % installed.)
  883. \ifthenelse{\boolean{@tufte@loadfonts}\AND\NOT\boolean{@tufte@xetex}}{%
  884. \IfFileExists{mathpazo.sty}{\RequirePackage[osf,sc]{mathpazo}}{}
  885. \IfFileExists{helvet.sty}{\RequirePackage[scaled=0.90]{helvet}}{}
  886. \IfFileExists{beramono.sty}{\RequirePackage[scaled=0.85]{beramono}}{}
  887. \RequirePackage[T1]{fontenc}
  888. \RequirePackage{textcomp}
  889. }{}
  890. %%
  891. % Turns newlines into spaces. Based on code from the `titlesec' package.
  892. \DeclareRobustCommand{\@tufte@newlinetospace}{%
  893. \@ifstar{\@tufte@newlinetospace@i}{\@tufte@newlinetospace@i}%
  894. }
  895. \def\@tufte@newlinetospace@i{%
  896. \ifdim\lastskip>\z@\else\space\fi
  897. \ignorespaces%
  898. }
  899. \DeclareRobustCommand{\newlinetospace}[1]{%
  900. \let\@tufte@orig@cr\\% save the original meaning of \\
  901. \def\\{\@tufte@newlinetospace}% turn \\ and \\* into \space
  902. \let\newline\\% turn \newline into \space
  903. #1%
  904. \let\\\@tufte@orig@cr% revert to original meaning of \\
  905. }
  906. %%
  907. % Sets up the running heads and folios.
  908. \RequirePackage{fancyhdr}
  909. % Set the default page style to 'fancy'
  910. \pagestyle{fancy}
  911. % Set the header/footer width to be the body text block plus the margin
  912. % note area.
  913. \AtBeginDocument{%
  914. \ifthenelse{\boolean{@tufte@symmetric}}
  915. {\fancyhfoffset[LE,RO]{\@tufte@overhang}}
  916. {\fancyhfoffset[RE,RO]{\@tufte@overhang}}
  917. }
  918. % The running heads/feet don't have rules
  919. \renewcommand{\headrulewidth}{0pt}
  920. \renewcommand{\footrulewidth}{0pt}
  921. % The 'fancy' page style is the default style for all pages.
  922. \fancyhf{} % clear header and footer fields
  923. \ifthenelse{\boolean{@tufte@twoside}}
  924. {\fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plainauthor}}}%
  925. \fancyhead[RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
  926. {\fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}}
  927. % The `plain' page style is used on chapter opening pages.
  928. % In Tufte's /Beautiful Evidence/ he never puts page numbers at the
  929. % bottom of pages -- the folios are unexpressed.
  930. \fancypagestyle{plain}{
  931. \fancyhf{} % clear header and footer fields
  932. % Uncomment the following five lines of code if you want the opening page
  933. % of the chapter to express the folio in the lower outside corner.
  934. %\ifthenelse{\boolean{@tufte@twoside}}
  935. % {\fancyfoot[LE,RO]{\thepage}}
  936. % {\fancyfoot[RE,RO]{\thepage}}
  937. }
  938. % The `empty' page style suppresses all headers and footers.
  939. % It's used on title pages and `intentionally blank' pages.
  940. \fancypagestyle{empty}{
  941. \fancyhf{} % clear header and footer fields
  942. }
  943. %%
  944. % Set raggedright and paragraph indentation for document
  945. \AtBeginDocument{\@tufte@justification}
  946. %%
  947. % Prints the list of class options and their states.
  948. \newcommand{\typeoutbool}[2]{%
  949. \ifthenelse{\boolean{#2}}
  950. {\typeout{\space\space#1: true}}
  951. {\typeout{\space\space#1: false}}
  952. }
  953. \newcommand{\typeoutstr}[2]{%
  954. \typeout{\space\space#1: #2}
  955. }
  956. \newcommand{\PrintTufteSettings}{%
  957. \typeout{-------------------- Tufte-LaTeX settings ----------}
  958. \typeout{Class: \@tufte@pkgname}
  959. \typeout{}
  960. \typeout{Class options:}
  961. \typeoutbool{a4paper}{@tufte@afourpaper}
  962. \typeoutbool{b5paper}{@tufte@bfivepaper}
  963. \typeoutbool{load fonts}{@tufte@loadfonts}
  964. \typeoutbool{fully-justified}{@tufte@justified}
  965. \typeoutbool{letterspacing}{@tufte@letterspace}
  966. \typeoutbool{sans-serif sidenotes}{@tufte@sfsidenotes}
  967. \typeoutbool{symmetric margins}{@tufte@symmetric}
  968. \typeoutbool{titlepage}{@tufte@titlepage}
  969. \typeoutbool{twoside}{@tufte@twoside}
  970. \typeoutbool{debug}{@tufte@debug}
  971. \typeout{}
  972. \typeout{Internal variables:}
  973. \typeoutbool{[twoside]}{@twoside}
  974. \typeoutbool{pdflatex}{@tufte@pdf}
  975. \typeoutbool{xelatex}{@tufte@xetex}
  976. \typeout{----------------------------------------------------}
  977. }
  978. %%
  979. % Color
  980. \RequirePackage[usenames,dvipsnames,svgnames]{xcolor}
  981. %%
  982. % Produces a full title page
  983. \newcommand{\maketitlepage}[0]{%
  984. \cleardoublepage%
  985. {%
  986. \sffamily%
  987. \begin{fullwidth}%
  988. \fontsize{18}{20}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}%
  989. \vspace{11.5pc}%
  990. \fontsize{36}{40}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklesstitle}}%
  991. \vfill%
  992. \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}%
  993. \end{fullwidth}%
  994. }
  995. \thispagestyle{empty}%
  996. \clearpage%
  997. }
  998. %%
  999. % Title block
  1000. \renewcommand{\maketitle}{%
  1001. \newpage
  1002. \global\@topnum\z@% prevent floats from being placed at the top of the page
  1003. \begingroup
  1004. \setlength{\parindent}{0pt}
  1005. \setlength{\parskip}{4pt}
  1006. \ifthenelse{\boolean{@tufte@sfsidenotes}}
  1007. {\begingroup
  1008. % FIXME fails with \thanks
  1009. \sffamily
  1010. \par{\LARGE\allcaps{\@title}}
  1011. \ifthenelse{\equal{\@author}{}}{}{\par{\Large\allcaps{\@author}}}
  1012. \ifthenelse{\equal{\@date}{}}{}{\par{\Large\allcaps{\@date}}}
  1013. \endgroup}
  1014. {\begingroup
  1015. \par{\LARGE\textit{\@title}}
  1016. \ifthenelse{\equal{\@author}{}}{}{\par{\Large\textit{\@author}}}
  1017. \ifthenelse{\equal{\@date}{}}{}{\par{\Large\textit{\@date}}}
  1018. \endgroup}
  1019. \par
  1020. \endgroup
  1021. \thispagestyle{plain}% suppress the running head
  1022. }
  1023. %%
  1024. % Title page (if the `titlepage' option was passed to the tufte-handout
  1025. % class.)
  1026. \ifthenelse{\boolean{@tufte@titlepage}}
  1027. {\renewcommand{\maketitle}{\maketitlepage}}
  1028. {}
  1029. %%
  1030. % When \cleardoublepage is called, produce a blank (empty) page -- i.e.,
  1031. % without headers and footers
  1032. \def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else
  1033. \hbox{}
  1034. %\vspace*{\fill}
  1035. %\begin{center}
  1036. % This page intentionally contains only this sentence.
  1037. %\end{center}
  1038. %\vspace{\fill}
  1039. \thispagestyle{empty}
  1040. \newpage
  1041. \if@twocolumn\hbox{}\newpage\fi\fi\fi}
  1042. %%
  1043. % Make Tuftian-style section headings and TOC formatting
  1044. \RequirePackage{titlesec,titletoc}
  1045. \titleformat{\chapter}%
  1046. [display]% shape
  1047. {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}% format applied to label+text
  1048. {\itshape\huge\thechapter}% label
  1049. {0pt}% horizontal separation between label and title body
  1050. {\huge\rmfamily\itshape}% before the title body
  1051. [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]% after the title body
  1052. \titleformat{\section}%
  1053. [hang]% shape
  1054. {\normalfont\Large\itshape}% format applied to label+text
  1055. {\thesection}% label
  1056. {1em}% horizontal separation between label and title body
  1057. {}% before the title body
  1058. []% after the title body
  1059. \titleformat{\subsection}%
  1060. [hang]% shape
  1061. {\normalfont\large\itshape}% format applied to label+text
  1062. {\thesubsection}% label
  1063. {1em}% horizontal separation between label and title body
  1064. {}% before the title body
  1065. []% after the title body
  1066. \titleformat{\paragraph}%
  1067. [runin]% shape
  1068. {\normalfont\itshape}% format applied to label+text
  1069. {\theparagraph}% label
  1070. {1em}% horizontal separation between label and title body
  1071. {}% before the title body
  1072. []% after the title body
  1073. \titlespacing*{\chapter}{0pt}{50pt}{40pt}
  1074. \titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
  1075. \titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus.2ex}
  1076. % Subsubsection and following section headings shouldn't be used.
  1077. % See Bringhurst's _The Elements of Typography_, section 4.2.2.
  1078. \renewcommand\subsubsection{%
  1079. \ClassError{\@tufte@pkgname}{\noexpand\subsubsection is undefined by this class.%
  1080. \MessageBreak See Robert Bringhurst's _The Elements of
  1081. \MessageBreak Typographic Style_, section 4.2.2.
  1082. \MessageBreak \noexpand\subsubsection was used}
  1083. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  1084. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  1085. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  1086. }
  1087. \renewcommand\subparagraph{%
  1088. \ClassError{\@tufte@pkgname}{\noexpand\subparagraph is undefined by this class.%
  1089. \MessageBreak See Robert Bringhurst's _The Elements of
  1090. \MessageBreak Typographic Style_, section 4.2.2.
  1091. \MessageBreak \noexpand\subparagraph was used}
  1092. {From Bringhurst's _The Elements of Typographic Style_, section 4.2.2: Use as
  1093. \MessageBreak many levels of headings as you need, no more and no fewer. Also see the many
  1094. \MessageBreak related threads on Ask E.T. at http://www.edwardtufte.com/.}
  1095. }
  1096. % Formatting for main TOC (printed in front matter)
  1097. % {section} [left] {above} {before w/label} {before w/o label} {filler + page} [after]
  1098. \ifthenelse{\boolean{@tufte@toc}}{%
  1099. \titlecontents{part}% FIXME
  1100. [0em] % distance from left margin
  1101. {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
  1102. {\contentslabel{2em}} % before w/label (label = ``II'')
  1103. {} % before w/o label
  1104. {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
  1105. [\end{fullwidth}] % after
  1106. \titlecontents{chapter}%
  1107. [0em] % distance from left margin
  1108. {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape} % above (global formatting of entry)
  1109. {\hspace*{0em}\contentslabel{2em}} % before w/label (label = ``2'')
  1110. {\hspace*{0em}} % before w/o label
  1111. {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
  1112. [\end{fullwidth}] % after
  1113. \titlecontents{section}% FIXME
  1114. [0em] % distance from left margin
  1115. {\vspace{0\baselineskip}\begin{fullwidth}\Large\rmfamily\itshape} % above (global formatting of entry)
  1116. {\hspace*{2em}\contentslabel{2em}} % before w/label (label = ``2.6'')
  1117. {\hspace*{2em}} % before w/o label
  1118. {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
  1119. [\end{fullwidth}] % after
  1120. \titlecontents{subsection}% FIXME
  1121. [0em] % distance from left margin
  1122. {\vspace{0\baselineskip}\begin{fullwidth}\large\rmfamily\itshape} % above (global formatting of entry)
  1123. {\hspace*{4em}\contentslabel{4em}} % before w/label (label = ``2.6.1'')
  1124. {\hspace*{4em}} % before w/o label
  1125. {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
  1126. [\end{fullwidth}] % after
  1127. \titlecontents{paragraph}% FIXME
  1128. [0em] % distance from left margin
  1129. {\vspace{0\baselineskip}\begin{fullwidth}\normalsize\rmfamily\itshape} % above (global formatting of entry)
  1130. {\hspace*{6em}\contentslabel{2em}} % before w/label (label = ``2.6.0.0.1'')
  1131. {\hspace*{6em}} % before w/o label
  1132. {\rmfamily\upshape\qquad\thecontentspage} % filler + page (leaders and page num)
  1133. [\end{fullwidth}] % after
  1134. }{}
  1135. %%
  1136. % Format lists of figures/tables
  1137. \renewcommand\listoffigures{%
  1138. \ifthenelse{\equal{\@tufte@class}{book}}%
  1139. {\chapter*{\listfigurename}}%
  1140. {\section*{\listfigurename}}%
  1141. % \begin{fullwidth}%
  1142. \@starttoc{lof}%
  1143. % \end{fullwidth}%
  1144. }
  1145. \renewcommand\listoftables{%
  1146. \ifthenelse{\equal{\@tufte@class}{book}}%
  1147. {\chapter*{\listtablename}}%
  1148. {\section*{\listtablename}}%
  1149. % \begin{fullwidth}%
  1150. \@starttoc{lot}%
  1151. % \end{fullwidth}%
  1152. }
  1153. \newcommand{\@tufte@lof@line}[2]{%
  1154. % #1 is the figure/table number and its caption text
  1155. % #2 is the page number on which the figure/table appears
  1156. \leftskip 0.0em
  1157. \rightskip 0em
  1158. \parfillskip 0em
  1159. \parindent 0.0em
  1160. \@afterindenttrue
  1161. \interlinepenalty\@M
  1162. \leavevmode
  1163. \@tempdima 2.0em
  1164. \advance\leftskip\@tempdima
  1165. \null\nobreak\hskip -\leftskip
  1166. {#1}\nobreak\qquad\nobreak#2%
  1167. \par%
  1168. }
  1169. \renewcommand*\l@figure{\@tufte@lof@line}
  1170. \let\l@table\l@figure
  1171. %%
  1172. % A handy command to disable hyphenation for short bits of text.
  1173. % Borrowed from Peter Wilson's `hyphenat' package.
  1174. \newlanguage\langwohyphens% define a language without hyphenation rules
  1175. \newcommand{\nohyphens}[1]{{\language\langwohyphens #1}}% used for short bits of text
  1176. \newcommand{\nohyphenation}{\language\langwohyphens}% can be used inside environments for longer text
  1177. %%
  1178. % The bibliography environment
  1179. \setlength\bibindent{1.5em}
  1180. \renewenvironment{thebibliography}[1]
  1181. {%
  1182. \ifthenelse{\equal{\@tufte@class}{book}}%
  1183. {\chapter{\bibname}}%
  1184. {\section*{\refname}}%
  1185. % \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
  1186. \list{\@biblabel{\@arabic\c@enumiv}}%
  1187. {\settowidth\labelwidth{\@biblabel{#1}}%
  1188. \leftmargin\labelwidth
  1189. \advance\leftmargin\labelsep
  1190. \@openbib@code
  1191. \usecounter{enumiv}%
  1192. \let\p@enumiv\@empty
  1193. \renewcommand\theenumiv{\@arabic\c@enumiv}}%
  1194. \sloppy
  1195. \clubpenalty4000
  1196. \@clubpenalty \clubpenalty
  1197. \widowpenalty4000%
  1198. \sfcode`\.\@m%
  1199. }
  1200. {%
  1201. \def\@noitemerr
  1202. {\@latex@warning{Empty `thebibliography' environment}}%
  1203. \endlist%
  1204. }
  1205. \renewcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
  1206. %%
  1207. % An index environment to mimic Tufte's indexes
  1208. \RequirePackage{multicol}
  1209. \renewenvironment{theindex}
  1210. {\begin{fullwidth}%
  1211. \small%
  1212. \ifthenelse{\equal{\@tufte@class}{book}}%
  1213. {\chapter{\indexname}}%
  1214. {\section*{\indexname}}%
  1215. \parskip0pt%
  1216. \parindent0pt%
  1217. \let\item\@idxitem%
  1218. \begin{multicols}{3}%
  1219. }
  1220. {\end{multicols}%
  1221. \end{fullwidth}%
  1222. }
  1223. \renewcommand\@idxitem{\par\hangindent 2em}
  1224. \renewcommand\subitem{\par\hangindent 3em\hspace*{1em}}
  1225. \renewcommand\subsubitem{\par\hangindent 4em\hspace*{2em}}
  1226. \renewcommand\indexspace{\par\addvspace{1.0\baselineskip plus 0.5ex minus 0.2ex}\relax}%
  1227. \newcommand{\lettergroup}[1]{}% swallow the letter heading in the index
  1228. %%
  1229. % If debugging is enabled, print the Tufte-LaTeX options and the list of
  1230. % files.
  1231. \ifthenelse{\boolean{@tufte@debug}}
  1232. {\PrintTufteSettings\listfiles}
  1233. {}
  1234. %%
  1235. % If there is a `tufte-common-local.tex' file, load it up.
  1236. \IfFileExists{tufte-common-local.tex}
  1237. {\input{tufte-common-local.tex}}
  1238. {}
  1239. %%
  1240. % End of file
  1241. \endinput