9

I have asked a similar question which sought to create a list of figures sources but with this one I want to attempt to do something slightly different, in that instead of a single entry per image there would be a single entry for multiple images from one source.

I have tried modifying one of the answers from this question to get the desired results but as an amateur I don't really know macros.

First up here is a sample picture of the desired results. enter image description here

This is my (copied/adapted from this answer) attempt at a MWE so far.

\documentclass[oneside]{memoir}
\usepackage{lstdoc}
\makeatletter
\def\tags{Physics,Computer Science,Chemistry,}
%% sorts the tags for later on
\def\tags@sorted{\lst@BubbleSort\tags}
\tags@sorted
%% we automatically create macros for each tag
 \def\macrofy@#1\@nil{%
      \expandafter\def\csname#1\endcsname{}
  }
\def\addtags#1{\g@addto@macro\tags{#1,}
   \tags@sorted
   \macrofy@@
}
%% Make macros to hold the lists for each tag
%% 
\def\macrofy@@{\@for\next:=\tags\do{%
    \expandafter\macrofy@\next\@nil
}}
\macrofy@@

\def\addtotag#1\@nil#2{%
   \expandafter\ifx\csname#2\endcsname\@empty
        \expandafter\g@addto@macro\csname#2\endcsname{#1}
    \else
        \expandafter\g@addto@macro\csname#2\endcsname{,#1}
    \fi
}
\def\tag#1{%
   \expandafter\addtotag\the\c@figure\@nil{#1}
}
\def\thetags{%
%% we now print the tags or save them to a file
  \section*{Image Sources}  
  \@for\next:=\tags\do{%
     \ifx\next\@empty\else\next: See figure(s) \@nameuse{\next}\par\fi
  }
}
\parindent0pt
\begin{document}
% add some tags
   \addtags{NANZ,NPG,Wiki}
% test to see everything ok and list is sorted   
   \tags
% list of figures   
   \listoffigures
% example text   
\chapter{foo}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption[A figure]{A longer image description}
\tag{NPG}
\end{figure}

\chapter{bar}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption[Another figure]{Another longer image description}
\tag{Wiki}
\end{figure}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption[Again Another figure]{Again Another longer image description}
\tag{NANZ}
\end{figure}

\chapter*{Images Credits}
%% prints the tags with the sections
\thetags
\end{document}

So first problem is that current code does not link to figure numbers in \thetags listing. Secondly I would like to be able to define the tags in short form and long form. In that I mean something like \tag{NPG}{National Portrait Gallery} so that I could tag the figures NPG but the listing would show National Portrait Gallery. Also I have used tags because I thought that was an easy way of doing this and had a example to work off but if there is an easier or better way to do it please share.

5
  • The picture looks like an index but with figure numbers instead of page numbers
    – cgnieder
    Sep 12, 2015 at 11:06
  • @clemens Yes, idea is to have page in the appendices where sources of images can be seen so is linked to the image number instead of the page number. This source would not be contained in the caption of the figure. There will also be a list of figures in the frontmatter listing images to there page no.
    – gman
    Sep 12, 2015 at 11:20
  • this is neither automatic nor particularly satisfying, but could be used as a fall-back. since the figure numbers are cited, if you compile the list of sources manually, you could simply use \ref for the numbers; you'll probably be assigning each figure a label anyway. using tags, unless you're very careful and clever with tag assignments, you might have problems getting the names of the sources into the correct alphabetical order. considering the "2-level" (or even more complicated) sources, this looks rather like an indexing task. Sep 12, 2015 at 12:41
  • If you want some thing like clemens's idea: index with description source, clickable figure number I have an idea.
    – touhami
    Sep 12, 2015 at 17:32
  • @touhami sure, any idea that works will be appreciated.
    – gman
    Sep 12, 2015 at 17:49

1 Answer 1

4

Here is my idea

First we define commands that write to special index file speindexfile.ids

Note: after pdflatex run makeindex speindexfile.ids and then 2* pdflatex

\newwrite\speidx
\immediate\openout\speidx=speindexfile.ids
\def\speindex{%
\@bsphack\begingroup
\@sanitize\spewrindex}
\newcommand{\spewrindex}[2]{%
   \protected@write\speidx{}%
      {\string\indexentry{#2|hidepage}{\thepage}}%
 \endgroup
 \@esphack}

Then newcommand \spelabel that work as label and write the new special index.

Note: so for you figures you don't need label use \spelabel instead.

\newcommand{\spelabel}[2]{%
\label{#1}%
\@ifundefined{mtidx#2}{%
\global\@namedef{mtidx#2}{\ref{#1}}}{%
\expandafter\g@addto@macro\csname mtidx#2\endcsname{, \ref{#1}}}
\speindex{#1}{#2}}

newcommand \printspeindex

\newcommand{\printspeindex}{%
\IfFileExists{speindexfile.ind}{%
\input{speindexfile.ind}}{}}

newcommand \newcommand{\hidepage}[1]{} to remove the page number from the special index

Last we redefine index item to print the figure number

Note: figure number was saved in a macro by \spelabel command

\let\mtindex\theindex
\renewcommand{\theindex}{%
\mtindex%
\gdef\item##1,{%
\par\hangindent 40pt ##1:\csname mtidx##1\endcsname}}

MWE

\documentclass[oneside]{memoir}
\usepackage{graphicx}

\usepackage{makeidx}
\makeindex
\usepackage{hyperref}

\makeatletter
\newwrite\speidx
\immediate\openout\speidx=speindexfile.ids
\def\speindex{%
\@bsphack\begingroup
\@sanitize\spewrindex}
\newcommand{\spewrindex}[2]{%
   \protected@write\speidx{}%
      {\string\indexentry{#2|hidepage}{\thepage}}%
 \endgroup
 \@esphack}
\newcommand{\spelabel}[2]{%
\label{#1}%
\@ifundefined{mtidx#2}{%
\global\@namedef{mtidx#2}{\ref{#1}}}{%
\expandafter\g@addto@macro\csname mtidx#2\endcsname{, \ref{#1}}}
\speindex{#1}{#2}}
\newcommand{\printspeindex}{%
\IfFileExists{speindexfile.ind}{%
\input{speindexfile.ind}}{}}
\newcommand{\hidepage}[1]{}

\makeatother
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

\begin{figure}
\centering
\includegraphics[scale=.5]{example-image}
\caption{ipsum}
\spelabel{figax}{Alexander bla bla}
\end{figure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

\begin{figure}
\centering
\includegraphics[scale=.5]{example-image}
\caption{ipsum}
\spelabel{figab}{Albert  bla bla}
\end{figure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

\begin{figure}
\centering
\includegraphics[scale=.5]{example-image}
\caption{ipsum}
\spelabel{figza}{Zigzoo foo}
\end{figure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum.

\begin{figure}
\centering
\includegraphics[scale=.5]{example-image}
\caption{ipsum}
\spelabel{figaxb}{Alexander bla bla}
\end{figure}


\let\mtindex\theindex
\renewcommand{\theindex}{%
\mtindex%
\gdef\item##1,{%
\par\hangindent 40pt ##1:\csname mtidx##1\endcsname}}
\printspeindex
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .