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

Thanks!

-
You should try adding \setcounter{tocdepth}{5} to your document preamble. I'm more-or-less referring to this entry in the UK TeX FAQ. – Werner Oct 3 '11 at 21:35
Yes, but that doesn't exclude levels 1 to 4... – Clément Oct 3 '11 at 21:46

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]{%
\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}

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.

\documentclass{article}

\makeatletter
\newcommand\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}

-
All right, Wow. – Clément Oct 4 '11 at 5:55
One small question : what does \l@ do? Also, is there a way to include a separator between exercises that doesn't get added to the end of the list too? – Clément Oct 4 '11 at 6:00
@Clément: 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. For the other question, the separator, see my updated answer. – Gonzalo Medina Oct 4 '11 at 17:00

\documentclass{book}

\usepackage{ntheorem}
\newtheorem{paralist}{Paragrahs}[chapter]

\let\oldparagraph\paragraph
\renewcommand*{\paragraph}[1]{%
\stepcounter{paralist}%
\oldparagraph{#1}
}

\begin{document}
\chapter*{List of Paragraphs}
\listtheorems{paralist}

\chapter{foo}
\paragraph{Bla1} Bla bla bla bla

\chapter{bar}
\paragraph{Bla2} Bla bla bla bla
\paragraph{Bla3} Bla bla bla bla
\paragraph{Bla4} Bla bla bla bla
\end{document}
-
Kind of a hack indeed ;-) – ℝaphink Oct 3 '11 at 21:53
Quite interesting =) But you loose the customization available through tocloft :/ – Clément Oct 3 '11 at 22:37

Here's a bizarre idea - How about switching LaTeX's interpretation of \section and \paragraph?! That way, you "upgrade" a paragraph to tocdepth level 1, while "downgrading" a section to tocdepth level 5. A little reconfiguring of the traditional formatting is necessary of all section-dependent counters (including section and subsection) though. The original definitions of \section and \paragraph were taken from the article document class:

\documentclass{article}
\usepackage{titletoc}% http://ctan.org/pkg/titletoc
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\makeatletter
\renewcommand\section{\@startsection {paragraph}{1}{\z@}% Sections are paragraphs
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}
\renewcommand\paragraph{\@startsection{section}{5}{\z@}% Paragraphs are sections
{3.25ex \@plus1ex \@minus.2ex}%
{-1em}%
{\normalfont\normalsize\bfseries}}
\makeatother
\renewcommand{\theparagraph}{\arabic{paragraph}}% Section numbering
\renewcommand{\thesubsection}{\theparagraph.\arabic{subsection}}% Subsection numbering

\begin{document}

\setcounter{tocdepth}{1}% Show only "sections"

\titlecontents*{section}[1.8pc]% "Section" formatting
{\small}
{\thecontentslabel. }
{}
{, \thecontentspage}
[---][.]

\tableofcontents

\section{Section 1}
\subsection{Subsection 1}

\paragraph{Bla1} \lipsum[1]
\paragraph{Bla2} \lipsum[2]
\paragraph{Bla3} \lipsum[3]
\paragraph{Bla4} \lipsum[4]
\paragraph{Bla5} \lipsum[5]
\paragraph{Bla6} \lipsum[6]

\end{document}

To obtain the required formatting, only tocdepth level 1 items are shown (the new paragraph) using \titlecontents* from the titletoc package.

The table of contents shows the paragraph name, following by a comma ,, the page number and a dash ---. The last entry ends with a period .. This can be modified by changing the paramaters of \titlecontents*.

-
Hmmm, that's nice too =) – Clément Oct 4 '11 at 7:38