XSIM 练习集练习之间的说明

XSIM 练习集练习之间的说明

我正在写一本书,我希望这本书在每章末尾都有练习,在末尾有解决方案。我正在使用xsim排版练习和解决方案。

我已经使用示例文件“xsim.texsx-576998”启动了我的 MWE,但在 MWE 输出中(这里),指令行“在练习 1-2 中,...”和“在练习 3-4 中,...”没有出现在我希望它们出现的位置。我希望它们像这样出现

In Exercise 1--2, solve for x.

1. x - 1 = 0
2. x^2 - 3x + 2 = 0

In Exercise 3--4, solve for y.

3. y^3 - 6 y^2 + 11 y - 6 = 0
4. y^4 - 10 y^3 + 35 y^2 - 50 y + 24 = 0

问题

我怎样才能使说明出现在不同的练习之间(见上文)?

平均能量损失

% TeXlive 2020
\documentclass[a4paper]{book}
\usepackage[margin=0.75in]{geometry}
\usepackage{lipsum}
\usepackage{xsim}

% -----from xsim.texsx-576998-----
\DeclareExerciseEnvironmentTemplate{number-only}{%
    \par\noindent
    \textbf{\GetExerciseProperty{counter}}%
    \GetExercisePropertyT{subtitle}{ \textit{#1}} %
}{\par}

\newcommand\printsectionexercises{%
    \ForEachUsedExerciseByType{%
        \ifnum\ExercisePropertyGet{##1}{##2}{chapter-value}=\value{chapter}
        \XSIMprint{exercise}{##1}{##2}%
        \fi
    }%
}

\renewcommand\printsolutions{%
    \def\currentchapter{}%
    \def\lastchapter{}%
    \ForEachUsedExerciseByType{%
        \let\lastchapter\currentchapter
        \edef\currentchapter{\ExercisePropertyGet{##1}{##2}{chapter-value}}%
        \ifx\lastchapter\currentchapter\else
        \section*{Chapter \ExercisePropertyGet{##1}{##2}{chapter}}
        \fi
        \XSIMprint{solution}{##1}{##2}%
    }%
}

\xsimsetup{
    exercise/template = number-only ,
    solution/template = number-only ,
    exercise/within = section ,
    exercise/the-counter = \arabic{exercise}. ,
    exercise/print = false
}

\begin{document}
\chapter{ChapterOne}

\section{SectionOneOne}
\lipsum[1-1]

\noindent In Exercise 1--2, solve for \(x\).

\begin{exercise}
\(x - 1 = 0\)
\end{exercise}

\begin{solution}
\(x = 1\)
\end{solution}

\begin{exercise}
    \(x^2 - 3x + 2 = 0\)
\end{exercise}

\begin{solution}
    \(x = 1, 2\)
\end{solution}

\noindent In Exercise 3--4, solve for \(y\).

\begin{exercise}
    \(y^3 - 6 y^2 + 11 y - 6 = 0\)
\end{exercise}

\begin{solution}
    \(y = 1, 2, 3\)
\end{solution}

\begin{exercise}
    \(y^4 - 10 y^3 + 35 y^2 - 50 y + 24 = 0\)
\end{exercise}

\begin{solution}
    \(y = 1, 2, 3, 4\)
\end{solution}

\subsection*{Exercises}
\printsectionexercises

\chapter*{Solutions to the exercises}
\printsolutions

\end{document}

MWE 输出 在此处输入图片描述

答案1

这里有这个想法,它使用一个新的锻炼属性instruction,该属性在锻炼之前打印在锻炼列表中(如果给出了该属性)和两个新命令\This,并且通过引用指定的锻炼\ExerciseRefID 来获取当前(\This)或引用锻炼的计数器值:

\DeclareExerciseProperty{instruction}
\newcommand\ExerciseRef[1]{%
  \expanded{\noexpand\ExercisePropertyGet{exercise}{\GetExerciseIdForProperty{ID}{#1}}{counter-value}}%
}
\newcommand\This{\GetExerciseProperty{counter-value}}

现在用法如下:

\begin{exercise}[instruction={In Exercises \This--\ExerciseRef{last:x}, solve for \(x\).}]
  \(x - 1 = 0\)
\end{exercise}
\begin{solution}
  \(x = 1\)
\end{solution}
\begin{exercise}
  \(3x - 12 = 0\)
\end{exercise}
\begin{solution}
  \(x = 4\)
\end{solution}
\begin{exercise}[ID=last:x]
  \(x^2 - 3x + 2 = 0\)
\end{exercise}
\begin{solution}
  \(x = 1, 2\)
\end{solution}

在此处输入图片描述


完整代码:

\documentclass[a4paper]{book}
\usepackage[margin=0.75in]{geometry}
\usepackage{lipsum}
\usepackage{xsim}

% -----from xsim.texsx-576998-----
\DeclareExerciseEnvironmentTemplate{number-only}{%
  \par\noindent
  \textbf{\GetExerciseProperty{counter}}%
  \GetExercisePropertyT{subtitle}{ \textit{#1}} %
}{\par}

\newcommand\printsectionexercises{%
  \ForEachUsedExerciseByType{%
    \ifnum\ExercisePropertyGet{##1}{##2}{chapter-value}=\value{chapter}
    \noindent\ExercisePropertyGet{##1}{##2}{instruction}\par
    \XSIMprint{exercise}{##1}{##2}%
    \fi
  }%
}

\renewcommand\printsolutions{%
  \def\currentchapter{}%
  \def\lastchapter{}%
  \ForEachUsedExerciseByType{%
    \let\lastchapter\currentchapter
    \edef\currentchapter{\ExercisePropertyGet{##1}{##2}{chapter-value}}%
    \ifx\lastchapter\currentchapter\else
    \section*{Chapter \ExercisePropertyGet{##1}{##2}{chapter}}
    \fi
    \XSIMprint{solution}{##1}{##2}%
  }%
}

\DeclareExerciseProperty{instruction}
\newcommand\ExerciseRef[1]{%
  \expanded{%
    \noexpand
    \ExercisePropertyGet{exercise}{\GetExerciseIdForProperty{ID}{#1}}{counter-value}%
  }%
}
\newcommand\This{\GetExerciseProperty{counter-value}}

\xsimsetup{
  exercise/template = number-only ,
  solution/template = number-only ,
  exercise/within = section ,
  exercise/the-counter = \arabic{exercise}. ,
  exercise/print = false
}

\begin{document}

\chapter{ChapterOne}
\section{SectionOneOne}
\lipsum[1-1]

\begin{exercise}[instruction={In Exercises \This--\ExerciseRef{last:x}, solve for \(x\).}]
  \(x - 1 = 0\)
\end{exercise}
\begin{solution}
  \(x = 1\)
\end{solution}
\begin{exercise}
  \(3x - 12 = 0\)
\end{exercise}
\begin{solution}
  \(x = 4\)
\end{solution}
\begin{exercise}[ID=last:x]
  \(x^2 - 3x + 2 = 0\)
\end{exercise}
\begin{solution}
  \(x = 1, 2\)
\end{solution}

\begin{exercise}[instruction={In Exercises \This--\ExerciseRef{last:y}, solve for \(y\).}]
  \(y^3 - 6 y^2 + 11 y - 6 = 0\)
\end{exercise}
\begin{solution}
  \(y = 1, 2, 3\)
\end{solution}

\begin{exercise}[ID=last:y]
  \(y^4 - 10 y^3 + 35 y^2 - 50 y + 24 = 0\)
\end{exercise}
\begin{solution}
  \(y = 1, 2, 3, 4\)
\end{solution}

\subsection*{Exercises}
\printsectionexercises

\chapter*{Solutions to the exercises}
\printsolutions

\end{document}

相关内容