시험 수업에서 기본 문제 점수를 어떻게 설정할 수 있나요?

시험 수업에서 기본 문제 점수를 어떻게 설정할 수 있나요?

수업 시간 에 시험을 작성하고 exam있는데 전체 문제 그룹에 대한 점수를 한 번에 설정하고 싶습니다. 예를 들어:

\documentclass{exam}
\title{Know your US States and Capitals!}


\begin{document}

\begin{questions}

\begingroup
\defaultpoints{2}
\question What is the capital of California?
\begin{choices}
    \choice Los Angeles
    \choice Sacramento
    \choice San Francisco
    \choice San Diego
\end{choices}

\question Which city serves as the capital of Texas?
\begin{choices}
    \choice Dallas
    \choice Houston
    \choice Austin
    \choice San Antonio
\end{choices}

\question What is the capital of Florida?
\begin{choices}
    \choice Miami
    \choice Orlando
    \choice Jacksonville
    \choice Tallahassee
\end{choices}

\endgroup

\begingroup
\defaultpoints{3}
\question Which city is the capital of New York?
\begin{choices}
    \choice Buffalo
    \choice Albany
    \choice New York City
    \choice Syracuse
\end{choices}

\question What is the capital of Nevada?
\begin{choices}
    \choice Reno
    \choice Henderson
    \choice Carson City
    \choice Las Vegas
\end{choices}

\question Which city serves as the capital of Colorado?
\begin{choices}
    \choice Denver
    \choice Boulder
    \choice Colorado Springs
    \choice Aurora
\end{choices}

\question What is the capital of Massachusetts?
\begin{choices}
    \choice Springfield
    \choice Boston
    \choice Worcester
    \choice Cambridge
\end{choices}

\question Which city is the capital of Washington state?
\begin{choices}
    \choice Seattle
    \choice Tacoma
    \choice Spokane
    \choice Olympia
\end{choices}
\endgroup

% no points should be specified
\question What is the capital of Hawaii?
\begin{choices}
    \choice Maui
    \choice Honolulu
    \choice Kauai
    \choice Hilo
\end{choices}

\question[5] Which city serves as the capital of Ohio?
\begin{choices}
    \choice Cincinnati
    \choice Columbus
    \choice Cleveland
    \choice Dayton
\end{choices}

\end{questions}    
\end{document}

(주의: 이 질문의 실제 난이도에 대해 언급하려는 것은 아닙니다!)

\question[2]출력은 처음 세 개의 질문이 로 선언 되고 다음 다섯 개의 질문이 로 선언된 것과 동일해야 합니다 \question[3]. 아홉 번째 질문은 기본 포인트 그룹 외부에 있으므로 여기에 포인트가 연결되어서는 안 됩니다. 마지막 질문은 포인트가 정의된 일반 질문으로 작동해야 합니다.

나는 이미 ah@cky 솔루션을 가지고 있고 결국에는 게시할 예정이지만 더 나은 솔루션이 있는지 궁금합니다.

답변1

기본적으로 \questioncall 로 재정의하면 됩니다 \oldQuestion[⟨default value⟩].

기본 포인트가 그룹에 이미 한 번 설정된 경우 \DeclareCommandCopy정의를 재정의하지 않으려면 (선언 = 이미 정의된 경우 아무것도 하지 않음) 을 사용하십시오 .\oldQuestion

이는 모든 명령이 그룹 내에서 로컬로 정의된다고 가정합니다(LaTeX 관리자가 이전 버전과의 호환성을 깨는 것을 정말로 원하지 않기 때문에 매우 안전한 것 같습니다).

%! TEX program = pdflatex
\documentclass{exam}
\title{Know your US States and Capitals!}

\NewDocumentCommand\defaultpoints{m}{%
  \DeclareCommandCopy\oldQuestion\question%
  \RenewDocumentCommand\question{O{#1}}{%
    \oldQuestion[##1]%
  }%
}

\begin{document}

\begin{questions}

\begingroup
\defaultpoints{2}
\question What is the capital of California?
\begin{choices}
    \choice Los Angeles
    \choice Sacramento
    \choice San Francisco
    \choice San Diego
\end{choices}

\question Which city serves as the capital of Texas?
\begin{choices}
    \choice Dallas
    \choice Houston
    \choice Austin
    \choice San Antonio
\end{choices}

\question What is the capital of Florida?
\begin{choices}
    \choice Miami
    \choice Orlando
    \choice Jacksonville
    \choice Tallahassee
\end{choices}

\endgroup

\begingroup
\defaultpoints{3}
\question Which city is the capital of New York?
\begin{choices}
    \choice Buffalo
    \choice Albany
    \choice New York City
    \choice Syracuse
\end{choices}

\question What is the capital of Nevada?
\begin{choices}
    \choice Reno
    \choice Henderson
    \choice Carson City
    \choice Las Vegas
\end{choices}

\question Which city serves as the capital of Colorado?
\begin{choices}
    \choice Denver
    \choice Boulder
    \choice Colorado Springs
    \choice Aurora
\end{choices}

\question What is the capital of Massachusetts?
\begin{choices}
    \choice Springfield
    \choice Boston
    \choice Worcester
    \choice Cambridge
\end{choices}

\question Which city is the capital of Washington state?
\begin{choices}
    \choice Seattle
    \choice Tacoma
    \choice Spokane
    \choice Olympia
\end{choices}
\endgroup

% no points should be specified
\question What is the capital of Hawaii?
\begin{choices}
    \choice Maui
    \choice Honolulu
    \choice Kauai
    \choice Hilo
\end{choices}

\question[5] Which city serves as the capital of Ohio?
\begin{choices}
    \choice Cincinnati
    \choice Columbus
    \choice Cleveland
    \choice Dayton
\end{choices}

\end{questions}    
\end{document}

답변2

제가 원래 생각해낸 해결책은 다음과 같습니다. 전문에서:

\makeatletter
\let\orig@doitem\@doitem
\newcommand{\defaultpoints}[1]{
   \def\@doitem{\@ifnextchar[{\@readpoints}{\@readpoints[#1]}}
}
\newcommand{\nodefaultpoints}{
    \let\@doitem\orig@doitem
}
\makeatother

보시다시피 내 LaTeX 습관은 오래되었습니다. 나는 \@doitem보관을 위해 복제하고 선언된 번호가 없을 때 기본 포인트 번호를 \@doitem호출하도록 재정의했습니다.\@readpoints

그러나 이는 명령 내부에 의존합니다 \question. user202729의 솔루션은 더 깨끗하고 간단합니다.

관련 정보