%% LaTeX package xassoccnt - version 1.1 (2016/10/29 -- 13:34:52)
%% Example file for backup counters file for xassoccnt.sty
%%
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2016 by Dr. Christian Hupfer <typography dot with dot latex at gmail dot com>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%%
%% This work has the LPPL maintenance status `author-maintained`
%%
%%

\documentclass{book}

\usepackage{xassoccnt}
\usepackage{blindtext}
%\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\DeclareBackupCountersGroupName{sectiontree}
\DeclareBackupCountersGroupName{chaptertree}

\AssignBackupCounters[name=chaptertree,cascading=true]{chapter} % Use all counters in the chapter counter driver reset list


\newcommand{\outputit}[1]{\csname the#1\endcsname\par}

\begin{document}
Checking for existence of a backup counter group:


\IsBackupCounterGroupTF{chaptertree}{Yes, \fbox{chaptertree} is a backup counter group}{no, \fbox{chaptertree} is no backup counter group}

\IsBackupCounterGroupT{chaptertree}{Yes, \fbox{chaptertree} is a backup counter group}

\IsBackupCounterGroupF{foochaptertree}{No, \fbox{foochaptertree} is no backup counter group}

\IsBackupCounterGroupTF{secondchaptertree}{Yes, \fbox{secondchaptertree} is a backup counter group}{no, \fbox{secondchaptertree} is no backup counter group}
\clearpage
\tableofcontents
\listoffigures

\chapter{First regular chapter}

\section{First section in first regular chapter}

\subsection{First subsection in first regular section}



\begin{figure}
\caption{My nice figure in 1st regular chapter}
\end{figure}


\begin{figure}
\caption{My other nice figure in 1st regular chapter}
\end{figure}



\chapter{Second regular chapter}

\section{First section in 2nd regular chapter}

\subsection{1st subsection in 1st regular section of 2nd regular chapter}


\begin{figure}
\caption{My nice figure in 2nd regular chapter}
\end{figure}


\begin{figure}
\caption{My other nice figure in 2nd regular chapter}
\end{figure}





\chapter{Third regular chapter}

\section{1st section in 3rd regular chapter}

\subsection{1st subsection in 1st regular section of 2nd regular chapter}
\subsection{2nd subsection in 1st regular section of 2nd regular chapter}

\section{2nd section in 3rd regular chapter}

\subsection{1st subsection in 2nd regular section of 2nd regular chapter}
\subsection{2nd subsection in 2nd regular section of 2nd regular chapter}

\chapter{Fourth regular chapter}



\BackupCounterGroup[backup-id={firstchaptertree},cascading=true]{chaptertree}



\chapter{First chapter after backup command}

\section{1st section in 1st backup chapter}

\subsection{1st subsection in 1st regular section of 1st backup chapter}
\subsection{2nd subsection in 1st regular section of 1st backup chapter}

\section{2nd section in 1st backup chapter}

\subsection{1st subsection in 2nd regular section of 1st backup chapter}
\subsection{2nd subsection in 2nd regular section of 1st backup chapter}


\begin{figure}
\caption{My nice figure in 1st backup chapter}
\end{figure}


\begin{figure}
\caption{My other nice figure in 1st backup chapter}
\end{figure}





\chapter{Second chapter after backup command}

\section{1st section in 2nd backup chapter}

\subsection{1st subsection in 1st regular section of 2nd backup chapter}
\subsection{2nd subsection in 1st regular section of 2nd backup chapter}

\section{2nd section in 2nd backup chapter}

\subsection{1st subsection in 2nd regular section of 2nd backup chapter}
\subsection{2nd subsection in 2nd regular section of 2nd backup chapter}


\chapter{Third chapter after first backup command}



\BackupCounterGroup[backup-id={secondchaptertree}]{chaptertree}

\chapter{First chapter after second backup command}

% Now restore the full chaptertree command with the backup id firstchaptertree, but don't keep the state afterwards. 

Checking the backup state: \IsBackupStateTF{chaptertree}{firstchaptertree}{Yes}{No}

Checking the backup state again: \IsBackupStateT{chaptertree}{firstchaptertree}{Yes}

Checking the backup state again: \IsBackupStateF{chaptertree}{foochaptertree}{No, it's no backup state}


\RestoreBackupCounterGroup[keep-after-restore=false,backup-id={firstchaptertree}]{chaptertree}

Now checking after restore with `keep-after-restore=false`:

Checking the backup state: \IsBackupStateTF{chaptertree}{firstchaptertree}{Yes}{No}

Checking the backup state again: \IsBackupStateT{chaptertree}{firstchaptertree}{Yes}

Checking the backup state again: \IsBackupStateF{chaptertree}{foochaptertree}{No, it's no backup state}





\chapter{First chapter after restoring of first backup}


\section{1st section in 1st backup chapter of 2nd backup}

\subsection{1st subsection in 1st regular section of 2nd backup chapter}
\subsection{2nd subsection in 1st regular section of 2nd backup chapter}

\section{2nd section in 2nd backup chapter of 2nd backup}

\subsection{1st subsection in 2nd regular section of 2nd backup chapter}
\subsection{2nd subsection in 2nd regular section of 2nd backup chapter}


\chapter{Another chapter after restoring}

% Now let us restore only some of the counters


\section{First section of another chapter}

\begin{figure}
\caption{My nice figure}
\end{figure}

\begin{figure}
\caption{My very nice figure}
\end{figure}


\subsection{First subsection of 1st section of another chapter}

\section{Now another section}


\RestoreBackupCounterGroup[keep-after-restore=true,backup-id={secondchaptertree}]{chaptertree}


\chapter{Another chapter after restoring with secondchaptertree}

% Now let us restore only some of the counters


\section{First section of another chapter}

\begin{figure}
\caption{My nice figure}
\end{figure}

\begin{figure}
\caption{My very nice figure}
\end{figure}


\subsection{First subsection of 1st section of another chapter}

\section{Now another section}


\RestoreBackupCounterGroup[keep-after-restore=true,backup-id={secondchaptertree},restore-id=first]{chaptertree}


\chapter{Another chapter after restoring, secondchaptertree,other restore-id}

% Now let us restore only some of the counters


\section{First section of another chapter}

\begin{figure}
\caption{My nice figure}
\end{figure}

\begin{figure}
\caption{My very nice figure}
\end{figure}


\subsection{First subsection of 1st section of another chapter}

\section{Now another section}

\RestoreBackupCounterGroup[keep-after-restore=true,backup-id={secondchaptertree},restore-id=newrestore]{chaptertree}


\chapter{Another chapter after restoring, secondchaptertree, yet another restore-id}

% Now let us restore only some of the counters


\section{First section of another chapter}

\begin{figure}
\caption{My nice figure}
\end{figure}

\begin{figure}
\caption{My very nice figure}
\end{figure}


\subsection{First subsection of 1st section of another chapter}

\section{Now another section}


%%%%%


%\ClearBackupCounterGroups{chaptertree}

%\DeleteBackupCounterGroups{chaptertree}


\RemoveCountersFromBackupGroup{chaptertree}{section}




\RestoreBackupCounterGroup[keep-after-restore=true,backup-id={secondchaptertree},restore-id=renewrestore]{chaptertree}

%\chapter{Another chapter after restoring, secondchaptertree, yet another restore-id}



Removing a specific backup-id

%\ClearCounterBackupState[backup-id=secondchaptertree]{chaptertree}{chapter}


\ClearBackupState[backup-id=secondchaptertree]{chaptertree}



\section{First section of another chapter}

\begin{figure}
\caption{My nice figure}
\end{figure}

\begin{figure}
\caption{My very nice figure}
\end{figure}


\subsection{First subsection of 1st section of another chapter}

\section{Now another section}



\end{document}