提问于:
浏览数:
2932
用exsheets宏包实现例1,练习1,例2,练习2,例3,练习3 的效果,谢谢!
例题与练习使用 question 环境时,虽然 name 不同,但计数器依然读数,知道如何处理。
https://paste.ubuntu.com/p/7Hb5smQSCS/
2 回答
2
**提醒**
exsheets 宏包作者[回复](https://tex.stackexchange.com/questions/249605/exsheets-counters-for-new-question-pairs/528436?noredirect=1#comment1336434_528436):
> `exsheets` is not developed any more. But its successor package `xsim` supports it from the beginning in early 2017.
1. `exsheets` 宏包尚不支持多个计数器功能。
1. 使用 `pre-hook` 和 `post-hook` 可以模拟多个计数器的功能。
1. 如果不需要用到分值等功能,可以用 `xsim` 宏包,它是支持的。
尝试一:使用 `pre-hook` 和 `post-hook` 模拟多个计数器:
```tex
\documentclass{ctexart}
\usepackage{exsheets}
\newcounter{exercise}
\newcounter{temp}
% set counter #1 to #2
\newcommand\replaceCounter[2]{%
\setcounter{temp}{\value{#1}}%
\setcounter{#1}{\value{#2}}%
}
% restore counter #1 to #2, and from temp,
\newcommand\restoreCounter[2]{%
\setcounter{#2}{\value{#1}}%
\setcounter{#1}{\value{temp}}%
}
\NewQuSolPair
{exercise}[name=练习, post-hook=\restoreCounter{question}{exercise}]
{exsolution}[name=解答~练习, print=true]
\RenewQuSolPair
{question}[name=例, post-hook=\replaceCounter{question}{exercise}]
{solution}[name=解答~例, 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}
```
尝试二:`pre-hook` 的位置不够前,为此增加选项 `pre-counter-hook`
```tex
\documentclass{ctexart}
\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 value of \default@counter
\newcommand\restoreCounter[1]{%
\setcounter{#1}{\value{\default@counter}}%
\setcounter{\default@counter}{\value{@\default@counter}}%
}
\makeatother
\newcounter{exercise}
\newcounter{@question}
\NewQuSolPair
{exercise}[
name=练习,
pre-counter-hook=\useCounter{exercise},
post-hook=\restoreCounter{exercise}]
{exsolution}[name=解答~练习, print=true]
\RenewQuSolPair
{question}[name=例]
{solution}[name=解答~例, print=true]
\begin{document}
同上,略
\end{document}
```
![](https://pics.latexstudio.net/data/images/202002/2a5b90e177e345f.png)
-
回复 undefined :多谢了,正在看xsim宏包 – 天津mike 2020-02-15 15:19 回复
-
回复 undefined :根据 exsheets 宏包作者的回复(https://tex.stackexchange.com/questions/249605/exsheets-counters-f – 论坛 github.com/CTeX 2020-02-15 14:21 回复
-
回复 undefined :更新了回答 – 论坛 github.com/CTeX 2020-02-14 22:07 回复
-
厉害!多谢啦! – 天津mike 2020-02-14 18:30 回复
-
非常感谢! – 天津mike 2020-02-14 18:30 回复
-
这个对! – latexstudio 2020-02-14 18:30 回复
1
找到对应的计数器,关联关系重置下
类似:
```tex
\usepackage{chngcntr}
\counterwithout{equation}{section}
\counterwithin{equation}{chapter}
```
你的回答
请登录后回答
你的回答将会帮助更多人,请务必认真回答问题。