添加另一个与问题本身超链接的答案

添加另一个与问题本身超链接的答案

我在这里问了这个问题 将答案与解决方案区分开来的最佳方法是什么? 并得到了很好的答案。虽然我现在遇到了一个新问题。

我想输入问题,然后让一个答案链接到数字。另一个答案链接到问题本身。(请参阅我在 Inked 线程中的 MWE 作为示例。单击问题旁边的数字应该会将您发送到一个位置,单击等式本身应该会将您发送到其他地方)

以下是我迄今为止取得的进展的 MWE

\documentclass{article}

\usepackage{answers}                            
\usepackage{enumitem}                       
\usepackage{hyperref}
\usepackage{multicol}
\usepackage{changepage}
\usepackage{mathtools}
\newcommand{\dx}{\mathop{}\! \text{d} x}
\setlength{\parindent}{0.0mm}

\hypersetup{colorlinks=true,
linkcolor=blue}

% very useful during de-bugging!
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% solutions file
\Opensolutionfile{mysolutions}
\Newassociation{mysolution}{mySoln}{mysolutions}

% new environment that sets up hypertargets both in the question
% section, and in the answer section
\newlist{myenum}{enumerate}{3}
\newcounter{question}[section]
\newenvironment{question}%
    {%
    \refstepcounter{question}%
    %  hyperlink to solution
         \hypertarget{question:{\thequestion}}{}%
         \Writetofile{mysolutions}{\protect\hypertarget{soln:\thequestion}{}}%
         \begin{myenum}[label=\bfseries\protect\hyperlink{soln:\thequestion}{\thequestion}),ref=\thequestion,itemsep=5pt]
         \item%
        }%
        {%
        \end{myenum}}

\newenvironment{IntList}[1]{%
\Opensolutionfile{mysolutions}
\centering
\setlength{\columnsep}{50pt}
\begin{adjustwidth}{-3em}{-2em}\begin{multicols}{#1}}{\end{multicols}\end{adjustwidth}\Closesolutionfile{mysolutions}}

\begin{document}

\begin{IntList}{3}
    \begin{question}
        $\displaystyle \int\sqrt{4-x}\dx$
            \begin{mysolution}
                $2+3+4$
            \end{mysolution}
    \end{question}
\end{IntList}

\section{helo}

\begin{IntList}{3}
    \begin{question}
        $\displaystyle \int\sqrt{4-x}\dx$
            \begin{mysolution}
                $ \int x^3 + 2$
            \end{mysolution}        
    \end{question}
    \begin{question}
        $\displaystyle \int \sqrt{\frac{1}{x^2+1}}\dx$
            \begin{mysolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{mysolution}        
    \end{question}    
\end{IntList}

% close solution file
\Closesolutionfile{mysolutions}

% renew the solution environment so that it hyperlinks back to 
% the question
\renewenvironment{mySoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hyperlink{question:#1}{#1.}}%
}%
{%
}%

\clearpage
\section{Answers!}
% input the file if it exists
\IfFileExists{mysolutions.tex}{\input{mysolutions.tex}}{}
\end{document}

因此,我想在每个问题下面添加另一个答案,例如下面这样

\begin{IntList}{3}
    \begin{question}
        $\displaystyle \int\sqrt{4-x}\dx$
            \begin{mysolution}
                $2+3+4$
            \end{mysolution}
             \begin{myanswer}
                To solve this problem one must first...
            \end{mysanswer}
    \end{question}
\end{IntList}

我的答案与整个问题相关联,而解决方案与数字相关联。最好链接方程的工作方式与答案相同。例如,超链接双向工作。有什么想法吗?

编辑:这是一个更简单的例子

\documentclass[10pt,a4paper]{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}

\usepackage{enumitem}
\usepackage{multicol}
\usepackage{mathtools}

\newenvironment{IntList}[1]{%
\centering
\setlength{\columnsep}{50pt}
\begin{multicols}{#1}\begin{enumerate}[itemsep=5pt]}{\end{enumerate}\end{multicols}}

\usepackage[hidelinks]{hyperref}
\newcommand{\IntExerc}[2]{\item \hyperref[#1]{\mbox{ \( \displaystyle #2 \) }}}

\begin{document}

\begin{IntList}{3}
\IntExerc{R1.1}{\int \frac{x^2+3x}{x^2} \,\mathrm{d}x}
\IntExerc{R1.22}{\int\sin(x)\,\mathrm{d}x}
\IntExerc{R1.2}{\int_0^1 \frac{x}{x^2+1} \,\mathrm{d}x}
\end{IntList}

\newpage

\newpage

\begin{align}
\int \frac{x^2+3x}{x^2} \, \mathrm{d}x & = \int \frac{x^2}{x^2} + \frac{3x}{x^2} \, \mathrm{d}x = \int 1 \mathrm{d}x + 3\int \frac{\mathrm{d}x}{x} = x + 3 \ln|x| + \mathcal{C}  \label{R1.1} \\
\int\sin(x)\,\mathrm{d}x & = -\cos(x) + C \label{R1.22} \\
\int\sin(x)\,\mathrm{d}x & = -\cos(x) + C \label{R1.2}
\end{align}

\end{document}

这更接近我想要的答案包的输出。请注意,我必须单独输入答案,添加标签。并且没有附加到数字的超链接。

(我也希望有下面的语法,但我想这是不可能的。)

\begin{Questions}[PartI]
\question
\solution
\answer

\question
\solution
\answer
\end{Questions}

\display{solution}{PartI}

\display{answer}{PartI}

现在,任何评论和帮助都将非常有用。


编辑:

我取得了一些进展!有什么方法可以让 \long 和 \short“答案”包含在开头吗?一遍又一遍地输入它们似乎很麻烦。

\documentclass{article}

\usepackage{answers}                            
\usepackage{enumitem}                       
\usepackage{hyperref}
\usepackage{multicol}
\usepackage{changepage}
\usepackage{etoolbox}

\newcommand\getcurrentref[1]{%
 \ifnumequal{\value{#1}}{0}
  {??}
  {\the\value{#1}}%
}    

\hypersetup{colorlinks=true}

\setlength{\parindent}{0.0mm}


% very useful during de-bugging!
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% solutions files
% short solutions
\Opensolutionfile{shortsolutions}
\Newassociation{shortsolution}{shortSoln}{shortsolutions}
\Newassociation{short}{shortSolns}{shortsolutions}
% long solutions
\Opensolutionfile{longsolutions}
\Newassociation{longsolution}{longSoln}{longsolutions}
\Newassociation{longs}{longsSolns}{longsolutions}

% new environment that sets up hypertargets both in the question
% section, and in the answer section
\newlist{myenum}{enumerate}{3}
\newcounter{question}[subsection]
\newenvironment{question}[1]%
    {%
    \refstepcounter{question}%
    %  hyperlink to solution
         \hypertarget{question:{\thesubsection\thequestion}}{}%
         \Writetofile{shortsolutions}{\protect\hypertarget{shortsoln:\thesubsection\thequestion}{}}%
         \Writetofile{longsolutions}{\protect\hypertarget{longsoln:\thesubsection\thequestion}{}}%
         \begin{myenum}[label=\bfseries\protect\hyperlink{shortsoln:\thesubsection\thequestion}{\thequestion.},ref=\thequestion]
         \item%
            \hypersetup{linkcolor=black}%
            \hyperlink{longsoln:\thesubsection\thequestion}{#1}%
        }%
        {%
        \end{myenum}}

\newenvironment{IntList}[1]{%
\Opensolutionfile{mysolutions}
\centering
\setlength{\columnsep}{50pt}
\begin{adjustwidth}{-3em}{-2em}\begin{multicols}{#1}}{\end{multicols}\end{adjustwidth}\Closesolutionfile{mysolutions}}


\begin{document}

\section{Problems}

\subsection{Questions}
\begin{multicols}{3}

                 \begin{short}
                \vspace*{\baselineskip}
                \color{white} hello
                \vspace*{-\baselineskip}
            \end{short}
            \begin{longs}
                 \vspace*{\baselineskip}
                \color{white} hello
                \vspace*{-\baselineskip}
            \end{longs}

    \begin{question}{$\int\sqrt{4-x}\mathrm{d}x$}
            \begin{shortsolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{shortsolution}
            \begin{longsolution}
                In order to do this, we must first make a substitution\ldots
            \end{longsolution}
    \end{question}
    \begin{question}{$\int(2x-1)^{50}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{1}{102}(2x-1)^{51}+C$
            \end{shortsolution}
            \begin{longsolution}
                A very long solution| much longer than the shorter solution
            \end{longsolution}
    \end{question}
    \begin{question}{$\int\sqrt[n]{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
            \end{longsolution}
    \end{question}
\end{multicols}

\subsection{Some more questions}

\begin{multicols}{3}

                 \begin{short}
                \vspace*{\baselineskip}
                \color{white} hello
                \vspace*{-\baselineskip}
            \end{short}
            \begin{longs}
                 \vspace*{\baselineskip}
                \color{white} hello
                \vspace*{-\baselineskip}
            \end{longs}

    \begin{question}{$\int\sqrt{4-x}\mathrm{d}x$}
            \begin{shortsolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{shortsolution}
            \begin{longsolution}
                hi
            \end{longsolution}
    \end{question}
    \begin{question}{$\int(2x-1)^{50}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{1}{102}(2x-1)^{51}+C$
            \end{shortsolution}
            \begin{longsolution}
                ho
            \end{longsolution}
    \end{question}
    \begin{question}{$\int\sqrt[n]{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
               lets go
            \end{longsolution}
    \end{question}

\end{multicols}

% close solution files
\Closesolutionfile{shortsolutions}
\Closesolutionfile{longsolutions}


\clearpage
\section{SHORT answers}
% renew the SHORT solution environment so that it hyperlinks back to 
% the question
\renewenvironment{shortSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{shortsolutions.tex}{\input{shortsolutions.tex}}{}

\clearpage
\section{LONG answers}
% renew the LONG solution environment so that it hyperlinks back to 
% the question
\renewenvironment{longSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hypersetup{linkcolor=blue}\hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{longsolutions.tex}{\input{longsolutions.tex}}{}
\end{document}

答案1

所以听起来你既想要shortsolution环境又longsolution想要环境。这里有一个解决方案可以做到这一点 - 它与我之前对你的问题的解决方案非常相似,希望它令人满意,如果不满意请告诉我。

我对链接进行了颜色编码,以便

  • 红色链接指向shortsolutions
  • 蓝色链接转到longsolutions

在此处输入图片描述

在此处输入图片描述

\documentclass{article}

\usepackage{answers}                            
\usepackage{enumitem}                       
\usepackage{hyperref}
\usepackage{multicol}

\hypersetup{colorlinks=true}

\setlength{\parindent}{0.0mm}


% very useful during de-bugging!
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% solutions files
% short solutions
\Opensolutionfile{shortsolutions}
\Newassociation{shortsolution}{shortSoln}{shortsolutions}
% long solutions
\Opensolutionfile{longsolutions}
\Newassociation{longsolution}{longSoln}{longsolutions}

% new environment that sets up hypertargets both in the question
% section, and in the answer section
\newlist{myenum}{enumerate}{3}
\newcounter{question}
\newenvironment{question}[1]%
    {%
    \refstepcounter{question}%
    %  hyperlink to solution
         \hypertarget{question:{\thequestion}}{}%
         \Writetofile{shortsolutions}{\protect\hypertarget{shortsoln:\thequestion}{}}%
         \Writetofile{longsolutions}{\protect\hypertarget{longsoln:\thequestion}{}}%
         \begin{myenum}[label=\bfseries\protect\hyperlink{shortsoln:\thequestion}{\thequestion},ref=\thequestion]
         \item%
            \hypersetup{linkcolor=blue}%
            \hyperlink{longsoln:\thequestion}{#1}%
        }%
        {%
        \end{myenum}}

\begin{document}

\section{Questions}
\begin{multicols}{3}
    \begin{question}{$\int\sqrt{4-x}\mathrm{d}x$}
            \begin{shortsolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{shortsolution}
            \begin{longsolution}
                In order to do this, we must first make a substitution\ldots
            \end{longsolution}
    \end{question}
    \begin{question}{$\int(2x-1)^{50}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{1}{102}(2x-1)^{51}+C$
            \end{shortsolution}
            \begin{longsolution}
                A very long solution| much longer than the shorter solution
            \end{longsolution}
    \end{question}
    \begin{question}{$\int\sqrt[n]{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
            \end{longsolution}
    \end{question}
\end{multicols}

% close solution files
\Closesolutionfile{shortsolutions}
\Closesolutionfile{longsolutions}


\clearpage
\section{SHORT answers}
% renew the SHORT solution environment so that it hyperlinks back to 
% the question
\renewenvironment{shortSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{shortsolutions.tex}{\input{shortsolutions.tex}}{}

\clearpage
\section{LONG answers}
% renew the LONG solution environment so that it hyperlinks back to 
% the question
\renewenvironment{longSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hypersetup{linkcolor=blue}\hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{longsolutions.tex}{\input{longsolutions.tex}}{}
\end{document}

随着问题更新,特别是是否可以在开头就给出答案?

是的,这是可能的,但请记住,您的解决方案文件(shortsolutions.texlongsolutions.tex)已更新每次编译时。如果您在开始文档的,你实际上看到的是它们的先前版本 - 这就是为什么当你将它们包含在结尾您的文档。

下面是一个 MWE,演示了它的工作原理 - 请注意,你需要编译两次编辑任何解决方案后。

\documentclass{article}

\usepackage{answers}                            
\usepackage{enumitem}                       
\usepackage{hyperref}
\usepackage{multicol}

\hypersetup{colorlinks=true}

\setlength{\parindent}{0.0mm}


% very useful during de-bugging!
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% solutions files
% short solutions
\Newassociation{shortsolution}{shortSoln}{shortsolutions}
% long solutions
\Newassociation{longsolution}{longSoln}{longsolutions}

% new environment that sets up hypertargets both in the question
% section, and in the answer section
\newlist{myenum}{enumerate}{3}
\newcounter{question}
\newenvironment{question}[1]%
    {%
    \refstepcounter{question}%
    %  hyperlink to solution
         \hypertarget{question:{\thequestion}}{}%
         \Writetofile{shortsolutions}{\protect\hypertarget{shortsoln:\thequestion}{}}%
         \Writetofile{longsolutions}{\protect\hypertarget{longsoln:\thequestion}{}}%
         \begin{myenum}[label=\bfseries\protect\hyperlink{shortsoln:\thequestion}{\thequestion},ref=\thequestion]
         \item%
            \hypersetup{linkcolor=blue}%
            \hyperlink{longsoln:\thequestion}{#1}%
        }%
        {%
        \end{myenum}}

\begin{document}

\section{SHORT answers}
% renew the SHORT solution environment so that it hyperlinks back to 
% the question
\renewenvironment{shortSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{shortsolutions.tex}{\input{shortsolutions.tex}}{}

\clearpage
\section{LONG answers}
% renew the LONG solution environment so that it hyperlinks back to 
% the question
\renewenvironment{longSoln}[1]{%
         % add some glue
         \vskip .5cm plus 2cm minus 0.1cm%
         {\bfseries \hypersetup{linkcolor=blue}\hyperlink{question:#1}{#1.}}%
}%
{%
}%
% input the file if it exists
\IfFileExists{longsolutions.tex}{\input{longsolutions.tex}}{}

\clearpage

\Opensolutionfile{shortsolutions}
\Opensolutionfile{longsolutions}

\section{Questions}
\begin{multicols}{3}
    \begin{question}{$\int\sqrt{4-x}\mathrm{d}x$}
            \begin{shortsolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{shortsolution}
            \begin{longsolution}
                In order to do this, we must first make a substitution\ldots
            \end{longsolution}
    \end{question}
    \begin{question}{$\int(2x-1)^{50}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{1}{102}(2x-1)^{51}+C$
            \end{shortsolution}
            \begin{longsolution}
                A very long solution| much longer than the shorter solution
            \end{longsolution}
    \end{question}
    \begin{question}{$\int\sqrt[n]{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
                Even longer!
            \end{longsolution}
    \end{question}
\end{multicols}

% close solution files
\Closesolutionfile{shortsolutions}
\Closesolutionfile{longsolutions}

\end{document}

相关内容