tags:

views:

56

answers:

1

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

+6  A: 

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).

ezod
Indeed it does. I added \ifthenelse{\equal{\value{section-level}}{3}}{\paragraph{#1}}{} \ifthenelse{\equal{\value{section-level}} {4}}{\subparagraph{#1}}{} I doubt I'll get that deep, but it's nice to have it there.AUCTeX unfortunately no longer puts the section title in a big font, but I can live with that.Thanks.Liam
Liam