我目前正在依靠考試課程為問題和解決方案製作單獨的練習表。有沒有辦法使用該類別產生帶有提示而不是完整解決方案的第三張表,或者更好的替代方案?
唯一的 tex 檔案的結構類似於:
\documentclass{exam} % or any other suggestion
\begin{document}
\begin{questions}
\question Prove that $A\implies B$.
\begin{hint}
Use contradiction.
\end{hint}
\begin{solution}
The details...
\end{solution}
\end{questions}
\end{document}
然後,按照本網站其他地方的說明,透過將正確的選項傳遞給所選類,適當的Makefile
with將產生sheet-questions.pdf、sheet-hints.pdf 和sheet-solutions.pdf。latexmk
答案1
我已經有很多使用該類別的文件exam
,因此我最終使用該optional
套件來定義一個簡單的環境,如果showhints
不使用選項,則不會顯示任何內容。這是一個基本範例:
\documentclass{exam}
\qformat{\textbf{Question \thequestion\hfill}}
% The "optional" package allows the definition of an environment
% hints that will only be printed if the showhints option is passed
\usepackage[dummy]{optional} % document fails to compile if optional has no options ...
\makeatletter
\@ifpackagewith{optional}{showhints}{
% environment definition for the case where hints must be shown
\newenvironment{hints}[1][]{\textbf{Hints:} #1}{}
}{
% environment definition for the case where hints must be hidden
\newenvironment{hints}[1][]{\setbox\z@\vbox\bgroup}{\egroup}
}
\makeatother
\begin{document}
\begin{questions}
\question How do you include a package in \LaTeX?
\begin{hints}
Ask around at tex.stackexchange.com if you dare.
\end{hints}
\begin{solution}
Use the \texttt{\textbackslash usepackage} command.
\end{solution}
\end{questions}
\end{document}
假設以上內容儲存到名為 的檔案中mwe.tex
,以下內容Makefile
會產生三個不同的輸出:
mwe-base.pdf
,這是預期的練習表;mwe-answers.pdf
,其中包含解決方案但沒有提示;mwe-hints.pdf
,其中有提示但沒有解決方案。
SOURCES = $(wildcard *.tex)
TARGETS = $(patsubst %.tex, %, $(SOURCES))
all: $(TARGETS)
%: %.tex
latexmk -jobname=$(basename $<)-base -pdf -pdflatex='pdflatex -shell-escape -interaction=nonstopmode' $<
latexmk -jobname=$(basename $<)-answers -pdf -pdflatex='pdflatex -jobname=$(basename $<)-answers -shell-escape -interaction=nonstopmode "\PassOptionsToClass{answers}{exam}\input{$(basename $<)}"' $<
latexmk -jobname=$(basename $<)-hints -pdf -pdflatex='pdflatex -jobname=$(basename $<)-hints -shell-escape -interaction=nonstopmode "\PassOptionsToPackage{showhints}{optional}\input{$(basename $<)}"' $<
clean:
rm -f *.out *aux *bbl *blg *log *toc *.ptb *.tod *.fls *.fdb_latexmk *.lof
很可能還有進步的空間。