# Extended figure caption and accompanying “List of”

I want to write an extended figure caption section, and wondered if I could get LaTeX to do most of the hard work for me.

Ideally, it would take the form of a function, let say \extcaption, that we could use within a float, like

\begin{figure}
\includegraphics{example-image-a.pdf}
\caption{Important things.}
\extcaption{Less important things.}
\label{fig:bigA}
\end{figure}


and that we could print with

\printextcaptions


and that would return

Figure 1.1, page 2: Less important things.

Anyway to do it? Here is a MWE:

\documentclass[a4paper,10pt]{report}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage[titles]{tocloft}

\begin{document}
\chapter{A chapter}

\section{A section}

\begin{figure}
\includegraphics{example-image-a.pdf}
\caption{Picture of a big A}
%\extcaption{This picture is magnificent}
\label{fig:bigA}
\end{figure}

\begin{figure}
\includegraphics{example-image-b.pdf}
\caption[This picture is horrible]{Picture of a big B}
%\extcaption{This picture is horrible.}
\label{fig:bigB}
\end{figure}

%\printextcaptions

\end{document}


The best result I got was by setting a new list with the tocloft package

\newlistof[section]{extfig}{efc}{Extended figure captions}
\newcommand{\extcaption}[1]{%
\refstepcounter{extfig}
\par\noindent\textbf{\theextfig #1}
\renewcommand{\theextfig}{}


But this prints a new chapter while I want nothing, it does not print the extended caption in the format the way I want, and does not read the label of the figure (or table) float, so I would have to set everything manually.

• You can always write \thefigure instead of \theextfig to the file. – cfr Nov 22 '15 at 3:49
• Where can I find locloft? – cfr Nov 22 '15 at 3:52
• @cfr tocloft ? It can be obtained from ctan: ctan.org/pkg/tocloft – HcN Nov 22 '15 at 3:58
• Oh, a typo. OK. \makeatletter \newwrite\@efcwrite \immediate\openout\@efcwrite\jobname.efc \newcommand\extcaption[1]{% \par\noindent\textbf{#1}% \protected@write\@efcwrite{}{\figurename{} \thefigure: #1\par}} \makeatother  Unfortunately, I don't know how to read it - only write it. – cfr Nov 22 '15 at 4:30
• That is, I have only figured out how to write the things. I can't read them back. Sadly. – cfr Nov 22 '15 at 4:38

The following writes out ToC-like entries to a new .efc file and reads it in using \printextcaptions:

\documentclass{report}
\usepackage{graphicx,lipsum}

\newcommand{\extcaption}[1]{% Write to .efc file
\makeatletter
\newcommand{\l@extfig}[2]{\noindent #1\par}% How each .efc entry is handled
\makeatother

\begin{document}

\sloppy% Just for this example

\chapter{A chapter}

\section{A section}

\printextcaptions

\lipsum[1-50]

\begin{figure}[ht]
\includegraphics{example-image-a}
\caption{Picture of a big A}
\extcaption{This picture is magnificent}
\end{figure}

\lipsum[1-50]\lipsum[1-50]

\begin{figure}[ht]
\includegraphics{example-image-b}
\caption[This picture is horrible]{Picture of a big B}
\extcaption{This picture is horrible}
\end{figure}

\end{document}

• Works perfectly, thanks ! Is there a way to write multiple-paragraphs in the extended caption ? – HcN Nov 22 '15 at 13:43
• @HcN: The command \addcontentsline is defined using a \def, not \long\def, and therefore doesn't accept paragraphs. One can either copy the definition and define it as \long\def or \newcommand, or "hide" the paragraph breaks by using \protect\endgraf. No empty/blank line should be in your \extcaption argument, as these translate to an implicit \par, which is not allowed for \def-ed macros. – Werner Nov 22 '15 at 18:26
• It is certainly worth at least trying to define an alternative \addcontentsline, but I cannot locate where the function is. Would you know where it is ? The \protect\endgraf works fine. – HcN Nov 22 '15 at 19:33
• @HcN Look in latex.ltx. Probably. – cfr Nov 22 '15 at 22:43
• @cfr Found it, and made something that essentially works. I asked another question for the remaining dodgy bits in tex.stackexchange.com/questions/279516/… – HcN Nov 23 '15 at 0:30