diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/titlesec |
Initial commit
Diffstat (limited to 'macros/latex/contrib/titlesec')
-rw-r--r-- | macros/latex/contrib/titlesec/CHANGES.old | 341 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/README.md | 62 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/titleps.pdf | bin | 0 -> 134004 bytes | |||
-rw-r--r-- | macros/latex/contrib/titlesec/titleps.sty | 837 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/titleps.tex | 835 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/titlesec.pdf | bin | 0 -> 183112 bytes | |||
-rw-r--r-- | macros/latex/contrib/titlesec/titlesec.sty | 1708 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/titlesec.tex | 2106 | ||||
-rw-r--r-- | macros/latex/contrib/titlesec/titletoc.sty | 600 |
9 files changed, 6489 insertions, 0 deletions
diff --git a/macros/latex/contrib/titlesec/CHANGES.old b/macros/latex/contrib/titlesec/CHANGES.old new file mode 100644 index 0000000000..fdbcb6b1db --- /dev/null +++ b/macros/latex/contrib/titlesec/CHANGES.old @@ -0,0 +1,341 @@ +## TITLESEC + +History of v1.0 +~~~~~~~~~~~~~~~ +1998/02/25 Added nops option +1998/02/28 Added \@mkboth stuff in \setmarks +1998/03/01 Changed test in \ttl@secnum +1998/03/03 Corrected some \fil... commands +1998/03/03 Replaced the faulty \@hangfrom by new commands +1998/03/03 Some \def replaced by \newcommand +1998/03/04 .dtx/.ins scheme finally rejected. Useless + for users, obtrusive for `readers' and proned + to errors +1998/03/04 Tidied up documentation +1998/03/06 \wordsep renamed and documented +1998/03/06 Added dummy asignation in \ttl@chap. +1998/03/06 Removed \ttl@xsect and merged into \tl@sect +1998/03/06 Added \ProvidesPackage + +History of v1.1 +~~~~~~~~~~~~~~~~ +1998/03/25 \chapter corrected, as well as the size options +1998/03/26 Added compact option +1998/03/26 Added flushleft, flushright and center options +1998/04/08 Changed all instances of \noindent by \parindent\z@ +1998/04/14 Added \filinner, \filouter +1998/04/14 Added drop shape +1998/05/01 Added rightmargin shape (and margin renamed to + leftmargin) +1998/05/03 Added \setheadindent + +History of v1.2 (unreleased) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +1998/06/01 Compatibility with AMS classes +1998/06/08 On-demand loading of shapes +1998/06/11 Frame shape. Some \fil... command + modified to work in the label of this + chapter shape. +1998/07/03 Bottomtitle option (at last...) +1998/07/14 ...margin styles bug fixed using a method + similar to bottomtitle. +1998/07/29 \titleline + +==================== + +History of v2.0 +~~~~~~~~~~~~~~~~ + +1998/08/05 to +1998/08/29 Fully reimplemented + +History of v2.1 +~~~~~~~~~~~~~~~~ +1999/01/05 We define in this file the three basic shapes. + Additional ones remain defined in external files. + Unified the shapes for sections and chapters. +1999/01/05 \ttl@shape merged into \ttl@format@iii. +1999/01/05 \titlerule +1999/01/07 \ttl@defkeys splitted from \ttl@keys +1999/01/10 Added the \part stuff, including a definition of \@openright +1999/01/11 Removed unnecessary \ttl@numsecfalse in \ttl@sect@i. +1999/01/14 Optimized \titlerule +1999/01/27 Changed \titleline to correct the spacing at the + top page and to fix a bug which changed the mode + to horizontal, thus introducing unwanted space + (\makebox -> \@makebox). +1999/02/02 \ttl@secnum renamed to \ttl@write and introduced the + \ttl@savewrite mechanism to sincronize the toc/marks + with the title in case there is a \newpage in <after>. +1999/02/03 wrap shape +1999/02/03 Added a \kern\z@ for not to avoid hyphenation + of the last word. Not strictly necessary, but + it is more LaTeX-like. +1999/02/05 \partmark defined (and in \setmarks, too). +1999/02/08 \ttl@row@i simplified. +1999/02/08 \ttl@savefn mechanism. +1999/02/10 Removed extra \leavevmode in display +1999/02/13 Now \titleline doesn't add the width. It's set. +1999/02/17 The part mark is catched, even if unused. +1999/02/17 old/newparttoc added. +1999/02/18 Changed many TeX assignments to the LaTeX + counterpart. +1999/02/19 Introduced \ttl@startargs. + +History of v2.1.1 +~~~~~~~~~~~~~~~~~ +1999/08/04 Moved misplaced lines in \ttl@makeboth + +History of v2.2 (unreleased) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +1999/11/03 We load titleps if pagestyles are required, but + some old definitions are restored. +1999/11/06 Improved outermarks test in \ttl@sect@i. Formerly + the section number could be printed if a page ended + with an unnumebered section followed by a numbered one. +1999/11/06 \ttl@startargs now adds (and passes) automatically the + section name. Involved macros modified accordingly. +1999/11/06 Replaced explicit part names by the parameter in + \ttl@part@i. The same for chapter. +1999/11/21 \ttl@try's are not given explicitly, but built by + \ttl@setkeys. Intruduced the \ttl@key@... and + \ttl@extra@... commands. +1999/11/23 Minor problems with keys fixed. +1999/12/10 Added the nobottomtitles* option and \ttl@addstretch. +2000/01/07 First steps towards the calcwidth feature (basic code). +2000/01/08 (Continued.) \titleline* for rules of width \titlewidth. + Option calcwidth implemented. +2000/01/12 Finished with changes in wrap.tss (no longer + "experimental" :-) ) + +History of v2.3 +~~~~~~~~~~~~~~~ +2000/01/19 All keys are grouped in a single file tttkeys. Removed + page.tsk and deleted the corresponding code in the sty. +2000/01/19 Classes begun. +2000/01/19 The level numbers are stored in \ttll@ macros, and not + passed as arguments. +2000/01/21 Introduced the new mark scheme. It's mostly compatible + with the old one, but a compatibility mode seems + imposible (it was introduced in a preliminary test + but eventually removed). +2000/01/23 loadonly package option. +2000/02/01 Classes finished. Many things had to be rewritten. +2000/02/02 Made partially compatible with hyperref (dvips). +2000/02/08 \ttl@savewrite moved from shapes to classes. But + explicit page breaks expand it, too, to avoid wrong + toc entries. +2000/02/18 A new box named \ttl@box stores the title in runin + leftmargin etc shapes, to increase reliability. + +(2.3.1 -- 2.3.3 No changes on this file) + +History of v2.3.4 +~~~~~~~~~~~~~~~~~ +2000/05/12 nonindentfirst redefine \titlespacing instead of + \@afterindent... so that they don't interfere with + the first entry in tocs. +2000/05/17 The marks in \ttl@select are protected to prevent + endless loop if the title is expanded, say, by + \MakeUppercase. + +History of v2.3.5 +~~~~~~~~~~~~~~~~~ +2000/05/21 Restores missing test for secnumdepth in \ttl@mkchap, + and instead of setting \ttl@toclevel in ttlps now is + done in \secdef. Except inside the macros, \ttl@toclevel + is false, so that an explicit \...mark works. +2000/06/04 \partmark defined with \providecommand +2000/06/14 A patch mechanism added, for small bug fixes. + +History of v2.4 +~~~~~~~~~~~~~~~~ +2001/01/18 Minor changes in code. Essentialy an incremental + update. +2001/01/22 \titleformat has a new "easy" starred variant. + +History of v2.5 +~~~~~~~~~~~~~~~ +2002/01/02 New macros for \ttl@assign. Now * length allow + non integer values. +2002/03/22 Added \ttl@calc and \ttl@calcneg to make titlesec + calc-savvy. + - Merged bug fixes of .new into this file. + - Bugs in frame fixed -- gap in lines, misplaced + label, wrong margins (sometimes), + - \leftskip, \rightskip and \linewidth (re)set in + margin shapes. + - Removed obsolete flush... options. + - indentafter and noindentafter, new names for + indentfirst and nonindentfirst. + - A new level (\titleclass) without its "location" + now raises a meaningful error. + - Bug in top-level \titleclass fixed. +2002/03/23 Tests for undefined and unformatted sectioning levels, + and horizontal material in <format>. + - Missing \if@openright inside \if@twoside in + page class added. + - Removed extra (but inoffensive) \expandafter + in \ttl@class@iii. +2002/03/27 Added \titlewidthfirst and ...last + - "Not definable" gives a more meaningful message in + the context of the package. + +History of v.2.6 +~~~~~~~~~~~~~~~~ +2004/08/30 Corrected typo in margin \hsiz -> \hsize. +2004/10/17 Added a couple of missing \noexpand's in drop. +2004/12/01 Removed the error about the mode in block because this + style is general purpose. +2005/01/16 Missing braces around #2 in the last else part of + \ttl@headinline added + - Replaced explicit \makeatother's by a saved value as + the macros can be used in a class/package file. +2005/01/18 newlinetospace mechanism + - // does not break pages; option pageatnewline to + restore the LaTeX behaviour. +2005/01/19 \...break in top shape. + - Renumbered several scratch registers to follow the + TeXbook (p. 346), with \ttl@box in a few cases. In + wrap \titlewidthfirst and \titlewidthlast made global. + - Float heads and foots have now a further argument for + additional stuff (eg, to remove rules). Option is now + psfloats while floatps enters in compatibility mode. + - \ttl@savetitle in all classes. Option toctitles. +2005/01/21 Changed pageatnewline to make it compatible with + titletoc, with \ttl@changecentercr. +2005/01/22 \...tolist in top class. + +History of v.2.7 +~~~~~~~~~~~~~~~~ +2007-03-27 Added the `explicit' option. + - Added \titlepagestyle. +2007-03-29 Fixed wrong number for chapter in log + - Patch file named .270 instead of .new +2007-05-09 Added <after> to leftmargin, so that you can add stuff + at the beginning of the paragraph, eg, the sec number. +2007-07-07 Removed the patch mechanism. +2007-08-07 `explicit' improved. + +History of v.2.8 +~~~~~~~~~~~~~~~~ +2007-08-12 \titlepagestyle already used by KOMA-Script. Renamed + to \assignpagestyle. + +History of v.2.9 +~~~~~~~~~~~~~~~~ +2010-05-04 Add \nobreak in \ttl@addcontentsline, to prevent the title + going to footnotes (!) in runin style in some (rare) cases. +2010-05-06 Option uppercase (and \ttl@case). +2011-02-25 \iftitlemeasuring test +2011-07-14 Fixed \assignpagestyle +2011-07-15 Introduced the \scantokens mechanism to make sure section + names are 'letters' and not 'others' +2011-07-18 Removed \if@nobreak test in wrap/drop, which added a line + to the title after another section (why?) + +History of v.2.9.1 +~~~~~~~~~~~~~~~~~~ +2011-08-28 Removed a spurious > in wrap.tss + +History of v.2.9.2 +~~~~~~~~~~~~~~~~~~ +2011-11-11 Fixed a typo in ttlps.def (\MessageBreag) + +History of v.2.10.0 +~~~~~~~~~~~~~~~~~~~~ + +2011-12-15 Split titlesp + +History of v.2.10.1 +~~~~~~~~~~~~~~~~~~~~ + +2015-02-27 Fix: An explict \newpage in 'after' wrote the toc entry twice +2015-03-09 Fix (partial): A list containing just a sectioning command + raised an error + +History of v.2.10.2 +~~~~~~~~~~~~~~~~~~~~ + +2015-03-21 Fix: With 2.10.1 labels vanished in hang shape (due to a + misplaced \noindent) + +## TITLEPS + +History of v.1.1.1 +~~~~~~~~~~~~~~~~~~ +2016-03-15 New macro \setmarkboth for compatibility + +## TITLETOC + +History of v1.1 +~~~~~~~~~~~~~~~ +99/04/22: A bug fix. Some missing global assignments in \ttl@tocentry + were missing, and page numbers messed up with + \titlecontents* + +History of v1.2 +~~~~~~~~~~~~~~~~ +1999/10/20: Added \contentsafter. \ttl@tocentry modified to accept + the new command for grouping in a paragraph entries of + different levels. +1999/10/27: Instead of defining the level numbers explicitly, that's + done with \ttl@setlevels and \ttl@levels. +1999/10/27: Added the basic code for multiple indexes. +1999/10/29: Added the toctop test to the \ttl@savel@... commands. +1999/12/28: Simplified \ttl@savel@... with \ttl@lselect. +2000/01/12: \contentsafter rejected. An aditional optional parameter + is used instead. (Too) many thing had to be rewritten. +2000/01/27: Removed \ttl@setlevels. Any change of levels are + best done with titlesec. +2000/02/14: Moved misplaced \vskip in ttl@tocentry. +2000/02/16: A few changes in the "block" separators. +2000/02/16: Fixed bug in \ttl@margin. For the right margin the + correction was used instead of the margin. + +History of v1.2.1 +~~~~~~~~~~~~~~~~~ +2000/04/25: Dirty trick to make sure that \ttl@finish is the very + last thing in lists of floats (lof, lot, etc.). +2000/05/14: Missing \global before \ttl@labelfalse added. + +History of 1.2.2 +~~~~~~~~~~~~~~~~ +2000/06/05: The optional argument no longer mandatory, but + still reporting an error if the length is missing. + Minor internal changes, and a patch mechanism added. + +History of 1.3 +~~~~~~~~~~~~~~ +2001/01/12: Minor changes and some missing \globals added for + partial tocs to work inside a group. +2001/01/21: Added \dottedcontents. + +History of 1.4 +~~~~~~~~~~~~~~ +2002/03/27: titletoc.new merged into this file +2002/03/27: \ttl@finish written by the last \newpage. +2002/03/27: \ttl@lsection broke paragraphs always. Now + only if the sublevel is typeset. +2002/03/27: \ttl@finish -> \contentsfinish + +History of 1.5 +~~~~~~~~~~~~~~ +2003/06/14: \contentspush didn't work because of the change of +(.new) \leftskip was done inside a group before the + corresponding \par +2003/06/14: Added an useful error if a partial TOC is not +(.new) defined. +2005/01/17: New options rubber/rigidseps, to remove if desired + the small vertical "plus" between entries. +2005/01/20: Begin work on partial lists. +2005/01/21: \ttl@outblock and \ttl@outnoblock just to avoid a + huge definition and to ease patching. +2005/01/22: Work on partial lists finished (but to be resumed). + +History of 1.6 +~~~~~~~~~~~~~~ +2007/05/04: Added the patch 2005/05/03 which fixed a wrong + result with \included (F. Mittelbach) +2007/07/14: Removed the patch mechanism. diff --git a/macros/latex/contrib/titlesec/README.md b/macros/latex/contrib/titlesec/README.md new file mode 100644 index 0000000000..1b9250a712 --- /dev/null +++ b/macros/latex/contrib/titlesec/README.md @@ -0,0 +1,62 @@ +## Titlesec, Titletoc, Titleps + +This directory holds 3 packages for sectioning titles -- when used as +such (titlesec), in headers and footers (titleps) and in tables of +contents (titletoc). They can be used separately, but you will get +most of them when used together. + +### Titlesec + +Sectioning titles, including margin and `wrap` titles, different +format in odd and even pages, rules above and below the title, +adding new sectioning levels, measuring the width of the title, etc. + +### Titletoc + +TOC entries, with the possibility of changing the format in the middle +of a document, grouping the entries in a single paragraph, pretty +free-forms entries, partial tocs, etc. It's described in +`titlesec.pdf`. + +### Titleps + +Page styles with working top marks, access to top, first and bot marks +in a single header/footer, rules, headers/footers for specific floats +(kinda `\thispagestyle`), multiple sets of marks, etc. An one-stage +mechanims is used, without intermediate `\leftmark`s or `\rightmark`s. + +### Latest changes + +``` +2.11 2019-07-16 + - New license: MIT. + - Option nostruts, to remove struts inserted by titlesec. + - Reorganized code: only sty files, removed def and tss ones + (although the mechanism for tss still works). + - Fix - Wrong hyperlinks in table of contents with the starred + versions, because of a change of behavior of hyperref (it + patches the behaviour of an internal macro in hyperref). + - Fix - Wrong spacing with titleps and displayed text after a + section. + - Fix - Newly defined floats raised an error with titletoc. +``` + +### Installation + +No .ins/.dtx preinstalation is required. Move the files to a place +where LaTeX can find them and typeset titlesec.tex. All of files in +this directory are necessary for titlesec.sty to work, except the +manual titlesec.tex (and this 'readme' file). The manual requires +titlesec.sty and titletoc.sty. + +Further details are available on + + http://www.texnia.com/titlesec.html + +### Contact + +Please, for suggestions, bug reports, etc., go to +More + http://www.texnia.com/contact.html + + diff --git a/macros/latex/contrib/titlesec/titleps.pdf b/macros/latex/contrib/titlesec/titleps.pdf Binary files differnew file mode 100644 index 0000000000..cef3495fdf --- /dev/null +++ b/macros/latex/contrib/titlesec/titleps.pdf diff --git a/macros/latex/contrib/titlesec/titleps.sty b/macros/latex/contrib/titlesec/titleps.sty new file mode 100644 index 0000000000..2d2a03cbea --- /dev/null +++ b/macros/latex/contrib/titlesec/titleps.sty @@ -0,0 +1,837 @@ +% +% Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com +% +% This file may be distributed and/or modified under the conditions of +% the MIT License. A version can be found at the end of this file. +% +% Repository: https://github.com/jbezos/titlesec +% +% +% Release +% ~~~~~~~ + +\ifx\ttl@coreps\@empty\else % START code for package + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{titleps}[2019/07/16 v2.11 Page styles] + +% This package is mainly a wrapper for the pagestyle macros provided +% by titlesec, so that they can be used without it. Functionality is +% almost similar. First, some definitions from titlesec. + +\expandafter\newif\csname ifttl@ps\endcsname +\expandafter\newif\csname ifttl@toclabel\endcsname +\ttl@toclabeltrue + +\def\ttl@calcneg#1#2{% + {\setlength\@tempskipa{#2}% + #1{-\@tempskipa}}} + +\expandafter\newif\csname ifttl@premark\endcsname +\ttl@premarkfalse + +% 2019-02-25. Added the \lastskip stuff, because a mark 'forgets' the +% last skip. + +\def\ttl@premark#1#2{% + \let\ttl@lastskip\relax + \ifvmode + \ifdim\lastskip=\z@\else + \edef\ttl@lastskip{\the\lastskip}% + \vskip-\ttl@lastskip\relax + \fi + \fi + \protected@xdef\ttl@prevmarks{\ttl@marks}% + \csname#1mark\endcsname{#2}% + \ifx\ttl@lastskip\relax\else + \vskip\ttl@lastskip\relax + \fi + \gdef\ttl@prevmarks{\ttl@marks}} + +\let\ttl@savemark\@empty + +% Patching sectioning commands + +\newcommand\TitlepsPatchSection{% + \@ifstar{\ttl@setsec\@gobbletwo}% + {\ttl@setsec\pretitlemark}} + +\def\ttl@setsec#1#2{% + \@ifundefined{#2}{}{% + \expandafter\let\csname ttl@s@#2\expandafter\endcsname + \csname#2\endcsname + \@namedef{#2}{% + \@ifstar{\ttl@presec@s{#2}}% + {\@dblarg{\ttl@presec@x#1{#2}}}}}}% + +% premark/gobble, sect-name, opt, title +\def\ttl@presec@x#1#2[#3]#4{% + #1{#2}{#3}% + \@nameuse{ttl@s@#2}[#3]{#4}} + +\def\ttl@presec@s#1#2{% + \gdef\ttl@savemark{\@nameuse{#1mark}{#2}}% + \@nameuse{ttl@s@#1}*{#2}} + +\def\ttl@atbegin{% + \TitlepsPatchSection*{chapter}% + \TitlepsPatchSection{section}% + \TitlepsPatchSection{subsection}% + \TitlepsPatchSection{subsubsection}% + \TitlepsPatchSection{paragraph}% + \TitlepsPatchSection{subparagraph}} + +\AtBeginDocument{\ttl@atbegin} + +% Package options + +\DeclareOption{psfloats}{\let\ttl@replace\@empty} % a flag + +\DeclareOption{outermarks}{% + \def\ttl@titlemarks{\outertitlemarks}} +\DeclareOption{topmarks}{ + \def\ttl@titlemarks{\toptitlemarks}} +\DeclareOption{botmarks}{% + \def\ttl@titlemarks{\bottitlemarks}} +\DeclareOption{innermarks}{% + \def\ttl@titlemarks{\innertitlemarks}} +\DeclareOption{extramarks}{\let\ttl@fetchmark\@empty} +\DeclareOption{nopatches}{\let\ttl@atbegin\relax} + +\ExecuteOptions{innermarks} + +\ProcessOptions + +% Load the package body + +\let\newpagestyle\@empty +\let\renewpagestyle\@empty +\let\widenhead\@empty + +\fi % PAUSE code for package + +% START core code + +% As before, all marks has two parts but now they don't refer to left or +% right pages at all. There are some issues related to top marks which +% are explained by Knuth in \textit{The \TeX book}, pp. 259f, as well +% as an incompatibility between them and \LaTeX{} floats. To overcome +% both limitations, in the \textsf{titleps} page styles, the second +% part in |\cs{firstmark}| is a \emph{fixed} top mark and the first one +% the actual first mark; the right way to get the bot mark is from the +% second part. Marks are stored at each section and used before and +% after the title (straight class); the first part contains the values +% of current title, but the second one contains the previously stored +% values in the mark before the title, and the current values in the +% mark after. + +\ifx\ttl@compatps\@undefined\else + \PackageWarningNoLine{titlesec} + {You are using an old interface for page styles\MessageBreak + (or you forgot the package option 'pagestyles').\MessageBreak + You could proceed but don't complain if you run\MessageBreak + into errors} +\fi + +\ttl@pstrue + +\let\parttitle\@empty +\let\chaptertitle\@empty +\let\sectiontitle\@empty +\let\subsectiontitle\@empty +\let\subsubsectiontitle\@empty +\let\paragraphtitle\@empty +\let\subparagraphtitle\@empty + +\newcommand\iftitle[1]{% + \expandafter\ifx\csname #1title\endcsname\@empty + \expandafter\@secondoftwo + \else + \expandafter\@firstoftwo + \fi} + +% \newtitlemarks belongs to a nameless markset (ie, \@empty). +% For named extra marksets see below. + +\newcommand\newtitlemark{% + \@ifstar{\@tempswafalse\ttl@newmk@i\@empty}% + {\@tempswatrue\ttl@newmk@i\@empty}} + +\def\ttl@newmk@i#1#2{% markset, macro/var + \edef\ttl@a{\expandafter\@gobble\string#2}% + \expandafter\ifx\csname\ttl@a\endcsname#2\else + \edef\ttl@a{c@#2}% + \fi + \expandafter\ttl@newmk@ii\expandafter{\ttl@a}{#1}} + +\def\ttl@newmk@ii#1#2{% macro/var, markset + \expandafter\let\expandafter\ttl@a\csname ttl@mks@#2\endcsname + \if@tempswa + \expandafter\def\expandafter\ttl@a\expandafter{% + \ttl@a + \protect\@namedef{#1}{\@nameuse{#1}}}% + \else + \expandafter\def\expandafter\ttl@a\expandafter{% + \ttl@a + \protect\@nameuse{#1}=\the\@nameuse{#1}\relax}% + \fi + \expandafter\let\csname ttl@mks@#2\endcsname\ttl@a} + +\let\ttl@mks@\@empty +\def\ttl@moremarks{\ttl@mks@} % backward compat + +\def\ttl@prevmarks{\ttl@marks} +\let\ttl@marks\relax + +% The following command sets the ifthe... commands to +% be used in heads. When the call is from inside a sectioning +% command, toclabel is either true (in most of cases) or false +% (a chapter in the front matter, for example). Otherwise (an +% explicit \...mark) is false + +\def\ttl@setifthe#1{% + \expandafter\protected@edef\csname ifthe#1\endcsname{% + \ifttl@toclabel + \protect\@firstoftwo + \else + \protect\@secondoftwo + \fi}} + +% At this point \ttl@toclabel is always false + +\ttl@setifthe{part} +\ttl@setifthe{chapter} +\ttl@setifthe{section} +\ttl@setifthe{subsection} +\ttl@setifthe{subsubsection} +\ttl@setifthe{paragraph} +\ttl@setifthe{subparagraph} + +% Putting marks +% ------------- + +\newtitlemark{\ttl@running} +\let\ttl@enccode\relax +\def\ttl@running{\ttl@enccode} + +% \ttl@markboth redefines temporarily \mark to fetch changes made by +% babel or ams, saved in \ttl@running. When this is done, the actual +% \mark es emitted, which has \ttl@running as part of the markset (see +% the \newtitlemark above). + +\def\ttl@mb@mark{\markboth} +\def\ttl@mb@warn{% + \PackageWarningNoLine{titleps} + {Direct use of \string\markboth\space and \string\markleft\space + can lead\MessageBreak + to unpredictable results. Please, read the manual\MessageBreak + for an explanation of this warning.}} + +\def\ttl@markboth#1{% + \begingroup + \let\protect\@unexpandable@protect + \let\@mkboth\@gobbletwo + \let\ttl@enccode\relax + \let\label\relax + \let\index\relax + \let\glossary\relax + \let\ttl@c\mark + \def\mark##1{\xdef\ttl@running{\expandafter\@gobble##1}}% + \ttl@mb@mark{}{\ttl@enccode}% + \expandafter\let\csname#1mark\endcsname\@gobble + \xdef\ttl@marks{\ttl@marks}% + \gdef\@themark{{\ttl@marks}{\ttl@prevmarks}}% + \ttl@c{\@themark\let\noexpand\ttl@mb@warn\relax}% + \@nameuse{ttl@tem@#1}% + \if@nobreak\ifvmode\nobreak\fi\fi + \endgroup} + +\newcommand\settitlemarks{\@ifstar\ttl@svmarks@s\ttl@svmarks@x} + +\def\ttl@svmarks@x#1{\def\ttl@marksset{{#1}}} +\def\ttl@svmarks@s#1{\def\ttl@marksset{*{#1}}} + +\newcommand\setmarks[2]{\settitlemarks{#1,#2}} % back compat + +\def\ttl@settopmark#1\@@{% + \expandafter\def\csname#1mark\endcsname##1{% + \expandafter\gdef\csname#1title\endcsname{##1}% + \ttl@setifthe{#1}% + \expandafter\let\expandafter\ttl@marks\csname ttl@tm@#1\endcsname + \ttl@markboth{#1}}% + \global\@namedef{ttl@tm@#1}{% + \protect\@namedef{#1title}{\@nameuse{#1title}}% + \protect\@namedef{the#1}{\@nameuse{the#1}}% + \protect\@namedef{ifthe#1}{\@nameuse{ifthe#1}}}% + \def\ttl@elt##1{% + \expandafter\ttl@setsubmark\ttl@a\@@{##1}}% + \ttl@c}% + +\def\ttl@setsubmark#1\@@#2{% + \expandafter\g@addto@macro\csname ttl@tm@#2\endcsname{% + \protect\@namedef{#1title}{}% + \protect\@namedef{the#1}{}% + \protect\@namedef{ifthe#1}{\protect\@secondoftwo}} + \expandafter\g@addto@macro\csname ttl@tm@#1\endcsname{% + \protect\@namedef{#2title}{\@nameuse{#2title}}% + \protect\@namedef{the#2}{\@nameuse{the#2}}% + \protect\@namedef{ifthe#2}{\@nameuse{ifthe#2}}}}% + +\def\ttl@setmarks@x#1{% + \let\ttl@c\@empty % sub list + \@for\ttl@a:=#1\do{% + \expandafter\ttl@settopmark\ttl@a\@@ + \let\ttl@elt\relax + \xdef\ttl@c{\ttl@c\ttl@elt{\ttl@a}}}% + \@for\ttl@a:=#1\do{% + \expandafter\g@addto@macro\csname ttl@tm@\ttl@a\endcsname{% + \ttl@moremarks}}} + +\def\ttl@setmarks@s#1{% Solo con extramarks + \PackageError{titleps}% + {You need `extramarks' for \string\settitlemarks*}% + {\string\settitlemarks* requires the package option `extramarks'}} + +\newcommand\pretitlemark{% + \global\ttl@premarktrue + \@ifstar{\ttl@pretitlemark\z@}% + {\ttl@pretitlemark\@ne}} + +\def\ttl@pretitlemark#1#2#3{% + \addtocounter{#2}#1% + \ttl@premark{#2}{#3}% + \addtocounter{#2}{-#1}} + +% Rules +% ----- + +\newcommand\headrule{\setheadrule{.4\p@}} +\newcommand\footrule{\setfootrule{.4\p@}} + +\newcommand\setheadrule[1]{% + \ifdim#1=\z@ + \let\makeheadrule\@empty + \else + \def\makeheadrule{\rule[-.3\baselineskip]{\linewidth}{#1}}% + \fi} +\newcommand\setfootrule[1]{% + \ifdim#1=\z@ + \let\makefootrule\@empty + \else + \def\makefootrule{\rule[.7\baselineskip]{\linewidth}{#1}}% + \fi} + +\renewcommand\newpagestyle[1]{% + \begingroup + \catcode`\^^M=9 + \@ifnextchar[% + {\ttl@pagestyle\newcommand{#1}}% + {\ttl@pagestyle\newcommand{#1}[]}} + +\renewcommand\renewpagestyle[1]{% + \begingroup + \catcode`\^^M=9 + \@ifnextchar[% + {\ttl@pagestyle\renewcommand{#1}}% + {\ttl@pagestyle\renewcommand{#1}[]}} + +\def\ttl@pagestyle#1#2[#3]#4{% + \endgroup + \expandafter#1\csname ps@#2\endcsname{% + \ttl@defaultps + \def\ttl@headfmt{#3}% + #4% + \def\settitlemarks{\@ifstar\ttl@svmarks@s\ttl@svmarks@x}}} + +\def\ttl@userunning#1#2{\csname ttlr@#1#2\endcsname} + +\def\ttl@defaultps{% + \let\makeheadrule\@empty + \let\makefootrule\@empty + \def\@mkboth{\ttl@savemark\@gobbletwo}% + \def\@oddfoot{\ttl@userunning of}% + \def\@evenfoot{\ttl@userunning ef}% + \def\@oddhead{\ttl@userunning oh}% + \def\@evenhead{\ttl@userunning eh}% + \def\ttlr@of{\ttl@makefoot\@empty\@@\ttl@hiol\ttl@hior}% + \def\ttlr@ef{\ttl@makefoot\@empty\@@\ttl@hiel\ttl@hier}% + \def\ttlr@oh{\ttl@makehead\@empty\@@\ttl@hiol\ttl@hior}% + \def\ttlr@eh{\ttl@makehead\@empty\@@\ttl@hiel\ttl@hier}% + \let\ttlr@of@b\relax \let\ttlr@of@p\relax + \let\ttlr@ef@b\relax \let\ttlr@ef@p\relax + \let\ttlr@oh@t\relax \let\ttlr@oh@p\relax + \let\ttlr@eh@t\relax \let\ttlr@eh@p\relax + \def\settitlemarks{\@ifstar\ttl@setmarks@s\ttl@setmarks@x}% + \expandafter\settitlemarks\ttl@marksset} + +\@ifundefined{chapter}% + {\settitlemarks{section,subsection}}% + {\settitlemarks{chapter,section}} + +\newcommand\usepage{\protect\thepage} % back compat + +\newcommand\toptitlemarks{\expandafter\@secondoftwo\firstmark{}{}{}} +\def\firsttitlemarks{% + \toks@\expandafter\expandafter\expandafter{% + \expandafter\@secondoftwo \firstmark{}{}{}}% + \@temptokena\expandafter\expandafter\expandafter{% + \expandafter\@secondoftwo \botmark{}{}{}}% + \edef\ttl@a{\the\toks@}% + \edef\ttl@b{\the\@temptokena}% + \ifx\ttl@a\ttl@b + \expandafter\@secondoftwo\firstmark{}{}{}% + \else + \expandafter\@firstoftwo \firstmark{}{}{}% + \fi} +\newcommand\bottitlemarks{\expandafter\@secondoftwo\botmark{}{}{}} +\newcommand\nexttoptitlemarks{\expandafter\@firstoftwo\botmark{}{}{}} +\newcommand\outertitlemarks{% + \if@twoside + \ifodd\c@page\relax + \bottitlemarks + \else + \toptitlemarks + \fi + \else + \toptitlemarks + \fi} +\newcommand\innertitlemarks{% + \if@twoside + \ifodd\c@page\relax + \firsttitlemarks + \else + \bottitlemarks + \fi + \else + \bottitlemarks + \fi} + +\def\ttl@duplthreeargs#1#2#3#4{#1[#2][#3][#4]{#2}{#3}{#4}} +\def\ttl@dupltwoargs#1#2#3{#1[#2][#3]{#2}{#3}} +\def\ttl@duplthreeargsrev#1#2#3#4{#1[#4][#3][#2]{#2}{#3}{#4}} +\def\ttl@dupltwoargsrev#1#2#3{#1[#3][#2]{#2}{#3}} + +\def\ttl@setany#1{% + \@ifstar{\ttl@duplthreeargsrev#1}% + {\@ifnextchar[{#1}{\ttl@duplthreeargs#1}}} + +\newcommand\setfoot{\ttl@setany\ttl@setfoot} +\newcommand\sethead{\ttl@setany\ttl@sethead} + +\def\ttl@setfoot[#1][#2][#3]#4#5#6{% + \def\ttlr@ef{\ttl@makefoot{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}% + \def\ttlr@of{\ttl@makefoot{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}} + +\def\ttl@sethead[#1][#2][#3]#4#5#6{% + \def\ttlr@eh{\ttl@makehead{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}% + \def\ttlr@oh{\ttl@makehead{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}} + +\def\ttl@headinline#1#2#3{% + \ttl@headfmt + \def\ttl@a{#1#3}\def\ttl@b{#2}% + \ifx\ttl@a\@empty + \hfil{#2}\hfil + \else\ifx\ttl@b\@empty + {#1}\hfil{#3}% + \else + \sbox\z@ {#1}% + \sbox\tw@{#3}% + \copy\z@ + \ifdim\wd\z@<\wd\tw@ + \kern-\wd\z@\kern\wd\tw@ + \fi + \hfil{#2}\hfil + \ifdim\wd\z@>\wd\tw@ + \kern-\wd\tw@\kern\wd\z@ + \fi + \box\tw@ + \fi\fi} + +\def\ttl@makeboth#1#2#3#4{% + \ttl@calcneg\hspace{#3}% + \normalsize + \linewidth\textwidth + \addtolength\linewidth{#3}% + \addtolength\linewidth{#4}% + \ifx#2\@empty\else + \setbox\z@\hb@xt@\linewidth{% + \color@begingroup + #2% + \color@endgroup}% + \wd\z@\z@ + \ht\z@\z@ + \dp\z@\z@ + \box\z@ + \fi + \ttl@titlemarks % Must precede the format. Defines \ttl@running + \def\ttl@enccode{\ttl@headinline#1{}{}{}}% which contains ttl@enccode + \ttl@running + \ttl@calcneg\hspace{#4}}% + +\def\ttl@makehead#1\@@{\ttl@makeboth{#1}\makeheadrule} +\def\ttl@makefoot#1\@@{\ttl@makeboth{#1}\makefootrule} + +\renewcommand\widenhead{% + \@ifstar{\ttl@dupltwoargsrev\ttl@widenhd}% + {\@ifnextchar[{\ttl@widenhd}{\ttl@dupltwoargs\ttl@widenhd}}} + +\def\ttl@widenhd[#1][#2]#3#4{% + \def\ttl@hiel{#1}\def\ttl@hier{#2}% + \def\ttl@hiol{#3}\def\ttl@hior{#4}} + +\let\setheadindent\widenhead + +\def\ttl@hiel{\z@}\def\ttl@hier{\z@} +\def\ttl@hiol{\z@}\def\ttl@hior{\z@} + +% A tool: + +\def\ifsamemark#1#2{% + {#1\global\let\ttl@c#2}% + \ifx\ttl@c#2% + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi} + +% Another tool: + +\newcommand\setmarkboth{% + \ifx\markboth\ttl@mb@use\else + \let\ttl@mb@mark\markboth + \let\markboth\ttl@mb@use + \fi + \def\ttl@mb@new##1##2} + +% \ttl@mb@temp is a trick to allow resetting inside \setmarkboth. + +\def\ttl@mb@use#1#2{% + \let\markboth\ttl@mb@mark + \def\ttl@mb@temp{\let\markboth\ttl@mb@use}% + \ttl@mb@new{#1}{#2}% + \ttl@mb@temp + \let\ttl@mb@temp\@undefined} + +\newcommand\resetmarkboth{% + \ifx\ttl@mb@temp\@undefined + \let\markboth\ttl@mb@mark + \def\ttl@mb@mark{\markboth}% + \else + \def\ttl@mb@temp{% + \let\markboth\ttl@mb@mark + \def\ttl@mb@mark{\markboth}}% + \fi} + +% =========== +% EXTRA MARKS +% =========== + +\ifx\ttl@fetchmark\@empty + +\ifx\newmarks\@undefined + \PackageInfo{titleps}{% + You have requested `extramarks' but etex or similar\MessageBreak + has not been loaded. I'll do it for you.} + \RequirePackage{etex} +\fi + +\def\ttl@setmarks@s#1{% + \@for\ttl@a:=#1\do{% + \@ifundefined{ttl@mkc@\ttl@a}{% + \expandafter\newmarks\csname ttl@mkc@\ttl@a\endcsname}{}% + \expandafter\xdef\csname ttl@tem@\ttl@a\endcsname{% + \marks\expandafter\noexpand\csname ttl@mkc@\ttl@a\endcsname + {\noexpand\@themark}}}% + \ttl@setmarks@x{#1}}% + +\newcommand\newmarkset[1]{% + \expandafter\newmarks\csname ttl@mkc@#1\endcsname + \@namedef{ttl@mks@#1}{}% + \@namedef{ttl@premks@#1}{\@nameuse{ttl@mks@#1}}} + +\newcommand\newextramark{% + \@ifstar{\@tempswafalse\ttl@newmk@i}% + {\@tempswatrue\ttl@newmk@i}} + +\def\ttl@extramark#1{% + \begingroup + \let\protect\@unexpandable@protect + \let\@mkboth\@gobbletwo + \let\label\relax + \let\index\relax + \let\glossary\relax\endgroup} + +\newcommand\extramark[1]{% + \begingroup + \let\protect\@unexpandable@protect + \let\@mkboth\@gobbletwo + \let\label\relax + \let\index\relax + \let\glossary\relax + \marks\csname ttl@mkc@#1\endcsname{% + {\@nameuse{ttl@mks@#1}}% + {\@nameuse{ttl@mks@#1}}}% + \expandafter\xdef\csname ttl@premks@#1\endcsname + {\@nameuse{ttl@mks@#1}}% + \endgroup + \if@nobreak\ifvmode\nobreak\fi\fi}% + +\newcommand\preextramark[1]{% + \begingroup + \let\protect\@unexpandable@protect + \let\@mkboth\@gobbletwo + \let\label\relax + \let\index\relax + \let\glossary\relax + \marks\csname ttl@mkc@#1\endcsname{% + {\csname ttl@mks@#1\endcsname}% + {\csname ttl@premks@#1\endcsname}}% + \endgroup + \if@nobreak\ifvmode\nobreak\fi\fi} + +\newcommand\newshortmark[1]{% + \newmarkset{\string#1}% + \newextramark{\string#1}#1} + +\newcommand\shortmark[1]{\extramark{\string#1}} +\newcommand\preshortmark[1]{\preextramark{\string#1}} + +\newcommand\topshortmark[1]{{\topextramarks{\string#1}#1}} +\newcommand\firstshortmark[1]{{\firstextramarks{\string#1}#1}} +\newcommand\botshortmark[1]{{\botextramarks{\string#1}#1}} +\newcommand\nexttopshortmark[1]{{\nexttopextramarks{\string#1}#1}} + +\def\ttl@fetchmark#1#2#3{% + \expandafter#1#2\csname ttl@mkc@#3\endcsname{}{}{}} + +\newcommand\topextramarks[1]{\ttl@fetchmark\@secondoftwo\firstmarks{#1}} +\newcommand\firstextramarks[1]{% + \toks@\expandafter\expandafter\expandafter{% + \ttl@fetchmark\@secondoftwo\firstmarks{#1}}% + \@temptokena\expandafter\expandafter\expandafter{% + \ttl@fetchmark\@secondoftwo\botmarks{#1}}% + \edef\ttl@a{\the\toks@}% + \edef\ttl@b{\the\@temptokena}% + \ifx\ttl@a\ttl@b + \ttl@fetchmark\@secondoftwo\firstmarks{#1}% + \else + \ttl@fetchmark\@firstoftwo\firstmarks{#1}% + \fi} +\newcommand\botextramarks[1]{\ttl@fetchmark\@secondoftwo\botmarks{#1}} +\newcommand\nexttopextramarks[1]{\ttl@fetchmark\@firstoftwo\botmarks{#1}} + +\newcommand\outerextramarks[1]{% + \if@twoside + \ifodd\c@page\relax + \botextramarks{#1}% + \else + \topextramarks{#1}% + \fi + \else + \topextramarks{#1}% + \fi} +\newcommand\innerextramarks[1]{% + \if@twoside + \ifodd\c@page\relax + \firstextramarks{#1}% + \else + \botextramarks{#1}% + \fi + \else + \botextramarks{#1}% + \fi} + +\fi + +% ====== +% FLOATS +% ====== +% +% Pagestyles with floats. There macros are defined only with the +% psfloats package option. + +\ifx\ttl@replace\@undefined\else + +% User interface + + \newcommand\setfloatfoot{% + \let\ttl@c\@empty % <- current float, empty if general + \ttl@setany\ttl@setftfoot} + + \newcommand\setfloathead{% + \let\ttl@c\@empty % <- current float, empty if general + \ttl@setany\ttl@setfthead} + + \def\ttl@setftfoot[#1][#2][#3]#4#5#6#7{% + \@ifnextchar[{\ttl@setftfoot@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% + {\ttl@setftfoot@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}[bp]}} + + \def\ttl@setfthead[#1][#2][#3]#4#5#6#7{% + \@ifnextchar[{\ttl@setfthead@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% + {\ttl@setfthead@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}[tp]}} + + \def\ttl@setftfoot@i#1#2#3#4#5#6#7[#8]{% + \@tfor\ttl@b:=#8\do{% + \@namedef{ttlr@ef@\ttl@b\ttl@c}% + {#7\ttl@makefoot{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}% + \@namedef{ttlr@of@\ttl@b\ttl@c}% + {#7\ttl@makefoot{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}} + + \def\ttl@setfthead@i#1#2#3#4#5#6#7[#8]{% + \@tfor\ttl@b:=#8\do{% + \@namedef{ttlr@eh@\ttl@b\ttl@c}% + {#7\ttl@makehead{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}% + \@namedef{ttlr@oh@\ttl@b\ttl@c}% + {#7\ttl@makehead{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}} + + \newcommand\nextfloathead{% + \ttl@nextfree % returns ttl@c with the next float + \ttl@setany\ttl@setfthead} + + \newcommand\nextfloatfoot{% + \ttl@nextfree % returns ttl@c with the next float + \ttl@setany\ttl@setftfoot} + +% Compat mode with floatps + + \ifx\ttl@replace\space + + \let\ttl@setnewfoot\ttl@setftfoot + \let\ttl@setnewhead\ttl@setfthead + + \def\ttl@setftfoot[#1][#2][#3]#4#5#6{% + \ttl@setnewfoot[#1][#2][#3]{#4}{#5}{#6}{}} + \def\ttl@setfthead[#1][#2][#3]#4#5#6{% + \ttl@setnewhead[#1][#2][#3]{#4}{#5}{#6}{}} + + \fi + +% The simple default value of \ttl@userunning is +% replaced by one more elaborated + + \def\ttl@userunning#1#2{% + \if@fcolmade % From a post by D. Arseneau to comp.text.tex + \def\@elt##1{\edef\ttl@pageft{\string##1}}% + \@flsucceed + \let\@elt\relax + \if#2h% + \ttl@replace #1hp\ttl@pageft + \else + \ttl@replace #1fp\ttl@pageft + \ttl@killftps\ttl@pageft + \fi + \else\if#2h% + \ifx\ttl@topft\@empty\else + \ttl@replace #1ht\ttl@topft + \fi + \else + \ifx\ttl@botft\@empty\else + \ttl@replace #1fb\ttl@botft + \fi + \fi\fi + \csname ttlr@#1#2\endcsname} + +% [Don't move above as \ttl@replace is used as a flag.] + + \def\ttl@replace#1#2#3#4{% + \@ifundefined{ttlr@#1#2@#3#4}% + {\@ifundefined{ttlr@#1#2@#3}{}% + {\@namedef{ttlr@#1#2}{\@nameuse{ttlr@#1#2@#3}}}}% + {\csname ttlr@xx@x#4\endcsname\@gobble + {\expandafter\let\csname ttlr@#1#2\expandafter\endcsname + \csname ttlr@#1#2@#3#4\endcsname}}} + + \def\ttl@nextfree{% + \def\@elt##1{% + \edef\ttl@c{\string##1}% + \let\@elt\@gobble}% + \@freelist + \let\@elt\relax + \@ifundefined{ttlr@xx@x\ttl@c}% + {\expandafter\let\csname ttlr@xx@x\ttl@c\endcsname\@secondoftwo + \@tfor\ttl@a:={eh@t}{oh@t}{ef@b}{of@b}{eh@p}{oh@p}{ef@p}{of@p}\do{% + \expandafter\global\expandafter + \let\csname ttlr@\ttl@a\ttl@c\endcsname\relax}}{}} + + \def\ttl@killftps#1{% + \expandafter\global\expandafter + \let\csname ttlr@xx@x#1\endcsname\relax} + + \let\ttl@topft\@empty + \let\ttl@botft\@empty + \let\ttl@pageft\@empty + + \def\ttl@combinefloats{% + \ifx\@toplist\@empty\else + \def\@elt##1{% + \edef\ttl@topft{\string##1}% + \def\@elt####1{\ttl@killftps{\string####1}}}% + \@toplist + \fi + \ifx\@botlist\@empty\else + \def\@elt##1{% + \def\@elt####1{% + \def\@elt####1{\ttl@killftps\ttl@botft}% + \edef\ttl@botft{\string####1}}% + \edef\ttl@botft{\string##1}}% + \@botlist + \fi + \let\@elt\relax + \ttl@combinefloats@x} + + \AtBeginDocument{% + \let\ttl@combinefloats@x\@combinefloats + \let\@combinefloats\ttl@combinefloats} + +\fi + +% END core code + +\ifx\ttl@coreps\@empty\else % CONTINUE code for package + +% Raise error if the following are used without titlesec + +\DeclareRobustCommand\ttl@naerror[1]{% + \PackageError{titleps}% + {#1\space only available in titlesec.\MessageBreak + Consider using it instead of titleps}% + {titleps provides a subset of the macros\MessageBreak + for pagestyles defined in titlesec.}} + +\def\ttl@setifthe#1{% + \expandafter\protected@edef\csname ifthe#1\endcsname{% + \ttl@naerror{\string\ifthe#1}}} + +\ttl@setifthe{part} +\ttl@setifthe{chapter} +\ttl@setifthe{section} +\ttl@setifthe{subsection} +\ttl@setifthe{subsubsection} +\ttl@setifthe{paragraph} +\ttl@setifthe{subparagraph} + +\fi + +\endinput + +MIT License +----------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/macros/latex/contrib/titlesec/titleps.tex b/macros/latex/contrib/titlesec/titleps.tex new file mode 100644 index 0000000000..51149c9fa8 --- /dev/null +++ b/macros/latex/contrib/titlesec/titleps.tex @@ -0,0 +1,835 @@ +% +% Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com +% +% This file may be distributed and/or modified under the conditions of +% the MIT License. A version can be found at the end of this file. +% +% Repository: https://github.com/jbezos/titlesec +% + +\def\fileversion{2.11} +\def\docdate{2019/07/16} + +\documentclass[a4paper]{ltxguide} +\usepackage[sf,bf,compact,topmarks,calcwidth,pagestyles]{titlesec} +\usepackage{titletoc} +\def\gobble#1{} +\DeclareRobustCommand\cs[1]{\expandafter\gobble\string\\#1} +\makeatletter +\newenvironment{desc} + {\if@nobreak + \vskip-\lastskip + \vspace*{-2.5ex}% + \fi + \decl} + {\enddecl} +\makeatother + +\usepackage{textcomp,pslatex} +\usepackage[linktocpage]{hyperref} + +\title{Headers and footers with \textsf{titleps}\footnote{The +\textsf{titleps} package is currently at version \fileversion. +\copyright{} 2016 Javier Bezos. All Rights Reserved.}} + +\author{Javier Bezos\footnote{For bug reports, comments and +suggestions go to \href{http://www.texnia.com/contact.html}% +{\texttt{http://www.texnia.com/contact.html}}. English +is not my strong point, so contact me when you find mistakes in the +manual. Other packages by the same author: \textsf{gloss} (with +Jos\'e Luis D\'{\i}az), \textsf{enumitem, accents, tensind, esindex, +dotlessi}.}} + +\date{\docdate} + +\widenhead{2.1pc}{0pc} +\titlelabel{\thetitle.\quad} + +\renewpagestyle{plain}[\small\sffamily\slshape]{ + \footrule + \setfoot{}{\thepage}{}} + +\newpagestyle{myps}[\small\sffamily\slshape]{ + \headrule + \sethead{titlesec -- titleps}{\sectiontitle}{\thepage}} + +\pagestyle{myps} + +\newcommand{\examplesep}{% + \begin{center}% + \rule{4pt}{4pt}% + \end{center}} + +\contentsmargin{0pt} + +\titlecontents*{section}[0pt]%[1.8pc] + {} + {\thecontentslabel. } + {} + {, \thecontentspage} + [. --- ][.] + +\addtolength{\topmargin}{-3pc} +\addtolength{\textwidth}{6pc} +\addtolength{\oddsidemargin}{-2pc} +\addtolength{\textheight}{7pc} + +\raggedright +\parindent1em +\parskip0pt + +\begin{document} + +\maketitle +\tableofcontents +\section{Introduction} + +The \textsf{titleps} package provides tools for one-stage setting of +page styles (headlines and footlines). A higher-level interface is +used, where the mark mechanism is hidden and there is no need to deal +with |\leftmark|s and |\rightmark|s -- just use a command or variable +registered as a ``mark'' as the expected value will be returned, i.e., +those when the mark was emitted, either by a sectioning command or +explicitly with |\chaptermark|, |\sectionmark|, etc. A simple +example, whose meaning should be obvious, is: +\begin{verbatim} +\newpagestyle{main}{ + \sethead[\thepage][\chaptertitle][(\thesection] % even + {\thesection)}{\sectiontitle}{\thepage}} % odd +\pagestyle{main} +\end{verbatim} + +Other features are: +\begin{itemize} +\item Working top marks, compatible with floats (unlike the standard +|\topmark|, which does not work correctly in \LaTeX{}). +\item Access to top, first and botttom marks in a single headline/footline +(e.g., the first and last section numbers). +\item Marks for more than 2 sectioning levels. +\item Auto-defining of suitable |\sectionmark| and the like. +\item Simple (and not so simple) headrules and footrules. +\item Headlines and footlines for pages with floats. +\item Headlines and footlines for specific floats (a sort of +|\thispagestyle| for floats). +\item Multiple sets of marks (named here \emph{markset}s and +\textit{extra marks}). +\end{itemize} + +It can be used without \textsf{titlesec}, but you will get most of +it when used together. To load it as a separate package, use the +customary \verb|\usepackage{titleps}|, but with \textsf{titlesec} you +have to load it with: +\begin{verbatim} +\usepackage[pagestyles]{titlesec} +\end{verbatim} + +Specific tools for sectioning command marks are provided, which are +considered the main \textit{markset} (unnamed) and carry out some +internal task. However, \textsf{titleps} can be used as well for +headers with the first an last entry of a page in a dictionary or index, +for example, thank to the \textit{extra marks} described below. + +It works with standard classes and many others; however, additional +\LaTeX{} layout adjustments could be necessary in some of them (for +instance the \textsc{AMS} classes) and several packages emitting marks +directly with \verb|\markboth| and \verb|\markleft|.\footnote{% +Two columns layout requires the \textsf{fix2col} package by David +Carlisle.} + +Once loaded the package, you can define your own page styles and then +activate them, but note page styles so defined cannot be used with +\verb|\thispagestyle| except if the surrounding page style has been +defined with \textsf{titleps}, too. + +%%%% empty ? plain ? + +\section{Defining Page Styles} + +\begin{desc} +|\newpagestyle{<name>}[<global-style>]{<commands>}|\\ +|\renewpagestyle{<name>}[<global-style>]{<commands>}| +\end{desc} + +Defines a new style or redefines an existing one, named |<name>|. For +convenience, spaces and end of lines are ignored, and you need not +``hide'' them with |%|.\footnote{Even if marks should be reserved +to pass information +to headers, some classes, like the AMS ones, introduce additional +code. When redefining the |plain| style of AMS classes, you must add +the following line: |\cs{global}\cs{topskip}\cs{normaltopskip}|.} + +|<global-style>| is any command to be applied to both footlines and +headlines. Fragile commands are allowed. + +In |<commands>| you can use: + + +\begin{desc} +|\sethead[<even-left>][<even-center>][<even-right>]|\\ +| {<odd-left>}{<odd-center>}{<odd-right>}|\\ +|\setfoot[<even-left>][<even-center>][<even-right>]|\\ +| {<odd-left>}{<odd-center>}{<odd-right>}| +\end{desc} + +Set the corresponding part in headlines and footlines (note the +``visual'' layout of parameters). The optional arguments are the +three or none. If no optional arguments are given the odd-page +settings applies to both even and odd pages. A couple of starred +variant (|\setfoot*|, |\sethead*|) reverses the order of the settings +for even pages (obviously, with them the optional arguments are not +allowed). If |\sethead| is not given, then the headline it is left +empty, and same for |\setfoot| and the footline. + +In the arguments of |\sethead|/|\setfoot| and because of its one-stage +mechanism, we must distinguish between two groups of commands: +\begin{itemize} +\item The first one includes those saved when the marks are emitted, +with information related to sections, and includes: +\begin{itemize} +\item |\thechapter|, |\thesection|, |\thesubsection|\dots{} +\item |\chaptertitle|, |\sectiontitle|, |\subsectiontitle|\dots{} which print the +chapter, section\dots{} title. +\item (Only \textsf{titlesec}. Not in \textsf{titleps}.) +|\ifthechapter{<true>}{<false>}|, |\ifthesection{<true>}{<false>}|, +|\ifthesubsection{<true>}{<false>}|\dots{} which expands to |<true>| +except if the corresponding title lacks of label or there is no title +yet after the superior level (for example, between |\chapter| and a +subsequent |\section|). +\item Any other command or value ``registered'' as ``mark.'' (See below.) +\end{itemize} +They are ordinary commands, with no internal marks at all, and you can +test if, for example, they are empty. + +\item The second group are those expanded on every page, and includes: +\begin{itemize} +\item |\thepage|. +\item Any other command not included in the previous items. +\end{itemize} +\end{itemize} + +\begin{desc} +|\settitlemarks{<level-name>,<sublevel-name>,<subsublevel-name>...}|\\ +|\settitlemarks*{<level-name>,<sublevel-name>,<subsublevel-name>...}| +\end{desc} +Sets which |\...title| commands are to be defined, and when the marks +are emitted; any number of levels is allowed (1, 2, 3...). For example +|\settitlemarks{chapter,section}| +means that: +\begin{itemize} +\item |\chaptertitle| and |\sectiontitle| are the allowed titles in + headlines, +\item |\sectiontitle| is reset in |\chapter|, +\item (Only \textsf{titlesec}. Not in \textsf{titleps}.) +|\ifthechapter| and |\ifthesection| are valid tests. +\item Marks are updated in |\chapter| and |\section|. +\end{itemize} +Default is |\settitlemarks{chapter,section}|, but +|\settitlemarks{section,subsection}| in \textsf{article} class. +|\settitlemarks| may be used outside |\(re)newpagestyle| to set the +default to be used in newly defined and redefined page styles -- it is +used in |\pagestyle|.\footnote{The command \texttt{\string\setmarks} is +deprecated. Now +\texttt{\string\setmarks\string{<primary>\string}\string{<secondary>\string}}is +\texttt{\string\settitlemarks\allowbreak\string{<primary>,\allowbreak<secundary>\string}}.} + +The starred version |\settitlemarks*| creates parallel extra marks +as described below. + +\begin{desc} +|\headrule \footrule|\\ +|\setheadrule{<length>} \setfootrule{<length>}| +\end{desc} + +If you want a rule below the headline and above the footline. You may +also set their width directly with the commands |\setheadrule| and +|\setfootrule|. (For instance, |\setheadrule{.4pt}| which is, by the +way, the default value.) + +These commands are local to a page style, i.e., defining them directly +in the preamble will not work because the page style settings will +override them. + +\begin{desc} +|\makeheadrule \makefootrule| +\end{desc} + +These commands are used by \textsf{titleps} to typeset the rules. +If there is no rule, both commands are empty (this value is the +default). +|\setheadrule{|\emph{dim}|}| just stands for +\begin{verbatim} +\renewcommand{\makeheadrule}{\rule[-.3\baselineskip]{\linewidth}{<dim>}} +\end{verbatim} +unless if \emph{dim} is 0 pt, which empties +|\makeheadrule| (and similarly |\setfootrule|). + +You can access the total header/footer width with |\linewidth| +but the box enclosing the rule is in fact dimensionless. Hence, +you must be concerned with the rule placement only. Its +baseline is the same as that of the header/footer. That means the +material to be used as rule should be raised or lowered with +|\raisebox|, the lifting argument in |\rule| or by using sensible +coordinates in |picture|, for instance. That makes easy to +place material above \emph{and} below. For instance, +the following code creates a headline with a black bold line +above and a red rule below (the \textsf{color} package is required): +\begin{verbatim} +\renewcommand{\makeheadrule}{% + \makebox[0pt][l]{\rule[.7\baselineskip]{\linewidth}{0.8pt}}% + \color[named]{Red}% + \rule[-.3\baselineskip]{\linewidth}{0.4pt}} +\end{verbatim} + +Of course, the material to be used as rule is not restricted to actual +rules; pictures and leaders, for instance, are allowed, too. + +\section{On \texttt{\cs{markboth}} and \texttt{\cs{markleft}}} + +As \textit{The \LaTeX{} Companion explains} ``Leslie Lamport had a +specific marking scheme in mind when he designed those +commands''. They are clearly intended for the \verb|heading| and +\verb|myheading| pagestyles, with a \textit{main-mark} on the left +page and a \textit{sub-mark} on the right one. + +In order to provide the functionality offered by \textsf{titleps}, a +more general, less specific mechanism is devised, which means +|\markboth| here does not make sense, because it doesn't work like in +standard \LaTeX, and in fact, can lead to unpredictable results. + +Therefore, using directly the marking commands is discouraged (see +|titlesec.pdf|), but if you need them, you may write: +\begin{verbatim} +\chapter*{My Chapter} +\chaptermark{My Chapter} +\end{verbatim} + +But some issues remain, because there are a number of packages +assuming the pagestyle is \verb|heading| or \verb|myheading|. This is, +of course, a reasonable guess, but not always correct (even if +\textsf{titleps} is not used at all). Most of them do the right thing +-- \verb|\markboth| is encapsulated into a macro easily redefinable so +that the user can modify it if necessary. This is true, for example, +for \textsf{biblatex}, but unfortunately not for \textsf{endnotes}. +When this happens, you can resort to the following macro. + +\begin{desc} +|\setmarkboth{<code-to-use>}| +\end{desc} + +From this point on, \verb|\markboth| behaves as defined. It doesn't +redefine directly the command, but rather provides a replacement code +(you can use |#1| and |#2| for the two arguments). With +|\resetmarkboth| (which can be used inside |\setmarkboth|) the +original definition will be again in force. For example, to cancel the +next |\markboth|: +\begin{verbatim} +\setmarkboth{\resetmarkboth\markboth{}{}} +\end{verbatim} + +\section{Headline/footline width} + +\begin{desc} +|\widenhead[<even-left>][<even-right>]{<odd-left>}{<odd-right>}|\\ +|\widenhead*{<even-right/odd-left>}{<even-left/odd-right>}| +\end{desc} + +Makes the headlines/footlines lines wider. The extra width is +asymmetrically added and hence the two [four] arguments. Like +|\sethead|, the starred version reverses the setting for even +pages---for example, |\widenhead*{0pt}{6pc}| is the same as +|\widenhead[6pc][0pt]{0pt}{6pc}|. + +To be used outside |\(re)newpagestyle|. + +\begin{desc} +|nopatches| \qquad (package option) +\end{desc} + +By default, sectioning commands are patched slightly for top marks +and |\@mkboth| to work, so that page styles behave like standard +|headings|. However, if you want to be explicit, like with standard +|myheadings|, and emit premarks and, if necessary, marks by yourself, +set this package option. Remenber you have to use |\sectionmark| and +the like, and not |\markboth| or |\markright|. + +You might also prefer to patch the sectioning commands by yourself, +either with low-level definitions or with the provided +|\TitlepsPatchSection| (with a starred version which adds no premark +and intended mainly for chapters). For example: +\begin{verbatim} +\TitlepsPatchSection*{chapter} % patches \chapter +\TitlepsPatchSection{section} % patches \section +\end{verbatim} +(In standard classes |\part| emits no mark, and therefore it is not +patched by default.) + +\section{Marks} + +Marks can be retrieved in 4 ways: +\begin{description} +\item[top marks] If a page begins with text, they are the marks +belonging to the sectioning unit of that text. If a page begin with a +sectioning title, they are the marks of that title. In other words, +top marks refer to the section immediately adjacent to the +headline. +\item[first marks] The marks of the very first sectioning title. +\item[botttom marks] The marks of the very last (bottom) sectioning +title (also known as \textit{bot marks}). +\item[next top marks] A botttom mark with the values of the top mark of +the next page (only |straight| class or equivalent); by picking some +value from it and comparing it with the corresponding value from the +botttom marks you may know if a section continues in the next page. +Of course, it will not be used very often. +\end{description} +Standard \LaTeX{} provides only first and bottom marks. As you see, with +\textsf{titleps} you have two additional marks, namely, top and next +top marks. + +It should be stressed top marks are not the same as the primitive +\verb|\topmark| (which, in fact, is not used internally at all). They +are true top marks, returning the expected result when the title is at +the top of the page. Further, they are compatible with floats, which +is not true with \verb|\topmark|s. However, they fail with explicit +page breaks, but you can use \verb|\pretitlemark| as described +below. + +\begin{desc} +|outermarks innermarks topmarks botmarks| \qquad (package options) +\end{desc} + +|innermarks| is the default in \LaTeX, with bottom marks in even pages +and first marks in odd pages. More convenient is |outermarks|, with +top marks in even pages and bottom marks in odd pages; it is the more +usual system in classic scientific literature and it is described in +\textit{The \TeX{}book}, p.~259.\footnote{|outermarks| may not work +well in conjunction with explicit |\string\<section>mark| commands} Both of them are intended for two side printing; +|topmarks|/|botmarks| are intended for one side printing with top/bot +marks in every page (they can be used in two side printing as well). + +\begin{desc} +|\bottitlemarks \toptitlemarks \firsttitlemarks \nexttoptitlemarks|\\ +|\outertitlemarks \innertitlemarks| +\end{desc} + +These commands set which mark the values of the subsequent +|\thesection|, |\sectiontitle|, etc., will be taken from. +These macros are switches, and therefore subsequent commands and +variables are taken from the selected mark. The following is valid: +\begin{verbatim} +\toptitlemarks\textbf{\thesection.} \sectiontitle -- +\bottitlemarks\textbf{\thesection.} \sectiontitle +\end{verbatim} + +You can use them freely in your headers;\,% +\footnote{Not exactly: top marks must not be used in the page where a +chapter begins, except by overriding the default definition and making +it of |top| class.} just for fun, the following header shows the +section label from three of these marks: +\begin{verbatim} +\newpagestyle{funny}{ + \sethead{\toptitlemarks Top is \thesection} + {\firsttitlemarks First is \thesection} + {\bottitlemarks Bot is \thesection}} +\end{verbatim} + +In multilingual documents, the language in force is that corresponding +to the package options -- command versions does not switch the +language, but you can do it easily with the help a new title mark and +then switching the language, as explained below. + +\begin{desc} +|\newtitlemark{<command-name>}|\\ +|\newtitlemark*{<variable-name>}| +\end{desc} + +Add a command or a variable to the list of ``marks'' to be emitted at +a sectioning command. The macro must be parameterless, and the +variable is either a length, if it has the form \verb|\<name>|, or a +counter, if it has the form \verb|<name>| (i. e., a string). +For example, if you write (with \textsf{babel}): +\begin{verbatim} +\newtitlemark{\languagename} +\end{verbatim} +then a |\languagename| in the head/foot will contain the language when +the corresponding mark was emitted; unfortunately, \textsf{babel} +does not allow |\languagename| as the first argument of +|\foreignlanguage| (it enters in a infinite loop), but there is a +simple trick -- just use an intermediate command: +\begin{verbatim} +\newcommand\titlelanguage{\languagename} +\newtitlemark{\titlelanguage} +\end{verbatim} +(What is saved is the expansion of |\titlelanguage|, which is turn is +the expansion of |\languagename|. Alternatively, you can create the +intermediate command with |\let| in the header itself.) + +Marks to be emitted at other places (not sectioning commands) are +handled with extra marks and \textit{marksets} (see below). + +Commands must be robust, but not protected, or the value returned will +not be the right one. Remember there are two kinds of robust commands +-- those containing in turn robust commands and those protected with, +say, |\DeclareRobustCommand|.\footnote{Unfortunately, +\texttt{\string\DeclareRobustCommand} has a misleading name, because a +command created with \texttt{\string\newcommand} can be robust, too. +A better name would have been +\texttt{\string\DeclareProtectedCommand}.} An example of how to use +protected commands is a layout used sometimes if sections are long as +well as their titles, where the title is splitted across the left and +the right pages. Here is how this can be carried out: +\begin{verbatim} +\DeclareRobustCommand\splitheader[2]{#1 #2} +\def\contsplitheader{} + +\def\dosplitheader{% + \gdef\contsplitheader{}% + \DeclareRobustCommand\splitheader[2]{##1\gdef\contsplitheader{##2}}} + +\renewpagestyle{headings}{ + \sethead[\thepage] + [] + [\dosplitheader\sectiontitle] + {\contsplitheader} + {} + {\thepage} +} + +\pagestyle{headings} +\end{verbatim} +(Note the header also uses |\DeclareRobustCommand|.) + +\begin{desc} +|\pretitlemark{<section>}{<text>}|\\ +|\pretitlemark*{<section>}{<text>}| +\end{desc} + +Top marks require in fact two marks, one before the page break and +other after it. This is done by \textsf{titlesec}, while +\textsf{titleps} patches the sectioning commands as described above. + +However, if you need an explicit page break you can emit the mark +with |\pretitlemark|. For example: +\begin{verbatim} +\pretitlemark{section}{Performing Brahms} +\newpage +\section{Performing Brahms} +\end{verbatim} +Note the text in the premark is the title of the next section. The +counter is advanced temporarily, so that it has the right value, but +if for some reason you do not want that, just use +\verb|\pretitlemark*|. + +\begin{desc} +|\ifsamemark{<group>}{<command>}{<true>}{<false>}| +\end{desc} + +One of the disavantaged of the switching mechanism is that comparing +a command from, say, the top marks and the botttom marks is not +trivial. +This macro just makes it simpler. If you want to compare the +currect \verb|\thesection| with that in the top mark, write: +\begin{verbatim} +\ifsamemark\toptitlemarks\thesection{<true>}{<false>} +\end{verbatim} + +\section{Running heads with floats} + +\begin{desc} +|psfloats| \qquad (package option) +\end{desc} + +This package option activates the commands described in this section.% +\footnote{It redefines some internal \LaTeX{} commands and there could be +incompatibilities with other packages modifying the same commands. That's +the very reason these commands are loaded only optionally. As of +version 2.6 the syntax was extended with a new argument to allow +extra stuff in running heads/foots. This change is backward +compatible---just preserve the old name \verb|floatps|, which +is deprecated, if you want the pre-2.6 behaviour.} + +\begin{desc} +|\setfloathead*{.}{.}{.}{<extra>}[<which-floats>]|\\ +|\setfloathead[.][.][.]{.}{.}{.}{<extra>}[<which-floats>]|\\ +(Similarly |\setfloatfoot|.) +\end{desc} + +The arguments with a dot are similar to those of |\sethead|. The final +argument says the head is used when there is a float of +the specified types (default is |tp| in headers, and |bp| in footers). +For example: +\begin{verbatim} +\newpagestyle{main}{% + \sethead ... your definition + \setfoot ... your definition + \headrule + \footrule + \setfloathead{}{}{}{\setheadrule{0pt}}[p] + \setfloatfoot{}{}{}{\setfootrule{0pt}}[p]} +\end{verbatim} +removes the header/footer on float pages, including the rules. + +\begin{desc} +|\nextfloathead*{.}{.}{.}{<extra>}[<which-floats>]|\\ +|\nextfloathead[.][.][.]{.}{.}{.}{<extra>}[<which-floats>]|\\ +(Similarly |\nextfloatfoot|.) +\end{desc} + +You may force a header (respectively footer) when a certain float is +the first top one (respectively last bottom) with those commands just +before the corresponding float, where the arguments with a dot are +similar to those of |\sethead|. Those commands are used by +themselves, without putting them inside |\(re)newpagestyle|. So, to +empty the headline when a certain figure is placed at the top (because +it is a bleed, for example): +\begin{verbatim} +\nextfloathead{}{}{}{}[t] +\begin{figure} +... +\end{figure} +\end{verbatim} + +\section{Extra marks} + +Both \textsf{titlesec} and \textsf{titleps} provide tools for handling +extra marks, if you are using an $\epsilon$-\TeX{} based engine +(currently most of them) and load the \textsf{etex} package or +equivalent. The way they work are conceptually similar to the title +marks described above -- you set which commands or variables are to +get synchronized in heads and foots. To use extra marks, you have to +load them with the following package option: + +\begin{desc} +|extramarks| \qquad (package option) +\end{desc} + +Extra marks are subsidiary. If page styles are modified internally by +another package and the document does not make use of sectioning +commands, you might still need an empty title mark (like +\verb|\sectionmark{}|), as well as to synchronize the language by +hand. + +In many cases, the following ``short'' marks mechanism will be enough. +With it, you simply say with \verb|\newshormark| the name of a command +to be used in heads or foots, and then emit the mark at appropiated +places (short marks for variables are not available). An example +illustrates how this is carried out: +\begin{verbatim} +\newcommand\lemmatitle{} + +\newshortmark\lemmatitle + +\newcommand\lemma[1]{% + \renewcommand\lemmatitle{#1}% + \preshortmark\lemmatitle % if you want top marks + \pagebreak[2]% + \vspace{1em}% + \textbf{#1}\enspace + \shortmark\lemmatitle} + +\newpagestyle{main}{ + \sethead{}{\topshortmark\lemmatitle + --\firstshortmark\lemmatitle + --\botshortmark\lemmatitle + --\nexttopshortmark\lemmatitle}{}} + +\pagestyle{main} +\end{verbatim} + +Top marks require emitting the marks before the page break -- just use +the command \verb|\preshortmark| as shown above. Otherwise, you may +omit it. Unlike title marks and extra marks, the selector of short +marks (\verb|\topshortmark|, \verb|\firstshortmark|, +\verb|\botshortmark|, \verb|\nexttopshortmark|), is \textit{not} a +switch and must be always immediately followed by the command to be +retrieved. + +For a more general approach use the following tools. + +\begin{desc} +|\newmarkset{<markset>}| +\end{desc} + +A \textit{markset} contains a set of related commands and variables +intended to be emitted simultaneously as marks, so that their values +can be retrieved in heads/foots. A typical \textit{markset} could be +a title and its counter (and perhaps, in a multilingual document, the +active language, i.e., \verb|\languagename| in \textsf{babel}, or an +intermediate command). There is always a special unnamed +\textit{markset} for sectioning marks, which is the main one and +handled with the tools described above (with |title| in their names). + +\begin{desc} +|\newextramark{<markset>}{<macro-name>}|\\ +|\newextramark*{<markset>}{<variable-name>}| +\end{desc} + +Add to a \textit{markset} a command or a variable to be synchronized . +They are identical to \verb|\newtitlemark| and \verb|\newtitlemark*|, +except for the additional parameter with the \textit{markset} name. + +\begin{desc} +|\botextramarks{<markset>} \topextramarks{<markset>}|\\ +|\firstextramarks{<markset>} \nexttopextramarks{<markset>}|\\ +|\outerextramarks{<markset>} \innerextramarks{<markset>}| +\end{desc} + +The \verb|extra| counterparts of the \verb|title| commands described +above, with the same behaviour. For example: +\begin{verbatim} +\newcommand{\lemmatitle}{} +\newcounter{lemma} + +\newmarkset{lemma} +\newextramark{lemma}{\lemmatitle} +\newextramark*{lemma}{lemma} % ie, the counter `lemma' + +\newcommand{\lemma}[1]{% + \renewcommand{\lemmatitle}{#1}% + \stepcounter{lemma}% + \preextramark{lemma}% + \pagebreak[2]% + \vspace{1em}% + \textbf{(\arabic{lemma}) #1}\enspace + \extramark{lemma}} + +\newpagestyle{main}{ + \sethead{} + {\topextramarks{lemma}(\arabic{lemma}) \textbf{\lemmatitle}} + {}} + +\pagestyle{main} +\end{verbatim} + +\begin{desc} +|\settitlemarks*{<level-name>,<sublevel-name>,<subsublevel-name>...}| +\end{desc} + +By default, \LaTeX{} and \textsf{titleps} use a single \textit{markset} for +all sectioning levels. This is problematic, for example, in the +\textsf{article} class, because sections does not start a new page. +Consider the following piece of code: +\begin{verbatim} +\section{A section} +\subsection{A subsection} +\end{verbatim} +On odd pages with first marks and subsection titles, the head has +no title, because \verb|\subsection| is the second mark, not the +first one. + +To overcome this limitation, you can use the starred version of +\verb|\settitlemarks|, which creates parallel \textit{marksets} (one per +level) synchonized with the main \textit{markset}. They are retrieved like +other extra marks, but they are special in that you cannot emit them +by yourself -- they are always emitted by the corresponding +sectioning mark. So, with +\begin{verbatim} +\settitlemarks*{section,subsection} +\end{verbatim} +and a page style containing +\begin{verbatim} +\firstextramarks{subsection}\subsectiontitle +\end{verbatim} +you retrieve the mark emitted by the first \verb|\subsection|, even +if preceded by a \verb|\section|. (Top marks are best retrieved from +the main \textit{markset}.) + +They are extra marks, and therefore language synchronization has to be +done by hand -- add \verb|\languagename| or an intermediate command to +the main \textit{markset} with \verb|\newtitlemark| and, if you want, +define a command. For example: +\begin{verbatim} +% use an intermediate command because we'll need \foreignlanguage +\newcommand\titlelanguage{\languagename} +\newtitlemark{\titlelanguage} + +% define a command to ease defining page styles +\newcommand{\toplang}[1]{% + {\topextramarks{section}% + \foreignlanguage{\titlelanguage}{#1}}} +\end{verbatim} + +\section{A couple of examples} + +Because of the way marks are handled, special constructs like this are +allowed: +\begin{verbatim} +\newpagestyle{main}[\small\sffamily]{ + \sethead[\textbf{\thepage}] + [\textsl{\chaptertitle}] + [[\toptitlemarks\thesection--\bottitlemarks\thesection] + {\toptitlemarks\thesection--\bottitlemarks\thesection]} + {\textsl{\sectiontitle}} + {\textbf{\thepage}}} +\end{verbatim} +As you can see, the range of sections in a page with |\thesection| is +printed in both left and right heads. Of course, this example should +be fine tuned to collapse the ranges if there is a single section in a +page (with |\ifsamemark|), but it gives a hint of how to get stunning +headers. + +In this document, the following styles are used: +\begin{verbatim} +\widenhead{2.1pc}{0pc} +\renewpagestyle{plain}[\small\sffamily\slshape]{ + \footrule + \setfoot{}{\thepage}{}} +\newpagestyle{myps}[\small\sffamily\slshape]{ + \headrule + \sethead{titlesec -- titleps}{\sectiontitle}{\thepage}} +\end{verbatim} + +The following definitions provide page styles similar to those in +Lamport's \textit{The \LaTeX\ book} (with the \textsf{calc} package): +\begin{verbatim} +\widenhead*{0pt}{\marginparsep + \marginparwidth} % symmetrically +\renewpagestyle{plain}{} +\newpagestyle{latex}[\bfseries]{ + \headrule + \sethead[\thepage][][\chaptertitle] + {\thesection\ \sectiontitle}{}{\thepage}} +\pagestyle{latex} +\end{verbatim} + +% \section{Remarks} +% +% Page styles in standard \LaTeX{} are somewhat rudimentary. For +% example |\thispagestyle| is not always correctly synchronized with +% sectioning marks, and if you set |\pagestyle{plain}| and then +% |\thispagestyle{headings}|, its behaviour is not the expected one. +% The same happens if a page style defined in \textsf{titleps} is used +% in a |\thispagestyle| in the context of a standard page style -- you +% have to define the main one as well. + +% \section{Some tips and tricks} +% +% star |\*| +% +% split heads +% +% bible + +\end{document} + +MIT License +----------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + diff --git a/macros/latex/contrib/titlesec/titlesec.pdf b/macros/latex/contrib/titlesec/titlesec.pdf Binary files differnew file mode 100644 index 0000000000..bf4525f3e9 --- /dev/null +++ b/macros/latex/contrib/titlesec/titlesec.pdf diff --git a/macros/latex/contrib/titlesec/titlesec.sty b/macros/latex/contrib/titlesec/titlesec.sty new file mode 100644 index 0000000000..f1f943fd21 --- /dev/null +++ b/macros/latex/contrib/titlesec/titlesec.sty @@ -0,0 +1,1708 @@ +% +% Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com +% +% This file may be distributed and/or modified under the conditions of +% the MIT License. A version can be found at the end of this file. +% +% Repository: https://github.com/jbezos/titlesec +% +% Notes +% ~~~~~ +% +% The following tags are used: +% ttl@ : the generic tag used through the style +% ttlh@ : a shape definition +% ttlf@ : a macro containing the title format +% ttls@ : id. the title space +% ttlp@ : page key related macros +% ttll@ : level number +% +% The ttlf@ and ttls@ contains data in the form {..}{..}. +% Perhaps in future releases they should be converted +% to a prop-like list, similar to that proposed by the +% latex team. +% +% Admittedly, the current implementation seems too +% complicated, but that's necessary in order to provide +% certain compatibility with the sections as defined by the +% used class. Other packages opt for providing the sections +% as defined by standard classes ignoring the class; for +% instance sectsty which does a simple task in a simple and +% nice way. However, that was not my goal. +% +% Release +% ~~~~~~~ + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{titlesec}[2019/07/16 v2.11 Sectioning titles] + +% Initialization +% ~~~~~~~~~~~~~~ + +\newif\ifttl@ps +\ttl@psfalse + +% The \ttl@label switch is used when printing the label in titles. +% A numberless variant makes it to true. +% There is a \ttl@toclabel as well, which is true iff the +% title is numbered; used in toc entries (except default part +% and chapter) and marks (only in titlesec pagestyles). + +\newif\ifttl@label +\newif\ifttl@toclabel + +\newbox\ttl@box + +% A provision for the report style: + +\@ifundefined{if@mainmatter} + {\let\if@mainmatter\iftrue}{} + +\@ifundefined{if@openright} + {\let\if@openright\iftrue}{} + +% and the ams styles as well + +\@ifundefined{@chapapp} + {\let\@chapapp\chaptername}{} + +\def\ttl@trylist{\ttl@try{}} + +\def\ttl@getkeys#1#2{% + \if\expandafter @\@gobble#1@\@empty + \edef\ttl@b{\expandafter\@gobble\string#1}% + \let\ttl@a\ttl@b + \else + \ttl@keys + \ttl@getkeys{#1}{#2}% + \fi} + +% A more meaningful error for \@notdefinable + +\expandafter\AtEndOfPackage\expandafter{\expandafter + \gdef\expandafter\@notdefinable\expandafter{\@notdefinable}} + +\def\@notdefinable{% + \PackageError{titlesec}% + {Incompatible package}% + {Titlesec cannot continue defining its own macros + because\MessageBreak + \@backslashchar\reserved@a\space is already used by other package, + the class\MessageBreak + or the document.}} + +% +-----------------+ +% | C L A S S E S | +% +-----------------+ + +\def\ttl@useclass#1#2{% + \@ifstar + {\ttl@labelfalse#1{#2}[]}% + {\ttl@labeltrue\@dblarg{#1{#2}}}} + +\def\ttl@straightclass{\ttl@useclass\ttl@straight@i} +\def\ttl@partclass{\ttl@useclass\ttl@part@i} +\def\ttl@topclass{\ttl@useclass\ttl@top@i} +\def\ttl@pageclass{\ttl@useclass\ttl@page@i} + +% Here \scantokens is used to make sure the unescaped name +% has `letters' and no `others'. Mainly for hyperref, so there +% should be no problems. + +\newcommand\titleclass[1]{% + \edef\ttl@a{\expandafter\@gobble\string#1}% + \ifx\scantokens\@undefined\else + \scantokens\expandafter{\expandafter + \def\expandafter\ttl@a\expandafter{\ttl@a}}% + \fi + \@ifnextchar[{\@tempswatrue\ttl@class@i{#1}}% + {\@tempswafalse\ttl@class@ii{#1}}} + +\def\ttl@class@i#1[#2]{% + \@namedef{ttll@\ttl@a}{#2}% + \expandafter\providecommand\csname\ttl@a title\endcsname{}%%%% + \@ifundefined{ttl@toplevel}{}% + {\expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname + \csname ttlss@\ttl@toplevel\endcsname}% + \edef\ttl@toplevel{\ttl@a}% + \ttl@class@ii{#1}} + +\def\ttl@class@ii#1#2{% + \@ifundefined{ttl@#2class}% + {\PackageError{titlesec}{Unknown sectioning class}% + {Valid names are top, page and straight}}% + {\expandafter\let\csname ttl@compat\ttl@a\endcsname\relax + \@ifundefined{\ttl@a mark}% + {\@namedef{\ttl@a mark}{\@gobble}}% + {}% + \edef#1{% + \expandafter\noexpand\csname ttl@#2class\endcsname{\ttl@a}}}% + \if@tempswa + \expandafter\@gobble + \else + \expandafter\@firstofone + \fi + {\@ifnextchar[% + {\ttl@class@iii}% + {\@ifundefined{ttll@\ttl@a}% + {\PackageError{titlesec}{Unknown sectioning level}% + {\string\titleclass\space with no optional arguments\MessageBreak + only changes the class of an *existing* level}}}}} + +\def\ttl@class@iii[#1]{% + \edef\ttl@b{\expandafter\@gobble\string#1}% + \expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname + \csname ttlss@\ttl@b\endcsname + \expandafter\edef\csname ttlss@\ttl@b\endcsname{\ttl@a}% + \let\ttl@a\ttl@toplevel + \count@\csname ttll@\ttl@toplevel\endcsname + \ttl@class@iv} + +\def\ttl@class@iv{% + \@ifundefined{ttlss@\ttl@a}{}% + {\advance\count@\@ne + \edef\ttl@a{\csname ttlss@\ttl@a\endcsname}% + \expandafter\edef\csname ttll@\ttl@a\endcsname{\the\count@}% + \ttl@class@iv}} + +% Typesetting Classes: General tools +% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +% The following command handles the *n spacing +% Some tricks are necessary to multiply a +% skip by a non integer number + +\newskip\beforetitleunit +\beforetitleunit=1ex\@plus.3ex\@minus.06ex +\newskip\aftertitleunit +\aftertitleunit=1ex\@plus.1ex + +\newdimen\ttl@plus +\newdimen\ttl@minus + +\def\ttl@assign#1{% + \@ifstar + {\ttl@assign@i{#1}}% + {\ttl@assign@d{#1}}} + +\def\ttl@assign@i#1#2\relax#3{% + \ttl@plus\z@ + \ttl@minus\z@ + \afterassignment\ttl@assign@ii + \dimen@\the#3, % <- space + #1 = #2\dimen@ + plus #2\ttl@plus + minus #2\ttl@minus} + +\def\ttl@assign@ii#1 {% <- space + \if#1,\else\afterassignment\ttl@assign@ii\fi + \csname ttl@\string#1\endcsname} + +\def\ttl@assign@d#1#2\relax#3{\setlength#1{#2}} + +% To be used with \v/vspace to make them calc-savvy + +\def\ttl@calc#1#2{% + {\setlength\@tempskipa{#2}% + #1\@tempskipa}} + +\def\ttl@calcneg#1#2{% + {\setlength\@tempskipa{#2}% + #1{-\@tempskipa}}} + +% Gets from ttls@ and passes the spacing parameters: + +\def\ttl@startargs#1#2{% Get the first arguments, with the spacing + \@ifundefined{ttlp@#2}% + {\let\ttl@key@page\@empty}% + {\ttlp@fetch{#2}}% + \begingroup + \def\ttl@b{ttls@#2}% + \edef\ttl@key@numberless{\ifttl@label//\else/*\fi}% + \def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try + \ttl@trylist + \xdef\ttl@b{\ttl@c}% + \endgroup + \ifx\ttl@b\@empty + \PackageError{titlesec}{Format/spacing not found}% + {I was unable to find the format corresponding to #2.\MessageBreak + Maybe you haven't set it with \string\titleformat\space and + \string\titlespacing} + \fi + \expandafter#1\ttl@b{#2}} + +% Used in ttl@select + +\def\ttl@savefn#1[#2]#3{% + \ifcase#1% + \footnotemark[#2]% + \gdef\ttl@fn{\footnotetext[#2]{#3}}% + \else + \footnotemark + \gdef\ttl@fn{\footnotetext{#3}}% + \fi} + +\def\ttl@nest@error{% + \PackageError{titlesec}{Nested titles}{Titles must not be nested}} + +\def\ttl@hmode@error{% + \PackageError{titlesec}{Entered in horizontal mode} + {The <format> argument cannot contain horizontal material\MessageBreak + such as text, \string\noindent, \string\makebox, etc.}} + +% \ttl@select not only selects the right version to be +% used. It also take steps to ensure that a mark +% is not lost inside a box by saving it into \ttl@mk, +% which in turn is used by the sect and chap commands. + +\newif\ifttl@explicit + +\def\ttl@gmk#1{\gdef\ttl@mk{#1}} + +\def\ttl@select#1#2#3#4{% + \ttl@Hy@saveanchor + \global\let\ttl@mk\@empty % global because of rigidchapters + \global\let\ttl@fn\@empty + \begingroup + \if@inlabel\else % Keep item's \everypar + \everypar{\setbox\z@\lastbox\ttl@strut}% + \fi + \let\ttl@straight@i\ttl@nest@error + \let\ttl@top@i \ttl@nest@error + \let\ttl@part@i \ttl@nest@error + \let\ttl@page@i \ttl@nest@error + \let\ttl@newpage\newpage + \def\newpage{\ttl@savewrite\ttl@newpage}% + \def\markboth##1##2{\protect\ttl@gmk{\protect\markboth{##1}{##2}}}% + \def\markright##1{\protect\ttl@gmk{\protect\markright{##1}}}% + \def\@mkboth##1##2{\protect\ttl@gmk{\protect\@mkboth{##1}{##2}}}% + \def\footnote{\@ifnextchar[% + {\ttl@savefn\z@}{\ttl@savefn\@ne[]}}% + \edef\ttl@key@numberless{\ifttl@label//\else/*\fi}% + \def\ttl@b{ttlf@#1}% + \def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try + \ttl@trylist + \ifttl@explicit + \def\ttl@passexplicit{\ttl@case{#4}}% + \ttl@c{#4}{#2}{#3}{}% ttl@c is returned by ttl@try with ttlf@... + \else + \let\ttl@passexplicit\ttl@case + \ttl@c{#2}{#3}{#4}% ttl@c is returned by ttl@try with ttlf@... + \fi + \endgroup} + +\let\ttl@savewrite\@empty + +\def\ttl@finmarks{% + \ttl@savewrite + \ttl@mk % Contains a possible mark, returned by \ttl@select + \ttl@fn} % And a footnote + +\def\ttl@try#1{% + \edef\ttl@c{#1}% #1 is a list in the form \ttl@a{key}\ttl@a{key} + \@ifundefined{\ttl@b\ttl@c}{}{% + \edef\ttl@c{\expandafter\noexpand\csname\ttl@b\ttl@c\endcsname}% + \def\ttl@a##1{\csname ttl@extra@##1\endcsname}% + #1% + \let\ttl@try\@gobble}} % locally modified to `break' testings + +% \ttl@write writes marks and toc. tocdepth is taken care of when +% the toc is typesetted and not here. Used always through +% ttl@savewrite, which is reset to \@empty to avoid duplicated +% calls. + +\def\ttl@write#1#2{% + \ttl@blinemarks + \csname#1mark\endcsname{#2}% + \def\ttl@a{\protect\numberline{\@nameuse{the#1}}}% + \@nameuse{ttl@toc#1}% eg, \ttl@tocpart modifies \ttl@a + \ttl@addcontentsline{#1}{#2}% Depends on toctitles, uses \ttl@a + \ttl@elinemarks + \global\ttl@toclabelfalse + \global\let\ttl@savewrite\@empty} + +\newif\ifttl@premark % to be used in ttlps.def +\ttl@premarkfalse + +% 2019-06-20. Added the \lastskip stuff, because a mark 'forgets' the +% last skip. + +\def\ttl@premark#1#2{% + \let\ttl@lastskip\relax + \ifvmode + \ifdim\lastskip=\z@\else + \edef\ttl@lastskip{\the\lastskip}% + \vskip-\ttl@lastskip\relax + \fi + \fi + \protected@xdef\ttl@prevmarks{\ttl@marks}% + \ttl@blinemarks + \csname#1mark\endcsname{#2}% + \ttl@elinemarks + \ifx\ttl@lastskip\relax\else + \vskip\ttl@lastskip\relax + \fi + \gdef\ttl@prevmarks{\ttl@marks}} + +% Must be preceded by a default \ttl@savewrite, which is used +% in starred variants--\@empty in top and straight classes. +% In straight class, it is preceded by the setting of +% prev marks to provide a "fixed" top mark. Otherwise, +% the default prev mark (= curr mark) is used (restored +% after ttl@labelling in straight). This is the command +% to be hacked if you want to change the behaviour of +% starred variants. + +\def\ttl@labelling#1#2{% + \let\ttl@Hy@saveanchor\@empty + \ifttl@label % 1st - if star + \def\ttl@savewrite{\ttl@write{#1}{#2}}% + \@nameuse{ttl@#1label}% eg, sets if mainmatter in chapter. + \ifttl@label % 2nd - eg, if not main matter + \ifnum\@nameuse{ttll@#1}>\c@secnumdepth\relax + \ttl@labelfalse % 3rd - if too deep + \else + \ttl@Hy@refstepcounter{#1}% + \@nameuse{ttl@#1out}% + \fi + \fi + \fi + \let\ifttl@toclabel\ifttl@label + \ifx\ttl@savewrite\@empty\else % If marks + \ifttl@ps + \ifttl@premark + \global\ttl@premarkfalse + \else % if no \pretitlemark + \ttl@premark{#1}{#2}% + \fi + \fi + \ifttl@label\else\ttl@Hy@steplink{#1}\fi + \fi} + +% Executed by ttl@labelling if the name of section is chapter: + +\def\ttl@chapterlabel{\if@mainmatter\else\ttl@labelfalse\fi} + +% Executed by ttl@labelling if chapter has a number. Note +% you can define messages for other sectioning levels (eg, +% \ttl@sectionout). + +\def\ttl@chapterout{\typeout{\chaptertitlename\space\thechapter.}} + +% Straight class +% ~~~~~~~~~~~~~ +% Default for nobottomtitles. Changed by nobottomtitles* + +\def\ttl@addstretch{\advance\@tempskipa-\pagestretch} + +% 1:name 2:level 3:indent 4:before 5:after 6:afind [7]:cap 8:title +% The second argument of ttl@sect is the level, which +% is empty if the star version is used. In this case +% neither the toc nor the marks are written. + +\def\ttl@straight@i#1[#2]#3{% + \def\@currentlabelname{#2}% for nameref + \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}% + \let\ttl@savewrite\@empty + \def\ttl@savetitle{#3}% + \gdef\thetitle{\csname the#1\endcsname}% + \if@noskipsec \leavevmode \fi + \par + \ttl@labelling{#1}{#2}% + \ttl@startargs\ttl@straight@ii{#1}{#3}} + +% 1:left 2:right 3:before 4:after 5:afterindent 6:name 7:title + +\def\ttl@straight@ii#1#2#3#4#5#6#7{% + \ttl@assign\@tempskipa#3\relax\beforetitleunit + \@ifundefined{ttl@ps@#6}{}% + {\PackageWarning{titlesec}{Page style in straight class ignored}}% + \if@nobreak + \ttl@titlespace{\@tempskipa}% + \else + \@ifundefined{#6break}% + {\addpenalty{\@secpenalty}}% + {\csname#6break\endcsname}% + \addvspace{\@tempskipa}% + \ifdim\bottomtitlespace<\z@ + \else + \begingroup + \@tempskipb\pagegoal + \@tempskipa\pagegoal + \ttl@addstretch % \relax if nobottomtitle* + \advance\@tempskipa-\bottomtitlespace\relax % not a register + \pagegoal\@tempskipa + \def\@textbottom{\vskip\z@\@plus.0001fil}% + \penalty9999 + \pagegoal\@tempskipb + \endgroup + \fi + \fi + \@afterindenttrue + \ifcase#5 \@afterindentfalse\fi + \ttl@assign\@tempskipb#4\relax\aftertitleunit + \ttl@select{#6}{#1}{#2}{#7}% + \ttl@finmarks + \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}% + \if@noskipsec + \global\@nobreakfalse + \everypar{% + \if@noskipsec + \global\@noskipsecfalse + \clubpenalty\@M + \hskip-\parindent + \begingroup + \@svsechd\unskip{\hspace{\@tempskipb}}% + \endgroup + \else + \clubpenalty\@clubpenalty\everypar{}% + \fi}% + \else + \par\nobreak + \vspace{\@tempskipb}% + \@afterheading + \fi + \ignorespaces} + +% Part class +% ~~~~~~~~~~ + +\providecommand\partmark[1]{\markboth{}{}} + +\def\ttl@part@i#1[#2]#3{% + \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}% + \ifx\ttl@notocparts\@undefined + \def\ttl@savewrite{\ttl@write{#1}{#3}}% Not #2! + \else + \let\ttl@savewrite\@empty + \fi + \def\ttl@savetitle{#3}% + \ttl@labelling{#1}{#2}% + \ttl@startargs\ttl@part@ii{#1}{#3}} + +\def\ttl@part@ii#1#2#3#4#5#6#7{% + \ttl@assign\@tempskipa#3\relax\beforetitleunit + \vspace*{\@tempskipa}% + \@ifundefined{ttl@ps@#6}{}% + {\PackageWarning{titlesec}{Page style in part class ignored}}% + \global\@afterindenttrue + \ifcase#5 \global\@afterindentfalse \fi + \ttl@assign\@tempskipb#4\relax\aftertitleunit + \ttl@select{#6}{#1}{#2}{#7}% + \ttl@finmarks + \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}% + \par\nobreak + \vspace{\@tempskipb}% + \@afterheading} + +% Page class +% ~~~~~~~~~~ + +\def\ttl@page@i#1[#2]#3{% + \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}% + \ifx\ttl@notocparts\@undefined + \def\ttl@savewrite{\ttl@write{#1}{#3}}% Not #2! + \else + \let\ttl@savewrite\@empty + \fi + \def\ttl@savetitle{#3}% + \ttl@labelling{#1}{#2}% + \ttl@startargs\ttl@page@ii{#1}{#3}} + +\def\ttl@page@ii#1#2#3#4#5#6#7{% + \ttl@assign\@tempskipa#3\relax\beforetitleunit + \if@openright + \cleardoublepage + \else + \clearpage + \fi + \@ifundefined{ttl@ps@#6}% + {\thispagestyle{plain}}% + {\thispagestyle{\@nameuse{ttl@ps@#6}}}% + \if@twocolumn + \onecolumn + \@tempswatrue + \else + \@tempswafalse + \fi + \vspace*{\@tempskipa}% + \@afterindenttrue + \ifcase#5 \@afterindentfalse\fi + \ttl@assign\@tempskipb#4\relax\aftertitleunit + \ttl@select{#6}{#1}{#2}{#7}% + \ttl@finmarks + \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}% + \vspace{\@tempskipb}% + \newpage + \if@twoside + \if@openright + \null + \@ifundefined{ttl@ps@#6}% + {\thispagestyle{empty}}% + {\thispagestyle{\@nameuse{ttl@ps@#6}}}% + \newpage + \fi + \fi + \if@tempswa + \twocolumn + \fi + \ignorespaces} + +% Top class and some makechapterhead stuff +% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +% +% \ttl@mkchap is the new make(s)chapterhead. + +\def\ttl@mkchap#1#2#3#4#5#6#7{% + \gdef\ttl@savemark{\csname#6mark\endcsname{#7}}% + \let\ttl@savewrite\@empty + \let\ttl@Hy@saveanchor\@empty + \@ifundefined{ttl@ps@#6}{}% + {\thispagestyle{\@nameuse{ttl@ps@#6}}}% + \let\ifttl@toclabel\ifttl@label + \ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}} + +% But \ttl@mkchap@i is used by both makechapterhead and +% the top class. + +\def\ttl@mkchap@i#1#2#3#4#5#6#7{% + \ttl@assign\@tempskipa#3\relax\beforetitleunit + \vspace*{\@tempskipa}% + \global\@afterindenttrue + \ifcase#5 \global\@afterindentfalse\fi + \ttl@assign\@tempskipb#4\relax\aftertitleunit + \ttl@topmode{\@tempskipb}{% + \ttl@select{#6}{#1}{#2}{#7}}% + \ttl@finmarks % Outside the box! + \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}} + +\def\ttl@top@i#1[#2]#3{% + \gdef\ttl@savemark{\csname#1mark\endcsname{#3}}% + \let\ttl@savewrite\@empty + \def\ttl@savetitle{#3}% + \ttl@labelling{#1}{#2}% + \ttl@startargs\ttl@top@ii{#1}{#3}} + +\def\ttl@top@ii#1#2#3#4#5#6#7{% + \@ifundefined{#6break}% + {\if@openright + \cleardoublepage + \else + \clearpage + \fi}% + {\csname#6break\endcsname}% + \@ifundefined{ttl@ps@#6}% + {\thispagestyle{plain}}% + {\thispagestyle{\@nameuse{ttl@ps@#6}}}% + \global\@topnum\z@ + \@ifundefined{#6tolists}% + {\addtocontents{lof}{\protect\ttl@tocsep}% + \addtocontents{lot}{\protect\ttl@tocsep}} + {\@nameuse{#6tolists}}% + \if@twocolumn + \@topnewpage[\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}]% + \else + \ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}% + \@afterheading + \fi + \ignorespaces} + +% \def\ttl@noskipsectrue{% +% \if@noskipsec +% \PackageError{titlesec}{Invalid shape for top class}% +% {The selected shape only makes sense when merged into\MessageBreak +% a paragraph. That is impossible in the top class}% +% \else + +\newcommand\chaptertitlename{\@chapapp} +\def\ttl@tocsep{\addvspace{10\p@}} + +% +-----------------+ +% | S H A P E S | +% +-----------------+ +% +% Reformatting Titles: Interface +% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +% The surrounding space is stored in a macro +% named \ttls@<section> whose content is +% {left}{right}{before}{after}{afterindent}. +% But if there is the page key, the name is +% \ttls@<section>/<page> + +\newcommand\titlespacing{% + \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\@ne}}} + +\def\ttl@spacing@i#1#2#3#4#5{% + \ttl@getkeys{#2}{titlesec}% + \@ifnextchar[{% + \ttl@spacing@ii{#1}{#3}{#4}{#5}% + }{% + \ttl@spacing@ii{#1}{#3}{#4}{#5}[\z@]}} + +\def\ttl@spacing@ii#1#2#3#4[#5]{% + \expandafter\def\csname ttls@\ttl@a\endcsname + {{#2}{#5}{#3}{#4}{#1}}} + +% The section name is built in \ttl@a. +% The format is stored in a macro named \ttlf@<section>, +% or \ttlf@<section>/<page> if there is the page spec, +% or \ttlf@.../* if numberless is true +% whose content is +% \ttl@<shape>{format}{label}{sep}{before}{after} + +\newtoks\ttl@toksa + +\newcommand\titleformat{% + \@ifstar{\ttl@format@s}% + {\ttl@format@i}} + +\def\ttl@format@s#1#2{% + \edef\ttl@a{\expandafter\@gobble\string#1}% + \@ifundefined{ttlf@\ttl@a}% + {\PackageError{titlesec}{Not allowed in `easy' settings} + {The sectiong command you are trying to redefine\MessageBreak + is not handled by the starred variant (eg, \string\part)}}{} + \expandafter\expandafter\expandafter + \ttl@format@si\csname ttlf@\ttl@a \endcsname + {#2}} + +\def\ttl@format@si#1#2#3#4#5#6#7{% + \@namedef{ttlf@\ttl@a}{#1{#7}{#3}{#4}{#5}{#6}}} + +\def\ttl@format@i#1{% + \@ifnextchar[{\ttl@format@ii{#1}}{\ttl@format@ii{#1}[hang]}} + +\def\ttl@format@ii#1[#2]#3#4#5#6{% + \ttl@getkeys{#1}{titlesec}% + \ttl@toksa{{#3}{#4}{#5}{#6}}% Save arguments + \@ifnextchar[{% + \ttl@format@iii{#2}% + }{% + \ttl@format@iii{#2}[]}} + +% First, we get the shape -- if not defined it loads +% the corresponding file. + +\def\ttl@format@iii#1[#2]{% + \@ifundefined{ttlh@#1}{% + \begingroup + \makeatletter + \InputIfFileExists{#1.tss}{}{% + \@ifundefined{ttlhx@#1}% + {\PackageError{titlesec}{Unknown shape}% + {Shapes are defined in files with extension tss\MessageBreak + Either you have misspelled the shape\MessageBreak + or there is no a #1.tss file}}% + {\global\expandafter + \let\csname ttlh@#1\expandafter\endcsname + \csname ttlhx@#1\endcsname}}% + \endgroup}{}% + \@temptokena{#2}% + \ifttl@explicit + \edef\ttl@b{% + \def\expandafter\noexpand\csname ttlf@\ttl@a\endcsname####1% + {\expandafter\noexpand\csname ttlh@#1\endcsname + \the\ttl@toksa{\the\@temptokena}}}% + \else + \edef\ttl@b{% + \def\expandafter\noexpand\csname ttlf@\ttl@a\endcsname + {\expandafter\noexpand\csname ttlh@#1\endcsname + \the\ttl@toksa{\the\@temptokena}}}% + \fi + \ttl@b + \csname ttl@compat\ttl@a\endcsname} + +% Styles +% ~~~~~~ + +% 1:global 2:label 3:sep 4:style 5:after 6:left 7:right 8:title +% \ttl@<shape> and \ttlh@<shape> take the following eight +% arguments: +% {format}{label}{sep}{before}{after}{left}{right}{title} +% where before and after refer to the format. +% With the option explicit, #4 contains the title and #8 is +% empty. + +\def\ttl@strut{\strut} + +\def\ttlh@display#1#2#3#4#5#6#7#8{% + \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}% + \setlength\leftskip{#6}% + \setlength\rightskip{#7}% + \interlinepenalty\@M + \ttl@changecentercr + \ttl@defnostruts + \ttl@beginlongest + #1\ifhmode\ttl@hmode@error\fi + \ttl@glcmds + \parindent\z@ + \ifttl@label + {#2\ttl@strut\@@par}\nobreak\ttl@calc\vspace{#3}% + \fi + #4{#8}% + \kern\z@\ttl@strut\@@par + \nobreak\ttl@midlongest#5\@@par + \ttl@endlongest} + +\def\ttlh@hang#1#2#3#4#5#6#7#8{% + \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}% + \setlength\leftskip{#6}% + \setlength\rightskip{#7}% + \interlinepenalty\@M + \ttl@changecentercr + \ttl@defnostruts + \ttl@beginlongest + #1{\ifhmode\ttl@hmode@error\fi + \ttl@glcmds + \parindent\z@ + \begingroup + \ifttl@label + \noindent + \sbox\z@{#2\ttl@strut\ttl@calc\hspace{#3}}% + \hangindent\wd\z@ + \box\z@ + \fi + #4{#8}% + \kern\z@\ttl@strut\@@par + \endgroup + \nobreak\ttl@midlongest#5\@@par}% + \ttl@endlongest} + +\def\ttlh@runin#1#2#3#4#5#6#7#8{% + \global\@noskipsectrue + \gdef\ttl@makeline##1{##1}% + \ttl@changecentercr + \ttl@defnostruts + #1{\ifhmode\ttl@hmode@error\fi + \global\sbox\ttl@box{% + \ttl@calc\hspace{#6}% + \ifttl@label{\ttl@strut#2}\ttl@calc\hspace{#3}\fi + #4{#8}#5\unskip}}% + \gdef\@svsechd{\unhbox\ttl@box}} + +% ---------- + +\gdef\ttlhx@block#1#2#3#4#5#6#7#8{% + \gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}% + \setlength\leftskip{#6}% + \setlength\rightskip{#7}% + \interlinepenalty\@M + \ttl@changecentercr + \ttl@defnostruts + \ttl@beginlongest + #1% \ifhmode\ttl@hmode@error\fi + \ttl@glcmds + \parindent\z@ + \leavevmode + \ifttl@label + {#2}% + \setlength\@tempskipa{#3}% + \ifdim\@tempskipa=\z@\else\ttl@calc\hspace{#3}\fi + \fi + #4{#8}% + \kern\z@\ttl@strut\@@par + \nobreak\ttl@midlongest#5\@@par + \ttl@endlongest} + + +\gdef\ttlhx@frame#1#2#3#4#5#6#7#8{% + \def\ttl@filleft##1{\hfill}% + \def\ttl@filright##1{\hfill}% + \gdef\ttl@makeline##1{% + \ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}% + \interlinepenalty\@M + \ttl@changecentercr + \ttl@defnostruts + #1\ifhmode\ttl@hmode@error\fi + \parindent\z@ + \leavevmode + \@tempdima\fboxrule + \addtolength\@tempdima{#3}% + \setlength\leftskip{#6}% + \setlength\rightskip{#7}% + \lower\@tempdima\hbox{% + \everypar{}% + \setbox\z@\hbox{#2}% + \addtolength\hsize{-#6}% + \addtolength\hsize{-#7}% + \@tempdima\dp\z@ % 2002/3/22 + \advance\@tempdima.5\ht\z@ + \vbox{% + \hbox to \hsize{% + \leaders\hrule\@height\fboxrule\ttl@filleft{#3}% + \ifttl@label\lower.5\ht\z@\box\z@\fi + \leaders\hrule\@height\fboxrule\ttl@filright{#3}}% + \vskip-\lineskip + \ifttl@label\vskip-\@tempdima\fi + \hbox{% + \vrule\@width\fboxrule + \kern-\fboxrule + \vbox{% + \ttl@calc\vspace{#3}% + \leavevmode + \addtolength\leftskip {#3}\addtolength\leftskip{-#6}% + \addtolength\rightskip{#3}\addtolength\rightskip{-#7}% + \ttl@strut#4{#8}\kern\z@\ttl@strut\@@par + \ttl@calc\vspace{#3}}% + \kern-\fboxrule + \vrule\@width\fboxrule}% + \hrule\@height\fboxrule}}% + \@@par\nobreak#5\@@par} + +\gdef\ttlhx@leftmargin#1#2#3#4#5#6#7#8{% + \global\@noskipsectrue + \addtolength\@tempskipb{#6}% + \xdef\ttl@makeline##1{\hskip-\the\@tempskipb\relax##1}% + \leftskip\z@skip + \rightskip\z@skip + \ttl@changecentercr + \ttl@defnostruts + #1\ifhmode\ttl@hmode@error\fi + \parindent\z@ + \global\setbox\ttl@box\vtop{% + \setlength\hsize{#6}% + \linewidth\hsize + \everypar{}% + \color@begingroup + \ifttl@label{\ttl@strut#2\ttl@strut}\ttl@calc\hspace{#3}\fi + \ttl@strut#4{#8}\kern\z@\ttl@strut\@@par + \color@endgroup}% + \advance\@tempskipa\ht\ttl@box + \advance\@tempskipa\dp\ttl@box + \advance\@tempskipa-\pagegoal + \advance\@tempskipa\pagestretch + \@tempskipb\pagegoal + \pagegoal-\@tempskipa + \ifdim\bottomtitlespace<\z@\else + \def\@textbottom{\vskip\z@\@plus.0001fil}% + \fi + \penalty9999 + \pagegoal\@tempskipb + \dp\ttl@box=\z@ + \gdef\@svsechd##1##2{% + \llap{\box\ttl@box##2}% + \if@afterindent\hskip\parindent\fi + #5}} + +\let\ttlhx@margin\ttlhx@leftmargin + +\gdef\ttlhx@rightmargin#1#2#3#4#5#6#7#8{% + \global\@noskipsectrue + \addtolength\@tempskipb{#6}% + \xdef\ttl@makeline##1{##1\hskip-\the\@tempskipb}% + \leftskip\z@skip + \rightskip\z@skip + \ttl@changecentercr + \ttl@defnostruts + #1\ifhmode\ttl@hmode@error\fi + \parindent\z@ + \global\setbox\ttl@box\vtop{% + \setlength\hsize{#6}% + \linewidth\hsize + \everypar{}% + \color@begingroup + \ifttl@label{\ttl@strut#2\ttl@strut}\ttl@calc\hspace{#3}\fi + \ttl@strut#4{#8}\kern\z@\ttl@strut\@@par + \color@endgroup}% + \advance\@tempskipa\ht\ttl@box + \advance\@tempskipa\dp\ttl@box + \advance\@tempskipa-\pagegoal + \advance\@tempskipa\pagestretch + \@tempskipb\pagegoal + \pagegoal-\@tempskipa + \ifdim\bottomtitlespace<\z@\else + \def\@textbottom{\vskip\z@\@plus.0001fil}% + \fi + \penalty9999 + \pagegoal\@tempskipb + \dp\ttl@box=\z@ + \gdef\@svsechd##1##2{% + \rlap{\hskip\textwidth##2\box\ttl@box}% + \if@afterindent\hskip\parindent\fi}} + +\gdef\ttlhx@wrap#1#2#3#4#5#6#7#8{% + \global\@noskipsectrue + \gdef\ttl@makeline##1{##1}% + \ttl@changecentercr + \ttl@defnostruts + \begingroup + #1\ifhmode\ttl@hmode@error\fi + \titlewidth\z@ + \def\\{\@ifstar{\@ifnextchar[{\ttl@bs}{\newline}}% + {\@ifnextchar[{\ttl@bs}{\newline}}}% + \def\ttl@bs[##1]{\newline}% + \let\@centercr\\% + \advance\rightskip 1\leftskip plus 1fil + \leftskip=\z@ + \parindent\z@ + \let\iftitlemeasuring\@firstoftwo + \global\setbox\ttl@box\vtop{\setlength\hsize{#6}% + \color@begingroup + \ifttl@label{#2}\ttl@calc\hspace{#3}\fi + #4{#8}\kern\z@\ttl@strut + \@@par + \color@endgroup}% + \let\iftitlemeasuring\@secondoftwo + \ttl@boxprocess + \global\titlewidth\titlewidth + \global\titlewidthfirst\titlewidthfirst + \global\titlewidthlast\titlewidthlast + \endgroup + \edef\ttl@maxdimen{\the\titlewidth}% + #1\ifhmode\ttl@hmode@error\fi + \global\setbox\ttl@box\vtop{\setlength\hsize{\ttl@maxdimen}% + \color@begingroup + \ifttl@label{#2}\ttl@calc\hspace{#3}\fi#4{#8}\kern\z@\ttl@strut + \@@par + \color@endgroup}% + \advance\@tempskipa1.5\baselineskip + \advance\@tempskipa\ht\ttl@box + \advance\@tempskipa\dp\ttl@box + \advance\@tempskipa-\pagegoal + \advance\@tempskipa\pagestretch + \@tempskipb\pagegoal + \pagegoal-\@tempskipa + \ifdim\bottomtitlespace<\z@\else + \def\@textbottom{\vskip\z@\@plus.0001fil}% + \fi + \penalty9999 + \pagegoal\@tempskipb + \@tempdima\ht\ttl@box \advance\@tempdima\dp\ttl@box + \@tempdimb\@tempdima + \divide\@tempdima\baselineskip \count@\@tempdima + \advance\count@ + \ifdim\@tempdimb<\the\count@.5\baselineskip\@ne\else\tw@\fi + \dp\ttl@box=\z@ + \xdef\@svsechd##1##2{% + \noexpand\llap{\box\ttl@box##2}% + \setbox\z@\hbox{\hskip\ttl@maxdimen\relax##2}% + \global\hangindent\wd\z@ + \global\hangafter-\the\count@\relax}} + +\gdef\ttlhx@drop#1#2#3#4#5#6#7#8{% + \global\@noskipsectrue + \gdef\ttl@makeline##1{##1}% + \ttl@changecentercr + \ttl@defnostruts + #1\ifhmode\ttl@hmode@error\fi + \parindent\z@ + \global\setbox\ttl@box\vtop{\setlength\hsize{#6}% + \color@begingroup + \ifttl@label{#2}\ttl@calc\hspace{#3}\fi + #4{#8}\kern\z@\ttl@strut + \@@par + \color@endgroup}% + \advance\@tempskipa1.5\baselineskip + \advance\@tempskipa\ht\ttl@box + \advance\@tempskipa\dp\ttl@box + \advance\@tempskipa-\pagegoal + \advance\@tempskipa\pagestretch + \@tempskipb\pagegoal + \pagegoal-\@tempskipa + \ifdim\bottomtitlespace<\z@\else + \def\@textbottom{\vskip\z@\@plus.0001fil}% + \fi + \penalty9999 + \pagegoal\@tempskipb + \@tempdima\ht\ttl@box \advance\@tempdima\dp\ttl@box + \@tempdimb\@tempdima + \divide\@tempdima\baselineskip \count@\@tempdima + \advance\count@ + \ifdim\@tempdimb<\the\count@.5\baselineskip\@ne\else\tw@\fi + \dp\ttl@box=\z@ + \xdef\@svsechd##1##2{% + \noexpand\llap{\box\ttl@box##2}% + \setbox\z@\hbox{\noexpand\ttl@calc\noexpand\hspace{#6}\relax##2}% + \global\hangindent\wd\z@ + \global\hangafter-\the\count@\relax}} + +% +-----------------+ +% | T O O L S | +% +-----------------+ +% +% calcwidth +% ~~~~~~~~~ +% Implemented after code from soul (but much modified...) + +\newdimen\titlewidth +\newdimen\titlewidthlast +\newdimen\titlewidthfirst + +\let\ttl@glcmds\relax +\let\ttl@beginlongest\@empty +\let\ttl@midlongest\@empty +\let\ttl@endlongest\@empty +\let\iftitlemeasuring\@secondoftwo + +\def\ttl@xbeginlongest#1\ttl@endlongest{% + \titlewidth\z@ + \titlewidthlast\z@ + \let\iftitlemeasuring\@firstoftwo + \setbox\ttl@box\vbox{% + \def\ttl@glcmds{% + \def\\{\@ifstar{\@ifnextchar[{\ttl@bs}{\newline}}% + {\@ifnextchar[{\ttl@bs}{\newline}}}% + \def\ttl@bs[####1]{\newline}% + \let\@centercr\\% + \def\ttl@midlongest####1\@@par{}% Very dirty... + \advance\rightskip 1\leftskip plus 1fil + \leftskip=\z@}% + #1}% + \let\iftitlemeasuring\@secondoftwo + \ttl@boxprocess + #1} + +\def\ttl@boxprocess{% + \setbox\ttl@box=\vbox{% + \unvcopy\ttl@box + \unskip\unpenalty + \global\setbox\@ne=\lastbox}% + \ifvoid\@ne + \else + \setbox\tw@=\hbox{\hskip-\leftskip\unhbox\@ne\hskip-\rightskip}% + \titlewidthfirst\wd\tw@ + \ifdim\titlewidth<\titlewidthfirst + \titlewidth\titlewidthfirst + \fi + \ifdim\titlewidthlast=\z@ + \titlewidthlast\titlewidthfirst + \fi + \expandafter\ttl@boxprocess + \fi} + +% Rules +% ~~~~~ + +\providecommand\titleline{% + \@ifstar{\ttl@line@i{\hb@xt@\titlewidth}}% + {\ttl@line@i{}}} + +\def\ttl@line@i#1{% + \@ifnextchar[{\ttl@line{#1}}{\ttl@line{#1}[s]}} + +\def\ttl@line#1[#2]#3{% + \vskip\topskip + \hrule \@height \z@ + \nobreak + \vskip-\topskip + \begingroup + \parindent\z@ + \everypar{}% + \leftskip\z@ + \rightskip\z@ % #1 is either \hb@xt@\titlewidth or empty: + \@makebox[\hsize][#2]{\ttl@makeline{#1{#3}}}% + \par + \endgroup + \hrule height \z@ + \nobreak} + +\providecommand\titlerule{\@ifstar{\ttl@row}{\ttl@rule}} + +\let\ttl@leaders\xleaders % For titletoc compatibility + +\def\ttl@row{\@ifnextchar[{\ttl@row@i}{\ttl@row@i[\wd\z@]}} +\def\ttl@row@i[#1]#2{% + \ifvmode\expandafter\titleline\fi + {\sbox\z@{#2}% + \ttl@calcneg\hspace{#1}% + \hskip\wd\z@ + \ttl@leaders\hb@xt@#1{\hss\box\z@}% + \hfill\kern\z@}} + +\def\ttl@rule{\@ifnextchar[{\ttl@rule@i}{\ttl@rule@i[.4\p@]}} +\def\ttl@rule@i[#1]{% + \ifvmode\expandafter\titleline\fi + {\leaders\hrule height #1\hfill\kern\z@}} + +% Par shapes and space +% ~~~~~~~~~~~~~~~~~~~~ + +\providecommand\filright{% + \gdef\ttl@filleft##1{\hskip##1}% + \gdef\ttl@filright##1{\hfill}% + \let\\\@centercr + \advance\rightskip\z@ \@plus 1fil\relax} +\providecommand\filleft{% + \gdef\ttl@filleft##1{\hfill}% + \gdef\ttl@filright##1{\hskip##1}% + \let\\\@centercr + \advance\leftskip\z@ \@plus 1fil + \parfillskip\z@} +\providecommand\filcenter{\filleft\filright + \gdef\ttl@filleft##1{\hfill}} +\providecommand\fillast{% + \gdef\ttl@filleft##1{\hfill}% + \gdef\ttl@filright##1{\hfill}% + \let\\\@centercr + \filleft\advance\rightskip\z@ \@plus -1fil + \parfillskip\z@ \@plus 2fil\relax} +\newcommand\filinner{% + \if@twoside + \ifodd\count\z@\filleft\else\filright\fi + \else + \filleft + \fi} +\newcommand\filouter{% + \if@twoside + \ifodd\count\z@\filright\else\filleft\fi + \else + \filright + \fi} + +\newcommand\wordsep{\fontdimen\tw@\font \@plus + \fontdimen\thr@@\font \@minus \fontdimen4\font} + +% Struts. +% ~~~~~~ +% A way to remove the struts added by styles. May be redefined below +% with option nostruts. + +\def\ttl@defnostruts{\def\nostruts{\let\ttl@strut\@empty}} + +% +-----------------+ +% | O P T I O N S | +% +-----------------+ + +\DeclareOption{pagestyles}{\let\sectiontitle\@empty} +\DeclareOption{extramarks}{\let\ttl@fetchmark\@empty} +\DeclareOption{floatps}{% + \ifx\sectiontitle\@empty + \let\ttl@replace\space + \else + \PackageWarning{titlesec}{Ignoring `floatps' without + `pagestyles'. This option is now deprecated.}% + \fi} +\DeclareOption{psfloats}{% + \ifx\sectiontitle\@empty + \let\ttl@replace\@empty + \else + \PackageWarning{titlesec}{Ignoring `psfloats' without + `pagestyles'}% + \fi} + +\DeclareOption{loadonly}{\let\ttl@extract\@empty} + +\DeclareOption{outermarks}{% + \def\ttl@titlemarks{\outertitlemarks}} +\DeclareOption{topmarks}{ + \def\ttl@titlemarks{\toptitlemarks}} +\DeclareOption{botmarks}{% + \def\ttl@titlemarks{\bottitlemarks}} +\DeclareOption{innermarks}{% + \def\ttl@titlemarks{\innertitlemarks}} + +\DeclareOption{footmarks}{} % Backward compat + +\DeclareOption{explicit}{\ttl@explicittrue} + +\DeclareOption{clearempty}{% + \def\cleardoublepage{% + \clearpage{\ps@empty\if@twoside\ifodd\c@page\else + \hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}}} + +\DeclareOption{rigidchapters}{% + \def\ttl@topmode#1#2{\vbox to #1{#2\vfil}}% + \def\ttl@chapafter{.26\textheight}} +\DeclareOption{rubberchapters}{% + \def\ttl@topmode#1#2{{#2}\ttl@calc\vspace{#1}}% + \def\ttl@chapafter{40\p@}} + +\DeclareOption{bottomtitles}{% + \def\bottomtitlespace{-1\p@}} +\DeclareOption{nobottomtitles}{% + \def\bottomtitlespace{.2\textheight}} +\DeclareOption{nobottomtitles*}{% + \let\ttl@addstretch\relax + \def\bottomtitlespace{.2\textheight}} + +\DeclareOption{calcwidth}{% + \let\ttl@beginlongest\ttl@xbeginlongest} + +\DeclareOption{aftersep}{% + \let\ttl@titlespace\@gobble} +\DeclareOption{largestsep}{% + \let\ttl@titlespace\addvspace} + +\DeclareOption{oldparttoc}{% + \def\ttl@tocpart{\def\ttl@a{\thepart\hspace{1em}}}} +\DeclareOption{newparttoc}{% + \let\ttl@tocpart\relax} +\DeclareOption{notocpart*}{% + \let\ttl@notocparts\@empty} + +\DeclareOption{rm}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\rmfamily}} +\DeclareOption{sf}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\sffamily}} +\DeclareOption{tt}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\ttfamily}} +\DeclareOption{md}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\mdseries}} +\DeclareOption{bf}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\bfseries}} +\DeclareOption{up}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\upshape}} +\DeclareOption{it}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\itshape}} +\DeclareOption{sl}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\slshape}} +\DeclareOption{sc}{% + \protected@xdef\ttl@fonts{\ttl@fonts\protect\scshape}} + +\DeclareOption{big}{% + \gdef\ttl@sizes#1{\ifcase#1\relax\Huge\or\Large\or\large + \or\normalsize\or\or\or\huge\fi}} +\DeclareOption{medium}{% + \gdef\ttl@sizes#1{\ifcase#1\relax\huge\or\Large\or\large + \or\normalsize\or\or\or\LARGE\fi}} +\DeclareOption{small}{% + \gdef\ttl@sizes#1{\ifcase#1\relax\LARGE\or\large + \or\normalsize\or\normalsize\or\or\or\Large\fi}} +\DeclareOption{tiny}{% + \gdef\ttl@sizes#1{\ifcase#1\relax\large\or\normalsize\or + \normalsize\or\normalsize\or\or\or\normalsize\fi}} + +\DeclareOption{raggedleft}{% + \gdef\ttl@fil{\filleft}} +\DeclareOption{center}{% + \gdef\ttl@fil{\filcenter}} +\DeclareOption{raggedright}{% + \gdef\ttl@fil{\filright}} + +\DeclareOption{uppercase}{% + \gdef\ttl@case{\MakeUppercase}} + +\DeclareOption{compact}{% + \gdef\ttl@space{1}% + \gdef\ttl@chapafter{30\p@}} + +% Deprecated. To be remmoved in a major upgrade (3.0) +\DeclareOption{indentfirst}{% + \gdef\@afterindentfalse{\let\if@afterindent\iftrue}% + \@afterindenttrue + \def\titlespacing{% + \@ifstar{\ttl@spacing@i{\@ne}}{\ttl@spacing@i{\@ne}}}} +\DeclareOption{nonindentfirst}{% + \def\titlespacing{% + \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\z@}}}} + +% New names +\DeclareOption{indentafter}{% + \gdef\@afterindentfalse{\let\if@afterindent\iftrue}% + \@afterindenttrue + \def\titlespacing{% + \@ifstar{\ttl@spacing@i{\@ne}}{\ttl@spacing@i{\@ne}}}} +\DeclareOption{noindentafter}{% + \def\titlespacing{% + \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\z@}}}} + +% newlinetospace +\let\ttl@blinemarks\relax +\let\ttl@elinemarks\relax + +\DeclareRobustCommand\ttl@linetosp{% + \@ifstar{\ttl@linetosp@i}{\ttl@linetosp@i}}% + +\def\ttl@linetosp@i{% + \ifdim\lastskip>\z@\else\space\fi + \ignorespaces} + +\DeclareOption{newlinetospace}{% + \def\ttl@blinemarks{% + \let\ttl@e\\% + \def\\{\ttl@linetosp}}% + \def\ttl@elinemarks{\let\\\ttl@e}}% + +% toctitles +\def\ttl@addcontentsline#1#2{% + \addcontentsline{toc}{#1}{\ifttl@toclabel\ttl@a\fi#2}% + \nobreak} + +\DeclareOption{toctitles}{% + \def\ttl@addcontentsline#1#2{% + \addcontentsline{toc}{#1}{\ifttl@toclabel\ttl@a\fi\ttl@savetitle}% + \nobreak}} + +% pageatnewline + +\def\ttl@changecentercr{% + \let\ttl@centercr\@centercr + \def\@centercr{\@ifstar{\ttl@centercr*}{\ttl@centercr*}}} + +\DeclareOption{pageatnewline}{\let\ttl@changecentercr\relax} + +\def\ttl@fonts{} + +% nostruts + +\DeclareOption{nostruts}{% + \let\ttl@strut\@empty + \def\ttl@defnostruts{% + \let\ttl@strut\@empty + \def\nostruts{\let\ttl@strut\@empty}}} + +\ExecuteOptions{rubberchapters,bottomtitles,aftersep,oldparttoc,% + innermarks} + +\ProcessOptions + +% +-----------------+ +% | H Y P E R R E F | +% +-----------------+ +% +% These two commands are provided by hyperref. But if they +% are not defined at \begin{document} hyperref has not been +% loaded or it is an old version. + +\AtBeginDocument{% + \ifx\ttl@Hy@steplink\@undefined + \let\ttl@Hy@steplink\@gobble + \let\ttl@Hy@refstepcounter\refstepcounter + \fi} + +% +-----------------+ +% | PAGE STYLES | +% +-----------------+ +% +% This is generic: + +\newcommand\assignpagestyle[2]{% + \@namedef{ttl@ps@\expandafter\@gobble\string#1}{#2}} + +% Old pagestyles +% ~~~~~~~~~~~~~~ + +\providecommand\newpagestyle{% + \let\ttl@compatps\@empty % marks the ``old interface'' + \let\ttl@coreps\@empty + \makeatletter + \edef\ttl@d{% + \noexpand\input{titleps.sty}% + \catcode`\noexpand\@=\the\catcode`\@}% + \ttl@d + \newpagestyle} + +\providecommand\renewpagestyle{% + \let\ttl@compatps\@empty % marks the ``old interface'' + \let\ttl@coreps\@empty + \makeatletter + \edef\ttl@d{% + \noexpand\input{titleps.sty}% + \catcode`\noexpand\@=\the\catcode`\@}% + \ttl@d + \renewpagestyle} + +\providecommand\widenhead{% + \let\ttl@compatps\@empty % marks the ``old interface'' + \let\ttl@coreps\@empty + \makeatletter + \edef\ttl@d{% + \noexpand\input{titleps.sty}% + \catcode`\noexpand\@=\the\catcode`\@}% + \ttl@d + \widenhead} + +% New pagestyles +% ~~~~~~~~~~~~~~ + +\@ifundefined{sectiontitle}{}{% + \let\ttl@coreps\@empty + \input{titleps.sty}} + +% +-----------------+ +% | K E Y S | +% +-----------------+ + +\def\ttl@keys{% + \let\ttl@keys\relax + \@ifundefined{define@key}{\RequirePackage{keyval}}{}% + \def\ttl@getkeys##1##2{% + \let\ttl@a\@empty + \if\expandafter @\@gobble##1@\@empty % if there is a single token + \edef\ttl@b{\expandafter\@gobble\string##1}% + \let\ttl@a\ttl@b + \else + \ttl@labelfalse % A temporary flag: true if there is page key + \setkeys{##2}{##1}% + \ifttl@label + \@ifundefined{ttlp@\ttl@b}{% + \expandafter\let\csname ttlp@\ttl@b\endcsname\@empty}{}% + \fi + \edef\ttl@a{\ttl@b\ttl@a}% + \fi}% + % + \define@key{titlesec}{name}{% + \edef\ttl@b{\expandafter\@gobble\string##1}}% + \define@key{titlesec}{numberless}[true]{% + \csname @tempswa##1\endcsname + \if@tempswa + \edef\ttl@a{\ttl@a/*}% + \fi}% + \define@key{titlesec}{page}{% + \ttl@labeltrue % Used as flag + \edef\ttl@a{/##1\ttl@a}}% + % + \def\ttl@extra@numberless{\ttl@labeltrue}% The actual meaning + \let\ttl@key@numberless\@empty + %\let\ttl@key@matter\@empty + \let\ttlp@append\@gobbletwo + \def\ttl@setkeys##1{% + \def\ttl@trylist{\ttl@try{}}% + \@for\ttl@b:=##1\do{% + \begingroup + \let\ttl@a\relax + \def\ttl@try####1{% + \noexpand\ttl@try{####1\ttl@a{\ttl@b}}% + \noexpand\ttl@try{####1}}% + \xdef\ttl@trylist{\ttl@trylist}% + \endgroup}}% + \ttl@setkeys{page,numberless}% matter + % + \if@twoside + \newcounter{ttlp@side}% + \newcount\ttlp@side + \def\ttlp@theside{\ifodd\c@page o\else e\fi}% + \def\ttlp@append##1##2{% + {\let\@elt\relax + \expandafter\xdef\csname ttlp@##1\endcsname{% + \csname ttlp@##1\endcsname\@elt ##2}}}% + \def\ttlp@write##1{% + {\let\ttlp@theside\relax + \protected@write\@auxout{}% + {\string\ttlp@append{##1}{\ttlp@theside}}}}% + \def\ttlp@fetch##1{% + \stepcounter{ttlp@side}% + \global\advance\ttlp@side\@ne + \@whilenum\ttlp@side<\c@ttlp@side\do{% + \expandafter\@next\expandafter\@tempa\csname ttlp@##1\endcsname{}{}% + \global\advance\ttlp@side\@ne}% + \expandafter\@next\expandafter\ttl@b\csname ttlp@##1\endcsname{% + \xdef\ttl@key@page{/\if\ttl@b oodd\else even\fi}% + }{% + \xdef\ttl@key@page{/\ifodd\c@page odd\else even\fi}% + \@@warning{Unsynchronized `##1' title on page \thepage}}}% + \else + \let\ttlp@write\@gobble + \def\ttlp@fetch##1{\gdef\ttl@key@page{/odd}}% + \fi} + +% +-----------------+ +% | C O M P A T | +% +-----------------+ +% Easy setup, i.e., that of package options, is +% taken care of, if necessary. + +\renewcommand\secdef[2]{% + \@ifstar + {\ttl@labelfalse + #2} + {\ttl@labeltrue + \ifx#1\@chapter + \if@mainmatter\else\ttl@labelfalse\fi + \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi + \else\ifx#1\@part + \ifnum\ttll@part>\c@secnumdepth\ttl@labelfalse\fi + \fi\fi + \let\ifttl@toclabel\ifttl@label + \@dblarg{#1}}} + +\@ifundefined{ttl@extract}{}{\endinput} + +\newcommand\titlelabel[1]{% + \def\@seccntformat##1{#1}} + +\expandafter\ifx\csname chapter\endcsname\relax + + \def\ttl@compatpart{\titleclass{\part}{part}\relax} + +\else + + \def\ttl@compatchapter{% + \def\@makechapterhead{% + \ttl@labeltrue + \if@mainmatter\else\ttl@labelfalse\fi + \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi + \ttl@startargs\ttl@mkchap{chapter}}% + \def\@makeschapterhead{% + \ttl@labelfalse + \if@mainmatter\else\ttl@labelfalse\fi + \ifnum\ttll@chapter>\c@secnumdepth\ttl@labelfalse\fi + \ttl@startargs\ttl@mkchap{chapter}}} + + \def\ttl@compatpart{\titleclass{\part}{page}\relax} + +\fi + +\def\ttl@@extract#1\@startsection#2#3#4#5#6#7#8{% + \@tempskipa=#5 + \@tempskipb=#6 + \ifdim\@tempskipa<\z@ + \toks@{\titlespacing*#8{#4}}% + \@tempskipa-\@tempskipa + \else + \toks@{\titlespacing#8{#4}}% + \fi + \@ifundefined{ttl@space}{}{% + \ttl@assign\@tempskipa*\ttl@space\relax\beforetitleunit}% + \ifdim\@tempskipb<\z@ + \if@tempswa + \titleformat#8[runin]% + {\ttl@fonts\ttl@sizes{#3}}{\@seccntformat{#2}}% + {\z@}\ttl@passexplicit + \else + \titleformat#8[runin]% + {#7}{\@seccntformat{#2}}% + {\z@}\ttl@passexplicit + \fi + \@tempskipb-\@tempskipb + \else + \if@tempswa + \titleformat#8% + {\ttl@fil\ttl@fonts\ttl@sizes{#3}}{\@seccntformat{#2}}% + {\z@}\ttl@passexplicit + \else + \titleformat#8% + {#7}{\@seccntformat{#2}}% + {\z@}\ttl@passexplicit + \fi + \@ifundefined{ttl@space}{}{% + \ttl@assign\@tempskipb*\ttl@space\relax\aftertitleunit}% + \fi + \edef\ttl@a{\the\toks@{\the\@tempskipa}{\the\@tempskipb}} + \ttl@a} + +\def\ttl@extract#1{% + \expandafter\in@\expandafter\@startsection\expandafter{#1}% + \ifin@ + \expandafter\ttl@@extract#1#1% + \else + \PackageWarningNoLine{titlesec}% + {Non standard sectioning command detected\MessageBreak + Using default spacing and no format} + \titlespacing*#1{\z@}{*3}{*2}% + \fi} + +\@tempswafalse + +\ifx\ttl@fonts\@empty + \def\ttl@fonts{\bfseries} +\else + \@tempswatrue +\fi + +\expandafter\ifx\csname ttl@sizes\endcsname\relax + \gdef\ttl@sizes#1{\ifcase#1\relax\Huge\or\Large\or\large + \or\normalsize\or\or\or\huge\fi} +\else + \@tempswatrue +\fi + +\expandafter\ifx\csname ttl@fil\endcsname\relax + \let\ttl@fil\@empty +\else + \@tempswatrue +\fi + +\expandafter\ifx\csname ttl@case\endcsname\relax + \let\ttl@case\@firstofone +\else + \@tempswatrue +\fi + +\if@tempswa + + \expandafter\ifx\csname chapter\endcsname\relax\else + \titleformat\chapter[display]% + {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6} + {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit} + \fi + +\fi + +\ttl@extract\section +\ttl@extract\subsection +\ttl@extract\subsubsection +\ttl@extract\paragraph +\ttl@extract\subparagraph + +\let\ttl@extract\@undefined +\let\ttl@@extract\@undefined + +\def\ttl@toplevel{part} + +\expandafter\ifx\csname chapter\endcsname\relax + + \@namedef{ttll@part}{0} + \titleclass{\section}{straight}[\part] + + \titlespacing*{\part} + {\z@} + {4ex} + {3ex} + +\else + + \let\ttl@save@mkchap\@makechapterhead + \let\ttl@save@mkschap\@makeschapterhead + + \def\@makechapterhead#1{% + \gdef\ttl@savemark{\chaptermark{#1}}% + \ttl@save@mkchap{#1}% + \@ifundefined{ttl@ps@chapter}{}% + {\thispagestyle{\@nameuse{ttl@ps@chapter}}}} + + \def\@makeschapterhead#1{% + \gdef\ttl@savemark{\chaptermark{#1}}% + \ttl@save@mkschap{#1}% + \@ifundefined{ttl@ps@chapter}{}% + {\thispagestyle{\@nameuse{ttl@ps@chapter}}}} + + \@namedef{ttll@part}{-1} + \@namedef{ttlss@part}{chapter} + \@namedef{ttll@chapter}{0} + \titleclass{\section}{straight}[\chapter] + +% The following is unoperant, unless when \chapter / \part +% format is redefined + + \titlespacing*{\part} + {\z@} + {\z@\@plus1fil} + {\z@\@plus1fil} + + \titlespacing*\chapter + {\z@}% + {50\p@}% + {\ttl@chapafter}% + +\fi + +\titleclass{\subsection} {straight}[\section] +\titleclass{\subsubsection}{straight}[\subsection] +\titleclass{\paragraph} {straight}[\subsubsection] +\titleclass{\subparagraph} {straight}[\paragraph] + +\endinput + +MIT License +----------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/macros/latex/contrib/titlesec/titlesec.tex b/macros/latex/contrib/titlesec/titlesec.tex new file mode 100644 index 0000000000..d10da1e040 --- /dev/null +++ b/macros/latex/contrib/titlesec/titlesec.tex @@ -0,0 +1,2106 @@ +% +% Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com +% +% This file may be distributed and/or modified under the conditions of +% the MIT License. A version can be found at the end of this file. +% +% Repository: https://github.com/jbezos/titlesec +% + +\def\fileversion{2.11} +\def\docdate{2019/07/16} + +\documentclass[a4paper]{ltxguide} +\usepackage[sf,bf,compact,topmarks,calcwidth,pagestyles]{titlesec} +\usepackage{titletoc} +\def\gobble#1{} +\def\cs#1{\expandafter\gobble\string\\#1} +\makeatletter +\newenvironment{desc} + {\if@nobreak + \vskip-\lastskip + \vspace*{-2.5ex}% + \fi + \decl} + {\enddecl} +\makeatother + +\usepackage{textcomp,pslatex} +\usepackage[linktocpage]{hyperref} + +\title{The \textsf{titlesec}, \textsf{titleps} and \textsf{titletoc} +Packages\footnote{The \textsf{titlesec} package is currently at +version 2.10.2. \copyright{} 1998--2016 Javier Bezos. +The \textsf{titletoc} package is currently at +version 1.6. The \textsf{titleps} package is currently at version +1.1.1 \copyright{} 1999--2016 Javier Bezos. All Rights +Reserved.}} + +\author{Javier Bezos\footnote{For bug reports, comments and +suggestions go to \href{http://www.tex-tipografia.com/contact.html}% +{\texttt{http://www.tex-tipografia.com/contact.html}}. English +is not my strong point, so contact me when you find mistakes in the +manual. Other packages by the same author: \textsf{gloss} (with +Jos\'e Luis D\'{\i}az), \textsf{enumitem, accents, tensind, esindex, +dotlessi, babeltools}.}} + +\date{\docdate} + +\widenhead{2.1pc}{0pc} +\titlelabel{\thetitle.\quad} + +\renewpagestyle{plain}[\small\sffamily\slshape]{ + \footrule + \setfoot{}{\usepage}{}} + +\newpagestyle{myps}[\small\sffamily\slshape]{ + \headrule + \sethead{Titlesec}{\sectiontitle}{\usepage}} + +\pagestyle{myps} + +\newcommand{\examplesep}{% + \begin{center}% + \rule{4pt}{4pt}% + \end{center}} + +\contentsmargin{0pt} +\titlecontents{section}[1.8pc] + {\addvspace{3pt}\bfseries} + {\contentslabel[\thecontentslabel.]{1.8pc}} + {} + {\quad\thecontentspage} + +\titlecontents*{subsection}[1.8pc] + {\small} + {\thecontentslabel. } + {} + {, \thecontentspage} + [.---][.] + +\addtolength{\topmargin}{-3pc} +\addtolength{\textwidth}{6pc} +\addtolength{\oddsidemargin}{-2pc} +\addtolength{\textheight}{7pc} + +\raggedright +\parindent1em +\parskip0pt + +\begin{document} + +\maketitle +\tableofcontents +\section{Introduction} + +This package is essentially a replacement---partial or total---for the +\LaTeX{} macros related with sections---namely titles, headers and +contents. The goal is to provide new features unavailable in current +\LaTeX{}; if you just want a more friendly interface than that of +standard \LaTeX{} but without changing the way \LaTeX{} works you may +consider using \textsf{fancyhdr}, by Piet van Oostrum, \textsf{sectsty}, +by Rowland McDonnell, and \textsf{tocloft}, by Peter Wilson, which you +can make pretty things with.\footnote{Since the sectioning commands +are rewritten, their behaviour could be somewhat different +in some cases.} + +Some of the new features provided are: +\begin{itemize} +\item Different classes and ``shapes'' of titles, with tools for very +fancy formats. You can define different formats for left and right +pages, or numbered and unnumbered titles, measure the width of the +title, add a new section level, use graphics, and many more. The +Appendix shows a good deal of examples, so jump forward right now! + +\item Headers and footers defined with no |\...mark| intermediates, +and perhaps containing top, first \emph{and} bot marks at the same time. +Top marks correctly synchronized with titles, without +incompatibilities with the float mechanism. Decorative elements easily +added, including picture environments. + +\item Pretty free form contents, with the possibility of grouping +entries of different levels in a paragraph or changing the format +of entries in the middle of a document. +\end{itemize} +\textsf{Titlesec} works with the standard classes and with many +others, including the AMS ones, and it runs smoothly with +\textsf{hyperref}.\footnote{However, be aware the AMS classes +reimplement the original internal commands. These changes will be +lost here. The compatibility with \textsf{hyperref} has been tested +with \textsf{dvips}, \textsf{dvipdfm} and \textsf{pdftex} but it is an +unsupported feature. Please, check your version of +\textsf{hyperref} is compatible with \textsf{titlesec}.} +Unfortunately, it is not compatible with \textsf{memoir}, which +provides its own tools with a limited subset of the features available +in \textsf{titlesec}. + +As usual, load the package in the standard way with +|\usepackage|. Then, redefine the sectioning commands with the +simple, predefined settings (see section ``Quick Reference'') or with +the provided commands if you want more elaborate formats (see section +``Advanced Interface.'') In the latter case, you only need to +redefine the commands you'll use. Both methods are available at the +same time, but because |\part| is usually implemented in a +non-standard way, it remains untouched by the simple settings and +should be changed with the help of the ``Advanced Interface.'' + +\section{Quick Reference} +%~~~~~~~~~~~~~~~~~~~~~~ + +The easiest way to change the format is by means of a set of package +options and a couple of commands. If you feel happy with the +functionality provided by this set of tools, you need not go +further in this manual. Just read this section and ignore the +subsequent ones. + +\subsection{Format} + +There are three option groups controlling font, size and align. You +need not set all of these groups, since a default is provided for each +one; however, you must use at least an option from them if you want +this ``easy setup.'' +\begin{desc} +|rm sf tt md bf up it sl sc| +\end{desc} +Select the corresponding family/series/shape. Default is |bf|. + +\begin{desc} +|big medium small tiny| +\end{desc} +Set the size of titles. +Default is |big|, which gives the size of standard classes. +With |tiny|, sections (except chapters) are typed in the text +size. |medium| and |small| are intermediate layouts. + +\begin{desc} +|raggedleft center raggedright| +\end{desc} + +Control the alignment. + +\subsection{Spacing} + +\begin{desc} +|compact| +\end{desc} +This option is independent from those above and reduces the spacing +above and below the titles. + +\subsection{Uppercase} + +\begin{desc} +|uppercase| +\end{desc} + +\fbox{2.9} Uppercases titles. Depending on the class, it might not work in +\verb|\chapter| and \verb|\part|. + +\subsection{Tools} + +\begin{desc} +|\titlelabel{<label-format>}| +\end{desc} +Changes the label format in sections, subsections, etc. A +|\thetitle| command is provided which is respectively |\thesection|, +|\thesubsection|, etc. The default value in standard classes is +\begin{verbatim} +\titlelabel{\thetitle\quad} +\end{verbatim} +and you may add a dot after the counter simply with +\begin{verbatim} +\titlelabel{\thetitle.\quad} +\end{verbatim} +That was done in this document. + +\begin{desc} +|\titleformat*{<command>}{<format>}| +\end{desc} + +This command allows to change the |<format>| of a sectioning +command, as for example: +\begin{verbatim} +\titleformat*{\section}{\itshape} +\end{verbatim} + +\section{Advanced Interface} +%~~~~~~~~~~~~~~~~~~~~~~~~ + +Two commands are provided to change the title format. The first one +is used for the ``internal'' format, i.~e., shape, font, label\dots, +the second one defines the ``external'' format, i.~e., spacing before +and after, indentation, etc. This scheme is intended to easy +definitions, since in most of cases you will want to modify either +spacing or format.\footnote{Information is ``extracted'' from the +class sectioning commands, except for chapter and part. Standard +definitions with |\cs{@startsection}| are presumed---if sections have +been defined without that macro, arbitrary values for the format an +the spacing are provided, which you may change later. (Sadly, there +is no way to catch the chapter or part formats, and one similar to +that of standard classes will be used.)} That redefines existing +sectioning commands, but does not create \emph{new} ones. New +sectioning levels can be added with |\titleclass|, as described below, +and then their format can be set with the commands described here. + +\subsection{Format} + +A set of shapes is provided, which controls the basic distribution of +elements in a title. The available shapes are: +\begin{description} +\item[hang] is the default value, with a hanging label. (Like the +standard |\section|.) + +\item[block] typesets the whole title in a block (a paragraph) without +additional formatting. Useful in centered titles\,\footnote{The label +will be slightly displaced to the left if the title is two or more +lines long and the \texttt{hang} shape is used, except with explicit +|\string\\|.} and special formatting (including graphic tools such as +|picture|, |pspicture|, etc.) + +\item[display] puts the label in a separate paragraph. (Like the +standard |\chapter|.) + +\item[runin] A run-in title, like the standard + |\paragraph|.\footnote{Well, not quite. The title is first boxed to + avoid some unexpected results if, for example, there is a + \texttt{\string\color} between the title and the + text. Unfortunately, due to an optimization done by \TeX{} + discretionaries may be lost. I have found no solution, except using + \textsf{luatex}, which works as one could expect. Anyway, if the + title doesn't contain hyphen or dashes, this is not usually a real + problem.} + +\item[leftmargin] puts the title at the left margin. Titles at the +very end of a page will be moved to the next one and will not stick +out in the bottom margin, which means large titles can lead to +underfull pages.\footnote{However, floats following the title a couple +of lines after will interfere with the page breaking used here and +sometimes the title may stick out.} In this case you may increase the +stretchability of the page elements, use |\raggedbottom| or use the +package option |nobottomtitles| described below. Since the mechanism +used is independent from that of the margin pars, they can overlap. +A deprecated synonymous is |margin|. + +\item[rightmargin] is like |leftmargin| but at the right margin. + +\item[drop] wraps the text around the title, provided the +first paragraph is longer than the title (if not, they overlap). +The comments in |leftmargin| also apply here. + +\item[wrap] is quite similar to drop. The only difference is +while the space reserved in drop for the title is fixed, in wrap is +automatically readjusted to the longest line. The limitations +explained below related to |calcwidth| also apply here. + +\item[frame] Similar to display, but the title will be framed. +\end{description} + +Note, however, some shapes do not make sense in chapters and +parts. + +\begin{desc} +|\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]| +\end{desc} + +Here +\begin{itemize} +\item |<command>| is the sectioning command to be redefined, i.~e., +|\part|, +|\chapter|, |\section|, |\subsection|, |\subsubsection|, |\paragraph| +or |\subparagraph|. + +\item The paragraph shape is set by |<shape>|, whose possible +values are those described above. + +\item |<format>| is the format to be applied to the whole +title---label and text. This part can contain vertical material (and +horizontal with some shapes) which is typeset just after the space +above the title. + +\item The label is defined in |<label>|. You may leave it empty if +there is no section label at that level, but this is not recommended +because by doing so the number is not suppressed in the table of +contents and running heads. + +\item |<sep>| is the horizontal separation between label and title +body and must be a length (it must not be empty). This space is +vertical in |display| shape; in |frame| it is the distance from text +to frame. Both |<label>| and |<sep>| are ignored in starred versions +of sectioning commands. If you are using |picture| and the like, set +this parameter to 0 pt. + +\item |<before-code>| is code preceding the title body. The very last +command can take an argument, which is the title +text.\footnote{Remember font size can be changed safely between +paragraphs only, and changes in the text should be made local with a +group; otherwise the leading might be wrong---too large or too small.} +However, with the package option \texttt{explicit} the title must be +given explicitly with |#1| (see below). Penalties in this argument may +lead to unexpected results. + +\item |<after-code>| is code following the title body. The typeset +material is in vertical mode with |hang|, |block| and |display|; in +horizontal mode with |runin| and |leftmargin| (\fbox{2.7} with the +latter, at the beginning of the paragraph). Otherwise is ignored. +Penalties in this argument may lead to unexpected results. +\end{itemize} + +Penalties, marks and the like must be properly synchronized with page +breaks. So, |<before-code>| and |<after-code>| are \textit{not} the +proper places for penalties. See |\sectionbreak| below. + +\begin{desc} +|\chaptertitlename| +\end{desc} + +It defaults to |\chaptername| except in appendices where it +is |\appendixname|. Use it instead of |\chaptername| when defining +a chapter. + +\subsection{Spacing} + +\begin{desc} +|\titlespacing*{<command>}{<left>}{<before-sep>}{<after-sep>}[<right-sep>]| +\end{desc} + +The starred version kills the indentation of the paragraph +following the title, except in |drop|, |wrap| and |runin| where this +possibility does not make sense. +\begin{itemize} +\item |<left>| increases the left margin, except in the |...margin|, +and |drop| shape, where this parameter sets the title width, in +|wrap|, the maximum width, and in |runin|, the indentation just before +the title. With negative value the title overhangs.\footnote{This +parameter is not equal to |<indent>| of |\cs{@startsection}|, which +doesn't work correctly. With a negative value in the latter and if +|<indent>| is larger than the label width, the first line of the title +will start in the outer margin, as expected, but the subsequent lines +will not; worse, those lines will be shortened at the right margin.} + +\item |<before-sep>| is the vertical space before the title. + +\item |<after-sep>| is the separation between title and text---vertical +with |hang|, |block|, and |display|, and horizontal with |runin|, +|drop|, |wrap| and |...margin|. By making the value negative, you may +define an effective space of less than |\parskip|.\footnote{See +Goossens, Mittelbach and Samarin: \textit{The \LaTeX{} Companion}, +Reading, Addison Wesley, 1993, p.~25.} + +\item The |hang|, |block| and |display| shapes have the +possibility of increasing the |<right-sep>| margin with this optional +argument. +\end{itemize} + +If you dislike typing the full skip values, including the |plus| and +|minus| parameters, an abbreviation |*|$n$ is provided. In the +|<before-sep>| argument this is equivalent to $n$ |ex| with some +stretchability and a minute shrinkability. In the +|<after-sep>| some stretchability (smaller) and no shrinkability.% +\footnote{They stand for $n$ times |1ex plus .3ex minus .06ex| and +|1ex plus .1ex|, respectively.} Thus, you can write +\begin{verbatim} +\titlespacing{\section}{0pt}{*4}{*1.5} +\end{verbatim} +The lengths |\beforetitleunit| and |\aftertitleunit| are used +as units in the |*| settings and you can change them if you do not like +the predefined values (or for slight changes in the makeup, for +example). + +\textbf{Notes.} |\titlespacing| does not work with either |\chapter| +and |\part| unless you change its title format as well by means of +|\titleformat|, the simple settings, or |\titleclass|. Arguments in +|\titlespacing| must be dimensions; |\stretch| includes a command and +hence raises an error. + +\subsection{Spacing related tools} + +These commands are provided as tools for |\titleformat| and +|\titlespacing|. + +\begin{desc} +|\filright \filcenter \filleft \fillast \filinner \filouter| +\end{desc} + +Variants of the |\ragged...| commands, with slight differences. In +particular, the |\ragged...| commands kills the left and right spaces +set by |\titlespacing|.\footnote{Remember the package +\textsf{ragged2e} provides some additional commands for alignment, +too, like \texttt{\string\justifying}.} |\fillast| justifies the +paragraph, except the last line which is +centered.\footnote{Admittedly, a weird name, but it is short.} These +commands work in the |frame| label, too. + +|\filinner| and |\filouter| are |\filleft| or |\filright| depending +on the page. Because of the asynchronous \TeX{} page +breaking, these commands can be used in |\chapter| only. +If you want a general tool to set different formats depending +on the page, see ``Extended settings'' below. + +\begin{desc} +|\wordsep| +\end{desc} + +The inter-word space for the current font. + +\begin{desc} +|indentafter noindentafter| \quad (Package options) +\end{desc} + +By-pass the settings for all of sectioning commands.% +\footnote{Formerly |indentfirst| and |nonindentfirst|, now +deprecated.} + +\begin{desc} +|rigidchapters rubberchapters| \quad (Package options) +\end{desc} + +With |rigidchapters| the space for chapter titles is always the same, +and |<after-sep>| in |\titlespacing| does not mean the space from the +bottom of the text title to the text body as described above, but from +the \textit{top} of the text title, i.~e., |<before-sep>| $+$ +|<after-sep>| now is a fixed distance from the top of the page body to +the main text. The default is |rubberchapters| where |<after-sep>| is +the separation between title and text as usual. Actually, the name is +misleading because it applies not only to the default chapter, but to +any title of top class. (More on classes below.) + +\begin{desc} +|bottomtitles nobottomtitles nobottomtitles*| \quad (Package options) +\end{desc} + +If |nobottomtitles| is set, titles close to the bottom margin will +be moved to the next page and the margin will be ragged. The minimal +space required in the bottom margin not to move the title is set +(approximately) by +\begin{verbatim} +\renewcommand{\bottomtitlespace}{<length>} +\end{verbatim} +whose default value is |.2\textheight|. A simple ragged bottom on the +page before is obtained with a value of 0 pt. |bottomtitles| is the +default, which simply sets |\bottomtitlespace| to a negative value. + +The |nobottomtitles*| option provides more accurate computations but +titles of |margin|, |wrap| or |drop| shapes could be badly +placed. Usually, you should use the starred version. + +\begin{desc} +|aftersep largestsep| \quad (Package options) +\end{desc} + +By default, when there are two consecutive titles the |<after-sep>| +space from the first one is used between them. Sometimes this is not +the desired behaviour, especially when the |<before-sep>| space is much +larger than the |<after-sep>| one (otherwise the default seems +preferable). With |largestsep| the largest of them is used. +Default is |aftersep|. + +\begin{desc} +|\\ \\*|\\ +|pageatnewline| \quad (Package option) +\end{desc} + +\fbox{2.6} In version 2.6 and later, \verb|\\| does not allow a page +break and therefore is equivalent to \verb|\\*|. Since I presume none +wants a page break inside a title, this has been made the default. If +for some extrange reason you want to allow page breaks inside the +titles, use the package option \verb|pageatnewline|, which is provided +for backward compatibility. + +\begin{desc} +|\nostruts|\\ +|nostruts| \quad (Package option) +\end{desc} + +\fbox{2.11} The styles defined by \textsf{titlesec} insert some struts +at certain places to make sure the vertical space is the same with +relation with the baseline. This is not always the desired behavior, so +the package options |nostruts| is provided. An alternative is the macro +|\nostruts| when defining a section (note this macros is defined only +within a title). + +\subsection{Rules} + +The package includes some tools for helping in adding rules and other +stuff below or above the title. Since the margins in titles may be modified, +these macros take into account the local settings to place rules properly. +They also take into account the space used by marginal titles. + +\begin{desc} +|\titleline[<align>]{<horizontal material>}|\\ +|\titlerule[<height>]|\\ +|\titlerule*[<width>]{<text>}| +\end{desc} + +The |\titleline| command allows inserting a line, which may +contain text and other ``horizontal'' material. it is intended +mainly for rules and leaders but in fact is also useful for other +purposes. The line has a fixed width and hence must be filled, i.e., +|\titleline{CHAPTER}| produces an underfull box. Here the optional +|<align>| (|l|, |r| or |c|) helps, so that you simply type, say, +|\titleline[c]{CHAPTER}|.% +\footnote{The default is the \texttt{s} parameter of the +\texttt{\cs{makebox}} command.} + +Using |\titleline| in places where vertical material is not expected +can lead to anomalous results. In other words, you can use it in the +|<format>| (always) and |<after-code>| (|hang|, |display| and |block|) +arguments; and in the |display| shape at the very beginning of the +|<before-code>| and |<label>| argument as well. But try it out, because +very likely it works in other places. + +The |\titlerule| command, which is enclosed automatically in +|\titleline| if necessary, can be used to build rules and +fillers. The unstarred +version draws rules of height .4 pt, or |<height>| if present. +For example: +\begin{verbatim} +\titlerule[.8pt]% +\vspace{1pt}% +\titlerule +\end{verbatim} +draws two rules of different heights with a separation of +1 pt. + +The starred version makes leaders with the |<text>| +repeated in boxes of its natural width. The width of the boxes +can be changed to |<width>|, but the first box remains with +its natural width so that the |<text>| is aligned to the left +and right edges of the space to be filled. + +For instance, with +\begin{verbatim} +\titleformat{\section}[leftmargin] + {\titlerule*[1pc]{.}% + \vspace{1ex}% + \bfseries} + {... definition follows +\end{verbatim} +leaders spanning over both main text and title precede the section. + +\begin{desc} +|calcwidth| \quad (Package option) +\end{desc} + +The |wrap| shape has the capability of measuring the lines in the title +to format the paragraph. This capability may be extended to other +three shapes---namely |display|, |block| and |hang|---with this +package option. The length of the longest line is returned in +|\titlewidth|.\footnote{There are two further +parameters, |\string\titlewidthfirst| and |\string\titlewidthlast|, +which return the length of the first and last lines. There are not +specific tools for using them, but you can assign their values to +|\string\titlewidth| and then use |\string\titleline*|.} + +As far as \TeX{} is concerned, any box is considered typeset material. +If the box has been enlarged with blank space, or if conversely a box +with text has been smashed, the value of |\titlewidth| may be wrong +(as far as humans is concerned). The |hang| shape, for instance, uses +internally such a kind of boxes, but in this case this behaviour is +desired when the title is flushed right; otherwise the |block| shape +produces better results. In other words, using boxes whose natural +width has been overridden may be wrong.\footnote{Which include +justified lines, whose interword spacing has been enlarged.} Further, +some commands may confuse \TeX{} and stop parsing the title. But if +you stick to text, |\\| and |\\[...]| (and it is very unlikely you +might want something else), there will be no problems. + +Another +important point is the |<before-code>|, |<label>|, |<sep>|, and +|<title>| parameters (but not |<after-code>|) are evaluated twice at local +scope; if you increase a counter \emph{globally}, you are increasing +it twice. In most of cases, placing the conflicting assignment in the +|<after-code>| parameter will be ok, but alternativey you can use the +following macro. + +\begin{desc} +|\iftitlemeasuring{<true>}{<false>}| +\end{desc} + +\fbox{2.9} When the title is being measured (first pass), the |<true>| +branch is used, and when the title is actually typeset (second pass) +the |<false>| branch is used. + +\begin{desc} +|\titleline*[<align>]{<horizontal material>}| +\end{desc} +A variant of |\titleline| to be used only with |calcwidth|. +The text will be enclosed first in a box of width |\titlewidth|; this box +will be in turn enclosed in the main box with the specified alignment. +There is no equivalent |\titlerule| and therefore you must enclose +it explicitly in a |\titleline*| if you want the |\titlewidth| to +be taken into account: +\begin{verbatim} +\titleline*[c]{\titlerule[.8pc]} +\end{verbatim} + +\subsection{Page styles} + +\fbox{2.8} You can assign a page style to levels of class |top| and +|page|, as well as the default chapter with the following command:% +\footnote{Named in the short-lived version 2.7 as +\texttt{\string\titlepagestyle}.} +\begin{desc} +|\assignpagestyle{<command>}{<pagestyle>}| +\end{desc} +For example, to suppress the page number in chapters write: +\begin{verbatim} +\assignpagestyle{\chapter}{empty} +\end{verbatim} + +\subsection{Breaks} + +\begin{desc} +|\sectionbreak \subsectionbreak \subsubsectionbreak|\\ +|\paragraphbreak \subparagraphbreak \<section>break| +\end{desc} + +By defining these command with |\newcommand| different page breaks +could be applied to different levels. In those undefined, a penalty +with the internal value provided by the class is used (typically +$-300$). For instance, +\begin{verbatim} +\newcommand{\sectionbreak}{\clearpage} +\end{verbatim} +makes sections begin a new page. In some layouts, the space +above the title is preserved even if the section begins a new +page; that's accomplished with: +\begin{verbatim} +\newcommand{\sectionbreak}{% + \addpenalty{-300}% + \vspace*{0pt}} +\end{verbatim} + +\fbox{2.6} \verb|\<section>break| is available in the \verb|top| class, +too. Suitable values would be \verb|\cleardoublepage| (the default if +\verb|openright|) and \verb|\clearpage| (the default if +\verb|openany|). Thus, you can override \verb|openright| by defining +\verb|\chapterbreak| as \verb|\clearpage|, provided its class has been +changed to \verb|top| (in this example, parts will continue with the +\verb|openright| setting). + +Note these macros apply the penalties at the right place. In other +words, penalties in |<before-code>| and |<after-code>| can lead to +unexpected (and even weird) results. + +\begin{desc} +|\chaptertolists| +\end{desc} + +\fbox{2.6} If defined, the usual white space written to lists (ie, +List of Figures and List of Tables) is replaced by the code in this +command. If you do not want the white space when a chapter begins, +define it to empty, i.e., +\begin{verbatim} +\newcommand{\chaptertolists}{} +\end{verbatim} + +This command is not a general tool to control +spacing in lists, and is available only in titles of top class, so +it will not work with the default chapters except if you change their +class (on the other hand, |\...tolists| can be used in any title whose +class is top). + +\subsection{Other Package Options} + +\begin{desc} +|explicit| \quad (Package option) +\end{desc} + +\fbox{2.7} With it, the title is not implicit after |<before-code>| but +must be given explicitly with |#1| as in, for example: +\begin{verbatim} +\titleformat{\section} + {..} + {\thesection}{..}{#1.} +\end{verbatim} +(Compare it with the example in section \ref{sec:dotafter}.) + +\begin{desc} +|newparttoc oldparttoc| \quad (Package options) +\end{desc} + +Standard parts write the toc entry number in a non standard way. +You may change that with |newparttoc| so that \textsf{titletoc} +or a similar package can manipulate the entry. (That works only if +|\part| has been redefined.) + +\begin{desc} +|clearempty| \quad (Package options) +\end{desc} + +Modifies the behaviour of |\cleardoublepage| so that the |empty| page +style will be used in empty pages. + +\begin{desc} +|toctitles| \quad (Package option) +\end{desc} + +\fbox{2.6} Changes the behaviour of the optional argument in +sectioning titles so that it sets only the running heads and not the +TOC entries, which will be based on the full title. + +\begin{desc} +|newlinetospace| \quad (Package option) +\end{desc} + +\fbox{2.6} Replaces every occurrence of \verb|\\| or \verb|\\*| in +titles by a space in running heads and TOC entries. This way, you +do not have to repeat the title just to remove a formatting command. + +\begin{desc} +|notocpart*| \quad (Package option) +\end{desc} + +\fbox{2.10.1} Long ago (by the year 2000) I decided for some reason +\verb|\part*| would behave like the AMS classes and therefore there +should be a contents entry for it. This is somewhat odd, indeed, but +the very fact is nobody has complained until now! On the other hand, +restoring the behaviour one could expect after 15 years doesn't seem a +good idea. A new page/part style in on the way, but for the moment +this option restores the standard behaviour. + +\subsection{Extended Settings} +%~~~~~~~~~~~~~~~~~~~~~~~~~ + +The first argument of both |\titleformat| and |\titlespacing| has an +extended syntax which +allows to set different formats depending on the context.\footnote{% +The \textsf{keyval} package is required for making use of it.} This +argument can be a list of key/value pairs in the form: +\begin{desc} +|<key>=<value>, <key>=<value>, <key>, <key>,...| +\end{desc} +Currently, only pages and unnumbered versions are taken care of, +besides the sectioning command name. Thus, the available keys are: +\begin{itemize} +\item |name|. Allowed values are |\chapter|, |\section|, etc. +\item |page|. Allowed values are |odd| or |even|. +\item |numberless|. A valueless key. it is not necessary unless you +want to set different numbered (without this key) and unnumbered +(with |numberless|) variants. +\end{itemize} +The basic form described above with the name of a sectioning +command, say +\begin{verbatim} +\titleformat{\section} ... +\end{verbatim} +is in fact an abbreviation for +\begin{verbatim} +\titleformat{name=\section} ... +\end{verbatim} + +Let's suppose we'd like a layout with titles in the +outer margin. We might set something like +\begin{verbatim} +\titleformat{name=\section,page=even}[leftmargin] + {\filleft\scshape}{\thesection}{.5em}{} + +\titleformat{name=\section,page=odd}[rightmargin] + {\filright\scshape}{\thesection}{.5em}{} +\end{verbatim} +Since the page information is written to the |aux| file, at +least two runs are necessary to get the desired result. + +The ``number'' version is usually fine when generating unnumbered +variants since removing the label is the only change required in most +cases, but if you need some special formatting, there is the +|numberless| key which defines an alternative version for sections +without numbers (namely those with level below |secnumdepth|, in the +front and back matters and, of course, the starred version). For +instance +\begin{verbatim} +\titleformat{name=\section}{...% The normal definition follows +\titleformat{name=\section,numberless}{...% The unnumbered +% definition follows +\end{verbatim} +Neither |<label>| nor |<sep>| are ignored in |numberless| +variants. + +These keys are available to both |\titleformat| and +|\titlespacing|. By using |page| in one (or both) of them, odd and +even pages will be formatted differently. Actually, +``even'' and ``odd'' are well established \LaTeX{} terms, but +misleading. In one side printing the ``odd'' pages refer +to ``even'' pages as well (cf.\@ |\oddsidemargin|.) + +If you intend to create different odd/even \emph{and} +different numbered/unnumbered versions, it is recommended defining +the four variants. + +If you remove the page specifier from a sectioning command you +must remove the |.aux| file. + +\subsection{Creating new levels and changing the class} + +While the shapes and the like modify the behaviour of titles related +to the surrounding text, title classes allow to change the generic +behaviour of them. With the help of classes you may insert, say, a +new |subchapter| level between |chapter| and |section|, or creating a +scheme of your own. \emph{Making a consistent scheme and defining all +of related stuff like counters, macros, format, spacing and, if there +is a TOC, TOC format is left to the responsibility of the user.} There +are three classes: |page| is like the book |\part|, in a single page, +|top| is like |\chapter|, which begins a page and places the title at +the top, and |straight| is intended for titles in the middle of +text.\footnote{There is an further class named |part| to emulate the +article |\cs{part}|, but you should not use it at all. Use the +|straight| class instead. Remember some features rely in these +classes and \textsf{titlesec} does not change by default the +definition of \texttt{\string\part} and \texttt{\string\chapter}.} + +\begin{desc} +|\titleclass{<name>}{<class>}|\\ +|\titleclass{<name>}{<class>}[<super-level-cmd>]| +\end{desc} + +If you do not use the optional argument, you just change +the |<class>| of |<name>|. For example: +\begin{verbatim} +\titleclass{\part}{straight} +\end{verbatim} +makes |part| of |straight| class. + +When the second form is used, the level number is the following of +|<super-level-cmd>|. For example: +\begin{verbatim} +\titleclass{\subchapter}{straight}[\chapter] +\newcounter{subchapter} +\renewcommand{\thesubchapter}{\Alph{subchapter}} +\end{verbatim} +creates a level under chapter (some additional code is shown as well, +but you must add to it the corresponding |\titleformat| and +|\titlespacing| settings).\footnote{Regarding counters, the +\textsf{remreset} package can be useful.} +If the chapter level is 0, then the subchapter one is 1; the levels +below are increased by one (section is 2, subsection is 3, and so on). + +There are two sectioning commands which perform some extra actions +depending of its name and ignoring the class: +\begin{itemize} +\item |\chapter| logs the string defined in |\chaptertitlename| + and the matter is taken into account. +\item |\part| does not encapsulates the label in the toc entry, +except if you use the |newparttoc| option. +\end{itemize} + +\begin{desc} +|loadonly| \quad (Package option) +\end{desc} + +Let us suppose you want to create your sectioning commands from scratch. +This package option ignores any previous definitions, if any, +and hence removes the possibility of using the options described +in ``Quick Reference.'' Then you use the \textsf{titlesec} +tools, and define the corresponding counters and labels. + +\begin{desc} +|\titleclass{<name>}[<start-level-num>]{<class>}| +\end{desc} + +Here, the |<name>| title is considered the top level, with number +|<start-level-num>| (typically 0 or $-$1). It should be used only when +creating sectioning commands from scratch with the help of |loadonly|, +and there must be exactly one (no more, no less) declaration of this +kind. After it, the rest of levels are added as explained above. + +\section{Additional Notes} +%~~~~~~~~~~~~~~~~~~~~~~~~ + +This part describes briefly some \LaTeX{} commands, useful +when defining sectioning titles. + +\subsection{Fixed Width Labels} + +The |\makebox| command allows to use fixed width label, which +makes the left margin of the actual title (not the label) to lie +in the same place. For instance (only the relevant code is +provided): +\begin{verbatim} +\titleformat{\section} + {..} + {\makebox[2em]{\thesection}}{..}{..} +\end{verbatim} + +See your \LaTeX{} manual for further reference on boxing commands. + +\subsection{Starred Versions} +\label{s:starred} + +Using sectioning commands in the starred version is strongly +discouraged. Instead, you can use a set of markup oriented commands +which are easy to define and modify, if necessary. Thus, you can test +different layouts before choosing amongst them. + +Firstly remember if you say +\begin{verbatim} +\setcounter{secnumdepth}{0} +\end{verbatim} +sections will be not numbered but they will be included in both toc +and headers. + +Now, let's +suppose you want to include some sections with a special content; +for example, a section (or more) with exercises. We will use an +environment named |exercises| whose usage is: +\begin{verbatim} +\section{A section} +Text of a normal section. + +\begin{exercises} +\section{Exercises A} +Some exercises + +\section{Exercises B} +Some exercises +\end{exercises} +\end{verbatim} + +The following definition suppresses numbers but neither toc lines +nor headers. +\begin{verbatim} +\newenvironment{exercises} + {\setcounter{secnumdepth}{0}} + {\setcounter{secnumdepth}{2}} +\end{verbatim} + +The following one adds a toc line but headers will remain +untouched: +\begin{verbatim} +\newenvironment{exercises} + {\setcounter{secnumdepth}{0}% + \renewcommand\sectionmark[1]{}} + {\setcounter{secnumdepth}{2}} +\end{verbatim} + +The following one updates the headers but there will be +no toc line: +\begin{verbatim} +\newenvironment{exercises} + {\setcounter{secnumdepth}{0}% + \addtocontents{toc}{\protect\setcounter{tocdepth}{0}\ignorespaces}} + {\setcounter{secnumdepth}{2}% + \addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}} +\end{verbatim} +(I find the latter a bit odd in this particular example; the +first and second options are more sensible. The |\ignorespaces| +is not very important, and you need not it unless there is +unwanted space in the toc.) + +That works with standard classes, but if you are using +\textsf{fancyhdr} or \textsf{titlesec} to define headers you need +further refinement to kill the section number. In \textsf{titlesec} +that's accomplished with |\ifthesection| (see below). + +As you can see, there are no |\addcontentsline|, no +|\markboth|, no |\section*|, just logical structure. Of +course you may change it as you wish; for example if you decide +these sections should be typeset in small typeface, include +|\small|, and if you realize you do not like that, remove it. + +While the standard \LaTeX{} commands are easier and more +direct for simple cases, I think the proposed method above is +far preferable in large documents. + +\subsection{Variants} + +Let's suppose we want to mark some sections as ``advanced topics'' +with an asterisk after the label. +The following code does the job: +\begin{verbatim} +\newcommand{\secmark}{} +\newenvironment{advanced} + {\renewcommand{\secmark}{*}} + {} +\titleformat{\section} + {..} + {\thesection\secmark\quad}{..}{..} +\end{verbatim} + +To mark the sections write +\begin{verbatim} +\begin{advanced} +\section{...} +... +\end{advanced} +\end{verbatim} + +That marks sections but not subsections. If you like being +redundant and marking the subsection level as well, you must +define it accordingly. + +\subsection{Putting a Dot after the Section Title} +\label{sec:dotafter} + +Today this styling is not used, but formerly it was fairly common. +The basic technique was described above, but here is a reminder: +\begin{verbatim} +\newcommand{\periodafter}[1]{#1.} +\titleformat{\section} + {..} + {\thesection}{..}{..\periodafter} +\end{verbatim} + +If you had to combine this dot with some command (perhaps an +underlining), you can say: +\begin{verbatim} +\newcommand{\periodafter}[2]{#1{#2.}} +\titleformat{\section} + {..} + {\thesection}{..}{..\periodafter{\ul}} % \ul from soul package +\end{verbatim} + +However, you might prefer the package option \texttt{explicit}. + +\section{\textsf{titleps} and Page Styles} +%~~~~~~~~~~~~~~~~~~~ + +The \textsf{titleps} package provides tools for one-stage setting of +page styles (headlines and footlines). A higher-level interface is +used, where the mark mechanism is hidden and there is no need to deal +with |\leftmark|s and |\rightmark|s -- just use a command or variable +registered as a ``mark'' as the expected value will be returned, i.e., +those when the mark was emitted, either by a sectioning command or +explicitly with |\chaptermark|, |\sectionmark|, etc. A simple +example, whose meaning should be obvious, is: +\begin{verbatim} +\newpagestyle{main}{ + \sethead[\thepage][\chaptertitle][(\thesection] % even + {\thesection)}{\sectiontitle}{\thepage}} % odd +\pagestyle{main} +\end{verbatim} + +Other features are: +\begin{itemize} +\item Working top marks, compatible with floats (unlike the standard +|\topmark|, which does not work correctly in \LaTeX{}). +\item Access to top, first and bot marks in a single headline/footline +(e.g., the first and last section numbers). +\item Marks for more than 2 sectioning levels. +\item Simple (and not so simple) headrules and footrules. +\item Headlines and footlines for pages with floats. +\item Headlines and footlines for specific floats (a sort of +|\thispagestyle| for floats). +\item Multiple sets of marks (named here \emph{markset}s and +\textit{extra marks}). +\end{itemize} + +It can be used without \textsf{titlesec}, but you will get most of +it when used together. To load it as a separate package, use the +customary \verb|\usepackage{titleps}|, but with \textsf{titlesec} you +have to load it with: +\begin{verbatim} +\usepackage[pagestyles]{titlesec} +\end{verbatim} + +Please, read |titleps.pdf| (or typeset |titleps.tex|) for further +information. + +\section{Contents: The \textsf{titletoc} package} +% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This package is a companion to the \textsf{titlesec} package and it +handles +toc entries. However, it is an independent package and you can use +it alone. The philosophy is similar to that of \textsf{titlesec}---instead +of hooking the commands as defined by standard \LaTeX{} and classes, +there are new commands which you can format the toc entries with +in a generic way. This means you have to learn just +two new basic command and a couple of tools, no more, and you have access +to +new features. Paragraph format +and fonts are set with commands like |\\|, +|\makebox|, +|\large|, |\itshape|, and so on, and entries are not shaped in any +fashion because they are pretty free form. + +The behaviour of entries +defined with \textsf{titletoc} are different at some points +to those created with the standard commands. In particular: +\begin{itemize} +\item Pages are never broken between entries if the first one is +of an higher level than the second one as, for instance, between +a section and a subsection. If both of them are of the same +level, the break is allowed, and if the first is lower than +the second, it is considered a good place for a page break. + +\item The symbols in the leaders are not centered but flushed +right. That is usually more convenient. +\end{itemize} + +I would like to note no attempt to handle tocs can be complete +because the standard \LaTeX{} commands write directly some formatting +commands which cannot be removed. This is particularly important in +lists of figures and tables, and in the |\part| command.\footnote{But +some of these issues are fixed by \textsf{titlesec}.} + +\subsection{A ten-minute guide to \textsf{titletoc}} + +Toc entries are treated as rectangular areas where the text +and probably a filler will be written. Let's draw such an +area (of course, the lines themselves are not printed): +\setlength{\unitlength}{1cm} +\begin{center} +\begin{picture}(8,2.2) +\put(1,1){\line(1,0){6}} +\put(1,2){\line(1,0){6}} +\put(1,1){\line(0,1){1}} +\put(7,1){\line(0,1){1}} +\put(0,.7){\vector(1,0){1}} +\put(8,.7){\vector(-1,0){1}} +\put(0,.2){\makebox(1,.5)[b]{\textit{left}}} +\put(7,.2){\makebox(1,.5)[b]{\textit{right}}} +\end{picture} +\end{center} + +The space between the left page margin and the left edge of +the area will be named |<left>|; similarly we have |<right>|. +You are allowed to modify the beginning of the first line and +the ending of the last line. For example by ``taking up'' both +places with |\hspace*{2pc}| the area becomes: +\begin{center} +\begin{picture}(8,2.2) +\put(1,1){\line(1,0){5.5}} +\put(6.5,1){\line(0,1){.5}} +\put(6.5,1.5){\line(1,0){.5}} +\put(1.5,2){\line(1,0){5.5}} +\put(1,1.5){\line(1,0){.5}} +\put(1.5,1.5){\line(0,1){.5}} +\put(1,1){\line(0,1){.5}} +\put(7,1.5){\line(0,1){.5}} +\put(0,.7){\vector(1,0){1}} +\put(8,.7){\vector(-1,0){1}} +\put(0,.2){\makebox(1,.5)[b]{\textit{left}}} +\put(7,.2){\makebox(1,.5)[b]{\textit{right}}} +\end{picture} +\end{center} +And by ``clearing'' space in both places with |\hspace*{-2pc}| +the area becomes: +\begin{center} +\begin{picture}(8,2.2) +\put(1,1){\line(1,0){6.5}} +\put(7.5,1){\line(0,1){.5}} +\put(7.5,1.5){\line(-1,0){.5}} +\put(.5,2){\line(1,0){6.5}} +\put(1,1.5){\line(-1,0){.5}} +\put(.5,1.5){\line(0,1){.5}} +\put(1,1){\line(0,1){.5}} +\put(7,1.5){\line(0,1){.5}} +\put(0,.7){\vector(1,0){1}} +\put(8,.7){\vector(-1,0){1}} +\put(0,.2){\makebox(1,.5)[b]{\textit{left}}} +\put(7,.2){\makebox(1,.5)[b]{\textit{right}}} +\end{picture} +\end{center} + +If you have seen tocs, the latter should be familiar to you-- +the label at the very beginning, the page at the very end: +\begin{verbatim} + 3.2 This is an example showing that toc + entries fits in that scheme . . . . 4 +\end{verbatim} + +All you need is to put these elements in the right way. If you have +reserved the space with |\hspace*{-2pc}|, simply put a box 2 pc +width +containing the section label or page so that this space will be +retrieved; this layout is used so often that two commands are provided +which does that for you: +\begin{itemize} +\item |\contentslabel{<length>}| creates the space at the beginning +and + prints the section number. +\item |\contentspage| creates a space at the end of length |<right>| + and prints the page number aligned at the right. +\end{itemize} + +Now, we are about to show the three basic commands: + +\begin{desc} +|\dottedcontents{<section>}[<left>]{<above-code>}|\\ +| {<label width>}{<leader width>}| +\end{desc} + +Here: +\begin{itemize} +\item |<section>| is the section name without backslash: |part|, + |chapter|, |section|, etc. |figure| and |table| are allowed, too. + (The backlash is omitted because we are dealing with the concept + and not the |\part|, |\section|, etc. macros themselves. + Furthermore, |figure| and |table| are environments.) + +\item |<above-code>| is code for the global formatting of the entry. + Vertical material is allowed. At this point the value of + |\thecontentslabel| (see below) is known which enables you to + take decisions depending on its value (with the help of + the \textsf{ifthen} package). You may use the \textsf{titlesec} + |\filleft|, |\filright|, |\filcenter| and |\fillast| commands. + +\item |<left>| even if bracketed is currently mandatory and it + sets the left margin from the left page margin. + +\item |<label width>| is the width of the space created for the label, + as described above. + +\item |<leader width>| is the width of the box containing the char to + be used as filler, as described below. +\end{itemize} + +The definitions for section and subsection entries in the \textsf{book} +class are roughly equivalent to: +\begin{verbatim} +\contentsmargin{2.55em} +\dottedcontents{section}[3.8em]{}{2.3em}{1pc} +\dottedcontents{subsection}[6.1em]{}{3.2em}{1pc} +\end{verbatim} + +\begin{desc} +|\titlecontents{<section>}[<left>]{<above-code>}|\\ +| {<numbered-entry-format>}{<numberless-entry-format>}|\\ +| {<filler-page-format>}[<below-code>]| +\end{desc} + +Here |<section>|, |<left>| and |<above-code>| like above, and +\begin{itemize} +\item |<numbered-entry-format>| is in horizontal mode and it will + be used just before the entry title. As in |\titleformat|, the + last command can take an argument with the title. + +\item |<numberless-entry-format>| is like the above if there is, well, + no label. + +\item|<filler-page-format>| is self explanatory. Fillers are created +with the |\titlerule| command which is shared by that package and +\textsf{titlesec}. However, when used in this context its behaviour +changes a little to fit the needs of toc leaders.\footnote{For +\TeX{}nicians, the default |\cs{xleaders}| becomes +|\cs{leaders}|.} You might prefer a |\hspace| instead. + +\item And finally |<below-code>| is code following the entry for, say, + vertical space. +\end{itemize} + +When defining entries, use |\addvspace| if you want to add vertical +space, and |\\*| instead of |\\| for line breaks. + +This command can be used in the middle of a document to change +the format of toc/lot/lof entries at any point. The new format is +written to the toc file and hence two runs are necessary to +see the changes. + +\begin{desc} +|\contentsmargin{<right>}| +\end{desc} + +The value set is used in all of sections. If you are wondering +why, the answer is quite simple: in most of cases the |<right>| +margin will be constant. However, you are allowed to change +it locally in the |<before-code>| arguments. Note as well that +the default space in standard classes does not leave room to +display boldfaced page number above 100 and therefore you +might want to set a larger margin with this command. + +The \textsf{book} class formats section entries +similarly (but not equally) to: +\begin{verbatim} +\titlecontents{section} + [3.8em] % ie, 1.5em (chapter) + 2.3em + {} + {\contentslabel{2.3em}} + {\hspace*{-2.3em}} + {\titlerule*[1pc]{.}\contentspage} +\end{verbatim} +Compare this definition with that given above and you will +understand how |\dottedcontents| is defined. + +Although standard classes use font dependent units (mainly em), +it is recommended using absolute ones (pc, pt, etc.) to ensure +they entries are aligned correctly. + +\subsection{And more} + +Strict typographical rules state full text lines shouldn't +surpass the last dot of the leaders; ideally they should be aligned. +Surprisingly enough, \TeX{} lacks of a tool for doing that +automatically---when you fill a box with leading dots, they can be +centered in the box with the |\cleaders| primitive , ``justified'' +with |\xleaders| or aligned with the outermost enclosing box with +|\leaders|, but there is no way to align them with the ``current'' +margin. + +So, the only way to get a fine layout is by hand. To do , you can +use the an optional argument in the |\contentsmargin| command whose +syntax in full is the following: +\begin{desc} +|\contentsmargin[<correction>]{<right>}| +\end{desc} + +The |<correction>| length is added to the |<right>| one in all of lines +except the last one, where the leaders are placed. For instance, if +the text lines are 6 pt longer than the last dot, you should rewrite the +|\contentsmargin| command to add a |<correction>| of 6 pt.% +\footnote{Usefully, many dvi previewers allow to get the coordinates of +the pointed location.} Unlike the standard \LaTeX{} tools, the +|\titlerule*| command has been designed so that the |<correction>| +will have the minimum value possible. + +\begin{desc} +|\thecontentslabel \thecontentspage| +\end{desc} + +Contains the text with the label and the page with no additional +formatting, except written by the class. + +\begin{desc} +|\contentslabel[<format>]{<space>}|\\ +|\contentspage[<format>]| +\end{desc} + +As described above, but with different |<format>|s. The defaults are +just |\thecontentslabel| and |\thecontentspage|, respectively. + +\begin{desc} +|\contentspush{<text>}| +\end{desc} + +Prints the |<text>| and increases +|<left>| by the width of |<text>|. It is similar to +the hang shape of \textsf{titlesec}. + +\begin{desc} +|\titlecontents*{<section>}[<left>]{<above-code>}|\\ +| {<numbered-entry-format>}{<numberless-entry-format>}|\\ +| {<filler-page-format>}[<separator>]|\\[3pt] +| |\textit{or ...}|{<filler-page-format>}[<separator>][<end>]|\\ +| |\textit{or ...}|{<filler-page-format>}[<begin>][<separator>][<end>]| +\end{desc} + +This starred version groups the entries in a single paragraph. +The |<separator>| argument is the separator between entries, and +there is a further optional argument with an ending +punctuation. For example, this document sets: +\begin{verbatim} +\titlecontents*{subsection}[1.5em] + {\small} + {\thecontentslabel. } + {} + {, \thecontentspage} + [.---][.] +\end{verbatim} +whose result is showed in the contents at the very beginning of +this document. Note the paragraph format must be written in +the |<above-code>| argument. + +Let us explain how the optional arguments works. First note the number +of them determines their meaning---since there should be a separator +between entries this one is always present; on the other hand, +|<begin>| is rarely used and hence it has the lowest ``preference.'' +The simplest case is when the titles are of the same level; in this +case the |<sepatator>| and the |<end>| parameters (which default to +empty) are inserted between consecutive entries and at the end of the +block, respectively. |<before-code>| is executed just once at the +very beginning of the block and its declarations are local to the +whole set of entries. + +Now suppose we want to group entries of two levels; in this +case a nesting principle applies. To fix ideas, we will use section +and subsection. When a subsection entry begins after a section one, +|<before-code>| is executed and |<begin>| of subsection is +inserted, which should contain text format only. Then subsections are +added inserting separators as explained above. When a section +arrives, the ending punctuation of subsection and the separator of +section is added (except if the block is finished by a subsection, +where the ending of section is added instead). We said ``after a +section'' because a subsection never begins a block.\footnote{In rare +cases that could be necessary, yet.} The +subsection entries are nested inside the section ones, and +declarations are again local. + +An example will illustrate that. +\begin{verbatim} +\titlecontents*{section}[0pt] + {\small\itshape}{}{} + {}[ \textbullet\ ][.] + +\titlecontents*{subsection}[0pt] + {\upshape}{}{} + {, \thecontentspage}[ (][. ][)] +\end{verbatim} +produces something similar to: +$$\begin{minipage}{\textwidth} +\small\itshape The first section \textbullet\ The second one \textbullet\ +The third one {\upshape(A subsection in it, 1. Another, 2)} \textbullet\ A +fourth section {\upshape(A subsection in it, 1. Another, 2)}. +\end{minipage}$$ + +\begin{desc} +|\contentsuse{<name>}{<ext>}| +\end{desc} + +Makes \textsf{titletoc} aware of the existence of a contents file with +|<ext>| extension. Mainly, it makes sure the command +|\contentsfinish| is added at the end of the corresponding +contents (and which must be added at the end of tocs made by hand). +The package performs +\begin{verbatim} +\contentsuse{figure}{lof} +\contentsuse{table}{lot} +\end{verbatim} + +% \begin{desc} +% |\titlelevels{<top>}{<level-list>}| +% \end{desc} +% +% If you are not using \textsf{titlesec}, this command modifies +% the list of level names. Only necessary if you have been devised +% your own scheme of titles. + +\begin{desc} +|leftlabels rightlabels| \quad (Package options) +\end{desc} + +These package options set how the labels are aligned in +|\contentslabel|. +Default is |rightlabels|. With |leftlabels| the default |<format>| for +|\contentslabel| becomes |\thecontenstlabel\enspace|. + +\begin{desc} +|dotinlabels| \quad (Package option) +\end{desc} + +With this package option, a dot is added after the label in +|\contentslabel|. + +\subsection{Partial TOC's} + +\begin{desc} +|\startcontents[<name>]| +\end{desc} + +At the point where this command is used, a partial toc begins (note +the document doesn't require a |\tableofcontents| for partial tocs to +work). The |<name>| argument allows different sets of tocs and it +defaults to |default|. These sets may be intermingled, but usually +will be nested. For example, you may want two kinds of partial tocs: +by part and by chapter (besides the full toc, of course). When a part +begins, write |\startcontents[parts]|, and when a chapter +|\startcontents[chapters]|. This way a new toc is started at each +part and chapter.\footnote{\emph{All} partial tocs are stored in a +single file with extension |.ptc|.} + +\begin{desc} +|\stopcontents[<name>]|\\ +|\resumecontents[<name>]| +\end{desc} + +Stops the partial toc of |<name>| kind, which may be resumed. +Since partial contents are stopped by |\startcontents| if necessary, +those macros will not be used very often. + +\begin{desc} +|\printcontents[<name>]{<prefix>}{<start-level>}[<toc-depth>]{<toc-code>}| +\end{desc} + +Print the current partial toc of |<name>| kind. The format +of the main toc entries are used, except if there is a |<prefix>|. +In such a case, the format of |<prefix><level>| is used, provided +it is defined. For example, if prefix is |l| and the format of +|lsection| is defined, then this definition will be used; otherwise, +the format is that of |section|. The |<start-level>| parameter sets the +top level of the tocs---for a part toc it would be |0| (chapter), for a +chapter toc |1| (section), and so on. The |<toc-code>| is +local code for the current toc; it may be used to change the +|\contentsmargin|, for instance. \textbf{New 2.11} Finally, +|<toc-depth>| sets the |tocdepth| locally (in former versions it was +suggested setting this value with |\setcounter| in the last argument, +but that was wrong, because this command set counters globally). + +A simple usage might look like (provided you are using +\textsf{titlesec} as well): +\begin{verbatim} +\titleformat{\chapter}[display] + {...}{...}{...} % Your definitions come here + [\vspace*{4pc}% + \startcontents + \printcontents{l}{1}[2]{}] + +\titlecontents*{lsection}[0pt] + {\small\itshape}{}{} + {}[ \textbullet\ ][.] +\end{verbatim} +The included entries are those in levels 1 to 2 inclusive (i.e., 1 +and 2). + +\subsection[Partial lists]{Partial lists \normalfont\normalsize\fbox{2.6}} + +You may want to create partial LOFs and LOTs. The systax is similar to +that of partial TOCs and what was said for them can be applied here. +The commands are: +\begin{desc} +|\startlist[<name>]{<list>}|\\ +|\stoplist[<name>]{<list>}|\\ +|\resumelist[<name>]{<list>}|\\ +|\printlist[<name>]{<list>}{<prefix>}[<toc-depth>]{<toc-code>}| +\end{desc} + +Here |<list>| is either |lof| or |lot|. Note as well |\printlist| +does not have the |<start-level>| argument, because figures and tables +have not levels. Currently, only those two float lists are supported, +but in a future release support for more kinds of float lists will be +added. Unfortunately, many classes write some formatting commands to +these lists (more precisely, \verb|\addvspace|s in chapters); I'm +still not sure how to remove these commands without removing as well +others which can be wanted, but for the time being a quick trick to +remove these spaces is to redefine \verb|\addvspace| in the +|<toc-code>| with |\renewcommand\addvspace[1]{}|. + +\subsection{Examples} + +\begin{verbatim} +\titlecontents{chapter} + [0pt] + {\addvspace{1pc}% + \itshape}% + {\contentsmargin{0pt}% + \bfseries + \makebox[0pt][r]{\huge\thecontentslabel\enspace}% + \large} + {\contentsmargin{0pt}% + \large} + {\quad\thepage} + [\addvspace{.5pc}] +\end{verbatim} + +The chapter number is out at the edge of the page margin, in a font +larger than the font of the title. If the chapter lacks of number +(because, say, it is the preface or the bibliography) it is not +boldfaced. The page number follows the title without fillers, but +after an em-space. + +\begin{verbatim} +\titlecontents{chapter} + [3pc] + {\addvspace{1.5pc}% + \filcenter} + {CHAPTER \thecontentslabel\\*[.2pc]% + \huge} + {\huge} + {} % That is, without page number + [\addvspace{.5pc}] +\end{verbatim} + +The chapter title is centered with the chapter label on top +of it. There is no page number. + +\subsection{Inserting a figure in the contents} + +The |\addtocontents| command is still available and you may use +it to perform special operation, like inserting a figure just before +or after of an entry. Sadly, fragile +arguments are not allowed and writing complex code could be a mess. +The trick is to define a command to perform the required operations +which in turn is written with |\protect|. + +Let's suppose we want to insert a figure before an entry. +\begin{verbatim} +\newcommand{\figureintoc}[1]{ + \begin{figure} + \includegraphics{#1}% + \end{figure}} +\end{verbatim} +makes the dirty work. + +In the place where a figure is inserted write: +\begin{verbatim} +\addtocontents{\protect\figureintoc{myfig}} +\end{verbatim} + +\subsection{Marking entries with asterisks} + +Let's now resume a problem explained in relation with +\textsf{titlesec}: marking sections with asterisks to +denote an ``advanced topic'' unless the star should +be printed in the toc as well. Here is the code: +\begin{verbatim} +\newcommand{\secmark}{} +\newcommand{\marktotoc}[1]{\renewcommand{\secmark}{#1}} +\newenvironment{advanced} + {\renewcommand{\secmark}{*}% + \addtocontents{toc}{\protect\marktotoc{*}}} + {\addtocontents{toc}{\protect\marktotoc{}}} +\titleformat{\section} + {..} + {\thesection\secmark}{..}{..} +\titlecontents{section}[..]{..} + {\contentslabel[\thecontentslabel\secmark]{1.5pc}}{..}{..} +\end{verbatim} + +\section{The \textsf{titlesec} philosophy} + +Once you have read the documentation it should be clear this +is not a package for the casual user who likes the standard +layout and wants to make simple changes. This is a tool for the +serious typographer who has a clear idea of what layout wants +and do not have the skill to get it. No attempt is made to improve +your taste in section formatting. + +\section{Appendix} + +The following examples will be illustrative. In this part, the +|\parskip| is 0 pt. + +\begingroup + +\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}\ignorespaces} +\setlength{\parskip}{0pt} + +\examplesep + +\titleformat{\section}[block] + {\normalfont\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{} + +\section[Appendix]{This is an +example of the section command defined below and, what's more, this +is an example of the section command defined below} + +\begin{verbatim} +\titleformat{\section}[block] + {\normalfont\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{} +\end{verbatim} + +\examplesep + +\titleformat{\section}[frame] + {\normalfont} + {\filright + \footnotesize + \enspace SECTION \thesection\enspace} + {8pt} + {\Large\bfseries\filcenter} + +\section[Appendix]{A framed title} + +\begin{verbatim} +\titleformat{\section}[frame] + {\normalfont} + {\filright + \footnotesize + \enspace SECTION \thesection\enspace} + {8pt} + {\Large\bfseries\filcenter} +\end{verbatim} + +\examplesep + +\titleformat{\section} + {\titlerule + \vspace{.8ex}% + \normalfont\itshape} + {\thesection.}{.5em}{} + +\section[Appendix]{A Ruled Title} + +\begin{verbatim} +\titleformat{\section} + {\titlerule + \vspace{.8ex}% + \normalfont\itshape} + {\thesection.}{.5em}{} +\end{verbatim} + +\examplesep + +\titleformat{\section}[block] + {\normalfont\sffamily} + {\thesection}{.5em}{\titlerule\\[.8ex]\bfseries} + +\section[Appendix]{Another Ruled Title} + +\begin{verbatim} +\titleformat{\section}[block] + {\normalfont\sffamily} + {\thesection}{.5em}{\titlerule\\[.8ex]\bfseries} +\end{verbatim} + +\examplesep + +\titleformat{\section}[block] + {\filcenter\large + \addtolength{\titlewidth}{2pc}% + \titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}% + \addvspace{6pt}% + \normalfont\sffamily} + {\thesection}{1em}{} +\titlespacing{\section} + {5pc}{*2}{*2}[5pc] + +\section[Appendix]{The length of the ``rule'' above + is that of the longest line in this title increased by + two picas} + +\leavevmode + +\section[Appendix]{This one is shorter} + +\begin{verbatim} +\titleformat{\section}[block] + {\filcenter\large + \addtolength{\titlewidth}{2pc}% + \titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}% + \addvspace{6pt}% + \normalfont\sffamily} + {\thesection}{1em}{} +\titlespacing{\section} + {5pc}{*2}{*2}[5pc] +\end{verbatim} + +\examplesep + +\titleformat{\section}[display] + {\normalfont\fillast} + {\scshape section \oldstylenums{\thesection}} + {1ex minus .1ex} + {\small} +\titlespacing{\section} + {3pc}{*3}{*2}[3pc] + +\section[Appendix]{This is an example of the section +command defined below +and, what's more, this is +an example of the section command defined below. Let us repeat it. +This is an example of the section command defined below +and, what's more, this is +an example of the section command defined below} + +\begin{verbatim} +\titleformat{\section}[display] + {\normalfont\fillast} + {\scshape section \oldstylenums{\thesection}} + {1ex minus .1ex} + {\small} +\titlespacing{\section} + {3pc}{*3}{*2}[3pc] +\end{verbatim} + +\examplesep + +\titleformat{\section}[runin] + {\normalfont\scshape} + {}{0pt}{} +\titlespacing{\section} + {\parindent}{*2}{\wordsep} + +\section*{This part is the title itself} +and this part is the section body\ldots + +\begin{verbatim} +\titleformat{\section}[runin] + {\normalfont\scshape} + {}{0pt}{} +\titlespacing{\section} + {\parindent}{*2}{\wordsep} +\end{verbatim} + +\examplesep + +\titleformat{\section}[wrap] + {\normalfont\fontseries{b}\selectfont\filright} + {\thesection.}{.5em}{} +\titlespacing{\section} + {12pc}{1.5ex plus .1ex minus .2ex}{1pc} + +\section[Appendix]{A Simple Example of the + ``wrap'' Section Shape} + +Which is followed by some text to show the result. Which is followed +by some text to show the result. Which is followed by some text to +show the result. Which is followed by some text to show the result. +Which is followed by some text to show the result. Which is followed +by some text to show the result. Which is followed +by some text to show the result. + +\section[Appendix]{And another} + +Note how the text wraps the title and the space reserved to it is +readjusted automatically. And it is followed by some text to +show the result. Which is followed by some text to show the result. + +\begin{verbatim} +\titleformat{\section}[wrap] + {\normalfont\fontseries{b}\selectfont\filright} + {\thesection.}{.5em}{} +\titlespacing{\section} + {12pc}{1.5ex plus .1ex minus .2ex}{1pc} +\end{verbatim} + +\examplesep + +\titleformat{\section}[runin] + {\normalfont\bfseries} + {\S\ \thesection.}{.5em}{}[.---] +\titlespacing{\section} + {\parindent}{1.5ex plus .1ex minus .2ex}{0pt} + +\section[Appendix]{Old-fashioned runin title} + +Of course, you would prefer just a dot after the title. In +this case the optional argument should be |[.]| and the space +after a sensible value (1em, for example). + +\begin{verbatim} +\titleformat{\section}[runin] + {\normalfont\bfseries} + {\S\ \thesection.}{.5em}{}[.---] +\titlespacing{\section} + {\parindent}{1.5ex plus .1ex minus .2ex}{0pt} +\end{verbatim} + +\examplesep + +\titleformat{\section}[leftmargin] + {\normalfont + \titlerule*[.6em]{\bfseries .}% + \vspace{6pt}% + \sffamily\bfseries\filleft} + {\thesection}{.5em}{} +\titlespacing{\section} + {4pc}{1.5pc plus .1ex minus .2ex}{1pc} + +\section*{Example of margin section} + +Which is followed by some text to show the result. +But do not stop reading, because the following example illustrates how +to take advantage of other packages. The last command in the last +argument can take an argument, which is the title with no +additional command inside it. We just give the code, but you +may try it by yourself. Thus, with the \textsf{soul} package +you may say +\begin{verbatim} +\newcommand{\secformat}[1]{\MakeLowercase{\so{#1}}} + % \so spaces out letters +\titleformat{\section}[block] + {\normalfont\scshape\filcenter} + {\thesection} + {1em} + {\secformat} +\end{verbatim} + +The margin title above was defined: +\begin{verbatim} +\titleformat{\section}[leftmargin] + {\normalfont + \titlerule*[.6em]{\bfseries.}% + \vspace{6pt}% + \sffamily\bfseries\filleft} + {\thesection}{.5em}{} +\titlespacing{\section} + {4pc}{1.5ex plus .1ex minus .2ex}{1pc} +\end{verbatim} + +\examplesep + +The following examples are intended for chapters. However, this +document lacks of |\chapter| and are showed using |\section|s +with slight changes. + +\titlespacing{\section}{0pt}{*4}{*4} +\titleformat{\section}[display] + {\normalfont\Large\filcenter\sffamily} + {\titlerule[1pt]% + \vspace{1pt}% + \titlerule + \vspace{1pc}% + \LARGE\MakeUppercase{chapter} \thesection} + {1pc} + {\titlerule + \vspace{1pc}% + \Huge} + +\section[Appendix]{The Title} + +\begin{verbatim} +\titleformat{\chapter}[display] + {\normalfont\Large\filcenter\sffamily} + {\titlerule[1pt]% + \vspace{1pt}% + \titlerule + \vspace{1pc}% + \LARGE\MakeUppercase{\chaptertitlename} \thechapter} + {1pc} + {\titlerule + \vspace{1pc}% + \Huge} +\end{verbatim} + +\examplesep + +\def\thesection{\Roman{section}} +\titleformat{\section}[display] + {\bfseries\Large} + {\filleft\MakeUppercase{chapter} \Huge\thesection} + {4ex} + {\titlerule + \vspace{2ex}% + \filright} + [\vspace{2ex}% + \titlerule] + +\section[Appendix]{The Title} + +\begin{verbatim} +\renewcommand{\thechapter}{\Roman{chapter}} +\titleformat{\chapter}[display] + {\bfseries\Large} + {\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter} + {4ex} + {\titlerule + \vspace{2ex}% + \filright} + [\vspace{2ex}% + \titlerule] +\end{verbatim} + +\addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces} +\setcounter{section}{9} +\endgroup + +\bigskip + +\subsection{A full example} + +Now an example of a complete title scheme follows. + +\begin{verbatim} +\documentclass[twoside]{report} +\usepackage[sf,sl,outermarks]{titlesec} + +% \chapter, \subsection...: no additional code + +\titleformat{\section} + {\LARGE\sffamily\slshape} + {\thesection}{1em}{} +\titlespacing{\section} + {-6pc}{3.5ex plus .1ex minus .2ex}{1.5ex minus .1ex} + +\titleformat{\paragraph}[leftmargin] + {\sffamily\slshape\filright} + {}{}{} +\titlespacing{\paragraph} + {5pc}{1.5ex minus .1 ex}{1pc} + +% 5+1=6, ie, the negative left margin in section + +\widenhead{6pc}{0pc} + +\renewpagestyle{plain}{} + +\newpagestyle{special}[\small\sffamily]{ + \headrule + \sethead[\usepage][\textsl{\chaptertitle}][] + {}{\textsl{\chaptertitle}}{\usepage}} + +\newpagestyle{main}[\small\sffamily]{ + \headrule + \sethead[\usepage][\textsl{\thechapter. \chaptertitle}][] + {}{\textsl{\thesection. \sectiontitle}}{\usepage}} + +\pagestyle{special} + +\begin{document} + +---TOC + +\pagestyle{main} + +---Body + +\pagestyle{special} + +---Index +\end{document} +\end{verbatim} + +\subsection{Standard Classes} + +Now follows, for your records, how sectioning commands of standard +classes could be defined. +\begin{verbatim} +\titleformat{\chapter}[display] + {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge} +\titleformat{\section} + {\normalfont\Large\bfseries}{\thesection}{1em}{} +\titleformat{\subsection} + {\normalfont\large\bfseries}{\thesubsection}{1em}{} +\titleformat{\subsubsection} + {\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{} +\titleformat{\paragraph}[runin] + {\normalfont\normalsize\bfseries}{\theparagraph}{1em}{} +\titleformat{\subparagraph}[runin] + {\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{} + +\titlespacing*{\chapter} {0pt}{50pt}{40pt} +\titlespacing*{\section} {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex} +\titlespacing*{\subsection} {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} +\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} +\titlespacing*{\paragraph} {0pt}{3.25ex plus 1ex minus .2ex}{1em} +\titlespacing*{\subparagraph} {\parindent}{3.25ex plus 1ex minus .2ex}{1em} +\end{verbatim} + +\subsection{Chapter Example} + +A final example shows how to take advantage of the |picture| +environment for fancy sectioning formats. Even with the simple +tools provided by standard \LaTeX{} you may create impressive +titles but you may devise more elaborated +ones with, for instance, |pspicture| (\textsf{PSTricks} +package) or by including graphics created with the help of external +programs. + +\begin{verbatim} +\usepackage[dvips]{color} +\usepackage[rigidchapters,explicit]{titlesec} + +\DeclareFixedFont{\chapterfont}{T1}{phv}{bx}{n}{11cm} + +\titlespacing{\chapter}{0pt}{0pt}{210pt} +% Most of titles have some depth. The total space is +% a bit larger than the picture box. + +\titleformat{\chapter}[block] + {\begin{picture}(330,200)} + {\put(450,80){% + \makebox(0,0)[rb]{% + \chapterfont\textcolor[named]{SkyBlue}{\thechapter}}} + \put(0,230){% + \makebox(0,0)[lb]{% + \Huge\sffamily\underline{Chapter \thechapter}}}} + {0pt} + {\put(0,190){\parbox[t]{300pt}{% + \Huge\sffamily\filright#1}}} + [\end{picture}] +\end{verbatim} + +(The exact values to be used depend on the text area, +class, |\unitlength|, paper size, etc.) + +\end{document} + +MIT License +----------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/macros/latex/contrib/titlesec/titletoc.sty b/macros/latex/contrib/titlesec/titletoc.sty new file mode 100644 index 0000000000..e54bce0173 --- /dev/null +++ b/macros/latex/contrib/titlesec/titletoc.sty @@ -0,0 +1,600 @@ +% +% Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com +% +% This file may be distributed and/or modified under the conditions of +% the MIT License. A version can be found at the end of this file. +% +% Repository: https://github.com/jbezos/titlesec +% + +\ProvidesPackage{titletoc}[2019/07/16 v2.11 TOC entries] + +% The following tags are used: +% ttl@ : the generic one, shared with titlesec +% ttlb@ : starting punctuation for block format +% ttlm@ : and middle +% ttle@ : and ending +% ttll@ : section level +% ttlx@ : file extension +% +% Fistly, comes the +% common stuff with titlesec +% ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +\newif\ifttl@label +\newif\ifttl@fromblock +\newdimen\ttl@leftsep + +\providecommand\titleline{% + \@ifstar{\ttl@line@i{\hb@xt@\titlewidth}}% + {\ttl@line@i{}}} + +\def\ttl@line@i#1{% + \@ifnextchar[{\ttl@line{#1}}{\ttl@line{#1}[s]}} + +\def\ttl@line#1[#2]#3{% + \vskip\topskip + \hrule \@height \z@ + \nobreak + \vskip-\topskip + \begingroup + \parindent\z@ + \everypar{}% + \leftskip\z@ + \rightskip\z@ % #1 is either \hb@xt@\titlewidth or empty: + \@makebox[\hsize][#2]{\ttl@makeline{#1{#3}}}% + \par + \endgroup + \hrule height \z@ + \nobreak} + +% Fillers: + +\providecommand\titlerule{\@ifstar{\ttl@row}{\ttl@rule}} + +\let\ttl@leaders\xleaders + +\def\ttl@row{\@ifnextchar[{\ttl@row@i}{\ttl@row@i[\wd\z@]}} +\def\ttl@row@i[#1]#2{% + \ifvmode\expandafter\titleline\fi + {\sbox\z@{#2}% + \hspace{-#1}% + \hskip\wd\z@ + \ttl@leaders\hb@xt@#1{\hss\box\z@}% + \hfill\kern\z@}} + +\def\ttl@rule{\@ifnextchar[{\ttl@rule@i}{\ttl@rule@i[.4pt]}} +\def\ttl@rule@i[#1]{% + \ifvmode\expandafter\titleline\fi + {\leaders\hrule height #1\hfill\kern\z@}} + +\providecommand\filright{% + \gdef\ttl@filleft##1{\hskip##1}% + \gdef\ttl@filright##1{\hfill}% + \let\\\@centercr + \advance\rightskip\z@ \@plus 1fil\relax} +\providecommand\filleft{% + \gdef\ttl@filleft##1{\hfill}% + \gdef\ttl@filright##1{\hskip##1}% + \let\\\@centercr + \advance\leftskip\z@ \@plus 1fil + \parfillskip\z@} +\providecommand\filcenter{\filleft\filright + \gdef\ttl@filleft##1{\hfill}} +\providecommand\fillast{% + \gdef\ttl@filleft##1{\hfill}% + \gdef\ttl@filright##1{\hfill}% + \let\\\@centercr + \filleft\advance\rightskip\z@ \@plus -1fil + \parfillskip\z@ \@plus 2fil\relax} + +% Now, the specific titletoc part + +% User interface +% ~~~~~~~~~~~~~~ +% Tools: + +\DeclareOption{dotinlabels}{\def\ttl@idot{.}} +\DeclareOption{nodotinlabels}{\let\ttl@idot\@empty} + +\DeclareOption{rigidseps}{% + \def\ttl@contentsstretch{\vskip\z@}} +\DeclareOption{rubberseps}{% + \def\ttl@contentsstretch{\vskip\z@\@plus.1\p@}} + +\DeclareOption{leftlabels}{% + \renewcommand\numberline[1]{\hb@xt@\@tempdima{#1\ttl@idot\hfil}}% + \newcommand\contentslabel[2][\thecontentslabel\ttl@idot]{% +% \let\ttl@a\thecontentslabel %%%%% For the star variant +% \def\thecontentslabel{#2}% %%% To be fully implemented... when? +% \setbox\z@\hbox{#1}% +% \dimen@\wd\z@ +% \let\thecontentslabel\ttl@a +% \hspace*{-\dimen@}\hb@xt@\dimen@{#1\hfil} +% \show\ttl@b \show\ttl@a + \hspace*{-#2}\hb@xt@#2{#1\hfil}}} + +\DeclareOption{rightlabels}{% + \renewcommand\numberline[1]{\hb@xt@\@tempdima{\hss#1\ttl@idot\enspace}}% + \let\contentslabel\relax + \newcommand\contentslabel[2][\thecontentslabel\ttl@idot\enspace]{% + \hspace*{-#2}\hb@xt@#2{\hfil#1}}} + +\newcommand\contentspage[1][\thecontentspage]{% + \hb@xt@\@pnumwidth{\hfil#1}% + \hspace*{-\@pnumwidth}} + +\newcommand\contentspush[1]{% + \sbox\z@{#1}% + \xdef\ttl@b{\advance\leftskip\the\wd\z@}% + \aftergroup\ttl@b + \leavevmode\llap{\box\z@}} + +% General commands. A level register. Explicit numbers +% because they are used in csnames. Ignored if already defined. + +\ifx\ttll@section\@undefined + + \@ifundefined{chapter} + {\def\ttll@part{0}} + {\def\ttll@part{-1}% + \def\ttll@chapter{0}} + \def\ttll@section{1} + \def\ttll@subsection{2} + \def\ttll@subsubsection{3} + \def\ttll@paragraph{4} + \def\ttll@subparagraph{5} + +\fi + +% We make sure that a series of * entries are finished and +% that a \titlecontents in the middle of a document is +% written to the right file. We need ship out floats before; +% that's very tricky. + +\newcommand\contentsuse[2]{% + \expandafter\def\csname ttlx@#1\endcsname{#2}% + \expandafter\def\csname ttll@#1\endcsname{-1000}% + \expandafter\def\expandafter\ttl@finishall\expandafter{% + \ttl@finishall + \@writefile{#2}{\contentsfinish}}} + +\def\ttl@finishall{\@writefile{toc}{\contentsfinish}} + +\AtEndDocument{% + \ttl@startlists + \let\ttl@newpage\newpage + \def\newpage{% + \let\newpage\ttl@newpage + \newpage + \if@filesw + \immediate\write\@mainaux{\string\ttl@finishall}% + \fi}} + +\contentsuse{figure}{lof} +\contentsuse{table}{lot} + +\def\contentsfinish{% + \ifttl@fromblock + \xdef\ttl@b{-10000}% ships out any saved punctuation + \ttl@preend + \@@par + \endgroup + \global\ttl@fromblockfalse + \fi} + +% The two basic commands. First \contentsmargin: + +\newcommand\contentsmargin[1][\z@]{% + \def\ttl@corr{#1}\def\@pnumwidth} + +% The following is the value of \contentsmargin when +% used inside \ttl@tocenty (ie, \titlecontents). + +\newcommand\ttl@margin[2][\z@]{% + \def\ttl@corr{#1}% + \advance\rightskip-\@pnumwidth\relax + \advance\rightskip#2\relax + \def\@pnumwidth{#2}} + +% \titlecontents deals with concepts, not commands; hence no +% escape char + +\newcommand\titlecontents{% + \@ifstar{\ttl@contents{\z@}}% + {\ttl@contents{\@ne}}} + +\def\ttl@contents#1#2{% + \@ifnextchar[{\ttl@contents@i{#1}{#2}}% + {\ttl@contents@i{#1}{#2}[\@nil]}} + +% A dirty hack to fix wrong destinations with hyperref. But activate +% only if some inline entry is defined (ie, #1 = 0): +\let\ttl@fixhyperref\relax + +\def\ttl@contents@i#1#2[#3]#4#5#6#7{% + \@ifundefined{ttll@#2}% + {\expandafter\def\csname ttll@#2\endcsname{-1000}}% + {}% + \ifcase#1\relax + \def\ttl@fixhyperref{% + \ifx\Hy@tocdestname\@undefined\else + \global\let\Hy@tocdestname\Hy@tocdestname + \fi}% + \fi + \expandafter\def\csname l@#2\endcsname + {\ttl@tocentry{#1}{#2}{#3}{#4}{{#5}{#6}}{#7}}% + \@ifnextchar[{\ttl@contents@ii{#1}{#2}}% + {\ttl@contents@ii{#1}{#2}[]}} + +\def\ttl@contents@ii#1#2[#3]{% + \ifcase#1\relax + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi + {\@ifnextchar[{\ttl@contents@iii{#1}{#2}{#3}}% + {\ttl@contents@iii{#1}{#2}{#3}[]}}% + {\ttl@contents@iv{#1}{#2}{#3}[][]}} + +\def\ttl@contents@iii#1#2#3[#4]{% + \@ifnextchar[{\@tempswatrue\ttl@contents@iv{#1}{#2}{#3}[#4]}% + {\@tempswafalse\ttl@contents@iv{#1}{#2}{#3}[#4][]}} + +\def\ttl@contents@iv#1#2#3[#4][#5]{% + \ifcase#1\relax + \if@tempswa + \ttl@contents@v{#2}{#3}{#4}{#5}% + \else + \ttl@contents@v{#2}{}{#3}{#4}% + \fi + \else + \ttl@contents@v{#2}{}{}{#3}% + \fi} + +\def\ttl@contents@v#1#2#3#4{% + \expandafter\def\csname ttlb@#1\endcsname{#2}% + \expandafter\def\csname ttlm@#1\endcsname{#3}% + \expandafter\def\csname ttle@#1\endcsname{#4}} + +\begingroup +\catcode`\-=12\catcode`\>=12 +\gdef\ttl@strip#1->#2\@@#3{\def#3{#2}} +\endgroup + +\AtBeginDocument{% + \def\ttl@change@i#1#2#3#4#5#6#7{% + \expandafter\def\csname l@#2\endcsname + {\ttl@tocentry{#1}{#2}{#3}{#4}{{#5}{#6}}{#7}}}% + \let\ttl@change@v\ttl@contents@v + \def\ttl@contents@i#1#2[#3]#4#5#6#7{% + \def\ttl@a{\ttl@change@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% + \@ifnextchar[{\ttl@contents@ii{#1}{#2}}% + {\ttl@contents@ii{#1}{#2}[]}}% + \def\ttl@contents@v#1#2#3#4{% + \def\ttl@b{\ttl@change@v{#1}{#2}{#3}{#4}}% + \expandafter\ttl@strip\meaning\ttl@a\@@\ttl@a + \expandafter\ttl@strip\meaning\ttl@b\@@\ttl@b + \edef\ttl@c{% + \expandafter\ifx\csname ttlx@#2\endcsname\relax + toc% + \else + \csname ttlx@#2\endcsname + \fi}% + \addtocontents{\ttl@c}{\ttl@a\relax}% + \addtocontents{\ttl@c}{\ttl@b\relax}}} + +% Printing the toc entry +% ~~~~~~~~~~~~~~~~~~~~~~ + +\def\ttl@lasttoc{-1000} % An inital dummy assignment + +% 1 ifblock, 2 sect name, 3 left, 4 before, +% 5 {with}{without}, 6 filler/page, 7 title 8 pageno + +\let\ttl@preend\@empty + +\def\ttl@outpunct{% + \ifnum\ttl@c>\ttl@b\relax + \ttl@preend + \fi} + +\def\ttl@outblock#1#2#3{% + \ifcase#1\relax + \ifnum\ttl@b>\ttl@a\relax + \begingroup + \protected@edef\ttl@preend{% + \@nameuse{ttle@#2}% + \endgroup + \protect\@namedef{ttl@c}{\ttl@a}% + \protect\ttl@outpunct}% + #3% + \@nameuse{ttlb@#2}% + \else\ifnum\ttl@b<\ttl@a\relax + \ttl@preend + \@nameuse{ttlm@#2}% + \else + \@nameuse{ttlm@#2}% + \fi\fi + \else + \ttl@preend + \@@par + \endgroup + \@firstoftwo + \fi} + +\def\ttl@outnoblock#1#2#3{% + \begingroup + \ifnum\ttl@b>\ttl@a + \nobreak + \else\ifnum\ttl@b<\ttl@a + \addpenalty{\@secpenalty}% + \else + \addpenalty{\z@}% + \fi\fi + \ttl@contentsstretch + \nobreak + \ifcase#1\relax\else\interlinepenalty\@M\fi + \parindent\z@ + \ifx\@nil#2% + \PackageError{titletoc}{Unimplemented}% + {The optional argument is currently mandatory}% + \else + \setlength\leftskip{#2}% + \fi + \setlength\rightskip{\@pnumwidth}% + \let\contentsmargin\ttl@margin + \def\ttl@makeline##1{##1}% + #3% + \addtolength{\parfillskip}{-\ttl@corr}% + \addtolength{\rightskip}{\ttl@corr}% + \let\ttl@leaders\leaders} + +\def\ttl@tocentry#1#2#3#4#5#6#7#8{% + \ttl@fixhyperref + \xdef\ttl@b{\csname ttll@#2\endcsname}% + \ifnum\ttl@b>\c@tocdepth\else + \ifnum\ttl@b<\ttl@toctop\else + \edef\ttl@a{\ttl@lasttoc}% + \gdef\thecontentspage{#8}% + \global\let\thecontentslabel\@empty + \global\ttl@labelfalse + \sbox\z@{% Unused box. It just catch the numberline + \def\numberline##1{\global\ttl@labeltrue\gdef\thecontentslabel{##1}}% + #7}% \ttl@b = current \ttl@a = previous + \ifttl@fromblock + \ttl@outblock{#1}{#2}{#4}% + \else + \ttl@outnoblock{#1}{#3}{#4}% + \fi + \def\numberline##1{\ignorespaces}% + \ifttl@label + {\leavevmode\strut\@firstoftwo#5{#7}\strut\kern\z@}% + \else + {\leavevmode\strut\@secondoftwo#5{#7}\strut\kern\z@}% + \fi + {#6}% + \ifcase#1\relax + \ifttl@fromblock\else + \protected@edef\ttl@preend{\@nameuse{ttle@#2}}% + \fi + \global\ttl@fromblocktrue + \else + \@@par + \nobreak + \csname ttle@#2\endcsname + \endgroup + \global\ttl@fromblockfalse + \fi + \xdef\ttl@lasttoc{\csname ttll@#2\endcsname}% + \fi + \fi + \ignorespaces} + +\newcommand\dottedcontents{} +\def\dottedcontents#1[#2]#3#4#5{% + \titlecontents{#1}[#2]{#3}% + {\contentslabel{#4}}% + {\hspace*{-#4}}% + {\titlerule*[#5]{.}\contentspage}} + +\ExecuteOptions{leftlabels,nodotinlabels,rubberseps} + +\ProcessOptions + +% Multiple tocs and lists +% ~~~~~~~~~~~~~~~~~~~~~~~~ +% After some attemps to adapt titletoc to minitoc, I decided to +% implement my own solution, because entries as written by minitoc are +% non standard. The new commands provides a good deal of flexibility, +% too. + +\let\ttl@startlists\@empty +\let\ttl@writefile\@writefile + +\def\ttl@partialtoc{ptc} +\def\ttl@partiallof{plf} +\def\ttl@partiallot{plt} + +\def\ttl@writepartial#1#2{% + \ttl@topartial{toc}{#1}{#2}% + \ttl@topartial{lof}{#1}{#2}% + \ttl@topartial{lot}{#1}{#2}% + \ttl@writefile{#1}{#2}} + +\def\ttl@topartial#1#2#3{% + \def\ttl@a{#1}% + \def\ttl@b{#2}% + \ifx\ttl@a\ttl@b + \ttl@writefile{\csname ttl@partial#2\endcsname}{#3}% + \fi} + +\def\ttl@xstartlist#1{% + \@ifundefined{ttl@startlist#1}{% + \global\@namedef{ttl@startlist#1}{% + \let\@writefile\ttl@writepartial + \if@filesw + \expandafter\newwrite\csname tf@#1\endcsname + \immediate\openout\csname tf@#1\endcsname\jobname.#1\relax + \fi + \@nobreakfalse}% + \expandafter\gdef\expandafter\ttl@startlists\expandafter{% + \ttl@startlists + \@nameuse{ttl@startlist#1}}}{}} + +\newcommand\startcontents[1][default]{\startlist[#1]{toc}} + +\newcommand\startlist[2][default]{% + \expandafter\ttl@xstartlist\csname ttl@partial#2\endcsname + \@ifundefined{c@ttl@#2@#1}% + {\newcounter{ttl@#2@#1}}% + {\stoplist[#1]{#2}}% + \stepcounter{ttl@#2@#1}% + \resumelist[#1]{#2}} + +\newcommand\stopcontents[1][default]{\stoplist[#1]{toc}} + +\newcommand\stoplist[2][default]{% + \protected@write\@auxout{}{% + \string\ttl@writefile{\csname ttl@partial#2\endcsname}{% + \string\ttl@stoptoc{#1@\arabic{ttl@#2@#1}}}}} + +\newcommand\resumecontents[1][default]{\resumelist[#1]{toc}} + +\newcommand\resumelist[2][default]{% + \protected@write\@auxout{}{% + \string\ttl@writefile{\csname ttl@partial#2\endcsname}{% + \string\ttl@starttoc{#1@\arabic{ttl@#2@#1}}}}} + +\def\ttl@starttoc#1{% + \ifx\@writefile\@gobbletwo\else % Is this test necessary? + \def\ttl@a{#1}% + \ifx\ttl@a\ttl@ptoc + \let\contentsline\ttl@contentsline + \fi + \fi + \ignorespaces} + +\def\ttl@stoptoc#1{% + \ifx\@writefile\@gobbletwo\else % Is this test necessary? + \def\ttl@a{#1}% + \ifx\ttl@a\ttl@ptoc + \let\contentsline\ttl@gobblecontents + \fi + \fi + \ignorespaces} + +\newcommand\printcontents[3][default]{% + \def\ttl@a{[#1]{toc}{#2}{#3}}% + \ttl@preprint} + +\newcommand\printlist[3][default]{% + \def\ttl@a{[#1]{#2}{#3}{-1001}}% + \ttl@preprint} + +\newcommand\ttl@preprint[2][\c@tocdepth]{% + \expandafter\ttl@printlist\ttl@a{#1}{#2}} + +% 1:name 2:list 3:prefix 4:startlevel 5:depth 6:toccode +\newcommand\ttl@printlist[6][default]{% + \begingroup + \@ifundefined{c@ttl@#2@#1}% + {\PackageError{titletoc}{No partial #2 named #1}% + {You must start before a partial toc/list\MessageBreak + with \string/startcontents/\string\startlist.}}{}% + \edef\ttl@ptoc{#1@\arabic{ttl@#2@#1}}% + \def\ttl@toctop{#4}% + \c@tocdepth=#5\relax + #6% + \let\ttl@xcontentsline\contentsline + \let\contentsline\ttl@gobblecontents + \def\ttl@contentsline##1{% + \@ifundefined{ttll@#3##1}% + {\expandafter\let\csname ttll@#3##1\expandafter\endcsname + \csname ttll@##1\endcsname}{}% + \@ifundefined{l@#3##1}% + {\ttl@xcontentsline{##1}}% + {\ttl@xcontentsline{#3##1}}}% + \makeatletter + \@input{\jobname.\csname ttl@partial#2\endcsname}% + \makeatother + \@nobreakfalse + \endgroup} + +\AtBeginDocument{% + \ifx\ttl@gobblecontents\@undefined + \def\ttl@gobblecontents#1#2#3{\ignorespaces}% + \fi} + +\def\ttl@toctop{-1000} + +% Now the we add \contentsfinish to the current definitions and a +% "selector" for partial tocs with a wrapper for the original +% definitions (saved as \ttl@savel@#1). + +\def\ttl@lselect#1{% + \ttl@fixhyperref + \ifnum\csname ttll@#1\endcsname>\c@tocdepth\else + \contentsfinish + \fi + \ifnum\csname ttll@#1\endcsname<\ttl@toctop\relax + \expandafter\@gobbletwo + \else + \expandafter\expandafter\csname ttl@savel@#1\endcsname + \fi} + +\let\ttl@savel@part\l@part +\def\l@part{\ttl@lselect{part}} + +\let\ttl@savel@chapter\l@chapter +\def\l@chapter{\ttl@lselect{chapter}} + +\let\ttl@savel@section\l@section +\def\l@section{\ttl@lselect{section}} + +\let\ttl@savel@subsection\l@subsection +\def\l@subsection{\ttl@lselect{subsection}} + +\let\ttl@savel@subsubsection\l@subsubsection +\def\l@subsubsection{\ttl@lselect{subsubsection}} + +\let\ttl@savel@paragraph\l@paragraph +\def\l@paragraph{\ttl@lselect{paragraph}} + +\let\ttl@savel@subparagraph\l@subparagraph +\def\l@subparagraph{\ttl@lselect{subparagraph}} + +\let\ttl@savel@figure\l@figure +\def\l@figure{\ttl@lselect{figure}} + +\let\ttl@savel@table\l@table +\def\l@table{\ttl@lselect{table}} + +\@tempskipa\@pnumwidth +\edef\@pnumwidth{\the\@tempskipa} +\advance\@tempskipa-\@tocrmarg +\edef\ttl@corr{-\the\@tempskipa} + +\endinput + +MIT License +----------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |