当定义一个新的问题/解决方案对时,是否可以指定它应该有自己的计数器?
\documentclass{article}
\usepackage{exsheets}
\NewQuSolPair{query}[name=Query]{exsol}
\SetupExSheets{counter-format=se.qu[1],counter-within=section}
\begin{document}
\section{Section 1}
\begin{question}
This is an exercise.
\end{question}
\begin{query}
This is a query, which I'd like to be numbered 1.1
\end{query}
\end{document}
答案1
在该功能实现之前,我使用以下解决方法:
- 创建新计数器
- 创建新环境
PS:您可以轻松更改新环境的风格。
\documentclass{article}
\usepackage{exsheets}
\NewQuSolPair{query}[name=Query]{exsol}
\SetupExSheets{counter-format=se.qu[1],counter-within=section}
% WORKAROUND
\newcounter{example}[section] % new counter resets every time the section counter is increased
\newenvironment{example}{%
\refstepcounter{example} % increases the counter by 1; makes it visible for referencing;
\textbf{Example~\thesection.\theexample}
}{%
}
\begin{document}
\section{Section 1}
\begin{question}
This is an exercise.
\end{question}
\begin{query}
This is a query, which I'd like to be numbered 1.1
\end{query}
\begin{example}
This is a query, which I'd like to be numbered 1.1
\end{example}
\end{document}
输出:
答案2
这个问题问了已经 4 年多了,所需功能仍然在的 TODO 列表中exsheets
(在 的最末尾查看exsheets.sty
)。因此,这里是另一个解决方法:
exsheets
新问题组以 的方式定义- 在计数器步进之前添加了新
exsheets
选项来插入代码,因为选项的值 插入得太晚了pre-counter-hook
questino
pre-hook
- 在新的问题环境开始和结束时,计数器的值
question
分别更改为新计数器(这里使用)并从新计数器恢复。exercise
这可能仍然会破坏某些exsheets
功能。
\documentclass{article}
\usepackage{exsheets}
\usepackage{xpatch}
\ExplSyntaxOn
\tl_new:N \l__exsheets_questions_pre_counter_hook_tl
\keys_define:nn { exsheets / question }
{
pre-counter-hook .tl_set:N = \l__exsheets_questions_pre_counter_hook_tl
}
\xpatchcmd \__exsheets_start_question_if_used:n
{ \refstepcounter{question} }
{
\l__exsheets_questions_pre_counter_hook_tl
\refstepcounter{question}
}
{}{\fail}
\ExplSyntaxOff
\makeatletter
\def\default@counter{question}
% use \default@counter as counter #1
\newcommand\useCounter[1]{%
\setcounter{@\default@counter}{\value{\default@counter}}%
\setcounter{\default@counter}{\value{#1}}%
}
% restore \default@counter from counter #1
\newcommand\restoreCounter[1]{%
\setcounter{#1}{\value{\default@counter}}%
\setcounter{\default@counter}{\value{@\default@counter}}%
}
\makeatother
\newcounter{exercise}
\newcounter{@question}
\NewQuSolPair
{exercise}[
name=Exercies,
pre-counter-hook=\useCounter{exercise},
post-hook=\restoreCounter{exercise}]
{exsolution}[name=Solution to Exercise, print=true]
\RenewQuSolPair
{question}[name=Question]
{solution}[name=Solution to Question, print=true]
\begin{document}
\begin{question} q1 \end{question}
\begin{solution} q1 \end{solution}
\begin{exercise} ex1 \end{exercise}
\begin{question} q2 \end{question}
\begin{exercise} ex2 \end{exercise}
\begin{exsolution} ex2 \end{exsolution}
\end{document}