2022.2

Table Of Contents
dotsbetweenheadingandpagenumber.
Thenumberclass(forthepagenumber)isnotonlyusedinCSS,butalsolateroninthescript.
Thetableofcontentsisinsertedinthesectionwith:results.html(toc);(see"html()"onpage1257).
Thetableofcontentsmaygettoolongforasinglepageandaffectthepagenumbersinothersections.
Inthatcaseitisnecessarytore-paginatethecontent;merge.section.paginate();doesthetrick.
Note: Whetherpagenumberingrestartsineachsection,dependsonthesettingsforpagenum-
bering;see"Configuringpagenumbers"onpage458.Bydefault,pagenumberingstartswith
page1foreachsection.
Ifthepaginationprocesshaschangedthepagenumbers,theTOCneedstobeupdatedaswell.
Todothat,thescriptfirsthastocollectthepagenumbersfromthetableofcontents.Thisiswherethe
numberclasscomesinhandy:var$numbers=query('.number');.
Notethatthisquery()function,asopposedtomerge.context.query(),onlysearchesthecurrentsection
(see"query()"onpage1197).
Then,thelevel1and2headingsarecollectedfromallPrintsectionsagainusingmerge.context.query
("h1,h2").
Thecallbackfunctionineach()retrievestheheading'snewpagenumber.Itthenusestheindexnum-
beroftheheadingintheresultsettogetthecorrespondingentryintheTOC:varentry=$numbers.get(
index);(see"get(index)"onpage1221),andreplacesitwiththenewpagenumber.
Excluding headings
Oftentherearecertainheadingsthatyoudon'twanttoappearinthetableofcontents.Thetitleofthe
tableofcontentsitself,forexample.
Toexcludetheseheadingsfromthetableofcontents,dothefollowing:
1. Givealltheheadingsthatyouwanttobeignoredthesameclass(see"IDandclass"on
page568),forexampleignore-me.
2. Addthe:notselectortothequeriesinthescript,specifyingthatclass.Remembertoputadot
beforethenameoftheclass.Forexample:merge.context.query("h1:not(.ignore-
me), h2").
Adding internal hyperlinks
Itispossibletocreatelinksinatableofcontentsthatpointtotherespectivepositioninthedocument
(forexamplewhengeneratingPDFoutput).Aninternalhyperlinkpointstoanelementwithaspecified
ID.(See:"Hyperlinkandmailtolink"onpage647.)
Here'showtochangetheeach()functioninthescriptinordertoaddinternalhyperlinkstothetableof
contents:
Page 854