我正在编写仅包含练习的文档,并且想为一些练习添加一些提示。
我想要的是提示在练习本身中指定但显示在文档末尾。
我尝试使用\atEndDocument
钩子但是没有作用。
以下是我想写的一个简短示例
\documentclass[14pt,a4paper]{extarticle}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper,landscape,border shrink=7mm]
\begin{document}
Exercise 1 :
Solve the following equation $x^2+1=2$
\hint{Exercise 1 : Don't forget that two solutions exist}
Exercise 2 :
Derivate the following function $f:x \to \cos(x^2)$
\hint{Exercise 2 : The result is not $-\sin(x^2)$ }
\end{document}
答案1
只是为了好玩:此解决方案将提示保存为宏以供以后扩展。
\documentclass{article}
\newcounter{nhint}
\newcommand{\hint}[1]% #1 = paragraph
{\stepcounter{nhint}\expandafter\gdef\csname hint\thenhint\endcsname{#1}}% global, just in case
\begin{document}
Exercise 1 :
Solve the following equation $x^2+1=2$
\hint{Exercise 1 : Don't forget that two solutions exists}%
Exercise 2 :
Derivate the following function $f:x \to \cos(x^2)$
\hint{Exercise 2 : The result is not simply $-\sin(x^2)$ }%
{\section{Hints}}% turn off \@afterheading
\edef\total{\arabic{nhint}}% or \countdef\total 0 \total=\value{nhint}%
\setcounter{nhint}{0}%
\loop\ifnum \value{nhint}<\total
\stepcounter{nhint}%
\csname hint\thenhint\endcsname
\par
\repeat
\end{document}
该解决方案将提示存储在保存箱中。
\documentclass{article}
\newsavebox{\hints}
\setbox\hints=\vbox{}
\newcommand{\hint}[1]% #1 = paragraph
{\global\setbox\hints=\vbox{\unvbox\hints
\parindent=0pt% set up formatting here
\strut#1\strut\par}%
}
\begin{document}
Exercise 1 :
Solve the following equation $x^2+1=2$
\hint{Exercise 1 : Don't forget that two solutions exists}
Exercise 2 :
Derivate the following function $f:x \to \cos(x^2)$
\hint{Exercise 2 : The result is not simply $-\sin(x^2)$ }
\section{Hints}
\unvbox\hints
\end{document}
答案2
使用宏的简单工作示例\AtEndDocument
:
\documentclass{article}
\AtEndDocument{\vfill}
\newcommand{\hint}[1]{\AtEndDocument{\par #1}}
\begin{document}
Exercise 1 :
Solve the following equation $x^2+1=2$
\hint{Exercise 1 : Don't forget that two solutions exists}
Exercise 2 :
Derivate the following function $f:x \to \cos(x^2)$
\hint{Exercise 2 : The result is not simply $-\sin(x^2)$ }
\end{document}