titlesec.sty 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. % +--------------------------------------------------+
  2. % | Typeset titlesec.tex to get the documentation. |
  3. % +--------------------------------------------------+
  4. %
  5. % Copyright (c) 1998-2011 by Javier Bezos.
  6. % All Rights Reserved.
  7. %
  8. % This file is part of the titlesec distribution release 2.10.0
  9. % -----------------------------------------------------------
  10. %
  11. % It may be distributed and/or modified under the
  12. % conditions of the LaTeX Project Public License, either version 1.3
  13. % of this license or (at your option) any later version.
  14. % The latest version of this license is in
  15. % http://www.latex-project.org/lppl.txt
  16. % and version 1.3 or later is part of all distributions of LaTeX
  17. % version 2003/12/01 or later.
  18. %
  19. % This work has the LPPL maintenance status "maintained".
  20. %
  21. % The Current Maintainer of this work is Javier Bezos.
  22. %
  23. % Notes
  24. % ~~~~~
  25. %
  26. % The following tags are used:
  27. % ttl@ : the generic tag used through the style
  28. % ttlh@ : a shape definition
  29. % ttlf@ : a macro containing the title format
  30. % ttls@ : id. the title space
  31. % ttlp@ : page key related macros
  32. % ttll@ : level number
  33. %
  34. % The ttlf@ and ttls@ contains data in the form {..}{..}.
  35. % Perhaps in future releases they should be converted
  36. % to a prop-like list, similar to that proposed by the
  37. % latex team.
  38. %
  39. % Admittedly, the current implementation seems too
  40. % complicated, but that's necessary in order to provide
  41. % certain compatibility with the sections as defined by the
  42. % used class. Other packages opt for providing the sections
  43. % as defined by standard classes ignoring the class; for
  44. % instance sectsty which does a simple task in a simple and
  45. % nice way. However, that was not my goal.
  46. %
  47. % Release
  48. % ~~~~~~~
  49. \NeedsTeXFormat{LaTeX2e}
  50. \ProvidesPackage{titlesec}[2011/12/15 v2.10.0 Sectioning titles]
  51. % Initialization
  52. % ~~~~~~~~~~~~~~
  53. \newif\ifttl@ps
  54. \ttl@psfalse
  55. % The \ttl@label switch is used when printing the label in titles.
  56. % A numberless variant makes it to true.
  57. % There is a \ttl@toclabel as well, which is true iff the
  58. % title is numbered; used in toc entries (except default part
  59. % and chapter) and marks (only in titlesec pagestyles).
  60. \newif\ifttl@label
  61. \newif\ifttl@toclabel
  62. \newbox\ttl@box
  63. % A provision for the report style:
  64. \@ifundefined{if@mainmatter}
  65. {\let\if@mainmatter\iftrue}{}
  66. \@ifundefined{if@openright}
  67. {\let\if@openright\iftrue}{}
  68. % and the ams styles as well
  69. \@ifundefined{@chapapp}
  70. {\let\@chapapp\chaptername}{}
  71. \def\ttl@trylist{\ttl@try{}}
  72. \def\ttl@getkeys#1#2{%
  73. \if\expandafter @\@gobble#1@\@empty
  74. \edef\ttl@b{\expandafter\@gobble\string#1}%
  75. \let\ttl@a\ttl@b
  76. \else
  77. \makeatletter
  78. \edef\ttl@d{%
  79. \noexpand\input{ttlkeys.def}%
  80. \catcode`\noexpand\@=\the\catcode`\@}%
  81. \ttl@d
  82. \ttl@getkeys{#1}{#2}%
  83. \fi}
  84. % A more meaningful error for \@notdefinable
  85. \expandafter\AtEndOfPackage\expandafter{\expandafter
  86. \gdef\expandafter\@notdefinable\expandafter{\@notdefinable}}
  87. \def\@notdefinable{%
  88. \PackageError{titlesec}%
  89. {Incompatible package}%
  90. {Titlesec cannot continue defining its own macros
  91. because\MessageBreak
  92. \@backslashchar\reserved@a\space is already used by other package,
  93. the class\MessageBreak
  94. or the document.}}
  95. % +-----------------+
  96. % | C L A S S E S |
  97. % +-----------------+
  98. \def\ttl@useclass#1#2{%
  99. \@ifstar
  100. {\ttl@labelfalse#1{#2}[]}%
  101. {\ttl@labeltrue\@dblarg{#1{#2}}}}
  102. \def\ttl@straightclass{\ttl@useclass\ttl@straight@i}
  103. \def\ttl@partclass{\ttl@useclass\ttl@part@i}
  104. \def\ttl@topclass{\ttl@useclass\ttl@top@i}
  105. \def\ttl@pageclass{\ttl@useclass\ttl@page@i}
  106. % Here \scantokens is used to make sure the unescaped name
  107. % has `letters' and no `others'. Mainly for hyperref, so there
  108. % should be no problems.
  109. \newcommand\titleclass[1]{%
  110. \edef\ttl@a{\expandafter\@gobble\string#1}%
  111. \ifx\scantokens\@undefined\else
  112. \scantokens\expandafter{\expandafter
  113. \def\expandafter\ttl@a\expandafter{\ttl@a}}%
  114. \fi
  115. \@ifnextchar[{\@tempswatrue\ttl@class@i{#1}}%
  116. {\@tempswafalse\ttl@class@ii{#1}}}
  117. \def\ttl@class@i#1[#2]{%
  118. \@namedef{ttll@\ttl@a}{#2}%
  119. \expandafter\providecommand\csname\ttl@a title\endcsname{}%%%%
  120. \@ifundefined{ttl@toplevel}{}%
  121. {\expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname
  122. \csname ttlss@\ttl@toplevel\endcsname}%
  123. \edef\ttl@toplevel{\ttl@a}%
  124. \ttl@class@ii{#1}}
  125. \def\ttl@class@ii#1#2{%
  126. \@ifundefined{ttl@#2class}%
  127. {\PackageError{titlesec}{Unknown sectioning class}%
  128. {Valid names are top, page and straight}}%
  129. {\expandafter\let\csname ttl@compat\ttl@a\endcsname\relax
  130. \@ifundefined{\ttl@a mark}%
  131. {\@namedef{\ttl@a mark}{\@gobble}}%
  132. {}%
  133. \edef#1{%
  134. \expandafter\noexpand\csname ttl@#2class\endcsname{\ttl@a}}}%
  135. \if@tempswa
  136. \expandafter\@gobble
  137. \else
  138. \expandafter\@firstofone
  139. \fi
  140. {\@ifnextchar[%
  141. {\ttl@class@iii}%
  142. {\@ifundefined{ttll@\ttl@a}%
  143. {\PackageError{titlesec}{Unknown sectioning level}%
  144. {\string\titleclass\space with no optional arguments\MessageBreak
  145. only changes the class of an *existing* level}}}}}
  146. \def\ttl@class@iii[#1]{%
  147. \edef\ttl@b{\expandafter\@gobble\string#1}%
  148. \expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname
  149. \csname ttlss@\ttl@b\endcsname
  150. \expandafter\edef\csname ttlss@\ttl@b\endcsname{\ttl@a}%
  151. \let\ttl@a\ttl@toplevel
  152. \count@\csname ttll@\ttl@toplevel\endcsname
  153. \ttl@class@iv}
  154. \def\ttl@class@iv{%
  155. \@ifundefined{ttlss@\ttl@a}{}%
  156. {\advance\count@\@ne
  157. \edef\ttl@a{\csname ttlss@\ttl@a\endcsname}%
  158. \expandafter\edef\csname ttll@\ttl@a\endcsname{\the\count@}%
  159. \ttl@class@iv}}
  160. % Typesetting Classes: General tools
  161. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162. % The following command handles the *n spacing
  163. % Some tricks are necessary to multiply a
  164. % skip by a non integer number
  165. \newskip\beforetitleunit
  166. \beforetitleunit=1ex\@plus.3ex\@minus.06ex
  167. \newskip\aftertitleunit
  168. \aftertitleunit=1ex\@plus.1ex
  169. \newdimen\ttl@plus
  170. \newdimen\ttl@minus
  171. \def\ttl@assign#1{%
  172. \@ifstar
  173. {\ttl@assign@i{#1}}%
  174. {\ttl@assign@d{#1}}}
  175. \def\ttl@assign@i#1#2\relax#3{%
  176. \ttl@plus\z@
  177. \ttl@minus\z@
  178. \afterassignment\ttl@assign@ii
  179. \dimen@\the#3, % <- space
  180. #1 = #2\dimen@
  181. plus #2\ttl@plus
  182. minus #2\ttl@minus}
  183. \def\ttl@assign@ii#1 {% <- space
  184. \if#1,\else\afterassignment\ttl@assign@ii\fi
  185. \csname ttl@\string#1\endcsname}
  186. \def\ttl@assign@d#1#2\relax#3{\setlength#1{#2}}
  187. % To be used with \v/vspace to make them calc-savvy
  188. \def\ttl@calc#1#2{%
  189. {\setlength\@tempskipa{#2}%
  190. #1\@tempskipa}}
  191. \def\ttl@calcneg#1#2{%
  192. {\setlength\@tempskipa{#2}%
  193. #1{-\@tempskipa}}}
  194. % Gets from ttls@ and passes the spacing parameters:
  195. \def\ttl@startargs#1#2{% Get the first arguments, with the spacing
  196. \@ifundefined{ttlp@#2}%
  197. {\let\ttl@key@page\@empty}%
  198. {\ttlp@fetch{#2}}%
  199. \begingroup
  200. \def\ttl@b{ttls@#2}%
  201. \edef\ttl@key@numberless{\ifttl@label//\else/*\fi}%
  202. \def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try
  203. \ttl@trylist
  204. \xdef\ttl@b{\ttl@c}%
  205. \endgroup
  206. \ifx\ttl@b\@empty
  207. \PackageError{titlesec}{Format/spacing not found}%
  208. {I was unable to find the format corresponding to #2.\MessageBreak
  209. Maybe you haven't set it with \string\titleformat\space and
  210. \string\titlespacing}
  211. \fi
  212. \expandafter#1\ttl@b{#2}}
  213. % Used in ttl@select
  214. \def\ttl@savefn#1[#2]#3{%
  215. \ifcase#1%
  216. \footnotemark[#2]%
  217. \gdef\ttl@fn{\footnotetext[#2]{#3}}%
  218. \else
  219. \footnotemark
  220. \gdef\ttl@fn{\footnotetext{#3}}%
  221. \fi}
  222. \def\ttl@nest@error{%
  223. \PackageError{titlesec}{Nested titles}{Titles must not be nested}}
  224. \def\ttl@hmode@error{%
  225. \PackageError{titlesec}{Entered in horizontal mode}
  226. {The <format> argument cannot contain horizontal material\MessageBreak
  227. such as text, \string\noindent, \string\makebox, etc.}}
  228. % \ttl@select not only selects the right version to be
  229. % used. It also take steps to ensure that a mark
  230. % is not lost inside a box by saving it into \ttl@mk,
  231. % which in turn is used by the sect and chap commands.
  232. \newif\ifttl@explicit
  233. \def\ttl@gmk#1{\gdef\ttl@mk{#1}}
  234. \def\ttl@select#1#2#3#4{%
  235. \ttl@Hy@saveanchor
  236. \global\let\ttl@mk\@empty % global because of rigidchapters
  237. \global\let\ttl@fn\@empty
  238. \begingroup
  239. \everypar{\setbox\z@\lastbox\strut}% or \hskip-\parindent?
  240. \let\ttl@straight@i\ttl@nest@error
  241. \let\ttl@top@i \ttl@nest@error
  242. \let\ttl@part@i \ttl@nest@error
  243. \let\ttl@page@i \ttl@nest@error
  244. \let\ttl@newpage\newpage
  245. \def\newpage{\ttl@savewrite\ttl@newpage}%
  246. \def\markboth##1##2{\protect\ttl@gmk{\protect\markboth{##1}{##2}}}%
  247. \def\markright##1{\protect\ttl@gmk{\protect\markright{##1}}}%
  248. \def\@mkboth##1##2{\protect\ttl@gmk{\protect\@mkboth{##1}{##2}}}%
  249. \def\footnote{\@ifnextchar[%
  250. {\ttl@savefn\z@}{\ttl@savefn\@ne[]}}%
  251. \edef\ttl@key@numberless{\ifttl@label//\else/*\fi}%
  252. \def\ttl@b{ttlf@#1}%
  253. \def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try
  254. \ttl@trylist
  255. \ifttl@explicit
  256. \def\ttl@passexplicit{\ttl@case{#4}}%
  257. \ttl@c{#4}{#2}{#3}{}% ttl@c is returned by ttl@try with ttlf@...
  258. \else
  259. \let\ttl@passexplicit\ttl@case
  260. \ttl@c{#2}{#3}{#4}% ttl@c is returned by ttl@try with ttlf@...
  261. \fi
  262. \endgroup}
  263. \let\ttl@savewrite\@empty
  264. \def\ttl@finmarks{%
  265. \ttl@savewrite
  266. \ttl@mk % Contains a possible mark, returned by \ttl@select
  267. \ttl@fn} % And a footnote
  268. \def\ttl@try#1{%
  269. \edef\ttl@c{#1}% #1 is a list in the form \ttl@a{key}\ttl@a{key}
  270. \@ifundefined{\ttl@b\ttl@c}{}{%
  271. \edef\ttl@c{\expandafter\noexpand\csname\ttl@b\ttl@c\endcsname}%
  272. \def\ttl@a##1{\csname ttl@extra@##1\endcsname}%
  273. #1%
  274. \let\ttl@try\@gobble}} % locally modified to `break' testings
  275. % \ttl@write writes marks and toc. tocdepth is taken
  276. % care of when the toc is typesetted and not here.
  277. % Used always through ttl@savewrite
  278. \def\ttl@write#1#2{%
  279. \ttl@blinemarks
  280. \csname#1mark\endcsname{#2}%
  281. \def\ttl@a{\protect\numberline{\@nameuse{the#1}}}%
  282. \@nameuse{ttl@toc#1}% eg, \ttl@tocpart modifies \ttl@a
  283. \ttl@addcontentsline{#1}{#2}% Depends on toctitles
  284. \ttl@elinemarks
  285. \global\ttl@toclabelfalse}
  286. \newif\ifttl@premark % to be used in ttlps.def
  287. \ttl@premarkfalse
  288. \def\ttl@premark#1#2{%
  289. \protected@xdef\ttl@prevmarks{\ttl@marks}%
  290. \ttl@blinemarks
  291. \csname#1mark\endcsname{#2}%
  292. \ttl@elinemarks
  293. \gdef\ttl@prevmarks{\ttl@marks}}
  294. % Must be preceded by a default \ttl@savewrite, which is used
  295. % in starred variants--\@empty in top and straight classes.
  296. % In straight class, it is preceded by the setting of
  297. % prev marks to provide a "fixed" top mark. Otherwise,
  298. % the default prev mark (= curr mark) is used (restored
  299. % after ttl@labelling in straight). This is the command
  300. % to be hacked if you want to change the behaviour of
  301. % starred variants.
  302. \def\ttl@labelling#1#2{%
  303. \let\ttl@Hy@saveanchor\@empty
  304. \ifttl@label % First: if star
  305. \def\ttl@savewrite{\ttl@write{#1}{#2}}%
  306. \@nameuse{ttl@#1label}% eg, sets if mainmatter in chapter.
  307. \ifttl@label % Second, eg, if not main matter
  308. \ifnum\@nameuse{ttll@#1}>\c@secnumdepth\relax
  309. \ttl@labelfalse % Third: if too deep
  310. \else
  311. \ttl@Hy@refstepcounter{#1}%
  312. \@nameuse{ttl@#1out}%
  313. \fi
  314. \fi
  315. \fi
  316. \let\ifttl@toclabel\ifttl@label
  317. \ifx\ttl@savewrite\@empty\else % If marks
  318. \ifttl@ps
  319. \ifttl@premark
  320. \global\ttl@premarkfalse
  321. \else % if no \pretitlemark
  322. \ttl@premark{#1}{#2}%
  323. \fi
  324. \fi
  325. \ifttl@label\else\ttl@Hy@steplink{#1}\fi
  326. \fi}
  327. % Executed by ttl@labelling if the name of section is chapter:
  328. \def\ttl@chapterlabel{\if@mainmatter\else\ttl@labelfalse\fi}
  329. % Executed by ttl@labelling if chapter has a number. Note
  330. % you can define messages for other sectioning levels (eg,
  331. % \ttl@sectionout).
  332. \def\ttl@chapterout{\typeout{\chaptertitlename\space\thechapter.}}
  333. % Straight class
  334. % ~~~~~~~~~~~~~
  335. % Default for nobottomtitles. Changed by nobottomtitles*
  336. \def\ttl@addstretch{\advance\@tempskipa-\pagestretch}
  337. % 1:name 2:level 3:indent 4:before 5:after 6:afind [7]:cap 8:title
  338. % The second argument of ttl@sect is the level, which
  339. % is empty if the star version is used. In this case
  340. % neither the toc nor the marks are written.
  341. \def\ttl@straight@i#1[#2]#3{%
  342. \def\@currentlabelname{#2}% for nameref
  343. \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
  344. \let\ttl@savewrite\@empty
  345. \def\ttl@savetitle{#3}%
  346. \gdef\thetitle{\csname the#1\endcsname}%
  347. \if@noskipsec \leavevmode \fi
  348. \par
  349. \ttl@labelling{#1}{#2}%
  350. \ttl@startargs\ttl@straight@ii{#1}{#3}}
  351. % 1:left 2:right 3:before 4:after 5:afterindent 6:name 7:title
  352. \def\ttl@straight@ii#1#2#3#4#5#6#7{%
  353. \ttl@assign\@tempskipa#3\relax\beforetitleunit
  354. \@ifundefined{ttl@ps@#6}{}%
  355. {\PackageWarning{titlesec}{Page style in straight class ignored}}%
  356. \if@nobreak
  357. \ttl@titlespace{\@tempskipa}%
  358. \else
  359. \@ifundefined{#6break}%
  360. {\addpenalty{\@secpenalty}}%
  361. {\csname#6break\endcsname}%
  362. \addvspace{\@tempskipa}%
  363. \ifdim\bottomtitlespace<\z@
  364. \else
  365. \begingroup
  366. \@tempskipb\pagegoal
  367. \@tempskipa\pagegoal
  368. \ttl@addstretch % \relax if nobottomtitle*
  369. \advance\@tempskipa-\bottomtitlespace\relax % not a register
  370. \pagegoal\@tempskipa
  371. \def\@textbottom{\vskip\z@\@plus.0001fil}%
  372. \penalty9999
  373. \pagegoal\@tempskipb
  374. \endgroup
  375. \fi
  376. \fi
  377. \@afterindenttrue
  378. \ifcase#5 \@afterindentfalse\fi
  379. \ttl@assign\@tempskipb#4\relax\aftertitleunit
  380. \ttl@select{#6}{#1}{#2}{#7}%
  381. \ttl@finmarks
  382. \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
  383. \if@noskipsec
  384. \global\@nobreakfalse
  385. \everypar{%
  386. \if@noskipsec
  387. \global\@noskipsecfalse
  388. \clubpenalty\@M
  389. \hskip-\parindent
  390. \begingroup
  391. \@svsechd\unskip{\hspace{\@tempskipb}}%
  392. \endgroup
  393. \else
  394. \clubpenalty\@clubpenalty\everypar{}%
  395. \fi}%
  396. \else
  397. \par\nobreak
  398. \vspace{\@tempskipb}%
  399. \@afterheading
  400. \fi
  401. \ignorespaces}
  402. % Part class
  403. % ~~~~~~~~~~
  404. \providecommand\partmark[1]{\markboth{}{}}
  405. \def\ttl@part@i#1[#2]#3{%
  406. \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
  407. \def\ttl@savewrite{\ttl@write{#1}{#3}}% A default value. Not #2!
  408. \def\ttl@savetitle{#3}%
  409. \ttl@labelling{#1}{#2}%
  410. \ttl@startargs\ttl@part@ii{#1}{#3}}
  411. \def\ttl@part@ii#1#2#3#4#5#6#7{%
  412. \ttl@assign\@tempskipa#3\relax\beforetitleunit
  413. \vspace*{\@tempskipa}%
  414. \@ifundefined{ttl@ps@#6}{}%
  415. {\PackageWarning{titlesec}{Page style in part class ignored}}%
  416. \global\@afterindenttrue
  417. \ifcase#5 \global\@afterindentfalse \fi
  418. \ttl@assign\@tempskipb#4\relax\aftertitleunit
  419. \ttl@select{#6}{#1}{#2}{#7}%
  420. \ttl@finmarks
  421. \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
  422. \par\nobreak
  423. \vspace{\@tempskipb}%
  424. \@afterheading}
  425. % Page class
  426. % ~~~~~~~~~~
  427. \def\ttl@page@i#1[#2]#3{%
  428. \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
  429. \def\ttl@savewrite{\ttl@write{#1}{#3}}% A default value. Not #2!
  430. \def\ttl@savetitle{#3}%
  431. \ttl@labelling{#1}{#2}%
  432. \ttl@startargs\ttl@page@ii{#1}{#3}}
  433. \def\ttl@page@ii#1#2#3#4#5#6#7{%
  434. \ttl@assign\@tempskipa#3\relax\beforetitleunit
  435. \if@openright
  436. \cleardoublepage
  437. \else
  438. \clearpage
  439. \fi
  440. \@ifundefined{ttl@ps@#6}%
  441. {\thispagestyle{plain}}%
  442. {\thispagestyle{\@nameuse{ttl@ps@#6}}}%
  443. \if@twocolumn
  444. \onecolumn
  445. \@tempswatrue
  446. \else
  447. \@tempswafalse
  448. \fi
  449. \vspace*{\@tempskipa}%
  450. \@afterindenttrue
  451. \ifcase#5 \@afterindentfalse\fi
  452. \ttl@assign\@tempskipb#4\relax\aftertitleunit
  453. \ttl@select{#6}{#1}{#2}{#7}%
  454. \ttl@finmarks
  455. \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
  456. \vspace{\@tempskipb}%
  457. \newpage
  458. \if@twoside
  459. \if@openright
  460. \null
  461. \@ifundefined{ttl@ps@#6}%
  462. {\thispagestyle{empty}}%
  463. {\thispagestyle{\@nameuse{ttl@ps@#6}}}%
  464. \newpage
  465. \fi
  466. \fi
  467. \if@tempswa
  468. \twocolumn
  469. \fi
  470. \ignorespaces}
  471. % Top class and some makechapterhead stuff
  472. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473. %
  474. % \ttl@mkchap is the new make(s)chapterhead.
  475. \def\ttl@mkchap#1#2#3#4#5#6#7{%
  476. \gdef\ttl@savemark{\csname#6mark\endcsname{#7}}%
  477. \let\ttl@savewrite\@empty
  478. \let\ttl@Hy@saveanchor\@empty
  479. \@ifundefined{ttl@ps@#6}{}%
  480. {\thispagestyle{\@nameuse{ttl@ps@#6}}}%
  481. \let\ifttl@toclabel\ifttl@label
  482. \ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}
  483. % But \ttl@mkchap@i is used by both makechapterhead and
  484. % the top class.
  485. \def\ttl@mkchap@i#1#2#3#4#5#6#7{%
  486. \ttl@assign\@tempskipa#3\relax\beforetitleunit
  487. \vspace*{\@tempskipa}%
  488. \global\@afterindenttrue
  489. \ifcase#5 \global\@afterindentfalse\fi
  490. \ttl@assign\@tempskipb#4\relax\aftertitleunit
  491. \ttl@topmode{\@tempskipb}{%
  492. \ttl@select{#6}{#1}{#2}{#7}}%
  493. \ttl@finmarks % Outside the box!
  494. \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
  495. \def\ttl@top@i#1[#2]#3{%
  496. \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
  497. \let\ttl@savewrite\@empty
  498. \def\ttl@savetitle{#3}%
  499. \ttl@labelling{#1}{#2}%
  500. \ttl@startargs\ttl@top@ii{#1}{#3}}
  501. \def\ttl@top@ii#1#2#3#4#5#6#7{%
  502. \@ifundefined{#6break}%
  503. {\if@openright
  504. \cleardoublepage
  505. \else
  506. \clearpage
  507. \fi}%
  508. {\csname#6break\endcsname}%
  509. \@ifundefined{ttl@ps@#6}%
  510. {\thispagestyle{plain}}%
  511. {\thispagestyle{\@nameuse{ttl@ps@#6}}}%
  512. \global\@topnum\z@
  513. \@ifundefined{#6tolists}%
  514. {\addtocontents{lof}{\protect\ttl@tocsep}%
  515. \addtocontents{lot}{\protect\ttl@tocsep}}
  516. {\@nameuse{#6tolists}}%
  517. \if@twocolumn
  518. \@topnewpage[\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}]%
  519. \else
  520. \ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
  521. \@afterheading
  522. \fi
  523. \ignorespaces}
  524. % \def\ttl@noskipsectrue{%
  525. % \if@noskipsec
  526. % \PackageError{titlesec}{Invalid shape for top class}%
  527. % {The selected shape only makes sense when merged into\MessageBreak
  528. % a paragraph. That is impossible in the top class}%
  529. % \else
  530. \newcommand\chaptertitlename{\@chapapp}
  531. \def\ttl@tocsep{\addvspace{10\p@}}
  532. % +-----------------+
  533. % | S H A P E S |
  534. % +-----------------+
  535. %
  536. % % Reformatting Titles: Interface
  537. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  538. % The surrounding space is stored in a macro
  539. % named \ttls@<section> whose content is
  540. % {left}{right}{before}{after}{afterindent}.
  541. % But if there is the page key, the name is
  542. % \ttls@<section>/<page>
  543. \newcommand\titlespacing{%
  544. \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\@ne}}}
  545. \def\ttl@spacing@i#1#2#3#4#5{%
  546. \ttl@getkeys{#2}{titlesec}%
  547. \@ifnextchar[{%
  548. \ttl@spacing@ii{#1}{#3}{#4}{#5}%
  549. }{%
  550. \ttl@spacing@ii{#1}{#3}{#4}{#5}[\z@]}}
  551. \def\ttl@spacing@ii#1#2#3#4[#5]{%
  552. \expandafter\def\csname ttls@\ttl@a\endcsname
  553. {{#2}{#5}{#3}{#4}{#1}}}
  554. % The section name is built in \ttl@a.
  555. % The format is stored in a macro named \ttlf@<section>,
  556. % or \ttlf@<section>/<page> if there is the page spec,
  557. % or \ttlf@.../* if numberless is true
  558. % whose content is
  559. % \ttl@<shape>{format}{label}{sep}{before}{after}
  560. \newtoks\ttl@toksa
  561. \newcommand\titleformat{%
  562. \@ifstar{\ttl@format@s}%
  563. {\ttl@format@i}}
  564. \def\ttl@format@s#1#2{%
  565. \edef\ttl@a{\expandafter\@gobble\string#1}%
  566. \@ifundefined{ttlf@\ttl@a}%
  567. {\PackageError{titlesec}{Not allowed in `easy' settings}
  568. {The sectiong command you are trying to redefine\MessageBreak
  569. is not handled by the starred variant (eg, \string\part)}}{}
  570. \expandafter\expandafter\expandafter
  571. \ttl@format@si\csname ttlf@\ttl@a \endcsname
  572. {#2}}
  573. \def\ttl@format@si#1#2#3#4#5#6#7{%
  574. \@namedef{ttlf@\ttl@a}{#1{#7}{#3}{#4}{#5}{#6}}}
  575. \def\ttl@format@i#1{%
  576. \@ifnextchar[{\ttl@format@ii{#1}}{\ttl@format@ii{#1}[hang]}}
  577. \def\ttl@format@ii#1[#2]#3#4#5#6{%
  578. \ttl@getkeys{#1}{titlesec}%
  579. \ttl@toksa{{#3}{#4}{#5}{#6}}% Save arguments
  580. \@ifnextchar[{%
  581. \ttl@format@iii{#2}%
  582. }{%
  583. \ttl@format@iii{#2}[]}}
  584. % First, we get the shape -- if not defined it loads
  585. % the corresponding file.
  586. \def\ttl@format@iii#1[#2]{%
  587. \@ifundefined{ttlh@#1}{%
  588. \begingroup
  589. \makeatletter
  590. \InputIfFileExists{#1.tss}{}{%
  591. \PackageError{titlesec}{Unknown shape}%
  592. {Shapes are defined in files with extension tss\MessageBreak
  593. Either you have misspelled the shape\MessageBreak
  594. or there is no a #1.tss file}}%
  595. \endgroup}{}%
  596. \@temptokena{#2}%
  597. \ifttl@explicit
  598. \edef\ttl@b{%
  599. \def\expandafter\noexpand\csname ttlf@\ttl@a\endcsname####1%
  600. {\expandafter\noexpand\csname ttlh@#1\endcsname
  601. \the\ttl@toksa{\the\@temptokena}}}%
  602. \else
  603. \edef\ttl@b{%
  604. \def\expandafter\noexpand\csname ttlf@\ttl@a\endcsname
  605. {\expandafter\noexpand\csname ttlh@#1\endcsname
  606. \the\ttl@toksa{\the\@temptokena}}}%
  607. \fi
  608. \ttl@b
  609. \csname ttl@compat\ttl@a\endcsname}
  610. % Styles
  611. % ~~~~~~
  612. % 1:global 2:label 3:sep 4:style 5:after 6:left 7:right 8:title
  613. % \ttl@<shape> and \ttlh@<shape> take the following eight
  614. % arguments:
  615. % {format}{label}{sep}{before}{after}{left}{right}{title}
  616. % where before and after refer to the format.
  617. % With the option explicit, #4 contains the title and #8 is
  618. % empty.
  619. \def\ttlh@display#1#2#3#4#5#6#7#8{%
  620. \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
  621. \setlength\leftskip{#6}%
  622. \setlength\rightskip{#7}%
  623. \interlinepenalty\@M
  624. \ttl@changecentercr
  625. \ttl@beginlongest
  626. #1\ifhmode\ttl@hmode@error\fi
  627. \ttl@glcmds
  628. \parindent\z@
  629. \ifttl@label
  630. {#2\strut\@@par}\nobreak\ttl@calc\vspace{#3}%
  631. \fi
  632. #4{#8}%
  633. \kern\z@\strut\@@par
  634. \nobreak\ttl@midlongest#5\@@par
  635. \ttl@endlongest}
  636. \def\ttlh@hang#1#2#3#4#5#6#7#8{%
  637. \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
  638. \setlength\leftskip{#6}%
  639. \setlength\rightskip{#7}%
  640. \interlinepenalty\@M
  641. \ttl@changecentercr
  642. \ttl@beginlongest
  643. #1{\ifhmode\ttl@hmode@error\fi
  644. \ttl@glcmds
  645. \parindent\z@
  646. \leavevmode
  647. \begingroup
  648. \ifttl@label
  649. \sbox\z@{#2\strut\ttl@calc\hspace{#3}}%
  650. \advance\leftskip\wd\z@
  651. \llap{\box\z@}%
  652. \fi
  653. #4{#8}%
  654. \kern\z@\strut\@@par
  655. \endgroup
  656. \nobreak\ttl@midlongest#5\@@par}%
  657. \ttl@endlongest}
  658. \def\ttlh@runin#1#2#3#4#5#6#7#8{%
  659. \global\@noskipsectrue
  660. \gdef\ttl@makeline##1{##1}%
  661. \ttl@changecentercr
  662. #1{\ifhmode\ttl@hmode@error\fi
  663. \global\sbox\ttl@box{%
  664. \ttl@calc\hspace{#6}%
  665. \ifttl@label{\strut#2}\ttl@calc\hspace{#3}\fi
  666. #4{#8}#5\unskip}}%
  667. \gdef\@svsechd{\unhbox\ttl@box}}
  668. % +-----------------+
  669. % | T O O L S |
  670. % +-----------------+
  671. %
  672. % calcwidth
  673. % ~~~~~~~~~
  674. % Implemented after code from soul (but much modified...)
  675. \newdimen\titlewidth
  676. \newdimen\titlewidthlast
  677. \newdimen\titlewidthfirst
  678. \let\ttl@glcmds\relax
  679. \let\ttl@beginlongest\@empty
  680. \let\ttl@midlongest\@empty
  681. \let\ttl@endlongest\@empty
  682. \let\iftitlemeasuring\@secondoftwo
  683. \def\ttl@xbeginlongest#1\ttl@endlongest{%
  684. \titlewidth\z@
  685. \titlewidthlast\z@
  686. \let\iftitlemeasuring\@firstoftwo
  687. \setbox\ttl@box\vbox{%
  688. \def\ttl@glcmds{%
  689. \def\\{\@ifstar{\@ifnextchar[{\ttl@bs}{\newline}}%
  690. {\@ifnextchar[{\ttl@bs}{\newline}}}%
  691. \def\ttl@bs[####1]{\newline}%
  692. \let\@centercr\\%
  693. \def\ttl@midlongest####1\@@par{}% Very dirty...
  694. \advance\rightskip 1\leftskip plus 1fil
  695. \leftskip=\z@}%
  696. #1}%
  697. \let\iftitlemeasuring\@secondoftwo
  698. \ttl@boxprocess
  699. #1}
  700. \def\ttl@boxprocess{%
  701. \setbox\ttl@box=\vbox{%
  702. \unvcopy\ttl@box
  703. \unskip\unpenalty
  704. \global\setbox\@ne=\lastbox}%
  705. \ifvoid\@ne
  706. \else
  707. \setbox\tw@=\hbox{\hskip-\leftskip\unhbox\@ne\hskip-\rightskip}%
  708. \titlewidthfirst\wd\tw@
  709. \ifdim\titlewidth<\titlewidthfirst
  710. \titlewidth\titlewidthfirst
  711. \fi
  712. \ifdim\titlewidthlast=\z@
  713. \titlewidthlast\titlewidthfirst
  714. \fi
  715. \expandafter\ttl@boxprocess
  716. \fi}
  717. % Rules
  718. % ~~~~~
  719. \providecommand\titleline{%
  720. \@ifstar{\ttl@line@i{\hb@xt@\titlewidth}}%
  721. {\ttl@line@i{}}}
  722. \def\ttl@line@i#1{%
  723. \@ifnextchar[{\ttl@line{#1}}{\ttl@line{#1}[s]}}
  724. \def\ttl@line#1[#2]#3{%
  725. \vskip\topskip
  726. \hrule \@height \z@
  727. \nobreak
  728. \vskip-\topskip
  729. \begingroup
  730. \parindent\z@
  731. \everypar{}%
  732. \leftskip\z@
  733. \rightskip\z@ % #1 is either \hb@xt@\titlewidth or empty:
  734. \@makebox[\hsize][#2]{\ttl@makeline{#1{#3}}}%
  735. \par
  736. \endgroup
  737. \hrule height \z@
  738. \nobreak}
  739. \providecommand\titlerule{\@ifstar{\ttl@row}{\ttl@rule}}
  740. \let\ttl@leaders\xleaders % For titletoc compatibility
  741. \def\ttl@row{\@ifnextchar[{\ttl@row@i}{\ttl@row@i[\wd\z@]}}
  742. \def\ttl@row@i[#1]#2{%
  743. \ifvmode\expandafter\titleline\fi
  744. {\sbox\z@{#2}%
  745. \ttl@calcneg\hspace{#1}%
  746. \hskip\wd\z@
  747. \ttl@leaders\hb@xt@#1{\hss\box\z@}%
  748. \hfill\kern\z@}}
  749. \def\ttl@rule{\@ifnextchar[{\ttl@rule@i}{\ttl@rule@i[.4\p@]}}
  750. \def\ttl@rule@i[#1]{%
  751. \ifvmode\expandafter\titleline\fi
  752. {\leaders\hrule height #1\hfill\kern\z@}}
  753. % Par shapes and space
  754. % ~~~~~~~~~~~~~~~~~~~~
  755. \providecommand\filright{%
  756. \gdef\ttl@filleft##1{\hskip##1}%
  757. \gdef\ttl@filright##1{\hfill}%
  758. \let\\\@centercr
  759. \advance\rightskip\z@ \@plus 1fil\relax}
  760. \providecommand\filleft{%
  761. \gdef\ttl@filleft##1{\hfill}%
  762. \gdef\ttl@filright##1{\hskip##1}%
  763. \let\\\@centercr
  764. \advance\leftskip\z@ \@plus 1fil
  765. \parfillskip\z@}
  766. \providecommand\filcenter{\filleft\filright
  767. \gdef\ttl@filleft##1{\hfill}}
  768. \providecommand\fillast{%
  769. \gdef\ttl@filleft##1{\hfill}%
  770. \gdef\ttl@filright##1{\hfill}%
  771. \let\\\@centercr
  772. \filleft\advance\rightskip\z@ \@plus -1fil
  773. \parfillskip\z@ \@plus 2fil\relax}
  774. \newcommand\filinner{%
  775. \if@twoside
  776. \ifodd\count\z@\filleft\else\filright\fi
  777. \else
  778. \filleft
  779. \fi}
  780. \newcommand\filouter{%
  781. \if@twoside
  782. \ifodd\count\z@\filright\else\filleft\fi
  783. \else
  784. \filright
  785. \fi}
  786. \newcommand\wordsep{\fontdimen\tw@\font \@plus
  787. \fontdimen\thr@@\font \@minus \fontdimen4\font}
  788. % +-----------------+
  789. % | O P T I O N S |
  790. % +-----------------+
  791. \DeclareOption{pagestyles}{\let\sectiontitle\@empty}
  792. \DeclareOption{extramarks}{\let\ttl@fetchmark\@empty}
  793. \DeclareOption{floatps}{%
  794. \ifx\sectiontitle\@empty
  795. \let\ttl@replace\space
  796. \else
  797. \PackageWarning{titlesec}{Ignoring `floatps' without
  798. `pagestyles'. This option is now deprecated.}%
  799. \fi}
  800. \DeclareOption{psfloats}{%
  801. \ifx\sectiontitle\@empty
  802. \let\ttl@replace\@empty
  803. \else
  804. \PackageWarning{titlesec}{Ignoring `psfloats' without
  805. `pagestyles'}%
  806. \fi}
  807. \DeclareOption{loadonly}{\let\ttl@extract\@empty}
  808. \DeclareOption{outermarks}{%
  809. \def\ttl@titlemarks{\outertitlemarks}}
  810. \DeclareOption{topmarks}{
  811. \def\ttl@titlemarks{\toptitlemarks}}
  812. \DeclareOption{botmarks}{%
  813. \def\ttl@titlemarks{\bottitlemarks}}
  814. \DeclareOption{innermarks}{%
  815. \def\ttl@titlemarks{\innertitlemarks}}
  816. \DeclareOption{footmarks}{} % Backward compat
  817. \DeclareOption{explicit}{\ttl@explicittrue}
  818. \DeclareOption{clearempty}{%
  819. \def\cleardoublepage{%
  820. \clearpage{\ps@empty\if@twoside\ifodd\c@page\else
  821. \hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}}}
  822. \DeclareOption{rigidchapters}{%
  823. \def\ttl@topmode#1#2{\vbox to #1{#2\vfil}}%
  824. \def\ttl@chapafter{.26\textheight}}
  825. \DeclareOption{rubberchapters}{%
  826. \def\ttl@topmode#1#2{{#2}\ttl@calc\vspace{#1}}%
  827. \def\ttl@chapafter{40\p@}}
  828. \DeclareOption{bottomtitles}{%
  829. \def\bottomtitlespace{-1\p@}}
  830. \DeclareOption{nobottomtitles}{%
  831. \def\bottomtitlespace{.2\textheight}}
  832. \DeclareOption{nobottomtitles*}{%
  833. \let\ttl@addstretch\relax
  834. \def\bottomtitlespace{.2\textheight}}
  835. \DeclareOption{calcwidth}{%
  836. \let\ttl@beginlongest\ttl@xbeginlongest}
  837. \DeclareOption{aftersep}{%
  838. \let\ttl@titlespace\@gobble}
  839. \DeclareOption{largestsep}{%
  840. \let\ttl@titlespace\addvspace}
  841. \DeclareOption{oldparttoc}{%
  842. \def\ttl@tocpart{\def\ttl@a{\thepart\hspace{1em}}}}
  843. \DeclareOption{newparttoc}{%
  844. \let\ttl@tocpart\relax}
  845. \DeclareOption{rm}{%
  846. \protected@xdef\ttl@fonts{\ttl@fonts\protect\rmfamily}}
  847. \DeclareOption{sf}{%
  848. \protected@xdef\ttl@fonts{\ttl@fonts\protect\sffamily}}
  849. \DeclareOption{tt}{%
  850. \protected@xdef\ttl@fonts{\ttl@fonts\protect\ttfamily}}
  851. \DeclareOption{md}{%
  852. \protected@xdef\ttl@fonts{\ttl@fonts\protect\mdseries}}
  853. \DeclareOption{bf}{%
  854. \protected@xdef\ttl@fonts{\ttl@fonts\protect\bfseries}}
  855. \DeclareOption{up}{%
  856. \protected@xdef\ttl@fonts{\ttl@fonts\protect\upshape}}
  857. \DeclareOption{it}{%
  858. \protected@xdef\ttl@fonts{\ttl@fonts\protect\itshape}}
  859. \DeclareOption{sl}{%
  860. \protected@xdef\ttl@fonts{\ttl@fonts\protect\slshape}}
  861. \DeclareOption{sc}{%
  862. \protected@xdef\ttl@fonts{\ttl@fonts\protect\scshape}}
  863. \DeclareOption{big}{%
  864. \gdef\ttl@sizes#1{\ifcase#1\relax\Huge\or\Large\or\large
  865. \or\normalsize\or\or\or\huge\fi}}
  866. \DeclareOption{medium}{%
  867. \gdef\ttl@sizes#1{\ifcase#1\relax\huge\or\Large\or\large
  868. \or\normalsize\or\or\or\LARGE\fi}}
  869. \DeclareOption{small}{%
  870. \gdef\ttl@sizes#1{\ifcase#1\relax\LARGE\or\large
  871. \or\normalsize\or\normalsize\or\or\or\Large\fi}}
  872. \DeclareOption{tiny}{%
  873. \gdef\ttl@sizes#1{\ifcase#1\relax\large\or\normalsize\or
  874. \normalsize\or\normalsize\or\or\or\normalsize\fi}}
  875. \DeclareOption{raggedleft}{%
  876. \gdef\ttl@fil{\filleft}}
  877. \DeclareOption{center}{%
  878. \gdef\ttl@fil{\filcenter}}
  879. \DeclareOption{raggedright}{%
  880. \gdef\ttl@fil{\filright}}
  881. \DeclareOption{uppercase}{%
  882. \gdef\ttl@case{\MakeUppercase}}
  883. \DeclareOption{compact}{%
  884. \gdef\ttl@space{1}%
  885. \gdef\ttl@chapafter{30\p@}}
  886. % Deprecated. To be remmoved in a major upgrade (3.0)
  887. \DeclareOption{indentfirst}{%
  888. \gdef\@afterindentfalse{\let\if@afterindent\iftrue}%
  889. \@afterindenttrue
  890. \def\titlespacing{%
  891. \@ifstar{\ttl@spacing@i{\@ne}}{\ttl@spacing@i{\@ne}}}}
  892. \DeclareOption{nonindentfirst}{%
  893. \def\titlespacing{%
  894. \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\z@}}}}
  895. % New names
  896. \DeclareOption{indentafter}{%
  897. \gdef\@afterindentfalse{\let\if@afterindent\iftrue}%
  898. \@afterindenttrue
  899. \def\titlespacing{%
  900. \@ifstar{\ttl@spacing@i{\@ne}}{\ttl@spacing@i{\@ne}}}}
  901. \DeclareOption{noindentafter}{%
  902. \def\titlespacing{%
  903. \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\z@}}}}
  904. % newlinetospace
  905. \let\ttl@blinemarks\relax
  906. \let\ttl@elinemarks\relax
  907. \DeclareRobustCommand\ttl@linetosp{%
  908. \@ifstar{\ttl@linetosp@i}{\ttl@linetosp@i}}%
  909. \def\ttl@linetosp@i{%
  910. \ifdim\lastskip>\z@\else\space\fi
  911. \ignorespaces}
  912. \DeclareOption{newlinetospace}{%
  913. \def\ttl@blinemarks{%
  914. \let\ttl@e\\%
  915. \def\\{\ttl@linetosp}}%
  916. \def\ttl@elinemarks{\let\\\ttl@e}}%
  917. % toctitles
  918. \def\ttl@addcontentsline#1#2{%
  919. \addcontentsline{toc}{#1}{\ifttl@toclabel\ttl@a\fi#2}%
  920. \nobreak}
  921. \DeclareOption{toctitles}{%
  922. \def\ttl@addcontentsline#1#2{%
  923. \addcontentsline{toc}{#1}{\ifttl@toclabel\ttl@a\fi\ttl@savetitle}%
  924. \nobreak}}
  925. % pageatnewline
  926. \def\ttl@changecentercr{%
  927. \let\ttl@centercr\@centercr
  928. \def\@centercr{\@ifstar{\ttl@centercr*}{\ttl@centercr*}}}
  929. \DeclareOption{pageatnewline}{\let\ttl@changecentercr\relax}
  930. \def\ttl@fonts{}
  931. \ExecuteOptions{rubberchapters,bottomtitles,aftersep,oldparttoc,%
  932. innermarks}
  933. \ProcessOptions
  934. % +-----------------+
  935. % | H Y P E R R E F |
  936. % +-----------------+
  937. %
  938. % These two commands are provided by hyperref. But if they
  939. % are not defined at \begin{document} hyperref has not been
  940. % loaded or it is an old version.
  941. \AtBeginDocument{%
  942. \ifx\ttl@Hy@steplink\@undefined
  943. \let\ttl@Hy@steplink\@gobble
  944. \let\ttl@Hy@refstepcounter\refstepcounter
  945. \fi}
  946. % +-----------------+
  947. % | PAGE STYLES |
  948. % +-----------------+
  949. %
  950. % This is generic:
  951. \newcommand\assignpagestyle[2]{%
  952. \@namedef{ttl@ps@\expandafter\@gobble\string#1}{#2}}
  953. % Old pagestyles
  954. % ~~~~~~~~~~~~~~
  955. \providecommand\newpagestyle{%
  956. \let\ttl@compatps\@empty % marks the ``old interface''
  957. \makeatletter
  958. \edef\ttl@d{%
  959. \noexpand\input{ttlps.def}%
  960. \catcode`\noexpand\@=\the\catcode`\@}%
  961. \ttl@d
  962. \newpagestyle}
  963. \providecommand\renewpagestyle{%
  964. \let\ttl@compatps\@empty % marks the ``old interface''
  965. \makeatletter
  966. \edef\ttl@d{%
  967. \noexpand\input{ttlps.def}%
  968. \catcode`\noexpand\@=\the\catcode`\@}%
  969. \ttl@d
  970. \renewpagestyle}
  971. \providecommand\widenhead{%
  972. \let\ttl@compatps\@empty % marks the ``old interface''
  973. \makeatletter
  974. \edef\ttl@d{%
  975. \noexpand\input{ttlps.def}%
  976. \catcode`\noexpand\@=\the\catcode`\@}%
  977. \ttl@d
  978. \widenhead}
  979. % New pagestyles
  980. % ~~~~~~~~~~~~~~
  981. \@ifundefined{sectiontitle}{}{\input{ttlps.def}}
  982. % +-----------------+
  983. % | C O M P A T |
  984. % +-----------------+
  985. % Easy setup, i.e., that of package options, is
  986. % taken care of, if necessary.
  987. \renewcommand\secdef[2]{%
  988. \@ifstar
  989. {\ttl@labelfalse
  990. #2}
  991. {\ttl@labeltrue
  992. \ifx#1\@chapter
  993. \if@mainmatter\else\ttl@labelfalse\fi
  994. \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi
  995. \else\ifx#1\@part
  996. \ifnum\ttll@part>\c@secnumdepth\ttl@labelfalse\fi
  997. \fi\fi
  998. \let\ifttl@toclabel\ifttl@label
  999. \@dblarg{#1}}}
  1000. \@ifundefined{ttl@extract}{}{\endinput}
  1001. \newcommand\titlelabel[1]{%
  1002. \def\@seccntformat##1{#1}}
  1003. \expandafter\ifx\csname chapter\endcsname\relax
  1004. \def\ttl@compatpart{\titleclass{\part}{part}\relax}
  1005. \else
  1006. \def\ttl@compatchapter{%
  1007. \def\@makechapterhead{%
  1008. \ttl@labeltrue
  1009. \if@mainmatter\else\ttl@labelfalse\fi
  1010. \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi
  1011. \ttl@startargs\ttl@mkchap{chapter}}%
  1012. \def\@makeschapterhead{%
  1013. \ttl@labelfalse
  1014. \if@mainmatter\else\ttl@labelfalse\fi
  1015. \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi
  1016. \ttl@startargs\ttl@mkchap{chapter}}}
  1017. \def\ttl@compatpart{\titleclass{\part}{page}\relax}
  1018. \fi
  1019. \def\ttl@@extract#1\@startsection#2#3#4#5#6#7#8{%
  1020. \@tempskipa=#5
  1021. \@tempskipb=#6
  1022. \ifdim\@tempskipa<\z@
  1023. \toks@{\titlespacing*#8{#4}}%
  1024. \@tempskipa-\@tempskipa
  1025. \else
  1026. \toks@{\titlespacing#8{#4}}%
  1027. \fi
  1028. \@ifundefined{ttl@space}{}{%
  1029. \ttl@assign\@tempskipa*\ttl@space\relax\beforetitleunit}%
  1030. \ifdim\@tempskipb<\z@
  1031. \if@tempswa
  1032. \titleformat#8[runin]%
  1033. {\ttl@fonts\ttl@sizes{#3}}{\@seccntformat{#2}}%
  1034. {\z@}\ttl@passexplicit
  1035. \else
  1036. \titleformat#8[runin]%
  1037. {#7}{\@seccntformat{#2}}%
  1038. {\z@}\ttl@passexplicit
  1039. \fi
  1040. \@tempskipb-\@tempskipb
  1041. \else
  1042. \if@tempswa
  1043. \titleformat#8%
  1044. {\ttl@fil\ttl@fonts\ttl@sizes{#3}}{\@seccntformat{#2}}%
  1045. {\z@}\ttl@passexplicit
  1046. \else
  1047. \titleformat#8%
  1048. {#7}{\@seccntformat{#2}}%
  1049. {\z@}\ttl@passexplicit
  1050. \fi
  1051. \@ifundefined{ttl@space}{}{%
  1052. \ttl@assign\@tempskipb*\ttl@space\relax\aftertitleunit}%
  1053. \fi
  1054. \edef\ttl@a{\the\toks@{\the\@tempskipa}{\the\@tempskipb}}
  1055. \ttl@a}
  1056. \def\ttl@extract#1{%
  1057. \expandafter\in@\expandafter\@startsection\expandafter{#1}%
  1058. \ifin@
  1059. \expandafter\ttl@@extract#1#1%
  1060. \else
  1061. \PackageWarningNoLine{titlesec}%
  1062. {Non standard sectioning command detected\MessageBreak
  1063. Using default spacing and no format}
  1064. \titlespacing*#1{\z@}{*3}{*2}%
  1065. \fi}
  1066. \@tempswafalse
  1067. \ifx\ttl@fonts\@empty
  1068. \def\ttl@fonts{\bfseries}
  1069. \else
  1070. \@tempswatrue
  1071. \fi
  1072. \expandafter\ifx\csname ttl@sizes\endcsname\relax
  1073. \gdef\ttl@sizes#1{\ifcase#1\relax\Huge\or\Large\or\large
  1074. \or\normalsize\or\or\or\huge\fi}
  1075. \else
  1076. \@tempswatrue
  1077. \fi
  1078. \expandafter\ifx\csname ttl@fil\endcsname\relax
  1079. \let\ttl@fil\@empty
  1080. \else
  1081. \@tempswatrue
  1082. \fi
  1083. \expandafter\ifx\csname ttl@case\endcsname\relax
  1084. \let\ttl@case\@firstofone
  1085. \else
  1086. \@tempswatrue
  1087. \fi
  1088. \if@tempswa
  1089. \expandafter\ifx\csname chapter\endcsname\relax\else
  1090. \titleformat\chapter[display]%
  1091. {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6}
  1092. {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit}
  1093. \fi
  1094. \fi
  1095. \ttl@extract\section
  1096. \ttl@extract\subsection
  1097. \ttl@extract\subsubsection
  1098. \ttl@extract\paragraph
  1099. \ttl@extract\subparagraph
  1100. \let\ttl@extract\@undefined
  1101. \let\ttl@@extract\@undefined
  1102. \def\ttl@toplevel{part}
  1103. \expandafter\ifx\csname chapter\endcsname\relax
  1104. \@namedef{ttll@part}{0}
  1105. \titleclass{\section}{straight}[\part]
  1106. \titlespacing*{\part}
  1107. {\z@}
  1108. {4ex}
  1109. {3ex}
  1110. \else
  1111. \let\ttl@save@mkchap\@makechapterhead
  1112. \let\ttl@save@mkschap\@makeschapterhead
  1113. \def\@makechapterhead#1{%
  1114. \gdef\ttl@savemark{\chaptermark{#1}}%
  1115. \ttl@save@mkchap{#1}%
  1116. \@ifundefined{ttl@ps@chapter}{}%
  1117. {\thispagestyle{\@nameuse{ttl@ps@chapter}}}}
  1118. \def\@makeschapterhead#1{%
  1119. \gdef\ttl@savemark{\chaptermark{#1}}%
  1120. \ttl@save@mkschap{#1}%
  1121. \@ifundefined{ttl@ps@chapter}{}%
  1122. {\thispagestyle{\@nameuse{ttl@ps@chapter}}}}
  1123. \@namedef{ttll@part}{-1}
  1124. \@namedef{ttlss@part}{chapter}
  1125. \@namedef{ttll@chapter}{0}
  1126. \titleclass{\section}{straight}[\chapter]
  1127. % The following is unoperant, unless when \chapter / \part
  1128. % format is redefined
  1129. \titlespacing*{\part}
  1130. {\z@}
  1131. {\z@\@plus1fil}
  1132. {\z@\@plus1fil}
  1133. \titlespacing*\chapter
  1134. {\z@}%
  1135. {50\p@}%
  1136. {\ttl@chapafter}%
  1137. \fi
  1138. \titleclass{\subsection} {straight}[\section]
  1139. \titleclass{\subsubsection}{straight}[\subsection]
  1140. \titleclass{\paragraph} {straight}[\subsubsection]
  1141. \titleclass{\subparagraph} {straight}[\paragraph]
  1142. \endinput