Edit: See the better versions at the of the code, the basic principles explained at the top did not change, however!
A really quick hack, that hooks into \listoffigures
and \listoftables
, advancing a counter for each \listof...
and writing the entries to 1lof
, 2lof
, etc. (the same for 1lot
, etc.)
This is done by redefining the \ext@lof
etc. command each time a \caption
is used.
\documentclass{book}
\usepackage{xpatch}
\newcounter{lofcntr}
\newcounter{lotcntr}
\newcommand{\clearcontents}{%
\stepcounter{lofcntr}%
\stepcounter{lotcntr}%
\setcounter{figure}{0}
\setcounter{table}{0}
}
\AtBeginDocument{%
\stepcounter{lofcntr}%
\stepcounter{lotcntr}%
}
\makeatletter
\xpretocmd{\caption}{%
\def\ext@figure{\number\value{lofcntr}lof}
\def\ext@table{\number\value{lotcntr}lot}
}{\typeout{Worked!}}{}
\xpatchcmd{\listoffigures}{%
\@starttoc{lof}%
}{%
\@starttoc{\number\value{lofcntr}lof}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\xpatchcmd{\listoftables}{%
\@starttoc{lot}%
}{%
\@starttoc{\number\value{lotcntr}lot}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\makeatother
\usepackage{caption}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\captionof{figure}{Some figure caption}
\captionof{figure}{Some figure caption}
\captionof{figure}{Some figure caption}
\captionof{figure}{Some figure caption}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\clearcontents
\listoffigures
\listoftables
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\end{document}

Update Some better version:
\documentclass{book}
\usepackage{xparse}
\usepackage{xpatch}
\usepackage{caption}
\usepackage{blindtext}
% Do not a driver counter, i.e. a resetting counter for those two counter fellows here:
\newcounter{lofcntr}
\newcounter{lotcntr}
\NewDocumentCommand{\clearcontents}{}{%
\stepcounter{lofcntr}% We don't need labels here, I suppose?
\stepcounter{lotcntr}%
\setcounter{figure}{0}
\setcounter{table}{0}
}
\AtBeginDocument{%
\stepcounter{lofcntr}%
\stepcounter{lotcntr}%
}
\makeatletter
% Store the definition of \ext@figure etc. first
\let\latex@ext@figure\ext@figure
\let\latex@ext@table\ext@table
\AtBeginDocument{%
\xpretocmd{\caption}{%
% Prepend the extension with the number of the current list of ...
\def\ext@figure{\number\value{lofcntr}\latex@ext@figure}
\def\ext@table{\number\value{lotcntr}\latex@ext@table}
}{\typeout{Worked!}}{\typeout{Failed miserably!}}
}
\xpatchcmd{\listoffigures}{%
\@starttoc{lof}%
}{%
\@starttoc{\number\value{lofcntr}lof}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\xpatchcmd{\listoftables}{%
\@starttoc{lot}%
}{%
\@starttoc{\number\value{lotcntr}lot}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\clearcontents
\listoffigures
\listoftables
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\end{document}
Update for minted
and listings
environment:
\documentclass{book}
\usepackage{minted}
\usepackage{xparse}
\usepackage{xpatch}
\usepackage{caption}
\usepackage{blindtext}
% Do not use a driver counter, i.e. a resetting counter for those two counter fellows here:
\newcounter{lofcntr}
\newcounter{lotcntr}
\newcounter{lolcntr}
\NewDocumentCommand{\clearcontents}{}{%
\stepcounter{lofcntr}% We don't need labels here, I suppose?
\stepcounter{lotcntr}%
\stepcounter{lolcntr}%
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{listing}{0}
}
\makeatletter
\NewDocumentCommand{\advancecontents}{}{%
\def\ext@figure{\number\value{lofcntr}\latex@ext@figure}
\def\ext@table{\number\value{lotcntr}\latex@ext@table}%
\@namedef{ext@listing}{\number\value{lolcntr}\latex@ext@listing}%
}
\AtBeginDocument{%
% Store the definition of \ext@figure etc. first
\let\latex@ext@figure\ext@figure
\let\latex@ext@table\ext@table
\let\latex@ext@listing\ext@listing
\stepcounter{lofcntr}%
\stepcounter{lotcntr}%
\stepcounter{lolcntr}%
\advancecontents%
}
\AtBeginDocument{%
\xpretocmd{\caption}{%
% Prepend the extension with the number of the current list of ...
\advancecontents%
}{\typeout{Patching caption worked!}}{\typeout{Patching caption failed miserably!}}
}
\xpatchcmd{\listoffigures}{%
\@starttoc{lof}%
}{%
\@starttoc{\number\value{lofcntr}lof}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\xpatchcmd{\listoftables}{%
\@starttoc{lot}%
}{%
\@starttoc{\number\value{lotcntr}lot}%
}{\typeout{Patch success}}{\typeout{Patch failure}}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\listoflistings
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 1st lol}
\end{listing}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 1st lol}
\end{listing}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 1st lol}
\end{listing}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 1st lol}
\end{listing}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\clearcontents
\listoffigures
\listoftables
\listoflistings
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 2nd lol}
\end{listing}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 2nd lol}
\end{listing}
\begin{listing}
\mint{c}
/* code */
\caption{A foo listing for 2nd lol}
\end{listing}
\end{document}
.lof
file usually per run.