使用 subsubsection 而不是 subsection 来增加计数器

使用 subsubsection 而不是 subsection 来增加计数器

我以前曾尝试制作一个包含问题和答案的文档。在之前的一个问题中,我了解到一种很好的方法,即使用包answer与 结合使用hyperref

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

问题是文档已经变得相当大,有 100 多页了。我需要在而subsubsection 不是“小节”中重置答案和问题的计数器。我尝试更改提供的答案中的计数器,但遗憾的是文档要么编译失败,要么根本没有改变。

这是一个最小的工作示例,计数器在子部分级别重置 http://spot.pcc.edu/~chughes/buzzard/

我知道这似乎是一个微不足道的问题,但对于像我这样的新手来说,代码很难解释。

一个更简单的例子,backhypperrefs 在这里失败了。此外,我无法重现无法区分子部分的错误

\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}[subsubsection]
\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}

\subsubsection{Set I}

\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!
            \end{longsolution}
    \end{question}
\end{multicols}

\subsubsection{Set II}

\begin{multicols}{3}
    \begin{question}{$\int\sqrt{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
                Even longer!
            \end{longsolution}
    \end{question}
    \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)^{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}
\end{multicols}

\clearpage

\section{Questions}

\subsubsection{Set I}

\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!
            \end{longsolution}
    \end{question}
\end{multicols}

\subsubsection{Set II}

\begin{multicols}{3}
    \begin{question}{$\int\sqrt{x}\mathrm{d}x$}
            \begin{shortsolution}
                $\frac{n}{n+1}x^{\frac{1+n}{n}}+C$
            \end{shortsolution}
            \begin{longsolution}
                Even longer!
            \end{longsolution}
    \end{question}
    \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)^{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}
\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}

相关内容