我的讲义里有一些练习,我想在讲义的末尾得到这些练习的解决方案。
为此,我endnotes
按以下方式使用包:
\documentclass{article}
\usepackage{endnotes}
\newcounter{cptdef}[section]
\renewcommand{\thecptdef}{\thesection.\arabic{cptdef}}
\newenvironment{theorem}{\textbf{Theorem \thecptdef}.}{\par\medskip}
\newenvironment{exo}{\refstepcounter{cptdef}\noindent\textbf{Exercise \thecptdef. }}{\par\medskip}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{Solutions}
\def\thesoluces{\theendnotes}
\begin{document}
\section{Pyth agore}
\begin{theorem}$A^2+B^2 = C^2$\end{theorem}
\begin{exo}
Prove this theorem
\soluce{Use Pytha!}
\end{exo}
\begin{exo}
Prove Al-Kashi's theorem.
\soluce{Blabla}
\end{exo}
\section{Arithmetic}
\begin{exo}1+1 = ? \soluce{2} \end{exo}
\thesoluces
\end{document}
除了答案的编号之外,它工作得很好。以下是渲染:
1. Pythagore
Theorem 1.1: A²+B²=C²
Exercise 1.2: Prove it
Exercise 1.3: Prove Al-Kashi
2. Arithmetic
Exercise 2.1: 1+1 = ?
Solutions
Exercise 2.1: Use Pytha
Exercise 2.1: Blabla
Exercise 2.1: 2
事实是,在 中endnotes
写入,并且当我调用 时会解析此文件,因此计数器没有在正确的时间“评估”。Exercise \thecptdef.
handout.ent
\thesoluces
是否可以“强制”\thecptdef
进行以下评估:
\def\soluce#1{%
\endnotetext{\small\textbf{Exercice \thecptdef. } #1 \medskip}
}
这样,handout.ent
将包含“练习 1.2”,“练习 1.3”......
答案1
\def\soluce#1{%
\edef\tmp{%
\noexpand\endnotetext{\noexpand\small\noexpand\textbf
{Exercise \thecptdef. } #1\noexpand\par\noexpand\medskip}}\tmp
}
强制在调用\thecptdef.
之前扩展。我还添加了一个,以确保文本的行距正确,并确保最终以垂直模式执行。\endnotetext
\par
\small
\vspace
\documentclass{article}
\usepackage{endnotes}
\newcounter{cptdef}[section]
\renewcommand{\thecptdef}{\thesection.\arabic{cptdef}}
\newenvironment{theorem}{\textbf{Theorem \thecptdef}.}{\par\medskip}
\newenvironment{exo}{\refstepcounter{cptdef}\noindent\textbf
{Exercise \thecptdef. }}{\par\medskip}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{Solutions}
\def\thesoluces{\theendnotes}
\def\soluce#1{%
\edef\tmp{%
\noexpand\endnotetext{\noexpand\small\noexpand\textbf
{Exercise \thecptdef. } #1\noexpand\par\noexpand\medskip}}\tmp
}
\begin{document}
\section{Pyth agore}
\begin{theorem}$A^2+B^2 = C^2$\end{theorem}
\begin{exo}
Prove this theorem
\soluce{Use Pytha!}
\end{exo}
\begin{exo}
Prove Al-Kashi's theorem.
\soluce{Blabla}
\end{exo}
\section{Arithmetic}
\begin{exo}1+1 = ? \soluce{2} \end{exo}
\thesoluces
\end{document}