将答案与解决方案区分开来的最佳方法是什么?

将答案与解决方案区分开来的最佳方法是什么?

现在,如果有人可以将标题改得更好,那就太好了=)

我正在写一篇相当长的文档,其中包含大量积分。我有一个以三列样式排序的积分列表,如下图所示

在此处输入图片描述

图片有点旧了。现在,我想使用 hyperref 将解决方案和答案链接到每个问题。(答案仅表示反导数,解决方案表示计算积分的所有小步骤)我的问题是我不知道最好的方法是什么。现在,我已将每个积分都变成了超链接,如 MWE 所示。

\documentclass[10pt,a4paper]{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage[english]{babel}
\usepackage{changepage}

\newcommand{\dx}{\mathop{}\! \text{d} x}
\newcommand{\R}{ \mathbb{R} }
\newcommand{\CC}{\mathcal{C}}

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

\usepackage[hidelinks]{hyperref}
\hypersetup{
    colorlinks=true,        %  false: boxed links; true: colored links
    linkcolor=black,        %  color of internal links
    citecolor=cyan,         %  color of links to bibliography
    filecolor=magenta,      %  color of file links
    urlcolor=cyan           %  color of external links
}
\newcommand{\IntExerc}[2]{\item \hyperref[#1]{\mbox{ \( \displaystyle #2 \) }}}

\begin{document}

\subsection{Huge ass list of problems}

\begin{IntList}{3}
\IntExerc{R1.1}{\int \frac{x^2+3x}{x^2} \dx }
\IntExerc{R1.22}{\int\sin(x)\,\mathrm{d}x}
\IntExerc{R1.2}{\int_0^1 \frac{x}{x^2+1} \dx}
\IntExerc{R1.3}{\int \frac{x}{x+1} \dx}
\IntExerc{R1.4}{\int_{-3}^{3} \frac{1}{1-x} \dx}
\IntExerc{R1.5}{\int \sqrt{4-x} \dx}
\IntExerc{R1.6}{\int_{0}^{1/2} \left( 2x - 1\right)^{50} \dx}
\IntExerc{R1.7}{\int \sqrt[n]{x} \dx}
\IntExerc{R1.8}{\int \frac{1}{x \ln x} \dx}
\IntExerc{R1.7}{\int \sin x \cos x \dx}
\IntExerc{R1.8}{\int_{1}^{\sqrt{e-1}} \ln\left( 1 + x^2 \right)x\dx}
\IntExerc{R1.9}{\int \frac{x}{e^x} \dx}
\IntExerc{R1.10}{\int \sin x \cos x \dx}
\IntExerc{R1.11}{\int_1^{e^n} \ln x \dx \ n \in \R}
\IntExerc{R1.12}{\int x \cdot a^x \dx}
\IntExerc{R1.13}{\int \log_{10} (x) \dx}
\IntExerc{R1.14}{\int_{\pi/6}^{\pi/3} \sin(x)^2 \dx}
\IntExerc{R1.15}{\int_1^e \int \frac{\pi}{-x^2} \dx \dx}
\IntExerc{R1.16}{\int_{0}^{\ln 2} x\ln(x+1) \dx}
\IntExerc{R1.17}{\int \frac{x e^x}{(x+1)^2} \dx}
\IntExerc{R1.18}{\int \frac{1}{1+\sqrt{x}}\dx}
\IntExerc{R1.19}{\int \frac{\ln x}{\sqrt{x}} \dx}
\IntExerc{R1.20}{\int_{\pi}^{\pi} \frac{\sin(1/x)e^{x^2}}{\sqrt{x!}} \dx}
\IntExerc{R1.21}{\int \frac{x-1}{\sqrt{x^2 + 2x + 7}} \dx}
\IntExerc{R1.22}{\int \frac{1 + e^x}{\sqrt{e^x + x}} \dx}
\IntExerc{R1.23}{\int \frac{e^x + 1}{e^x - 1} \dx}
\IntExerc{R1.24}{\int_{a}^{a+2\pi} \sin x+1 \dx}
\IntExerc{R1.25}{\int \frac{x^2 + 2x + 2}{x-1} \dx}
\IntExerc{R1.26}{\int_{0}^1 e^{-y^2}  \dx}
\IntExerc{R1.30}{\int_{-3/4}^{4} \frac{x+1}{(x+2)^4}\dx}
\IntExerc{R1.27}{\int x^3\sqrt{1-x^2} \dx}
\IntExerc{R1.40}{\int \ln\left(\frac{1}{\sqrt{x}}\right) \dx}
\IntExerc{R1.28}{\int \sin(2x)e^{\sin(x)^2} \dx}
\IntExerc{R1.29}{\int x \ln \left( \frac{1}{x}\right) \dx}
\IntExerc{R1.30}{\int 2^x e^x \dx}
\IntExerc{R1.30}{\int \binom{x+1}{x} \dx}
\IntExerc{R1.31}{\int \frac{1}{\sqrt{x}\left( 1 + \sqrt{x}\right)} \dx}
\IntExerc{R1.32}{\int_{1}^{\log_e(a)^2} e^{\sqrt{x}}\dx}
\IntExerc{R1.33}{\int \frac{x^2}{x^2 - 1} \dx}
\IntExerc{R1.34}{\int \frac{x}{1 - x^2 + \sqrt{1 - x^2}} \dx}
\IntExerc{R1.34}{\int_{1}^{\sqrt{e-1}} \ln\left( 1 + x^2 \right)x\dx}
\IntExerc{R1.36}{\int \frac{x^2}{x^2 + 4x + 8}\dx}
\IntExerc{R1.37}{\int \frac{1}{x \ln(x)^n} \dx}
\IntExerc{R1.38}{\int_{0}^{\infty} x^3 e^{-x}  \dx}
\IntExerc{R1.39}{\int e^{x + e^x} \dx}
\IntExerc{R1.40}{\int \ln(x)^3 \dx}
\IntExerc{R1.41}{\int \frac{x e^x}{\left( x + 1\right)^2}\dx}
\IntExerc{R1.42}{\int_n^m (m-x)(x-n)\dx}
\IntExerc{R1.41}{\int \frac{\pi}{\sqrt{e^2-16}}\dx}
\IntExerc{R1.40}{\int \frac{\sin(2x)}{\sin x} \dx}
\IntExerc{R1.40}{\int_0^{\pi/3n} \tan(nx) \dx}
\IntExerc{R1.40}{\int \frac{4a}{x^2-a^2} \dx}
\IntExerc{R1.40}{\int e^{\sin(x)^2}e^{\cos(x)^2}  \dx}
\IntExerc{R1.40}{\int \frac{e^{\ln\left(x^2 + 1 \right)}}{x+1} \dx}
\IntExerc{R1.40}{\int_{\pi/6}^{\pi/2} \frac{1}{\tan x} \dx}
\IntExerc{R1.40}{\int \frac{x^2+1}{x(x^2+3)} \dx}
\IntExerc{R1.40}{\int \frac{1}{\sqrt[3]{x} + x} \dx}
\IntExerc{R1.40}{\int \frac{1}{x \ln x - x} \dx}
\IntExerc{R1.40}{\int_{0}^{\pi} \frac{x^2 \sin(x)}{\pi - 2} \dx}
\IntExerc{R1.40}{\int \sqrt{\sqrt{x} + \sqrt{x}\,} \dx}
\IntExerc{R1.40}{\int 2^{\ln x} \dx}
\IntExerc{R1.40}{\int_{2}^{5} \frac{2 - 4}{x^4 - x^2} \dx}
\IntExerc{R1.40}{\int \cos( \sin(x) ) \cos x \dx}
\IntExerc{R1.40}{\int \left(x + x^2\right)e^{3(x+\ln 3)} \dx}
\IntExerc{R1.40}{\int \cos(x)\sin(2x) \dx}
\IntExerc{R1.40}{\int \frac{1}{2x \sqrt{\ln x}} \dx}
\IntExerc{R1.40}{\int \frac{\log_5(x)}{\log_{25}(x)} \dx}
\end{IntList}

\subsubsection{Word problems}

$$ \int_{1/2}^{\sqrt{3}/2} \frac{x^3}{\left( \frac{5}{8} - x^4\right)\sqrt{\frac{5}{8} - x^4}}\quad $$

\newpage

\newpage

\begin{align}
\int \frac{x^2+3x}{x^2} \dx & = \int \frac{x^2}{x^2} + \frac{3x}{x^2} \dx = \int 1 \dx + 3\int \frac{dx}{x} = x + 3 \ln|x| + \CC  \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.40}
\end{align}

First straight integration problems, then word problems

\end{document}

问题): 将简单的答案与解决方案分开的最佳方法是什么?(以下任何想法都很好吗?)

  • 是否可以添加剧透标签(点击后打开)?
  • 将数字做成单独的链接?
  • 在每个积分旁边添加单独的链接?(我认为这会使其变得非常混乱)

哦,有没有什么方法可以让超链接双向运行?我可以点击答案,然后返回问题吗?

谢谢,提前感谢任何建议、答案或评论 =)

答案1

所有这些都可以使用answershyperref包来实现。

hypertarget在下面的 MWE 中,我使用包中的andhyperlink机制将问题编号链接到解决方案,并将解决方案编号链接回问题hyperref

我所展示的例子非常简单,但你可以用它变得相当复杂,正如我在回答中展示的那样

竞赛:在 TeX & Friends 中展示你的技能 [TeX.sx 生日]

需要注意的主要一点是,我在renewenvironment输入解决方案文件之前必须立即输入它 - 您必须等到这一点,以避免弄乱写入文件的过程。

截屏

\documentclass{article}

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

\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}
\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]
         \item%
        }%
        {%
        \end{myenum}}

\begin{document}

\section{Questions}
\begin{multicols}{3}
    \begin{question}
        $\int\sqrt{4-x}\mathrm{d}x$
            \begin{mysolution}
                $-\frac{2}{3}(4-x)^{\frac{3}{2}}+C$
            \end{mysolution}
    \end{question}
    \begin{question}
        $\int(2x-1)^{50}\mathrm{d}x$
            \begin{mysolution}
                $\frac{1}{102}(2x-1)^{51}+C$
            \end{mysolution}
    \end{question}
    \begin{question}
        $\int\sqrt[n]{x}\mathrm{d}x$
            \begin{mysolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{mysolution}
    \end{question}
\end{multicols}

% 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}

答案2

您可以定义一个新环境,将答案逐字写入单独的文件中,然后\input在必要时使用答案文件。

这是我自己的书的私人包裹:

\ProvidesPackage{latexexercise}[2011/08/03 by Leo]

\RequirePackage{verbatim}

\newwrite\ltxex@ansfile

\def\ltxex@ansfilename{\jobname.ans}

\newcounter{exercise}
\ifdefined\c@chapter
  \@addtoreset{exercise}{chapter}
  \def\theexercise{\arabic{chapter}.\arabic{exercise}}
\else\ifdefined\c@section
  \@addtoreset{exercise}{section}
  \def\theexercise{\arabic{section}.\arabic{exercise}}
\else
  \def\theexercise{\arabic{exercise}}
\fi\fi

\def\exercisename{Exercise}

\newcommand\startexercise{%
  \immediate\openout\ltxex@ansfile=\ltxex@ansfilename
  \immediate\write\ltxex@ansfile{\noexpand\begin{answerlist}}}
\newcommand\stopexercise{%
  \immediate\write\ltxex@ansfile{\noexpand\end{answerlist}}%
  \immediate\closeout\ltxex@ansfile}
\newcommand\printanswer{%
  \InputIfFileExists{\ltxex@ansfilename}%
    {\PackageInfo{latexexercise}{answer file `\ltxex@ansfilename' inputed.}}%
    {\PackageWarning{latexexercise}%
      {answer file `\ltxex@ansfilename' does not exsist.}}}

\newenvironment{exercise}%
  {\list{\ltxex@labelstyle\theexercise}%
     {\ltxex@listargs\normalfont\normalsize}%
   \ltxex@pre}%
  {\endlist}
\newenvironment{answer}%
  {\immediate\write\ltxex@ansfile{\noexpand\item[\theexercise]}%
   \ltxex@startwrite}%
  {\ltxex@endwrite}
\newenvironment{answerlist}%
  {\list{}{\ltxex@anslistargs\normalfont\normalsize}}%
  {\endlist}
%

\def\ltxex@pre{\item[]\hskip-\labelsep {\large\bfseries \exercisename}}
\def\ltxex@listargs{%
  \@nmbrlisttrue\def\@listctr{exercise}%
  %\topsep=0pt
  \partopsep=0pt
  \itemsep=0pt
  \leftmargin=0pt
  \rightmargin=0pt
  \parsep=\parskip
  \listparindent=\parindent
  \itemindent=\parindent
  \labelwidth=0pt
  \labelsep=0.5em}
\def\ltxex@labelstyle{\bfseries}

\def\ltxex@anslistargs{%
  \def\makelabel##1{\ltxex@anslabelstyle ##1}
  \topsep=0pt
  \partopsep=0pt
  \itemsep=0pt
  \leftmargin=0pt
  \rightmargin=0pt
  \parsep=\parskip
  \listparindent=\parindent
  \itemindent=\parindent
  \labelwidth=0pt
  \labelsep=0.5em}
\def\ltxex@anslabelstyle{\bfseries}

\def\ltxex@startwrite{%
  \begingroup
  \@bsphack
  \let\do\@makeother \dospecials
  \catcode`\^^M\active
  \def\verbatim@processline{%
    \immediate\write\ltxex@ansfile{\the\verbatim@line}}%
  \verbatim@start}

\def\ltxex@endwrite{\@esphack\endgroup}

\endinput

测试代码:

\documentclass{article}
\usepackage{latexexercise}
\begin{document}

\startexercise

\section{Foo}

\begin{exercise}
\item $1+1=?$
\begin{answer}
$1+1=2$.
\end{answer}

\item $2\times 2 = ?$
\begin{answer}
That's 4.
\end{answer}
\end{exercise}

\section{Bar}

\begin{exercise}
\item Foo
\begin{answer}
Bar
\end{answer}
\end{exercise}

\stopexercise

\section{Solutions}
\printanswer
\end{document}

答案3

另一种方法是使用eqexam适用于常见驱动程序(如pdflatexxelatextex等)的包 - 请参阅 CTAN 上有关此包的文档。

这里是代码:

\documentclass{article}
\usepackage{amsmath}
\usepackage[%
links,        % to activate links between problem and solutions (within the solution set there is a \square symbol to link back to the problem)
%answerkey,   % to present the solutions right after the problem (no hyperlink then needed)
%nosolutions  % to not setup the solutions at all -- and erase the hyperlinks
]{eqexam}
\autotabOn    % to allow to setup the parts of the problem within a tabular environment

\begin{document}
\begin{exam}{myExam}
\begin{problem*}
Solve each of the integrals.

\begin{parts}[3] % Setting up 3 columns for the parts of the problem
\item $\int \frac{x^2+3x}{x^2}\,\text{d}x$
%
\begin{solution}
Solution to item 1 a
\end{solution}
%
\item $\int\sin(x)\,\text{d}x$
%
\begin{solution}
Solution to item 1 b
\end{solution}
%
\item $\int_0^1 \frac{x}{x^2+1}\,\text{d}x$
%
\begin{solution}
Solution to item 1 c
\end{solution}
%
\item $\int \frac{x}{x+1}\,\text{d}x$
%
\begin{solution}
Solution to item 1 d
\end{solution}
%
\item $\int_{-3}^{3} \frac{1}{1-x}\,\text{d}x$
%
\begin{solution}
Solution to item 1 e
\end{solution}
%
\item $\int \sqrt{4-x}\,\text{d}x$
%
\begin{solution}
Solution to item 1 f
\end{solution}
%
\item $\int_{0}^{1/2} \left( 2x - 1\right)^{50}\,\text{d}x$
%
\begin{solution}
Solution to item 1 g
\end{solution}
%
\item $\int \sqrt[n]{x}\,\text{d}x$
%
\begin{solution}
Solution to item 1 h
\end{solution}
%
\item $\int \frac{1}{x \ln x}\,\text{d}x$
%
\begin{solution}
Solution to item 1 i
\end{solution}
\end{parts}
\end{problem*}
\end{exam}
\end{document}

在此处输入图片描述

笔记:

您可以使用以下选项来抑制解决方案:nosolutions

您可以使用以下选项在问题之后立即添加解决方案:answerkey

这或许是一种可以将您的问题和解决方案完整地相互关联起来的方式。

相关内容