4

In a report I have multiple chapters as separate tex files that I include by means of \input{chapter_title}. Furthermore I have a chapter 0 which deals as an introduction. The introduction shall contain a single paragraph for each chapter roughly describing what's written in the chapter. The order in which the chapters appear is not yet fixed and might change a couple of times. Since I'm a sort of lazy fellow I would like to have the short description paragraph in the actual chapter file and have the introduction chapter generate the order of the description paragraphs based on the order of the \input{chapter} calls.

Document class is scrreprt.

The description paragraphs of the chapters as they are defined in the chapter tex-files could look like this:

\<some_reference_to_current_chapter> describes...

or

In \<some_reference_to_current_chapter> ... will be explained. 

The references to the current chapter should be generated automatically so that the result is always in the order of the chapters and the chapter numbers in the description paragraphs as it is printed in the introduction chapter will always be consistent.

I assume this might possible by means of something similar to the table of contents, just not using the chapter headlines but the description paragraphs instead.

Is there an easy way to achieve this?

2 Answers2

1

A first version without hyperlinking, the tcolorbox is just an option and can be removed.

\documentclass{book}

\usepackage[most]{tcolorbox}
\usepackage{blindtext}

\makeatletter

\newcounter{chapterdesc}


\newcommand{\l@cd}[2]{%
  \begin{tcolorbox}[enhanced jigsaw, sharp corners, colback=white!60!yellow,colframe=red!80!black]
    In \cref{#1} we will see #2
  \end{tcolorbox}
}

\newcommand{\chapterdescription}[2]{%
  \addtocontents{cd}{\protect\contentsline{cd}{#1}{#2}}
}

\newcommand{\listofchapterdescriptions}{%
  \@starttoc{cd}
}

\makeatother


\usepackage{cleveref}


\begin{document}

\listofchapterdescriptions

\chapterdescription{foochapter}{This is the first 

chapter description}
\chapter{Foo}\label{foochapter}


\chapterdescription{somechapter}{\blindtext  

\blindtext}
\chapter{Third}\label{somechapter}

\chapterdescription{foobarchapter}{This is the second chapter description}
\chapter{Second}\label{foobarchapter}




\end{document}
1

You can use the tocloft package to create your own toc-like lists. Minimal example:

\documentclass[totocnumbered]{article}
\usepackage{lipsum}

\usepackage[titles]{tocloft}
\newlistof{intro}{intro}{Introductions}
\newcommand{\introduction}[1]{%
    \refstepcounter{intro}%
    \addtocontents{intro}{#1}%
    \addtocontents{intro}{}%
}

\begin{document}

\listofintro

\section{First}
\label{sec:first}
\introduction{Chapter \ref{sec:first} has the first two paragraphs of \emph{Lorem ipsum}. This is a very interesting start to this document.}
\lipsum[1-2]

\section{Second}
\label{sec:second}
\introduction{In Chapter \ref{sec:second}, we find the third and fourth paragraph.}
\lipsum[3-4]

\end{document}

enter image description here

I didn't find an easy way to have a \thischapter (or so) macro that you can use in the introductions, however using the \label and \ref pair for the chapters should be fair enough. Also, this gives you correct hyperlinks (in case you want them).

Edit 1: If you also load the package subfigure, you have to load tocloft with the option subfigure:

\usepackage[titles,subfigure]{tocloft}

Edit 2: If you want to have the introductions without the "Introductions" headline (note that you can adjust this label), you can redefine (after the call of \newlistof) the \listofintro macro like this (credits):

\makeatletter
\renewcommand\listofintro{%
    \@starttoc{intro}%
}
\makeatother

A side effect is that you furthermore don't insert a page break before.

Tiuri
  • 7,749
  • For some reason I'm getting the error message ! LaTeX Error: Command \c@lofdepth already defined.Or name \end... illegal, see p.192 of the manual.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \newcounter{lofdepth} when trying to run with \usepackage[titles]{tocloft} – Hendrik Wiese Jun 12 '17 at 13:16
  • Then there is probably a problem with one of your packages or your documentclass. What do you use? – Tiuri Jun 12 '17 at 13:19
  • The documentclass is scrreprt. The other packages are listed here, including the used options: https://pastebin.com/1fDqakQd

    I might not need all of them. The list of packages comes from a template that we use in our company.

    – Hendrik Wiese Jun 12 '17 at 13:26
  • I've figured it collides with package subfigure – Hendrik Wiese Jun 12 '17 at 13:33
  • I see! Just add subfigure as an option to tocloft. I'll also add that to the answer. – Tiuri Jun 12 '17 at 13:34
  • Yepp, this works. Thank you. Seems to be a known issue... known for almost a decade (see http://latex.org/forum/viewtopic.php?t=1747).

    One last thing: how do I insert the list without its own headline (which is "Introduction" in this case) and without a page break before the list?

    – Hendrik Wiese Jun 12 '17 at 13:37
  • @HendrikWiese: See my update to the answer. – Tiuri Jun 12 '17 at 13:53
  • Great! Works like a charm. Thank you very much. – Hendrik Wiese Jun 12 '17 at 14:03
  • @HendrikWiese: subfigure is an completely outdated package –  Jun 12 '17 at 14:20
  • @ChristianHupfer: yeah, and maybe even completely redundant in my case. Like I said, it's part of the template I've got from my colleague. I'll just remove the package. – Hendrik Wiese Jun 12 '17 at 14:22
  • @Tiuri Thanks for your help. I've got another question that you might be able to answer. I've been using your solution for quite a while now without any issues. Until I tried to also use the package glossaries in my document. Now I get the error message "No room for a new \write" where the \listofintro command is used. It is somehow related to \makeglossaries; without it everything keeps working aside from I don't get a glossary. – Hendrik Wiese Aug 15 '17 at 07:08
  • I don't have an answer to that at hand. Maybe you get more attention for this new issue by asking a new question. – Tiuri Aug 15 '17 at 07:29
  • Okay, thanks nevertheless. I've solved it already by switching to LuaLaTeX. The cause of the error seems to be that my document exceeds the maximum open file limit that pdfLaTeX has. LuaLaTeX apparently does not suffer from this issue. – Hendrik Wiese Aug 15 '17 at 08:31