条件标题的内容取决于 xsim 解决方案是否被打印

条件标题的内容取决于 xsim 解决方案是否被打印

有没有办法根据是否打印解决方案来设置标题内容?

\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}

相关内容