# Automate the description of the paper

Most or all papers have a final paragraph in the introduction that describes the sections that are present. I'd like to generate it automatically, I guess this should be possible because it is mostly like an index, but in fact I have no idea about how this could be done (therefore I can't provide a mwe, I'm very sorry for this).

My guess is that it should be possible to add a description for each section, something like:

\section{Preliminaries}
\label{sec:preliminaries}
\description{we introduce the concepts that will be relevant along the paper}


What I would like is to insert at the end of the introduction something like this:

\descriptions{}


Which should expand to:

The structure of the paper is as follows: In Section 2 we introduce the concepts that will be relevant along the paper. In Section 3 we...

This is pretty much like the table of contents (TOC) that you would find in any book, this is prose and not a table and there is one additional field, but in short it's the same. Seems feasible.

Pointers to what should I check are also welcome, I really have no idea. I don't know how those TOCs are generated either.

PD: I'd prefer not to destroy the possibility of having a regular TOC additionally to this, i.e. I'd prefer not to modify the commands for the TOC (but maybe duplicate some of them).

PD: I found this package, but I get an error (\l@paragraph undefined) http://texblog.org/2008/07/13/define-your-own-list-of/

-
I'm a fan of automation, I can't help it, this may be taking it a bit too far. Maybe I'm an addict. This still looks cool to me. –  Trylks May 29 '14 at 14:47
@egreg 's answer to tex.stackexchange.com/questions/60738/… may help you here –  Ethan Bolker May 29 '14 at 15:01
thank you, this is fine, but it relies on commands for the toc that are still magic to me –  Trylks May 29 '14 at 15:10
So I've been using the solution I linked for a while. Beyond 5 sections or so I get an error, solved with \usepackage{morewrites}, but beyond 7 sections I get a similar error ("no room for a new \read"). I also added a counter, which may interfere (showing how fragile and crappy LaTeX is in fact...). I'll try to find a solution, I simply wanted to add this comment here now because I may very well not find any. –  Trylks Sep 8 '14 at 14:41
OMG!!!! I can't believe it was so easy! (after knowing the commands) The commands that are needed are \AtBeginDocument and \AtEndDocument. I've updated the gist accordingly. I'll try to have a MWE soon... –  Trylks Sep 8 '14 at 15:56

Just initialize the production of this “table of contents” and add a command \l@desc that will be used for printing the entries gathered in the previous run. Of course, two runs are necessary for synchronizing.

\documentclass{article}

\makeatletter
\newcommand{\sectiondescriptions}{%
\par
The structure of the paper is as follows.
\par
\@starttoc{dsc}%
}
\newcommand{\sectiondescription}[1]{%
}
\newcommand{\l@desc}[2]{#1\par}
\makeatother

\begin{document}

\section{Introduction}

We say something about the paper.

\sectiondescriptions

\section{Preliminaries}\label{sec:preliminaries}
\sectiondescription{we introduce the concepts that will be relevant along the
paper.}

\section{Conclusion}
\label{sec:conclusion}
\sectiondescription{we are done.}

\end{document}


-
I like your solution better than mine. The OP seems to want each section description in its section as well as at the beginning - easy to add that #1. –  Ethan Bolker May 29 '14 at 23:58
I'm not particularly concerned with content-replication but more with an intelligent behaviour of some parts of the paper wrt to others. E.g. switching the order of two sections, which could now be as simple as switching two lines with \input{sectionfile}. –  Trylks May 30 '14 at 13:32
I like this solution because it relies on commands that are already defined (and tested, and higher-level) but these commands make the text in the description clickable and that is puzzling (potentially annoying) to people reading the paper. Do you know if there is any way to avoid this? –  Trylks May 30 '14 at 13:33
BTW: I have made some (really small) changes to this solution and put the code here: gist.github.com/trylks/6bbbdaff10b5dd35d676 in toclike.tex I should produce a mwe at some point. –  Trylks May 30 '14 at 13:36

Compiling this twice does what you ask for. It's a little fragile.

Edited to use @Dan 's \InputIfFileExists but still prefer closing the file explicitly.

\documentclass{article}

\newcommand{\structure}{\InputIfFileExists{structure}{}}

\newcommand{\beginstructure}[1]{%
\newwrite\delayedtext
\immediate\openout\delayedtext=structure.tex
\immediate\write\delayedtext{#1}
}

\immediate\write\delayedtext{%
In Section \arabic{section} #1}
In this section #1
}

\newcommand{\myendstructure}{%
\immediate\closeout\delayedtext
}

\begin{document}
\structure

\beginstructure{The structure of the paper is as follows.}

\section{Preliminaries}
\label{sec:preliminaries}
\addtostructure{we introduce the concepts that will be relevant along the
paper.}

\section{Conclusion}
\label{sec:conclusion}

\myendstructure
\end{document}


Edit: If you don't like the tex extension on the auxiliary file you can give it any extension you like, and name it with the tex source filename - for example

\immediate\openout\delayedtext=\jobname.struct
...
\newcommand{\structure}{\InputIfFileExists{\jobname.struct}{}}

-
Probably \InputIfFileExists would be better than a plain \input, so that structure.tex wouldn't have to exist already. Also, one can close the file automatically by putting the commands to do so in \AtEndDocument{}. However, latex should automatically close all open files when it terminates. –  Dan May 29 '14 at 18:04
What I like less from this solution is that the contents of this "special toc" are stored in a tex file, which is confusing visually (wrt icons) when exploring the folder, copy-pasting relevant files (*.tex), etc. therefore inspired by this solution I have made some modifications. They are in fileread.tex: gist.github.com/trylks/6bbbdaff10b5dd35d676 I'll produce a mwe at some point. –  Trylks May 30 '14 at 13:35