summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/thmtools/thm-autoref.dtx
blob: 850d171046e4b924b6e958aac64a9028becb21c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
% \iffalse meta-comment
%
% Copyright (C) 2008-2014 by Ulrich M. Schwarz
% Copyright (C) 2019      by Frank Mittelbach
% Copyright (C) 2020-     by Yukai Chou
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c.
% The license can be obtained from
% http://www.latex-project.org/lppl/lppl-1-3c.txt
%
% \fi
%
%\iffalse (hide this from DocInput)
%<*autoref>
%\fi
%
% \pkg{hyperref}'s |\autoref| command does not work well with theorems that
% share a counter: it'll always think it's a Lemma even if it's a Remark
% that shares the Lemma counter. Load this package to fix it. No further
% intervention needed.
%
%\StopEventually{}
%    \begin{macrocode}

\RequirePackage{thm-patch, aliasctr, parseargs, keyval}

\let\@xa=\expandafter
\let\@nx=\noexpand

\newcommand\thmt@autorefsetup{%
  \@xa\def\csname\thmt@envname autorefname\@xa\endcsname\@xa{\thmt@thmname}%
  \ifthmt@hassibling
    \@counteralias{\thmt@envname}{\thmt@sibling}%
    \@xa\def\@xa\thmt@autoreffix\@xa{%
      \@xa\global\@xa\let\csname the\thmt@envname\@xa\endcsname
        \csname the\thmt@sibling\endcsname
      \def\thmt@autoreffix{}%
    }%
    \protected@edef\thmt@sibling{\thmt@envname}%
  \fi
}
\g@addto@macro\thmt@newtheorem@predefinition{\thmt@autorefsetup}%
\g@addto@macro\thmt@newtheorem@postdefinition{\csname thmt@autoreffix\endcsname}%

\def\thmt@refnamewithcomma #1#2#3,#4,#5\@nil{%
  \@xa\def\csname\thmt@envname #1utorefname\endcsname{#3}%
  \ifcsname #2refname\endcsname
    \csname #2refname\@xa\endcsname\@xa{\thmt@envname}{#3}{#4}%
  \fi
}
\define@key{thmdef}{refname}{\thmt@trytwice{}{%
  \thmt@refnamewithcomma{a}{c}#1,\textbf{?? (pl. #1)},\@nil
}}
\define@key{thmdef}{Refname}{\thmt@trytwice{}{%
  \thmt@refnamewithcomma{A}{C}#1,\textbf{?? (pl. #1)},\@nil
}}


\ifcsname Autoref\endcsname\else
\let\thmt@HyRef@testreftype\HyRef@testreftype
\def\HyRef@Testreftype#1.#2\\{%
  \ltx@IfUndefined{#1Autorefname}{%
    \thmt@HyRef@testreftype#1.#2\\%
  }{%
    \edef\HyRef@currentHtag{%
      \expandafter\noexpand\csname#1Autorefname\endcsname
      \noexpand~%
    }%
  }%
}


\let\thmt@HyPsd@@autorefname\HyPsd@@autorefname
\def\HyPsd@@Autorefname#1.#2\@nil{%
  \tracingall
  \ltx@IfUndefined{#1Autorefname}{%
    \thmt@HyPsd@@autorefname#1.#2\@nil
  }{%
    \csname#1Autorefname\endcsname\space
  }%
}%
\def\Autoref{%
  \parse{%
  {\parseFlag*{\def\thmt@autorefstar{*}}{\let\thmt@autorefstar\@empty}}%
  {\parseMand{%
    \bgroup
    \let\HyRef@testreftype\HyRef@Testreftype
    \let\HyPsd@@autorefname\HyPsd@@Autorefname
    \@xa\autoref\thmt@autorefstar{##1}%
    \egroup
    \let\@parsecmd\@empty
  }}%
  }%
}
\fi % ifcsname Autoref

% not entirely appropriate here, but close enough: 
\AtBeginDocument{%
  \@ifpackageloaded{nameref}{%
    \addtotheorempostheadhook{%
      \expandafter\NR@gettitle\expandafter{\thmt@shortoptarg}%
  }}{}
}

\AtBeginDocument{%
  \@ifpackageloaded{cleveref}{%
    \@ifpackagelater{cleveref}{2010/04/30}{%
    % OK, new enough
    }{%
      \PackageWarningNoLine{thmtools}{%
        Your version of cleveref is too old!\MessageBreak
        Update to version 0.16.1 or later%
      }
    }
  }{}
}
%    \end{macrocode}
%\iffalse
%</autoref>
%\fi