Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Similar to the backref package that enables back-referencing for bibliographic items in a LaTeX document, I want to use back-references in my list of figures. Is there a clean way to accomplish this?

EDIT: I want to add text behind the caption in the LoF, on what pages a given figure is referenced.

For example:

2.3 Visualisation of the manufacturing process (referenced on page 3,4 and 8) ......... 3

share|improve this question
    
The LoF and LoT are usually furnished with links when using the hyperref package. So this is probably what you are looking for. –  Thorsten Donig Feb 23 '12 at 8:34
    
@Thorsten: That is true. A link is already established and when clicked, the view jumps to the corresponding page. I want to insert text behind the caption, though. –  Eric Feb 23 '12 at 9:12
add comment

1 Answer 1

up vote 5 down vote accepted

This is just a proof of concept, it do not check for duplicate references on the same page or for two or more ref, etc. It still need a lot of refinement and protection against active chars, make it work with hyperref, etc.

To use it, put the command \makefigreflist in your preamble and use the custom \figcaption[shortcap]{longcap}{label} and \figref{label} commands. It must be latexed twice.

EDIT 1: Write info direct to output file and made it a little bit more safe

\documentclass{article}
\makeatletter

\newcommand*\figreflistout[1]{}

\newcommand*\makefigreflist{%
    \begingroup
        \makeatletter
        \@input{\jobname.frl}%
        \newwrite\frl@outfile
        \immediate\openout\frl@outfile=\jobname.frl\relax
    \endgroup
    \let\makefigreflist\@empty
    \renewcommand*\figreflistout{%
        \@bsphack
        \begingroup
            \@sanitize
            \@figreflistout}%
    }

\newcommand*\@figreflistout[1]{%
        \protected@write\frl@outfile{}%
            {\string\addtofigreflist{#1}{\thepage}}%
    \endgroup
    \@esphack}

\newcommand*\addtofigreflist[2]{%
    \@ifundefined{frl@#1}%
        {\expandafter\protected@xdef\csname frl@#1\endcsname{#2}}%
        {\expandafter\protected@xdef\csname frl@#1\endcsname{\csname frl@#1\endcsname, #2}}}

\newcommand*\printfigreflist[1]{%
    \@ifundefined{frl@#1}%
        {\ (not referenced)}%
        {\ (referenced on page~\@nameuse{frl@#1})}}

\newcommand\defaultcapt{}

\newcommand\figcaption[3][\defaultcapt]{%
    \renewcommand\defaultcapt{#2}%
    \caption[#1\protect\printfigreflist{#3}]{#2}%
    \label{#3}}

\newcommand\figref[1]{%
    \ref{#1}\figreflistout{#1}}

\makeatother

\makefigreflist

\begin{document}
\listoffigures

\begin{figure}
    \figcaption{First figure}{fig:01}
    \figcaption{Second figure}{fig:02}
    \figcaption{Third figure}{fig:03}
\end{figure}

\bigskip

In figure \figref{fig:01} and \figref{fig:02} it is..
\clearpage
In figure \figref{fig:01}
\clearpage
In figure \figref{fig:01} and \figref{fig:02} it is..

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.