Estoy escribiendo un examen en la exam
clase y me gustaría establecer el valor en puntos para un grupo completo de preguntas a la vez. Por ejemplo:
\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}
(NB: ¡No pretendo comentar sobre la dificultad real de estas preguntas!)
El resultado debería ser el mismo que si las tres primeras preguntas se declararan con \question[2]
, y las cinco siguientes con \question[3]
. La novena pregunta está fuera de un grupo de puntos predeterminados, por lo que no debería tener ningún punto adjunto. La última pregunta debería funcionar como una pregunta normal con puntos definidos.
Ya tengo una solución ah@cky y la publicaré eventualmente, pero tengo curiosidad por ver si hay otras mejores.
Respuesta1
Básicamente simplemente redefina \question
call \oldQuestion[⟨default value⟩]
.
Tenga en cuenta el uso de \DeclareCommandCopy
(declarar = si ya está definido, no hacer nada) para no anular la definición de \oldQuestion
en caso de que el punto predeterminado ya esté configurado una vez en un grupo.
Esto supone que todos los comandos están definidos localmente en un grupo (lo que parece ser bastante seguro porque los mantenedores de LaTeX realmente no quieren romper la compatibilidad con versiones anteriores).
%! 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}
Respuesta2
Aquí está la solución que se me ocurrió originalmente. En el preámbulo:
\makeatletter
\let\orig@doitem\@doitem
\newcommand{\defaultpoints}[1]{
\def\@doitem{\@ifnextchar[{\@readpoints}{\@readpoints[#1]}}
}
\newcommand{\nodefaultpoints}{
\let\@doitem\orig@doitem
}
\makeatother
Como puedes ver, mis hábitos con LaTeX son viejos. Lo dupliqué \@doitem
para guardarlo y lo redefiní \@doitem
para llamar \@readpoints
al número de punto predeterminado en ausencia de cualquier número declarado.
Pero esto depende de las partes internas del \question
comando. La solución del usuario202729 es más limpia y sencilla.