同じ場所を指すハイパーリファレンスリンク(thmtools および回答パッケージを使用)

同じ場所を指すハイパーリファレンスリンク(thmtools および回答パッケージを使用)

各問題の最後に、その問題の解答のページ番号を示していただきたいです。

もし私がこんなことをしたら、

\documentclass{article}

\usepackage{amsthm,thmtools}

\declaretheoremstyle[
notefont=\bfseries,
notebraces={}{}, 
headformat={\large\NUMBER.\NOTE},
headpunct={\vspace{\topsep}\newline},
spacebelow=40pt,
prefoothook={\hfill Solução: pág. \pageref{solucao:\Currentlabel}}
]{problemastyle}

\declaretheorem[style=problemastyle]{problema}

\usepackage{answers}

\Newassociation{solucao}{Sol}{solucoes}
\renewenvironment{Sol}[1]{\begin{trivlist}
 \item[\hskip\labelsep\textbf{#1.}] \label{solucao:#1} \ignorespaces}%
 {\end{trivlist}}

\usepackage{hyperref}

\usepackage{lipsum}

\begin{document}
\Opensolutionfile{solucoes}

\begin{problema}[Primeiro problema]
 Problema 1.
 \begin{solucao}
   \lipsum
 \end{solucao}
\end{problema}

\begin{problema}[Segundo problema]
 Problema 2.
 \begin{solucao}
   \lipsum[1]
 \end{solucao}
\end{problema}

\begin{problema}[Terceiro problema]
 Problema 3.
 \begin{solucao}
   \lipsum[1]
 \end{solucao}
\end{problema}


\Closesolutionfile{solucoes}

\include{solucoes}

\end{document}

欲しいものは手に入りましたが、ページ番号のリンクはすべて同じ場所を指しています。

これを修正するにはどうすればいいでしょうか?

答え1

環境が必要ですソルは相互参照ラベルを作成するだけでなく、リンク用の名前付き宛先/ターゲット/アンカーも作成します。その名前はマクロの新しい定義になり\@currentHref、相互参照ラベルを作成するときにコマンドによって使用されます\label。 を使用できます\phantomsectionが、の引数を使用する独自のものを実装することもできます。ソル-environmentを、指定された宛先/ターゲット/アンカーの名前としても使用します。この場合、ソル-環境は、PDFビューアが宛先/ターゲット/アンカーの名前のコンポーネントとして処理できるもののみで構成され、2つの宛先/ターゲット/アンカーが同じ名前を持つことはできず、この場合、2つの宛先/ターゲット/アンカーが同じ名前を持つことはないため、ソル-environment には、同じものに展開される引数がある場合があります。

\documentclass{article}

\usepackage{amsthm,thmtools}

\declaretheoremstyle[
notefont=\bfseries,
notebraces={}{}, 
headformat={\large\NUMBER.\NOTE},
headpunct={\vspace{\topsep}\newline},
spacebelow=40pt,
prefoothook={\hfill Solução: pág. \pageref{solucao:\Currentlabel}}
]{problemastyle}

\declaretheorem[style=problemastyle]{problema}

\usepackage{answers}

\Newassociation{solucao}{Sol}{solucoes}

\renewenvironment{Sol}[1]{\begin{trivlist}%
 \item[\hskip\labelsep\SolutionAnchor{#1}\textbf{#1.}]\ignorespaces}%
 {\end{trivlist}}%

\makeatletter
\DeclareRobustCommand\SolutionAnchor[1]{%
  \begingroup
  \Hy@localanchornametrue
  \Hy@MakeCurrentHref{solution.#1}%
  \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
  \label{solucao:#1}%
  \endgroup
}%
%
% Alternatively, using \phantomsection:
% 
% \DeclareRobustCommand\Hy@SolutionAnchor[1]{%
%   \begingroup
%   \Hy@localanchornametrue
%   \phantomsection
%   \label{solucao:#1}%
%   \endgroup
% }%
%
% Or, with a very recent TeX installation, use \MakeLinkTarget*
%
%\DeclareRobustCommand\SolutionAnchor[1]{%
%  \MakeLinkTarget*{solution.#1}%
%  \label{solucao:#1}%
%}%

\makeatother


\usepackage{hyperref}

\usepackage{lipsum}

\begin{document}
\Opensolutionfile{solucoes}

\begin{problema}[Primeiro problema]
 Problema 1.
 \begin{solucao}
   \lipsum
 \end{solucao}
\end{problema}

\begin{problema}[Segundo problema]
 Problema 2.
 \begin{solucao}
   \lipsum[1]
 \end{solucao}
\end{problema}

\begin{problema}[Terceiro problema]
 Problema 3.
 \begin{solucao}
   \lipsum[1]
 \end{solucao}
\end{problema}


\Closesolutionfile{solucoes}

\include{solucoes}

\end{document}

関連情報