From: Stefan Huber Date: Wed, 21 Oct 2026 06:25:53 +0000 (+0200) Subject: Add coloranswers option to exsheet2 X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmain;p=exsheet.git Add coloranswers option to exsheet2 With the new class option coloranswers, answers shown via showanswers are typeset in color, gray by default. The color can be changed with \answercolor{...}. Without the option, the output is unchanged and xcolor is not loaded. Co-Authored-By: Claude Opus 5.5 --- diff --git a/README.markdown b/README.markdown index f5d8c6e..defe3d6 100644 --- a/README.markdown +++ b/README.markdown @@ -47,6 +47,10 @@ formulieren. Man kann auch die Antwort mitformulieren und über die Option \end{answer} ``` +Mit der zusätzlichen Option `coloranswers` werden die Antworten farbig +gesetzt, standardmäßig grau. Die Farbe lässt sich mit `\answercolor{...}` +ändern, z.B. `\answercolor{blue!70!black}`. Die Option lädt `xcolor`. + Ein optionales Argument erlaubt es die Punkteanzahl bekanntzugeben. Die Umgebung `choices` erlaubt es single- oder multiple-choice Fragen zu formulieren: diff --git a/exsheet2.cls b/exsheet2.cls index 833bb6a..04914db 100644 --- a/exsheet2.cls +++ b/exsheet2.cls @@ -12,6 +12,7 @@ \DeclareOption{austrian}{\def \exsheetgerman{}} \DeclareOption{naustrian}{\def \exsheetgerman{}} \DeclareOption{showanswers}{\def \exsheetshowanswers{}} +\DeclareOption{coloranswers}{\def \exsheetcoloranswers{}} \DeclareOption{exam}{\def \exsheetexam{}} \DeclareOption{nostudentinfo}{\def \exsheetnostudentinfo{}} \DeclareOption{nogradeinfo}{\def \exsheetnogradeinfo{}} @@ -76,10 +77,19 @@ \newline} {} +% Color of answers, only effective with option coloranswers. +\def\exsheet@answercolor{gray} +\newcommand{\answercolor}[1]{\def\exsheet@answercolor{#1}} + +\@ifundefined{exsheetcoloranswers}{}{\RequirePackage{xcolor}} + \@ifundefined{exsheetshowanswers}{ \excludecomment{answer} }{ - \newenvironment{answer}{\vspace*{0.5em}\textit{\theanswer:} \hspace*{0.5em} }{} + \newenvironment{answer}{% + \vspace*{0.5em}% + \@ifundefined{exsheetcoloranswers}{}{\color{\exsheet@answercolor}}% + \textit{\theanswer:} \hspace*{0.5em} }{} } \newenvironment{choices}{%