如何将练习的数量与其解决方案联系起来

如何将练习的数量与其解决方案联系起来

我正在使用以下软件包:hyperref 和 answers。我想将定理的数量与其证明联系起来,或将练习的数量与其解决方案联系起来,或将问题的数量与其提示联系起来,等等。这是我到目前为止从这里和那里的片段中得到的结果(它几乎满足了我的要求,除了问题的数量被打印了两次):

    \documentclass{article}

\usepackage[english]{babel} 
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{answers}
\usepackage{color}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=blue,
    urlcolor=black
}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{blindtext}

\newtheorem{Thm}{Theorem}[section]

%Exercises and solutions
\newtheorem{Ex}[Thm]{\hyperlink{\theEx}{Exercise \theEx}}
\Newassociation{Sol}{Solution}{Answ}

\makeatletter % To adjust the final position of target
 \newcommand{\adj}[1]{\Hy@raisedlink{\hypertarget{#1}{}}}
\makeatother

\renewenvironment{Solution}[1]
  {\par\bigskip\noindent{\bfseries \adj{#1}{Answer #1}}  \par\bigskip}




\begin{document}
\section{This is a section}
\blindtext
\begin{Thm}
This is a theorem
\end{Thm}

\subsection{Exercises}

\Opensolutionfile{Answ}

\begin{Ex}
This is  the first exercise
\begin{Sol}
This is the solution to the first exercise
\end{Sol}
\end{Ex}


\begin{Ex}
This is  the second exercise
\begin{Sol}
This is the solution to the second exercise
\end{Sol}
\end{Ex}


\Closesolutionfile{Answ}

\Blindtext

\input{Answ}


\end{document}

答案1

可以重新定义plain样式或定义新样式

\newtheoremstyle{plain}%
{}{}%
{\itshape}{}%
{\bfseries}{.}%
{ }%
{\hyperlink{\theEx}{\thmname{#1}\thmnumber{ #2}}\thmnote{ (#3)}}

完整代码

\documentclass{article}

\usepackage[english]{babel} 
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{answers}
\usepackage{color}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=blue,
    urlcolor=black
}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{blindtext}


\newtheoremstyle{plain}%
{}{}%
{\itshape}{}%
{\bfseries}{.}%
{ }%
{\hyperlink{\theEx}{\thmname{#1}\thmnumber{ #2}}\thmnote{ (#3)}}

\newtheorem{Thm}{Theorem}[section]

\newtheorem{Ex}[Thm]{Exercise}
\Newassociation{Sol}{Solution}{Answ}

\makeatletter % To adjust the final position of target
 \newcommand{\adj}[1]{\Hy@raisedlink{\hypertarget{#1}{}}}
\makeatother

\renewenvironment{Solution}[1]
  {\par\bigskip\noindent{\bfseries \adj{#1}{Answer #1}}  \par\bigskip}




\begin{document}
\section{This is a section}
\blindtext
\begin{Thm}
This is a theorem
\end{Thm}

\subsection{Exercises}

\Opensolutionfile{Answ}

\begin{Ex}
This is  the first exercise
\begin{Sol}
This is the solution to the first exercise
\end{Sol}
\end{Ex}


\begin{Ex}
This is  the second exercise
\begin{Sol}
This is the solution to the second exercise
\end{Sol}
\end{Ex}


\Closesolutionfile{Answ}

\Blindtext

\input{Answ}


\end{document}

相关内容