我正在用该exsheets
软件包排版一本习题书。我希望解决方案的结构重复习题集的结构。Chapter-hook
并且section-hook
选项允许在打印新章节/部分的解决方案时将自定义代码添加到解决方案列表中。这是我的 MWE:
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\SetupExSheets{
chapter-hook = \chapter{Solutions to the chapter \thechapter},
section-hook = \section{Solutions to the section \thesection},
}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}
\section{Kinematics}
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}
\section{Electrostatics}
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
我想要实现的是使用1 Solutions to Mechanics
而不是 当前1 Solutions to the chapter 1
,2 Solutions to Electricity
而不是2 Solutions to the chapter 2
等等。任何帮助都值得感激。
答案1
通过引用包的解决方案nameref
。章节/节号用作标签名称。
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\usepackage{nameref}
\SetupExSheets{
chapter-hook = \chapter{Solutions to \nameref{CHAP:\thechapter}},
section-hook = \section{Solutions to \nameref{SEC:\thesection}},
}
\newcommand*{\chaplabel}{\label{CHAP:\thechapter}}
\newcommand*{\seclabel}{\label{SEC:\thesection}}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}\chaplabel
\section{Kinematics}\seclabel
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}\seclabel
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}\chaplabel
\section{Electrostatics}\seclabel
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}\seclabel
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
标签设置可以包括在\chapter
和中\section
:
\mychapter
添加的新命令\chaplabel
。- 保存 的旧定义
\chapter
(例如通过包letltxmacro
)并重新定义\chapter
以执行保存的版本并附加\chaplabel
。 - 根据所需的参数类型(星号形式、可选参数),(重新)定义或多或少会变得更加复杂。
版本,其中\chaplabel
和\seclabel
用于 的参数<after code>
,\titleformat
由包 提供titlesec
:
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\usepackage{nameref}
\SetupExSheets{
chapter-hook = \chapter{Solutions to \nameref{CHAP:\thechapter}},
section-hook = \section{Solutions to \nameref{SEC:\thesection}},
}
\newcommand*{\chaplabel}{\label{CHAP:\thechapter}}
\newcommand*{\seclabel}{\label{SEC:\thesection}}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}%
{}[\chaplabel]
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}%
{}[\seclabel]
\usepackage{etoolbox}
\pretocmd\printsolutions{%
\let\chaplabel\relax
\let\seclabel\relax
}{}{\errmessage{Patching \noexpand\printsolutions failed.}}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}
\section{Kinematics}
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}
\section{Electrostatics}
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
避免无限递归的技巧如下评论是在处理章节和部分之前禁用\chaplabel
和。\seclabel
\printsolutions
使用开关进行轻微变化\ifwithlabels
。然后可以禁用未编号章节的标签设置,例如:
[...]
\newif\ifwithlabels
\newcommand*{\chaplabel}{\ifwithlabels\label{CHAP:\thechapter}\fi}
\newcommand*{\seclabel}{\ifwithlabels\label{SEC:\thesection}\fi}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}%
{}[\chaplabel]
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}%
{}[\seclabel]
\usepackage{etoolbox}
\pretocmd\printsolutions{%
\withlabelsfalse
}{}{\errmessage{Patching \noexpand\printsolutions failed.}}
\begin{document}
\tableofcontents
\withlabelstrue
\part{Problems}
[...]