This has been asked several times.
I thought that I had solved this out in the past,
but I cannot get it to work.
What I want:
I am seeking a solution which:
Typesets the complete section number (ex:
A.1.3 — 10) in all float counters,
and any other counters which the author wishes to use.Provides the option of automatically choosing the current section depth.
Permits the author to set the options in the preamble as well as in the document.
Permits the author to alter the options mid-document if they have already been set.
What I'm Getting:
The \renewcommand in the preamble is not resetting the counter syntax,
as is evident in the equation counter numbering.
Also:
Beyond that, I do not belive that \determineSection works as intended.
I believe that it provides a counter value, rather than the coded name \thesection, etc.
How do I use the if switch in \determineSection to output code such as:
subsubsection\thesubsection
Anything to do with csname?
MWE
Subfiles/Preamble.tex:
% meta tools
\usepackage{etoolbox} % allows if/else statements in code. [required for: standalone+nocite fix, equation numbering.]
% math
\usepackage{mathtools} % includes amsmath, supplements it.
% font
\usepackage{listings} % improved version of verbatim. imports script languages (with syntax coloring).
\usepackage{color} % color commands.
\usepackage[dvipsnames]{xcolor} % additional color commands.
% layout: page/spacing/headings
\usepackage{appendix} % appendices.
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
% references
\usepackage{tocloft} % allows generation of list of equations. (used in MWE only.)
\usepackage{chngcntr} % allows changes mid-document to section depth of equation counter reset.
% floats: figures/tables/lists
% Sectioned Counters:
% Save a copy of the original float counters.
\let\xtheequationOriginal\theequation
\let\xthefigureOriginal\thefigure
\let\xthetableOriginal\thetable
\let\xthelstlistingOriginal\thelstlisting
% Create blank commands which will later act as variable rich-format counters.
\newcommand{\sectionedEquation}{.}
\newcommand{\sectionedFigure }{.}
\newcommand{\sectionedTable }{.}
\newcommand{\sectionedListing }{.}
% Set the float counters to the rich-format counter commands.
\let\theequation\sectionedEquation
\let\thefigure\sectionedFigure
\let\thetable\sectionedTable
\let\thelstlisting\sectionedListing
% Command: Determine Section
\newcommand{\determineSection}{% [Provides full section counter of current section, independent of the section depth.]
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0 \theparagraph
\else \thesubsubsection \fi
\else \thesubsection \fi
\else \thesection \fi
}
% Command: Sectioned Counter
\newcommand{\sectionedCounterStyle}[2]{#2--\arabic{#1}} % Input #1: equation, lstlisting, table, figure
% Input #2: \determineSection, \thesection, \thesubsection, ..
\newcommand{\sectionedCounter} [2] % Input #1: \determineSection, \thesection, \thesubsection, ..
{ % Input #2: section, section, subsection, ..
\counterwithin*{equation} {#2} % Reset counter whenever there is a new \section
\counterwithin*{figure} {#2}
\counterwithin*{table} {#2}
\counterwithin*{lstlisting}{#2} % The listings counter is not actually defined until \AtBeginDocument.
% Thus, if using this command (including listings) within the preamble,
% use ``\AtBeginDocument{\sectionedCounter{<input>}}'' instead.
\renewcommand{\sectionedEquation}{\sectionedCounterStyle{equation} {#1}}
\renewcommand{\sectionedFigure }{\sectionedCounterStyle{figure} {#1}}
\renewcommand{\sectionedTable }{\sectionedCounterStyle{table} {#1}}
\renewcommand{\sectionedListing }{\sectionedCounterStyle{lstlisting}{#1}}
}
% Set float counters to include their full section number.
\AtBeginDocument{\sectionedCounter{\thesubsection}{subsection}}
% -\determineSection is chosen by default as a catch-all, such that
% float counters adapt to any section level when running standalone subfiles
% which do not contain a \sectionedCounter command.
% It is assumed that in most cases, the author will set the counter depth to a specific level.
% Settings for importing scripts [listings package]
\lstset{frame = single}
% Settings for creating Lists of Equations
\newcommand{\listnameEquations}{List of Equations}
\newlistof{equations}{equ}{\listnameEquations}
\newcommand{\eqRef}[1]{%
\addcontentsline{equ}{equations}{\protect\numberline{\theequation}#1}\par}
masterFile.tex:
%! arara: lmkclean
%! arara: pdflatex: { draft: yes }
%! arara: bibtex
% arara: pdflatex: { draft: yes }
% arara: pdflatex: { synctex: yes }
% arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\providecommand{\main}{.}
\input{\main/Subfiles/Preamble.tex} % Preamble [document configuration]
\begin{document}
\addcontentsline{toc}{section}{List of Contents} \tableofcontents \clearpage
\addtocontents {toc}{\string\vspace{-1em}}
\addcontentsline{toc}{section}{List of Equations} \listofequations \clearpage
\addtocontents {toc}{\string\vspace{-1em}}
\addcontentsline{toc}{section}{List of Code Listings} \lstlistoflistings \clearpage
\begin{equation} \mathrm{Equation\ null.1} \label{eq:null.1} \end{equation} \eqRef{Equation null.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ null.2} \label{eq:null.2} \end{equation} \eqRef{Equation null.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section 1} \clearpage
\begin{equation} \mathrm{Equation\ 1.0.1} \label{eq:1.0.1} \end{equation} \eqRef{Equation 1.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.0.2} \label{eq:1.0.2} \end{equation} \eqRef{Equation 1.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.1} \clearpage
\begin{equation} \mathrm{Equation\ 1.1.1} \label{eq:1.1.1} \end{equation} \eqRef{Equation 1.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.1.2} \label{eq:1.1.2} \end{equation} \eqRef{Equation 1.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.2} \clearpage
\begin{equation} \mathrm{Equation\ 1.2.1} \label{eq:1.2.1} \end{equation} \eqRef{Equation 1.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.2.2} \label{eq:1.2.2} \end{equation} \eqRef{Equation 1.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section 2} \clearpage
\begin{equation} \mathrm{Equation\ 2.0.1} \label{eq:2.0.1} \end{equation} \eqRef{Equation 2.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.0.2} \label{eq:2.0.2} \end{equation} \eqRef{Equation 2.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 2.1} \clearpage
\begin{equation} \mathrm{Equation\ 2.1.1} \label{eq:2.1.1} \end{equation} \eqRef{Equation 2.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.1.2} \label{eq:2.1.2} \end{equation} \eqRef{Equation 2.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 2.2} \clearpage
\begin{equation} \mathrm{Equation\ 2.2.1} \label{eq:2.2.1} \end{equation} \eqRef{Equation 2.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.2.2} \label{eq:2.2.2} \end{equation} \eqRef{Equation 2.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\textbf{\LARGE{Appendices}}
\addappheadtotoc
\begin{appendices}
\section{Section A} \clearpage
\begin{equation} \mathrm{Equation\ A.0.1} \label{eq:A.0.1} \end{equation} \eqRef{Equation A.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.0.2} \label{eq:A.0.2} \end{equation} \eqRef{Equation A.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection A.1} \clearpage
\begin{equation} \mathrm{Equation\ A.1.1} \label{eq:A.1.1} \end{equation} \eqRef{Equation A.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.1.2} \label{eq:A.1.2} \end{equation} \eqRef{Equation A.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection A.2} \clearpage
\begin{equation} \mathrm{Equation\ A.2.1} \label{eq:A.2.1} \end{equation} \eqRef{Equation A.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.2.2} \label{eq:A.2.2} \end{equation} \eqRef{Equation A.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section B} \clearpage
\begin{equation} \mathrm{Equation\ B.0.1} \label{eq:B.0.1} \end{equation} \eqRef{Equation B.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.0.2} \label{eq:B.0.2} \end{equation} \eqRef{Equation B.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.1} \clearpage
\begin{equation} \mathrm{Equation\ B.1.1} \label{eq:B.1.1} \end{equation} \eqRef{Equation B.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.1.2} \label{eq:B.1.2} \end{equation} \eqRef{Equation B.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.2} \clearpage
\begin{equation} \mathrm{Equation\ B.2.1} \label{eq:B.2.1} \end{equation} \eqRef{Equation B.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.2.2} \label{eq:B.2.2} \end{equation} \eqRef{Equation B.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\end{appendices}
\end{document}
Notes:
Use of \AtBeginDocument with listings counters comes from here.
\addtocontentsetc. for the ToC and other stuff. Isn't KOMA providing this out of the box? – Aug 18 '16 at 16:53\addtocontents; it's certainly possible I missed something. This is unrelated to the question though. The tocs are only there to more easily line up the numbering for testing. – kando Aug 18 '16 at 17:00standalone. The subfiles were removed for the purposes of the MWE. I do not believe thestandaloneclass is related to the issue.) – kando Aug 18 '16 at 17:30\renewcommands are now within another command. – kando Aug 18 '16 at 19:17\renewcommandcontinues to have no effect on the syntax of the counter. This is a problem since larger section depths begin to mask that the final digit represents a float counter. What am I missing that\renewcommandcannot affect the counter syntax? (I thought that\counterwithinwithout an*was needed to allow\renewcommandto be able to change the syntax. Really,\counterwithinis changing the counter and\renewcommandcontinues to run without an error, but continues to whiff as well.) – kando Aug 19 '16 at 12:46\counterwithin, but\counterwithinseparates the section number from the float number with the same punctuation (a period). This is terrible, so we want the added ability to change the counter from<section>.<float>, which appears as<2.1.3.5>to<section>-<float>, which appears as<2.1.3-5>. – kando Aug 19 '16 at 13:09[n.inputs]in\renewcommand{label}[n.inputs]{def}. Remove[n.inputs], no problems. Copypasta error I think. – kando Aug 19 '16 at 16:55\the[float]to that command (Example:\let\theequation\sectionedEquation). I don't know what was going wrong there, but I don't have the time to delve on that one : j – kando Aug 19 '16 at 17:01