![条件标题的内容取决于 xsim 解决方案是否被打印](https://linux22.com/image/431540/%E6%9D%A1%E4%BB%B6%E6%A0%87%E9%A2%98%E7%9A%84%E5%86%85%E5%AE%B9%E5%8F%96%E5%86%B3%E4%BA%8E%20xsim%20%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E6%98%AF%E5%90%A6%E8%A2%AB%E6%89%93%E5%8D%B0.png)
有没有办法根据是否打印解决方案来设置标题内容?
\documentclass[headsepline]{scrartcl}
\usepackage{xsim}
\usepackage{scrlayer-scrpage}
\cohead{Solutions are not printed}
%\xsimsetup{solution/print}
%\cohead{Solutions are printed}
\begin{document}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\end{document}
答案1
您可以设置一个新\if
标志\ifprintsolutions
(默认false
)。通过声明\printsolutionstrue
,标题会随着要打印的解决方案而改变。
\newif\ifprintsolutions
\printsolutionstrue% COMMENT THIS LINE OR NOT
\documentclass[headsepline]{scrartcl}
\usepackage{xsim}
\usepackage{scrlayer-scrpage}
\ifprintsolutions
\xsimsetup{solution/print}
\cohead{Solutions are printed}
\else
\cohead{Solutions are not printed}
\fi
\begin{document}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\begin{exercise}
body of exercise \theexercise
\end{exercise}
\begin{solution}
solution of the exercise number \theexercise
\end{solution}
\end{document}