1

I have previously tried to make a document with questions and answers. In a previous question I was shown a great way to do this, using the answer package in combination with hyperref.

Adding another answer hyperlinked to the question itself

The problem is that the document has grown quite large, counting over 100 pages. I need to reset the counters for the answers and questions at the subsubsection instead of at the 'subsection'. I tried changing the counters in the answer provided, but alas either the document failed to compile, or nothing changed at all.

Here is a minimal working example with the counters reset at the subsection level http://spot.pcc.edu/~chughes/buzzard/

I know this must seem like a trivial question, but for a novice like me the code was quite hard to interpret.

A even more minimal example, the backhypperrefs fail here. Also I am not able to reproduce the error where it fails to distinguish between the subsubsections

\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}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114
  • Try to change here \newcounter{question}[subsection] – Sigur Dec 12 '13 at 23:26
  • Already tried that, nothing ;) – N3buchadnezzar Dec 12 '13 at 23:27
  • Shouldn't that be \newcounter{question}[subsubsection]? – Werner Dec 12 '13 at 23:35
  • @Werner, this was my suggestion. I wrote to change. But I don't know if the OP tried it. – Sigur Dec 12 '13 at 23:38
  • I did try that =) – N3buchadnezzar Dec 13 '13 at 06:03
  • your mwe isn't very minimal. please shorten it and also include it in your question to make it easier for people to help you. I don't think many people would want to click through three links and browse through 200 lines of code to figure out what you're doing. – sheß Dec 13 '13 at 16:27
  • Comparing with my document of close to 10 000 lines, a mwe of around 200 lines IS minimal. An example working in a sterile enviroment is of no use, if it fails to be compatible with other packages and system.

    For your amusement I did try to narrow it down a notch =)

    – N3buchadnezzar Dec 15 '13 at 00:07

0 Answers0