带有答案包的超链接

带有答案包的超链接

我正在用这个answers包做练习册。我想在生成的 pdf 文件中创建可点击的超链接,从练习到相应的解决方案,再从解决方案返回到练习。

这是我的ex(锻炼)环境:

\documentclass[12pt, openany]{extbook}
\usepackage{pstricks,pstricks-add,pst-math,pst-xkey}
\usepackage[frenchb]{babel}
\usepackage{slashbox}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,amstext}
\usepackage[latin1]{inputenc}
\usepackage[OT1]{fontenc}
\usepackage{fancybox}
\usepackage{a4wide}
\usepackage{rotating}
\usepackage{epic}
\usepackage{answers}
\usepackage{fancyvrb}
\usepackage{thmbox}
\thmboxoptions{headstyle=\bfseries\boldmath#1 #2~,thickness=0.6pt, cut=false}
\usepackage[hidelinks]{hyperref}
\newcounter{moncompteur}
\newtheorem[M]{exc}[moncompteur]{ \textbf{Exercise}}{}
\newenvironment{ex}{\begin{exc}\normalfont}{\end{exc}}
\Newassociation{sol}{Soln}{corr}
\renewenvironment{Soln}[1]{\par\bigskip\noindent {\bfseries Solution  of exercise #1}\quad}{}

答案1

您可以使用包提供的\hyperlink,机制。一个小例子:\hypertargethyperref

\documentclass[12pt,a4paper]{article}
\usepackage{answers}
\usepackage{amsthm}
\usepackage{hyperref}

\newcounter{moncompteur}
\theoremstyle{definition}
\newtheorem{ex}{%
  \hyperlink{ex:\theex}{Exercise}\hypertarget{sol:\theex}{}}
\Newassociation{sol}{Soln}{corr}
\renewenvironment{Soln}[1]
  {\par\bigskip\noindent{\bfseries \hypertarget{ex:#1}{}\hyperlink{sol:#1}{Solution  of exercise #1}}\quad}
  {\par\bigskip}

\begin{document}
\Opensolutionfile{corr}[ans1]
\section{Problems}
\begin{ex}
First exercise.
\begin{sol}
First solution.
\end{sol}
\end{ex}

\begin{ex}
Second exercise.
\begin{sol}
Second solution.
\end{sol}
\end{ex}
\Closesolutionfile{corr}
\section{Solutions}
\input{ans1}
\end{document}

请注意,我修改了使用包中的ex定理类结构的定义,并删除了计数器。\theoremstyle{definition}amsthmmoncompteur

答案2

hyperref将 添加到\phantomsection您的环境定义中Soln

\renewenvironment{Soln}[1]{\par\bigskip\noindent\phantomsection {\bfseries Solution  of exercise #1}\quad}{}

现在,在您的文档中,使用\hyperref[<reference>]{<text>}将跳转到解决方案给出的相应超链接/标签。例如,尝试以下操作:

\begin{document}
\begin{ex}
Here is an exercise. Solution is \hyperref[sol:first]{here}. \label{ex:first}
\end{ex}

\begin{ex}
Here is another exercise. Solution is \hyperref[sol:second]{here}. \label{ex:second}
\end{ex}

\newpage

\begin{Soln}{\ref{ex:first}}
Here is the solution. \label{sol:first}
\end{Soln}

\begin{Soln}{\ref{ex:second}}
Here is the solution. \label{sol:second}
\end{Soln}

相关内容