Wie kann ich im Prüfungskurs einen Standardfragepunktwert festlegen?

Wie kann ich im Prüfungskurs einen Standardfragepunktwert festlegen?

Ich schreibe eine Prüfung im examUnterricht und möchte den Punktwert für eine ganze Gruppe von Fragen auf einmal festlegen. Beispiel:

\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: Ich möchte den tatsächlichen Schwierigkeitsgrad dieser Fragen nicht kommentieren!)

Die Ausgabe sollte dieselbe sein, als ob die ersten drei Fragen mit deklariert worden wären \question[2]und die nächsten fünf mit \question[3]. Die neunte Frage liegt außerhalb einer Gruppe von Standardpunkten, daher sollten ihr keine Punkte zugeordnet werden. Die letzte Frage sollte wie eine normale Frage mit definierten Punkten funktionieren.

Ich habe bereits eine lahme Lösung und werde sie irgendwann veröffentlichen, aber ich bin gespannt, ob es bessere gibt.

Antwort1

Definieren Sie es grundsätzlich einfach neu \questionin „call“ \oldQuestion[⟨default value⟩].

Beachten Sie die Verwendung von \DeclareCommandCopy(declare = if already defined, do nothing), um die Definition nicht zu überschreiben, \oldQuestionfalls der Standardpunkt bereits einmal in einer Gruppe festgelegt wurde.

Dies setzt voraus, dass alle Befehle lokal in einer Gruppe definiert sind (was ziemlich sicher erscheint, da die LaTeX-Betreuer die Abwärtskompatibilität wirklich nicht beeinträchtigen möchten).

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

Antwort2

Hier ist die Lösung, die mir ursprünglich eingefallen ist. In der Präambel:

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

Wie Sie sehen, sind meine LaTeX-Gewohnheiten alt. Ich habe sie \@doitemzur Sicherheit dupliziert und neu definiert, \@doitemum \@readpointsdie Standardpunktzahl aufzurufen, wenn keine deklarierte Zahl angegeben ist.

Dies hängt jedoch von den internen Vorgängen im \questionBefehl ab. Die Lösung von user202729 ist sauberer und einfacher.

verwandte Informationen