답변 링크가 포함된 연습 문제(카운터 사용 문제)

답변 링크가 포함된 연습 문제(카운터 사용 문제)

죄송합니다. 웹사이트에서는 댓글로 자세한 질문을 할 수 없으므로(서식 도구 모음도 표시되지 않음) 새 질문을 추가하세요.

문제: 운동 목록(해당 답변에 대한 링크 포함)을 만들려고 합니다. 문서 끝에 모든 답변이 있습니다. 그러나 각 질문에 수동으로 레이블을 지정하고 싶지 않습니다. 그래서 문제 번호를 라벨로 사용하려고 했는데, 아무래도 전체 문제 개수를 라벨로 사용하고 있는 것 같습니다. 도움을 주시면 감사하겠습니다. 원래 질문에 답변해 주신 @CarLaTeX에게 감사드립니다.여기.

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

출력(잘못됨):

여기에 이미지 설명을 입력하세요

답변1

찾고 있는 '질문 번호'는 Exercise(적어도 연습 환경의 경우) 적절한 이름의 카운터로 저장됩니다. 다음을 사용하여 카운터에 액세스할 수 있습니다.

\the\value{Exercise}

따라서 NET에서 옵션으로 전달할 때 이를 레이블로 사용하기만 하면 됩니다 \begin{Exercise}. 예를 보려면 아래를 참조하세요.

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


추가 정보

다음과 같은 경우 라벨을 입력하는 것을 덜 번거롭게 만들 수 있습니다.

(옵션 1)다음과 같은 매크로를 정의합니다 \blah.

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

또는

(옵션 2)게으른 느낌이 든다면 간단히 새로운 환경을 정의하십시오.

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

그런 다음 기본 문서에서 연습문제를 다음과 같이 호출하세요.

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

관련 정보