1

In a previous question, I asked how could I get an automatically produced local TOC from an enumeration, with the TOC picking just the titles of the enumeration (this has been solved with the etoc package). Now I'd like to write some command in between items of my enumeration so that a separator (e.g. a blank line) appears between the corresponding entries of the local TOC.

Example:

\myitem{Fact 1} Explanation 1

\myitem{Fact 2} Explanation 2

\separatehere

\myitem{Fact 3} Explanation 3

\myitem{Fact 4} Explanation 4

should produce the TOC

Fact 1

Fact 2

[blank space here]

Fact 3

Fact 4

1

Here is one way to do it. The aim is to insert something in the .toc file which will get executed only for a specific local TOC.

etoc uses only the standard toc file for all local tocs)

There are various ways to do that, I use here a trick of defining an extra dummy sectioning level only seen by etoc.

\documentclass{article}

\usepackage{etoc}
\usepackage{hyperref}

\makeatletter
\etocsetlevel{myitem}{6}% dummy sectioning level
\etocsetlevel{myitemseparator}{6}% dummy thing will be used for
                                % injecting code in TOC executed
                                % ONLY when we want it executed

\newcommand\mylistofitems{%
  \begingroup
  \etocsetlevel{subsection}{6}% ignore real subsections  (level 2)
  \etocsetlevel{subsubsection}{6}% ignore subsubsections (level 3)
  \etocsetlevel{myitem}{2}% because this is used in \section (level 1)
  \etocsetlevel{myitemseparator}{3}% because this is used in \section (level 1)
%
  \etocsetnexttocdepth{myitemseparator}%
  \etocsettocstyle{}{}%
  % to avoid problem on first compilation (missing \item), we do not insert
  % the \begin{enumerate} in \etocsettocstyle arguments,
  % but directly here.
  % 
  % Note: one could have hoped that putting it in \etocsettocstyle
  % and issueing \etocchecksemptiness would have worked. But alas,
  % the etoc doc says: 
  %    For a finalized document compiled with initially no
  %    auxiliary files, the first LaTeX run will declare all local
  %    TOCs non empty and print for each of them a heading (and no
  %    contents naturally).
  % This is bad here, because empty enumerate environment
  % raises LaTeX error.
  \etocsetstyle{myitem}
    {\begin{enumerate}}
    {}
    {\item\textbf{\etocname}}
    {\end{enumerate}}%
  \etocsetstyle{myitemseparator}
    {}
    {\par\addvspace{\myextraspace}}
    {}
    {}%
  \subsection*{Linked list of definitions}
    \localtableofcontents
  \hrule
  \endgroup
}

\makeatother

\newcommand\myitem[1]{\item\textbf{#1:}\etoctoccontentsline{myitem}{#1}}

\newlength\myextraspace
\setlength\myextraspace{12pt}

\newcommand\separatehere{\etoctoccontentsline{myitemseparator}{}}

\begin{document}

\tableofcontents

\section{SECTION 1}

\mylistofitems

\begin{enumerate}
% don't use colons at end of item titles here
\myitem{Linear cones} Let $F$ be an ordered field and $V$ an $F$-vector space. A \emph{linear cone} $C$ is a subset of $V$ closed under positive scalar products. 

\myitem{Partial order defined by a convex cone} If $C$ is a pointed salient convex cone, then the relation $x\leq y$ iff $y-x\in C$ is a partial order.

\separatehere

\myitem{Dual cone} Let $S$ be any subset of a vector space $V$ over an ordered field. The \emph{dual cone} $S^*$ of $S$ is the convex cone
$$S^*:=\{v\in V \ | \ \langle v,x\rangle\geq0 \ \forall x\in S\}.$$
\end{enumerate}

\end{document}

Gives

enter image description here

It is perfectly feasible to let \separatehere accept some (optional, perhaps) argument, which would indicate a custom level of separation in the TOC at the end.

Two compilations as usual with TOCs

Note that the code is for list of items at top level beneath sections. If you need them beneath subsections you need to adapt a little the code.


Variant working with amsart

\documentclass{amsart}

\usepackage{etoc}
% avoid clash with amsart
% https://tex.stackexchange.com/questions/423110/can-one-use-etoc-with-amsart
\etocsettocstyle{\noindent\textbf{\contentsname}\par}{}

\usepackage{hyperref}

\makeatletter
\etocsetlevel{myitem}{6}% dummy sectioning level
\etocsetlevel{myitemseparator}{6}% dummy thing will be used for
                                % injecting code in TOC executed
                                % ONLY when we want it executed

\newcommand\mylistofitems{%
  \begingroup
  \etocsetlevel{subsection}{6}% ignore real subsections  (level 2)
  \etocsetlevel{subsubsection}{6}% ignore subsubsections (level 3)
  \etocsetlevel{myitem}{2}% because this is used in \section (level 1)
  \etocsetlevel{myitemseparator}{3}% because this is used in \section (level 1)
%
  \etocsetnexttocdepth{myitemseparator}%
  \etocsettocstyle{}{}%
  % to avoid problem on first compilation (missing \item), we do not insert
  % the \begin{enumerate} in \etocsettocstyle arguments,
  % but directly here.
  % 
  % Note: one could have hoped that putting it in \etocsettocstyle
  % and issueing \etocchecksemptiness would have worked. But alas,
  % the etoc doc says: 
  %    For a finalized document compiled with initially no
  %    auxiliary files, the first LaTeX run will declare all local
  %    TOCs non empty and print for each of them a heading (and no
  %    contents naturally).
  % This is bad here, because empty enumerate environment
  % raises LaTeX error.
  \etocsetstyle{myitem}
    {\begin{enumerate}}
    {}
    {\item\textbf{\etocname}}
    {\end{enumerate}}%
  \etocsetstyle{myitemseparator}
    {}
    {\par\addvspace{\myextraspace}}
    {}
    {}%
  \noindent\textbf{Linked list of definitions}\par
    \localtableofcontents
  \hrule
  \endgroup
}

\makeatother

\newcommand\myitem[1]{\item\textbf{#1:}\etoctoccontentsline{myitem}{#1}}

\newlength\myextraspace
\setlength\myextraspace{12pt}

\newcommand\separatehere{\etoctoccontentsline{myitemseparator}{}}

\begin{document}

\tableofcontents

\section{SECTION 1}

\mylistofitems

\begin{enumerate}
% don't use colons at end of item titles here
\myitem{Linear cones} Let $F$ be an ordered field and $V$ an $F$-vector space. A \emph{linear cone} $C$ is a subset of $V$ closed under positive scalar products. 

\myitem{Partial order defined by a convex cone} If $C$ is a pointed salient convex cone, then the relation $x\leq y$ iff $y-x\in C$ is a partial order.

\separatehere

\myitem{Dual cone} Let $S$ be any subset of a vector space $V$ over an ordered field. The \emph{dual cone} $S^*$ of $S$ is the convex cone
$$S^*:=\{v\in V \ | \ \langle v,x\rangle\geq0 \ \forall x\in S\}.$$
\end{enumerate}

\end{document}

(see Can one use etoc with amsart?)

enter image description here

The layout needs some fine-tuning (add space after horizontal rule etc..)

In particular it would be nice here to add some code to avoid a pagebreak right after "List of definitions". (we don't use \subsection anymore in amsart case). Possibly some \nopagebreak[4].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.