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

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