3

How can I count the total number of subsection within each section. Actually, both section within each chapter, and subsections within each section for the article class. Based on this post I have tried to do my best, but unsuccessfully. (I am a newbie).

Is it possible? could anyone help me?

EDIT

Thank you very much for your prompt response. The following, is a very short example of what I'd like to achive too:

enter image description here

1
  • 1
    There are no chapters in article
    – user31729
    May 8, 2016 at 11:29

1 Answer 1

6

Update (2017/01/14)

I've uploaded a new version of cntperchap to CTAN, being called xcntperchap now, it allows for tracking by labels and multiple track levels.

Edit (2016/05/09): Update: I found a small weird bug in xassoccnt, that lead to some nasty off-by-one value. See the scratch version of a new cntperchap - look-alike at the bottom of this post.

The cntperchap could be used for this (normally), but there's a mismatch in cntperchap and assoccnt (I am the author of both packages, so I know about this and have to correct this (soon)).

Use this by-pass solution with cntchap as long as there's no other way:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cntchap}[2015/06/01 v0.3 -- store counter values per chapter]%
%%
%% License: LaTeX Project Public License version 1.3 
%% Copyright (2015) Dr. Christian Hupfer 
%% Author: Christian Hupfer christian.hupfer@yahoo.de
%%
%% 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 `maintained'.
%%
%% This work consists of all files listed in README
%%
%%%%


\RequirePackage{ifthen}
\RequirePackage{xassoccnt}
\RequirePackage{morewrites}
\RequirePackage{xkeyval}
\RequirePackage{xpatch}
\RequirePackage{xparse}

%%%% Data macros


\def\cps@@data@@tracklevel{chapter}
\edef\cps@@data@@packagename{\@currname} % Store the actual packagename

\newcommand{\cpspackagename}{%
  \cps@@data@@packagename%
}

\newcommand{\@cps@@writefilehandleprefix}{tf@cps}

%%%%%

%%%% Preconfiguration depending on the class in the background


\edef\cps@@config@@tracklevel{\cps@@data@@tracklevel}%

\@ifclassloaded{article}{%
  \edef\cps@@config@@tracklevel{section}
}{%
  \@ifclassloaded{scrartcl}{%
    \edef\cps@@config@@tracklevel{section}%
  }{%
  }%    
}


\newif\ifcpsstorage

\newcommand{\EnableCPSStorage}{%
  \cpsstoragetrue%
}

\newcommand{\DisableCPSStorage}{%
  \cpsstoragefalse%
}

\EnableCPSStorage


%%%% Command options

\define@boolkey{cpskeys}{autodefine}[false]{}

\define@key{cpskeys}{tracklevel}[\cps@@config@@tracklevel]{%
  \gdef\@cps@@keymacro@@tracklevel{#1}%
}

\presetkeys{cpskeys}{autodefine=false,tracklevel=\cps@@config@@tracklevel}{}%

\NewDocumentCommand{\DeclareCPSCounter}{s+O{cps}m}{%
  \ifltxcounter{#3}{%
  }{%
    \newcounter{#2@@cps@@#3}%
  }
  % Not really useful so far
  % \expandafter\newcommand\csname #3countername\endcsname{#2@@cps@@#3}%
}

\@onlypreamble{\DeclareCPSCounter}


%%%% Package options

\newif\ifcpsnoendclose
\cpsnoendclosefalse

\newif\ifcpsverbose
\cpsverbosefalse

\newif\ifcpsautodefine
\cpsautodefinefalse

\newif\ifcpsdraftmode
\cpsdraftmodetrue


\DeclareOptionX{autodefine}{\cpsautodefinetrue\presetkeys{cpskeys}{autodefine=true}{}}
\DeclareOptionX{draft}{\cpsdraftmodetrue}
\DeclareOptionX{final}{\cpsdraftmodefalse}
\DeclareOptionX{noendclose}{\cpsnoendclosetrue}
\DeclareOptionX{tracklevel}{\presetkeys{cpskeys}{tracklevel=#1}{}}
\DeclareOptionX{verbose}{\cpsverbosetrue}


\ProcessOptionsX*


\newcommand{\@cps@@counterlistname}{cps@@counterstostore}
\listcsadd{\@cps@@counterlistname}{}





%%%% Internal commands

% Instead of using totcount package
\newcounter{cps@@totaltracklevelcount}

% Intermediate package counters 
\newcounter{cps@@currentlevelcount}
\newcounter{cps@@togglecounter}
\newcounter{cps@@tempcounter}
\newcounter{cps@@tempcounterstorage}
\newcounter{cps@@cpscounters}


\newcommand{\@cps@@cpscountersname}{%
  cps@@cpscounters%
}


\newcommand{\@cps@@typeout}[1]{%
  \ifcpsverbose%
  \typeout{\cps@@data@@packagename: #1}%
  \fi%
}


\NewDocumentCommand{\@cps@@tracklevelstarthook}{}{%
  \stepcounter{cps@@currentlevelcount}%
  \ifnumgreater{\value{cps@@currentlevelcount}}{0}{%
    \StoreCounters%
  }{}%
  \ResetStoredCounters%
}


% This disables the usage of the automatic counter storage for ToC - like macros, since those use `\chapter*` and confuse the tracking counter  
\NewDocumentCommand{\PrepareTocCommand}{m}{%
  \xpretocmd{#1}{\DisableCPSStorage}{}{}%  Lazy so far
  \xapptocmd{#1}{\EnableCPSStorage}{}{}% Lazy so far
}



\AtBeginDocument{%
  % Do a check first whether the given tracklevel does exist at all
  \expandafter\ifx\csname \@cps@@keymacro@@tracklevel\endcsname\relax
  \GenericError{Error}{Error in \jobname.tex: At line \the\inputlineno: The section level \@cps@@keymacro@@tracklevel\ is unknown}{%
    Please check your document class and the tracklevel option}{%
  }%
  \else
  % Generate a read file handle
  \@cps@@generatereadfilehandle%
  % Prepending the \csname \@cps@keymacro@tracklevel\endcsname command with some starter hook
  \expandafter\xpretocmd\expandafter{\csname \@cps@@keymacro@@tracklevel\endcsname}{\@cps@@tracklevelstarthook}{\typeout{\@cps@@keymacro@@tracklevel{} command redefined}}{}%
  \PrepareTocCommand{\tableofcontents}%
  \PrepareTocCommand{\listoffigures}%
  \PrepareTocCommand{\listoftables}%
  \PrepareTocCommand{\printindex}%
  \fi%
}

\AtEndDocument{%
  % Store the total value of the considered sectioning level to the `.aux` file
  \immediate\write\@auxout{%
    \string\setcounter{cps@@totaltracklevelcount}{\number\value{cps@@currentlevelcount}}^^J
  }% End of \immediate\write
}

\newcommand{\@cps@@readfilehandlename}{%
  tfr@cpsreadfile%
}

\newcommand{\@cps@@readfilehandle}{%
  \csname\@cps@@readfilehandlename\endcsname%
}


\newcommand{\@cps@@generatereadfilehandle}{%
  \@cps@@typeout{Generating read filehandle}%
  \expandafter\newread\csname \@cps@@readfilehandlename\endcsname%
}

\newcommand{\@cps@@generatewritefilehandle}[1]{%
  \@cps@@typeout{Generating write filehandle #1}%
  \expandafter\newwrite\csname\@cps@@writefilehandlename{#1}\endcsname%  Generate the file handles
}

\newcommand{\@cps@@writefilehandle}[1]{%
  \csname\@cps@@writefilehandlename{#1}\endcsname%  Generate the file handles
}


\newcommand{\@cps@@writefilehandlename}[1]{%
  \@cps@@writefilehandleprefix#1%
}

\newcommand{\@cps@@closeinfile}[1]{%
  \immediate\closein#1%
}

\newcommand{\@cps@@openincpsfile}[2][\@cps@@readfilehandle]{%
  \expandafter\immediate\openin#1=\jobname.cps#2\relax%
}

\newcommand{\@cps@@openoutcpsfile}[1]{%
  \expandafter\immediate\openout\@cps@@writefilehandle{#1}=\jobname.cps#1\relax%
}

\newcommand{\@cps@@closeoutfile}[1]{%
  \immediate\closeout#1%
}

\newcommand{\@cps@@closeoutcpsfile}[1]{%
  \@cps@@typeout{Closing cps#1 file}%
  \@cps@@closeoutfile{\csname\@cps@@writefilehandlename{#1}\endcsname}%
}



\newcommand{\@startcountertoc}[1]{%
  \begingroup%
  % The file handles are generated either by `\@registercounterspertracklevel` or in \AtBeginDocument
  \makeatletter
  % Read first before deleting it
  \IfFileExists{\jobname.cps#1}{%
    \@cps@@openincpsfile{#1}%
    \@cps@@readcounternumbers{\@cps@@readfilehandle}{#1}%
    \@cps@@closeinfile{\@cps@@readfilehandle}%
  }{%
    \typeout{No #1{} counter values so far}%
  } 
  \if@filesw
  % Write only if not `\nofiles` is specified
  \@cps@@openoutcpsfile{#1}%
  \fi%
  \@nobreakfalse%
  \endgroup%
}



\newcommand{\@cps@@readcounternumbers}[2]{%
  \setcounter{cps@@togglecounter}{0}%  
  \whiledo {\value{cps@@togglecounter} < 1}{%
    \read#1 to \@cps@@numberfromfile%
    \ifeof #1%
    \stepcounter{cps@@togglecounter}%
    \else%
    \listcsxadd{#2countlist}{\@cps@@numberfromfile}%
    \fi%
  }%
}

\newcommand{\@cps@@storecounter}[1]{%
  \addtocontents{cps#1}{%
    \number\value{cps@@cps@@total#1}%
  }%
}


\newcommand{\@cps@@csloop}[1]{%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \expandafter\forlistcsloop{\csname #1\endcsname}{\@cps@@counterlistname}
  }{%
  }%
}

\newcommand{\@cps@@loopstorecounters}{%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\@cps@@storecounter}{\@cps@@counterlistname}%
  }{%
  }%
}


\newcommand{\@cps@@registercounter}[1]{%
  \listcsxadd{\@cps@@counterlistname}{#1}%
  \stepcounter{cps@@cpscounters}%
  \listcsxadd{#1countlist}{}%
  \DeclareCPSCounter{total#1}%
  \DeclareCPSCounter{grandtotaltemp#1}%
  \DeclareCPSCounter{grandtotal#1}%
  \@cps@@generatewritefilehandle{#1}%
  % This needs some work to do
  \DeclareAssociatedCounters{#1}{cps@@cps@@total#1,cps@@cps@@grandtotaltemp#1}%
}

%% Searches the list of counter values for the  tracklevel (#2)
\newcommand{\@cps@@searchcountervalue}[3]{%
  \setcounter{cps@@tempcounterstorage}{-1}%
  \ifnumequal{#1}{\value{#2}}{%
    % Value found, store it temporarily
    \setcounter{cps@@tempcounterstorage}{#3}%
    \listbreak%
  }{%
    \stepcounter{#2}%
  }%
}


\newcommand{\@cps@@auxsetcounter}[2]{%
  \immediate\write\@auxout{%
    \string\setcounter{#1}{\number\value{#2}}
  }
}%

\newcommand{\@cps@@storegrandtotal}[1]{%
  \@cps@@auxsetcounter{cps@@cps@@grandtotal#1}{cps@@cps@@grandtotaltemp#1}%
}




%%%%%%%%%%%%%% User commands  %%%%%%%%%%%%%%%%%%%%


\newcommand{\RegisterCounter}[2][]{%
  \begingroup
  \setkeys{cpskeys}{#1}%
  \ifltxcounter{#2}{%
    \@cps@@registercounter{#2}%
  }{%
    \ifKV@cpskeys@autodefine
    \newcounter{#2}%
    \@cps@@registercounter{#2}%
    \else%
    % Ignore non existing counters
    \GenericWarning{Counter #1 is not defined}{}%
    \fi
  }%
  \endgroup
}

\newcommand{\RegisterCounters}[1]{%
  \forcsvlist{\RegisterCounter}{#1}%
}

% Prevent usage later in document body

\@onlypreamble{\@registercounters}
\@onlypreamble{\RegisterCounter}
\@onlypreamble{\RegisterCounters}
\@onlypreamble{\PrepareToCCommands}


\newcommand{\ResetStoredCounter}[1]{%
  \setcounter{cps@@cps@@total#1}{0}%
}


% Reset all total counters
\newcommand{\ResetStoredCounters}{%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\ResetStoredCounter}{\@cps@@counterlistname}%
  }{}%  
}

%% Only for statistical purposes. Do not use it in a production run
\newcommand{\IndividualCounterStatistics}[2][\number\value{cps@@currentlevelcount}]{%
  \ifcpsdraftmode
  \GetStoredCounterValue[#1]{#2}%
  \ifnumgreater{\value{cps@@tempcounterstorage}}{-1}{%
    \noindent \@cps@@keymacro@@tracklevel\ #1~has \number\value{cps@@tempcounterstorage} #2(s)\par 
  }{}
  \fi  
}%

%% Only for statistical purposes. Do not use it in a production run
\newcommand{\ShowStatistics}[1][\number\value{cps@@currentlevelcount}]{%
  \ifcpsdraftmode%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\IndividualCounterStatistics[\number#1]}{\@cps@@counterlistname}%
  }{%
    \typeout{No counters registered}%
  }%
  \fi%
}

\newcommand{\fullstatistics}[1]{%
\hspace{1cm}  \number\value{cps@@cps@@grandtotal#1}{} #1(s)% 

}


\newcommand{\Fullstatistics}{%
  This document has 

  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\fullstatistics}{\@cps@@counterlistname}%
  }{%
    \typeout{No counters registered}%
  }%
}


\newcommand{\GetStoredCounterValue}[2][\number\value{cps@@currentlevelcount}]{%
  \setcounter{cps@@tempcounter}{0}%
  \ifnumgreater{#1}{\value{cps@@totaltracklevelcount}}{%
    \def\cps@@trackleveltoshow{\value{cps@@totaltracklevelcount}}%
  }{%
    \def\cps@@trackleveltoshow{#1}%
  }%
  \ifcsdef{#2countlist}{%
    \forlistcsloop{\@cps@@searchcountervalue{\cps@@trackleveltoshow}{cps@@tempcounter}}{#2countlist}%
  }{%
    \typeout{Warning: List for counter #2 not defined}%
  }% Failure branch should be improved 
}

\newcommand{\FetchStoredCounterValue}[2][\number\value{cps@@currentlevelcount}]{%
  \GetStoredCounterValue[#1]{#2}%
  \number\value{cps@@tempcounterstorage}%
}


\newcommand{\StartCounterToc}{%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\@startcountertoc}{\@cps@@counterlistname}%
  }{%
  }%
}



\newcommand{\CloseCPSFiles}{%
  \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
    \forlistcsloop{\@cps@@closeoutcpsfile}{\@cps@@counterlistname}%
  }{%
  }%
}

\newcommand{\StoreCounters}{%
  \ifcpsstorage% Only store counters if \cpsstoragetrue
  \@cps@@loopstorecounters%
  \fi%
}

\newcommand{\StoreGrandTotalCounters}{%
  \forlistcsloop{\@cps@@storegrandtotal}{\@cps@@counterlistname}%
}


\newcommand{\StopCounting}{%
  \StoreCounters%
}



%% Informational macros  -- very hackish so far

\newcommand{\CPSGetCounterList}{%
  \csname\@cps@@counterlistname\endcsname%
}

\newcommand{\numberofstoredcounters}{%
  \number\value{\@cps@@cpscountersname}%
}

\AtBeginDocument{%
  \StartCounterToc%
}


\AtEndDocument{%
  % Write the last counter values to the file
  \StopCounting%
  % Full counter values
  \StoreGrandTotalCounters%
}

%% etoolbox - addition
\AfterEndDocument{%
  \ifcpsnoendclose
  % Prevent the explicit closing 
  \else
  \CloseCPSFiles%
  \fi
}


\endinput

Here's the working document for getting the number of subsections in a particular section:

Register the counters to be tracked within section first with \RegisterCounters{subsection} first, then compile twice. The particular number of subsections in section n can be retrieved with \FetchStoredCounterValue[n]{subsection}.

The \Fullstatistics macro is for convenience overview.

\documentclass{article}


\usepackage{cntchap}
\RegisterCounters{subsection}
\begin{document}


There are \FetchStoredCounterValue[1]{subsection} in Section 1 and \FetchStoredCounterValue[2]{subsection} in Section 2


\Fullstatistics


\section{First section}

\subsection{My first subsection}

\subsection{other subsection}


\section{Second section}

\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}




\end{document}

enter image description here

I'll provide a new version of cntperchap within the next weeks.

Update -- Using a new scratch version of cntchap and making a patch to xassoccnt

\documentclass{book}


\usepackage{xassoccnt}


% Patch -- is in the development version 


\makeatletter

\ExplSyntaxOn


\RenewDocumentCommand{\stepcounter}{m}{% 
  \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#1}%
  \xassoccnt_is_suspendedcounter:nF{#1}{%
    \xassoccnt_is_coupledcounter:nTF {#1}
    { \xassoccnt_stepcounter_coupledcounters:n{#1} }
    {% No, not a coupled counter!
      \cs_gset_nopar:Nn \__xassoccnt_laststeppedcounter: {\l_tmpa_tl}%
      \xassoccnt_countersinresetlist:n{\l_tmpa_tl}%
      \__xassoccnt_getresetlist:n {\l_tmpa_tl}%
      \seq_if_empty:NTF  \l__xassoccnt_counterreset_seq 
      {%
        \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one}% Use the original one!
        \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{\l_tmpa_tl}}%
        \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} 
      }{ % reset list is not empty!
        % This is the replacement of \csname cl@#1\endcsname
        \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one}
        \seq_map_inline:Nn \l__xassoccnt_counterreset_seq {%
          \xassoccnt_is_drivercounter:nTF{##1}{%
            \use:c{c@##1}\c_zero% Reset but do not increase 
          }{%
            \use:c{c@##1}\c_minus_one
            \xassoccnt_standardstepcounter{##1}%
          }
        }
        \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} % step the remaining associated counters
      }% End of not empty reset list
    }% End of coupled counters
  } % end of not suspended counter
}




\let\latex@@stepcounter\stepcounter


\seq_new:N \g_cntchap_registeredcounters_seq

\seq_new:N \g_cntchap_storedcounters_seq
\seq_new:N \g_cntchap_trackcounters_seq

\seq_gput_right:Nn \g_cntchap_trackcounters_seq {chapter}

\NewDocumentCommand{\RegisterCounters}{m}{%
  \seq_set_from_clist:Nn \g_cntchap_registeredcounters_seq {#1}
  \seq_map_inline:Nn \g_cntchap_registeredcounters_seq {
  }
  \seq_map_inline:Nn \g_cntchap_registeredcounters_seq {
    \IfIsDocumentCounterF{cps@@total##1}{%
      \NewDocumentCounter{cps@@total##1}%
      \DeclareAssociatedCounters{##1}{cps@@total##1}% Define associated counters 
    }
  }
}

\ior_new:N \g_trackfile_storage_read
\iow_new:N \g_trackfile_storage_write



\NewDocumentCommand{\StoreCounterValues}{m}{%
  \tl_clear:N \l_tmpa_tl
  \int_zero:N \l_tmpa_int
  \tl_if_eq:nnT {#1} {chapter} {%
  \ifnum\value{#1} > 0\relax % Replace later one with expl3 - version
  \seq_map_inline:Nn \g_cntchap_registeredcounters_seq {%
    \int_incr:N \l_tmpa_int
    \int_compare:nNnTF {\l_tmpa_int } < {\seq_count:N \g_cntchap_registeredcounters_seq }
    {  \tl_put_right:Nx \l_tmpa_tl { \number\value{cps@@total##1},} }{  \tl_put_right:Nx \l_tmpa_tl { \number\value{cps@@total##1} } }
    \setcounter{cps@@total##1}{0}% Reset the total counter values
  }
  \iow_now:Nx \g_trackfile_storage_write {\l_tmpa_tl}%
  \fi
}
}


% Redefine again, to provide the storage feature
\RenewDocumentCommand{\stepcounter}{m}{%
  \StoreCounterValues{#1}%
  \latex@@stepcounter{#1}%
}


\cs_new:Nn \l_cntchap_read_countervalues:n {%
  \clist_set:Nx \l_tmpa_clist {#1}%
  \clist_map_inline:Nn \l_tmpa_clist {%
    \seq_gput_right:Nn \g_cntchap_storedcounters_seq {##1}
  }
}

\AtBeginDocument{%
  \IfFileExists{ \jobname.cpc }{%
    \seq_gclear:N \g_cntchap_storedcounters_seq
    \ior_open:Nn \g_trackfile_storage_read {\jobname.cpc}
    \ior_map_inline:Nn \g_trackfile_storage_read { \l_cntchap_read_countervalues:n{##1}  }
    \ior_close:N \g_trackfile_storage_read
  }{}
  \iow_open:Nn \g_trackfile_storage_write {\jobname.cpc}
}

\newcommand{\closestoragefile}{%
  \iow_close:N \g_trackfile_storage_write%
}

\cs_generate_variant:Nn \int_set:Nn {NV, Nx}
\int_new:N \l_currentchapter_int

\NewDocumentCommand{\FetchStoredCounterValue}{om}{%
  \IfValueTF{#1}{%
    \int_set:Nx \l_currentchapter_int {#1} 
  }{%
    \int_set:Nx \l_currentchapter_int {\number\value{chapter}} 
  }
  \seq_if_in:NnTF \g_cntchap_registeredcounters_seq {#2} 
  {
    \int_zero:N \l_tmpa_int
    \seq_map_inline:Nn \g_cntchap_registeredcounters_seq {%
      \int_incr:N \l_tmpa_int
      \tl_if_eq:nnT { ##1 } {#2 } { 
        \seq_map_break:
      }
    }
    \int_set:NV \l_tmpb_int { \l_tmpa_int }
    \int_set:Nx \l_tmpa_int { \seq_count:N \g_cntchap_registeredcounters_seq * (\l_currentchapter_int -1) + \l_tmpb_int  }
    \seq_item:Nn \g_cntchap_storedcounters_seq {\int_use:N \l_tmpa_int}
  }{%
    % Perhaps some error message here
  }
}




\ExplSyntaxOff

\@onlypreamble\RegisterCounters
\makeatother

\AtEndDocument{%
  \StoreCounterValues{chapter}%
  \closestoragefile%
}

\RegisterCounters{section,subsection}


\begin{document}
\tableofcontents


\cleardoublepage
\markboth{}{}
\begingroup
\parindent=0em
Chapter 1 has \FetchStoredCounterValue[1]{section} sections and \FetchStoredCounterValue[1]{subsection} subsections

Chapter 2 has \FetchStoredCounterValue[2]{section} sections and \FetchStoredCounterValue[2]{subsection} subsections
\endgroup



\chapter{Foo}

This chapter has \FetchStoredCounterValue{section} sections and \FetchStoredCounterValue{subsection} subsections

\section{First section}

\subsection{My first subsection}

\subsection{other subsection}


\section{Second section}

\subsection{My first subsection}

\subsection{other subsection}

\section{Third section}
\subsection{other subsection}

\subsection{other subsection}
\subsection{other subsection}

\section{Fourth section}


\subsection{other subsection}

\subsection{other subsection}
\subsection{other subsection}




\chapter{Foo bar chapter}

This chapter has \FetchStoredCounterValue{section} sections and \FetchStoredCounterValue{subsection} subsections

\section{Foo}

\section{Second section}

\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}

\section{Third section}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}


\subsection{My first subsection}

\subsection{other subsection}





\end{document}

enter image description here

8
  • Please note, that there's no possibility yet to cascade down from chapterwise counting of 'foo' and counting in 'foo' other stuff. This will be done with the new version
    – user31729
    May 8, 2016 at 11:40
  • @zagalico: See the update please!
    – user31729
    May 9, 2016 at 21:48
  • @ChristianHupfher: Nice update! It would be great having the \fullstatistics macro for all the whole document
    – zagalico
    May 9, 2016 at 23:27
  • @zagalico: I'll try within the next days (sorry, I am a little bit busy)
    – user31729
    May 9, 2016 at 23:28
  • It suits me perfectly
    – zagalico
    May 9, 2016 at 23:34

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