Document Classes ⇒ to know the number of chapters at the preamble
to know the number of chapters at the preamble
I am trying to extract a class file from a tex document in order to be able to reuse the style of document. This document has a pattern that I am trying to generalize in order to create automatically this code. The pattern is:
For each chapter it declares a counter in the preamble.
At begin of document, for each counter it uses \setcounterpageref{<chaptercounter>}{<chapterlabel>}%
At begin of chapter it uses:
\hypertarget{<chapterlabel>}{}%
\label{<chapterlabel>}{}%
This pattern lets to use \hyperlink{topofpage.\arabic{<chaptercounter>}}{<description>}
in any location of document to create a link to top of the chapter page.
Note the value of <chaptercounter> and <chapterlabel> are hard-coded in the document, and these change chapter to chapter. I wish create a command with parameters to replace hard-coded values.
I am not sure if this pattern is the best way of do it, but works fine.
My problem to generalize it is that I don't known the count of chapters at the preamble, so, I don't knwow how many counters I must declares in "afterPreamble" hook and how many of \setcounterpageref lines I need to write in "at begin document" hook.
Thanks!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis