从环境中自动输入目录

从环境中自动输入目录

我创建了一个环境,用于在我的文本中创建示例。该类是出版商 Wiley 指定的类,基本上是一本书。

环境当前将示例的名称作为参数,并在文本中显示,例如“示例部分.forinstancecounter‘第一个参数中的文本’”,然后将以下文本的格式与周围文本略有不同以进行设置。我希望“示例部分.forinstancecounter‘第一个参数中的文本’”自动出现在目录中。

换句话说,我希望我的环境能够与我的示例同一级别的其他部分得到同样的对待(subsection)。

这是一件很难的事吗?

环境:

\newcounter{forinstancecounter}[chapter]
\renewcommand{\theforinstancecounter}{\thechapter.\arabic{forinstancecounter}}
\newenvironment{forinstance}[1]{
\begin{quote}
  \refstepcounter{forinstancecounter}
  \textbf{Example \arabic{chapter}.\arabic{forinstancecounter}\quad #1}
  \quad
}{
\end{quote}
}

谢谢你,Bull

答案1

不确定是否需要这个:‘例如’列表?

\documentclass{book}

\usepackage{tocloft}
\newcommand{\listofforinstancename}{List of Examples}
\newlistof[chapter]{forinstancecounter}{exa}{\listofforinstancename}

%\newcounter{forinstancecounter}[chapter]
\renewcommand{\theforinstancecounter}{\thechapter.\arabic{forinstancecounter}}
\newenvironment{forinstance}[1]{
\begin{quote}
  \refstepcounter{forinstancecounter}
  \textbf{Example \arabic{chapter}.\arabic{forinstancecounter}\quad #1}
  \addcontentsline{exa}{chapter}{\protect\numberline{\theforinstancecounter~}#1}
  \quad
}{
\end{quote}
}

\begin{document}
\listofforinstancecounter
\chapter{My first chapter}
\begin{forinstance}{A title}
Hello World
\end{forinstance}
\end{document}

相关内容