Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

1440 wiersze
46KB

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