%!TEX root=template.tex %% ---------------------------------------------------------------------------- %% novathesis — fix-hyperref.sty %% ---------------------------------------------------------------------------- %% %% Version 8.4.0 (2026-09-27) %% Copyright (C) 2004-26 by João M. Lourenço %% Departamento de Informática (www.di.fct.unl.pt) %% Faculdade de Ciências e Tecnologia (www.fct.unl.pt) %% Universidade NOVA de Lisboa (www.unl.pt) %% %% Minor fixes to hyperref and localized autoref capitalization. %% ---------------------------------------------------------------------------- \ProvidesPackage{fix-hyperref}[2026/03/03 v1.1] \typeout{NT FILE StyFiles/fix-hyperref.sty}% %%======================================================================= %% LANGUAGE FIXES %%======================================================================= \def\HyLang@portuguese{\HyLang@portuges} \ExplSyntaxOn % Table of {alias}{canonical}{extra-code} triples, one \HyLang@DeclareLang % call per entry. No entry carries typeset prose (only language codes and, % for russian, an unexpanded \hypersetup{unicode} call), so looping over it % under expl3 is safe. \clist_const:Nn \c_nt_hylang_data_clist { {english}{english}{}, {UKenglish}{english}{}, {british}{english}{}, {USenglish}{english}{}, {american}{english}{}, {german}{german}{}, {austrian}{german}{}, {ngerman}{german}{}, {naustrian}{german}{}, {russian}{russian}{\noexpand\hypersetup{unicode}}, {brazil}{portuguese}{}, {brazilian}{portuguese}{}, {portuguese}{portuguese}{}, {spanish}{spanish}{}, {afrikaans}{afrikaans}{}, {french}{french}{}, {frenchb}{french}{}, {francais}{french}{}, {acadian}{french}{}, {canadien}{french}{}, {italian}{italian}{}, {magyar}{magyar}{}, {hungarian}{magyar}{} } \cs_new_protected:Npn \@nt@fixhyperref { \clist_map_inline:Nn \c_nt_hylang_data_clist { \HyLang@DeclareLang ##1 } } %%======================================================================= %% AUTOREF CAPITALIZATION (\Autoref) %%======================================================================= % Provide a local fallback if nt-core.sty is not loaded first. % (In a normal novathesis build, nt-core.sty defines this function.) \cs_if_exist:NF \nt_titlecase_first:N { \cs_new_protected:Nn \nt_titlecase_first:N { \tl_if_empty:NF #1 { \tl_set:Ne #1 { \exp_not:N \MakeUppercase { \tl_head:N #1 } \tl_tail:N #1 } } } } % Declare unique variables for autoref \tl_new:N \l_nt_autoref_type_tl \tl_new:N \l_nt_autoref_name_tl \tl_new:N \l_nt_autoref_data_tl \seq_new:N \l_nt_autoref_anchor_seq % Aux function to handle label data % #1=ref, #2=page, #3=title, #4=anchor (e.g. section.1), #5=extra \cs_new_protected:Npn \nt_autoref_aux:nnnnn #1 #2 #3 #4 #5 { % Extract type from anchor (e.g. "section" from "section.1") \seq_set_split:Nnn \l_nt_autoref_anchor_seq { . } { #4 } \seq_get_left:NN \l_nt_autoref_anchor_seq \l_nt_autoref_type_tl % Remove star if present (e.g. "chapter*" -> "chapter") \regex_replace_all:nnN { \* } { } \l_nt_autoref_type_tl \cs_if_exist:cT { \l_nt_autoref_type_tl autorefname } { % Get current autorefname \tl_set_eq:Nc \l_nt_autoref_name_tl { \l_nt_autoref_type_tl autorefname } % Titlecase it (first letter uppercase) - uses helper from nt-core.sty \nt_titlecase_first:N \l_nt_autoref_name_tl % Redefine locally within the group established in \Autoref \cs_set:cpe { \l_nt_autoref_type_tl autorefname } { \tl_use:N \l_nt_autoref_name_tl } } } \cs_new_protected:Nn \nt_autoref_logic:n { \group_begin: \cs_if_exist:cT { r@ \tl_to_str:n { #1 } } { \tl_set_eq:Nc \l_nt_autoref_data_tl { r@ \tl_to_str:n { #1 } } \exp_last_unbraced:NV \nt_autoref_aux:nnnnn \l_nt_autoref_data_tl } \autoref{#1} \group_end: } %%======================================================================= %% INITIALIZATION %%======================================================================= \AtBeginDocument { \@nt@fixhyperref \DeclareRobustCommand{\Autoref} [ 1 ] { \ExplSyntaxOn \nt_autoref_logic:n {#1} \ExplSyntaxOff } % \ntindex{text} is non-expandable, so hyperref warns when it appears in % section headings used as PDF bookmark strings. Register a safe fallback % that emits only the visible text and skips the \index call. % Must use \def (not \renewcommand) to avoid triggering \@protected@testopt, % which is itself trapped in the PDF string context. \pdfstringdefDisableCommands{% \def\ntindex{\@nt@pdfstring@index}% }% % \ntindex has an optional [key] and a mandatory {text}; in a bookmark we want % only the visible {text}. A plain [#1]#2 delimited match mis-scans the common % \ntindex{text} (no brackets). Instead grab everything up to the mandatory % brace group (nothing, or "[key]") and discard it, then emit the mandatory % argument. This is fully expandable, so it works inside \pdfstringdef (where % \@ifnextchar / the optional-argument machinery does not). \long\def\@nt@pdfstring@index#1#{\@nt@pdfstring@index@mand}% \long\def\@nt@pdfstring@index@mand#1{#1}% % Fix duplicate PDF destinations across main matter and appendices. % Hyperref's \theHchapter defaults to \arabic{chapter}, which resets to 0 % when \appendix is called. Appendix B therefore gets the same raw counter % value (2) as main chapter 2, producing clashing anchor names like % "table.2.1". Redefining \theHchapter to use \thechapter (which gives % letters in appendices: A, B, C …) makes every anchor globally unique. \renewcommand { \theHchapter } { \thechapter } % \HyperLocalCurrentHref is used as a 'dest' in \bookmark calls. \newcommand { \HyperLocalCurrentHref } { \@currentHref } } \ExplSyntaxOff