tulhypref.sty 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. %
  2. % This package complements the thesul class and is aimed to replace
  3. % the hyperref package in this context. The hyperref package does not
  4. % address the intricacies of thesul and this is what we are doing here.
  5. % This package load hyperref and passes its options so that one can write
  6. % \usepackage[pdftex]{tulhypref} or whatever.
  7. %
  8. % Versions:
  9. \def\fileversion{0.11}
  10. \def\filedate{2013/10/06}
  11. \NeedsTeXFormat{LaTeX2e}
  12. \ProvidesPackage{tulhypref}[\filedate\space\fileversion\space
  13. thesul wrapper for hyperref package (D. Roegel)]
  14. \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{hyperref}}
  15. \ProcessOptions
  16. \RequirePackage{hyperref}
  17. % We cancel modifications from hyperref (in hpdftex.def and pdftex.def).
  18. \let\@sect\H@old@sect
  19. \let\@schapter\H@old@schapter
  20. \let\@spart\H@old@spart
  21. \let\refstepcounter\H@refstepcounter
  22. % Now, \@part, \@chapter, \@sect and \refstepcounter have the good values
  23. % of thesul.
  24. % Addition of \TULtopbookmark in front of \tableofcontents
  25. % in order to make sure that the bookmark entry for the table of contents
  26. % is at the top level. Works with the chapter hook.
  27. \let\@old@tableofcontents\tableofcontents
  28. \def\tableofcontents{\TULtopbookmark\@old@tableofcontents}
  29. % These definitions are for the purpose of comparisons in \refstepcounter:
  30. \def\@partcountername{part}
  31. \def\@chaptercountername{chapter}
  32. \def\@annexcountername{annex}
  33. % \refstepcounter is redefined so that \@currentHref is uptodate
  34. % in each chapter, section, etc.
  35. \def\refstepcounter#1{%
  36. \H@refstepcounter{#1}%
  37. \edef\This@name{#1}%
  38. \ifx\This@name\name@of@slide
  39. \else
  40. \if@skiphyperref
  41. \else
  42. \if@hyper@item
  43. \stepcounter{Item}%
  44. \hyper@refstepcounter{Item}%
  45. \else
  46. % \hyper@refstepcounter is only performed when it is neither a part,
  47. % nor a chapter/annex; the \hyper@refstepcounter is done
  48. % in the hook of thesul with \hyper@refstepcounter{division}.
  49. \def\@countername{#1}%
  50. \ifx\@countername\@partcountername
  51. \else
  52. \ifx\@countername\@chaptercountername
  53. \else
  54. \ifx\@countername\@annexcountername
  55. \else
  56. \hyper@refstepcounter{#1}%
  57. \fi
  58. \fi
  59. \fi
  60. \fi
  61. \fi
  62. \fi
  63. }
  64. % We add \hyper@refstepcounter{division} to the division counter hook
  65. \let\@old@division@inc@hook\@division@inc@hook
  66. \renewcommand{\@division@inc@hook}{%
  67. \@old@division@inc@hook
  68. \hyper@refstepcounter{division}
  69. }
  70. \newcommand\theHdivision {\arabic{division}}
  71. \renewcommand\theHfigure {\theHdivision.\arabic{figure}}
  72. \renewcommand\theHtable {\theHdivision.\arabic{table}}
  73. \renewcommand\theHsection {\theHdivision.\arabic{section}}
  74. % This boolean forces a bookmark to be at the topmost level;
  75. % it is only taken into account at the level of chapters (\chapter & \chapter*)
  76. % and it will thus act on the next \chapter(*).
  77. \newif\if@top@bookm@rk
  78. \@top@bookm@rkfalse
  79. \newcommand{\TULtopbookmark}{\@top@bookm@rktrue}
  80. % We input the file \jobname.flg in order to get the value of
  81. % `@there@were@p@rts':
  82. \InputIfFileExists{\jobname.flg}{}{}%
  83. % Numerical equivalent of `@there@were@p@rts':
  84. \if@there@were@p@rts
  85. \newcommand{\TUL@topbookmarkpos}{-1}
  86. \else
  87. \newcommand{\TUL@topbookmarkpos}{0}
  88. \fi
  89. \newcommand{\TUL@bookmarkpos}{0}
  90. % needed by \addcontentsline :
  91. \newcommand{\toclevel@tulstarchapter}{0}
  92. \newcommand{\toclevel@starpart}{-1}
  93. \newcommand{\toclevel@spsection}{\TUL@topbookmarkpos}
  94. % Changes of various hooks in thesul:
  95. \renewcommand{\@tulann@hook}[1]{%
  96. \@division@inc@hook
  97. \if@top@bookm@rk
  98. \renewcommand{\toclevel@tulstarchapter}{\TUL@topbookmarkpos}
  99. \fi
  100. }
  101. \renewcommand{\@tulann@lasthook}[1]{\renewcommand{\toclevel@tulstarchapter}{0}}
  102. \renewcommand\@generic@schapter@hook[2]{%
  103. \if@top@bookm@rk
  104. \renewcommand{\toclevel@tulstarchapter}{\TUL@topbookmarkpos}%
  105. \fi
  106. }
  107. \renewcommand\@generic@schapter@lasthook[2]{%
  108. \renewcommand{\toclevel@tulstarchapter}{0}%
  109. }
  110. \renewcommand\@generic@chapter@hook[3]{%
  111. \@generic@schapter@hook{#1}{#2}%
  112. }
  113. \renewcommand\@generic@chapter@lasthook[3]{%
  114. \@generic@schapter@lasthook{#1}{#2}%
  115. }
  116. \renewcommand{\@acknowledgment@hook}{%
  117. \@division@inc@hook
  118. \pdfbookmark[\TUL@topbookmarkpos]{\AcknowledgmentName}%
  119. {acknowledgment.\theHdivision}%
  120. }
  121. \newcommand{\DedicationName}{D\'edicace}
  122. \renewcommand{\@dedication@hook}{%
  123. \@division@inc@hook
  124. \pdfbookmark[\TUL@topbookmarkpos]{\DedicationName}{dedication.\theHdivision}%
  125. }
  126. \renewcommand{\@abstract@hook}[1]{%
  127. \@division@inc@hook
  128. \pdfbookmark[\TUL@topbookmarkpos]{#1}{abstract.\theHdivision}%
  129. }
  130. \newcommand{\CoverName}{Couverture}
  131. \renewcommand{\@cover@hook}{%
  132. \@division@inc@hook
  133. \pdfbookmark[\TUL@topbookmarkpos]{\CoverName}{cover.\theHdivision}%
  134. }
  135. \renewcommand{\@toc@hook}{%
  136. \pdfbookmark[\TUL@topbookmarkpos]{\contentsname}{}%
  137. }
  138. \endinput
  139. % end of file tulhypref.sty