Exercícios com links para respostas (problema usando contador)

Exercícios com links para respostas (problema usando contador)

Desculpe, o site não me permite fazer perguntas detalhadas como comentário (nem mostra a barra de ferramentas de formatação), portanto, adicione uma nova pergunta.

Problema: Tentando criar uma lista de exercícios (com links para as respostas correspondentes). todas as respostas no final do documento. No entanto, não quero rotular manualmente cada pergunta. Então, pensei em usar o número da pergunta como rótulo, mas aparentemente ele usa o número total de perguntas como rótulo. Qualquer ajuda será apreciada. Obrigado a @CarLaTeX por responder à pergunta originalaqui.

\documentclass{article}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}

\begin{document}

    \begin{Exercise}[label={exerciseNumber}]
        What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
    \end{Exercise}
    \begin{Answer}[ref=\ExerciseLabel]
        7
    \end{Answer}

    \begin{Exercise}[label={exerciseNumber}]
        What is the value of 4-1? (To see the answer click here: \refAnswer{\ExerciseLabel})
    \end{Exercise}
    \begin{Answer}[ref=\ExerciseLabel]
        3
    \end{Answer}

     \begin{Exercise}[label={exerciseNumber}]
        What is the value of 2*4? (To see the answer click here: \refAnswer{\ExerciseLabel})
    \end{Exercise}
    \begin{Answer}[ref=\ExerciseLabel]
        8
    \end{Answer}
    \shipoutAnswer
\end{document}

Saída (incorreta):

insira a descrição da imagem aqui

Responder1

O 'número da pergunta' que você está procurando é armazenado como um contador, apropriadamente nomeado como Exercise(pelo menos, para o ambiente Exercício). Você pode acessar o contador usando:

\the\value{Exercise}

Então tudo que você precisa fazer é usar isso como um rótulo ao passá-lo como uma opção em \begin{Exercise}. Veja abaixo um exemplo.

MWE:

\documentclass{article}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}

\begin{document}
  \begin{Exercise}[label={\the\value{Exercise}}]
    What is the value of $2+5$? (To see the answer click here:~\refAnswer{\ExerciseLabel})
  \end{Exercise}
  \begin{Answer}[ref=\ExerciseLabel]
    7
  \end{Answer}

  \begin{Exercise}[label={\the\value{Exercise}}]
    What is the value of $4-1$? (To see the answer click here:~\refAnswer{\ExerciseLabel})
  \end{Exercise}
  \begin{Answer}[ref=\ExerciseLabel]
    3
  \end{Answer}

  \begin{Exercise}[label={\the\value{Exercise}}]
    What is the value of $2\times 4$? (To see the answer click here:~\refAnswer{\ExerciseLabel})
  \end{Exercise}
  \begin{Answer}[ref=\ExerciseLabel]
    8
  \end{Answer}
  \shipoutAnswer
\end{document}

Ex-v2


Informações adicionais

Talvez você possa tornar menos complicado digitar o rótulo, se

(Opção 1)você define uma macro como \blah:

% Preamble:    
\newcommand*{\blah}{\the\value{Exercise}}
% Main document:
\begin{Exercise}[label=\blah]

ou

(Opção 2)se você estiver com preguiça extra, basta definir um novo ambiente:

% In Preamble
\newcounter{Ex}
\newenvironment{Ex}{\begin{Exercise}[name={Exercise},
    counter={Ex},
    label=\the\value{Ex}]}
{\end{Exercise}}

e então no documento principal, chame seus exercícios assim:

% In Main document
\begin{Ex}
    What is the value of $2+5$? (To see the answer click here:~\refAnswer{\ExerciseLabel})
\end{Ex}
\begin{Answer}[ref=\ExerciseLabel]
    7
\end{Answer}

informação relacionada