如何修改 xsim 包的练习/解决方案环境的 runin 模板以忽略源代码中环境开头的空行?
谢谢
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{xsim}
% template taken from xsim manual
% https://ctan.math.illinois.edu/macros/latex/contrib/xsim/xsim-manual.pdf
\usepackage{needspace}
\DeclareExerciseEnvironmentTemplate{runin}
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}} % <<< notice the space
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}
{}
\xsimsetup{%
exercise/template = runin,
solution/print = true
}
\begin{document}
\begin{exercise}
\lipsum[1]
\end{exercise}
\begin{exercise}
\lipsum[1]
\end{exercise}
\vspace{2cm}
I would like the text of exercise 2 to start on the same line as ``Exercise 2'' (looking like Exercise 1) despite the presence of an empty line at the beginning of the environment.
\end{document}
答案1
您可以使用以下方式定义它\paragraph*
:
\documentclass{article}
\usepackage{xsim}
\DeclareExerciseEnvironmentTemplate{runin}{%
\paragraph*{%
\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}%
\normalfont
\GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}%
}%
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}{\par\addvspace{\baselineskip}}
\xsimsetup{
exercise/template = runin,
solution/print = true
}
\usepackage{lipsum}
\begin{document}
\begin{exercise}
\lipsum[1]
\end{exercise}
\begin{exercise}
\lipsum[1]
\end{exercise}
I would like the text of exercise 2 to start on the same line as
``Exercise~2'' (looking like Exercise~1) despite the presence of an empty line
at the beginning of the environment.
\end{document}
不过,更改默认模板的标题命令可能会更容易:
\documentclass{article}
\usepackage{xsim}
\xsimsetup{
exercise/heading = \paragraph* ,
exercise/post-hook = \addvspace{\baselineskip} ,
solution/print = true
}
\usepackage{lipsum}
\begin{document}
\begin{exercise}
\lipsum[1]
\end{exercise}
\begin{exercise}
\lipsum[1]
\end{exercise}
I would like the text of exercise 2 to start on the same line as
``Exercise~2'' (looking like Exercise~1) despite the presence of an empty line
at the beginning of the environment.
\end{document}
两个例子都给出: