Is it possible to specify the \section \subsection \subsubsection etc. level relative to the previous level? What I'm thinking of is something like
\thissection The top level
\pushsection
\thissection The next level down
\thissection One more
\pushsection
\thissection Deeper
\popsection
\thissection At the same level and follows "one more"
etc. The idea is that I'm writing a document from the inside out, i.e., starting at a deeper levels, and I don't know how many layers will be on top of it. This will avoid the need to do a massive re-leveling by renaming \subsection to \subsubsection etc.
BTW, a Google search for latex and "relative section" results in hits that almost exclusively involve misuse of the word "relative"; the authors meant to say "relevant section".
Thank you for any ideas.
Liam
You could implement your \pushsection
, \popsection
, and \thissection
using a counter and if-then-else logic:
\usepackage{ifthen}
\newcounter{section-level}
\setcounter{section-level}{0}
\newcommand{\pushsection}{\addtocounter{section-level}{1}}
\newcommand{\popsection}{\addtocounter{section-level}{-1}}
\newcommand{\thissection}[1]
{
\ifthenelse{\equal{\value{section-level}}{0}}{\section{#1}}{}
\ifthenelse{\equal{\value{section-level}}{1}}{\subsection{#1}}{}
\ifthenelse{\equal{\value{section-level}}{2}}{\subsubsection{#1}}{}
}
This will work exactly as you show above, for 3 levels of section. Of course, you should probably do something to handle out-of-range nesting levels (such as crashing the TeX build and printing a warning).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With