[Tex/LaTex] Include only paragraph titles in the table of contents

sectioningsections-paragraphstable of contents

My Latex document has a large number of paragraphs (about 10 per page), and I'd like to build a list of the titles of all these paragraphs.

For example, given the following document:

\paragraph{Bla1} Bla bla bla bla
\paragraph{Bla2} Bla bla bla bla
\paragraph{Bla3} Bla bla bla bla
\paragraph{Bla4} Bla bla bla bla

the output would look like

Bla1 — Bla2 — Bla3 — Bla4

Ideas? I tried customizing the table of contents, but I can't exclude sections and subsections…

Thanks!

Best Answer

The following code shows one possibility which can be modified according to the document class used and to specific needs:

\documentclass{article}

\makeatletter
\newcommand\Paragraph[1]{%
  \addcontentsline{prg}{Paragraph}{#1}%
  \paragraph{#1}}
\newcommand\l@Paragraph[2]{#1,~\textit{#2}}
\newcommand\listParagraphname{List of Paragraphs}
\newcommand\listofParagraphs{%
  \section*{\listParagraphname}\@starttoc{prg}}
\makeatother

\begin{document}

\section{Test section}
\subsection{Test subsection}
\subsubsection{Test subsubsection}
\listofParagraphs
\Paragraph{Test paragraph one}
\Paragraph{Test paragraph two}
\Paragraph{Test paragraph three}
\Paragraph{Test paragraph four}
\Paragraph{Test paragraph five}

\end{document}

enter image description here

The main points are

  1. To use a newly defined command \Paragraph with one mandatory argument; \Paragraph writes its argument and the current page number (if you don't need the page number, simply remove ,~\textit{#2} in the code below) to a new contents file with extension .prg; it also uses the argument as the mandatory argument of the standard \paragraph command to actually typeset the paragraph ion the document.

  2. To use another newly defined command \listofParagraphs to read the information written on the contents file .prg and to typeset it at the point where the command is invoked (this is done through \@starttoc{prg}). \listofParagraphs also uses \section* to produce a title which can be controlled by \listParagraphname.

  3. The command \l@Paragraph actually typesets the entries in the new table of contents. The first argument is the title, and the second one is the page number.

To add a separator between the entries, you can use \addtocontents:

\documentclass{article}

\makeatletter
\newcommand\Paragraph[1]{%
  \addcontentsline{prg}{Paragraph}{#1}%
  \paragraph{#1}}
\newcommand\l@Paragraph[2]{#1,~\textit{#2}}
\newcommand\listParagraphname{List of Paragraphs}
\newcommand\listofParagraphs{%
  \section*{\listParagraphname}\@starttoc{prg}}
\makeatother
\newcommand\AddSep{\addtocontents{prg}{--}}

\begin{document}

\section{Test section}
\subsection{Test subsection}
\subsubsection{Test subsubsection}
\listofParagraphs
\Paragraph{Test paragraph one}
\AddSep
\Paragraph{Test paragraph two}
\AddSep
\Paragraph{Test paragraph three}
\AddSep
\Paragraph{Test paragraph four}
\AddSep
\Paragraph{Test paragraph five}

\end{document}

enter image description here