Suppose I have my own counter as in
\newcounter{x}
\setcounter{x}{0}
and now I want to start a new "section" based on the value of x. For example, if x==-1 I want \part, and if x==0 then it will be \chapter and if x==1 it will be \section and so on.
I do not want to write each time something like this (do not even know it is valid syntax)
\ifnum \value{x} \eq -1
\part
\else
\ifnum \value{x} \eq 0
\chapter
...
\fi
\fi
...
I'd like to just write
\makeSectionTypeBasedOnThisValue{x}{title of the section of chapter is here}
and this command will map to the correct command based on the value of x. I will make sure x is always between -1 and 5 since these are the valid values. I am using book style.
I have a reason to want to do it this way. (briefly, I am building my large tree of latex documents, combining them to one document, and I want to be able to build it starting from any level going down. Hence depending on where in the tree I start the build, section numbering will be different. One time the same level can be a \section while some other time that level can become a \subsection. So I do not want to hardcode the \section or \chapter commands in Latex files, but I want these to depend on the level the file is in the tree. The counter will represent the level in the tree I am starting the build from)
Is there is an easy way to do this? I am a newbie in Latex.


\def\Sect#1#2{\ifcase#1\or \part\or\chapter\or\…\fi\relax #2}? If you want to start counter from -1, you'll need to increment in before\ifcaseor do other check. – Eddy_Em Jan 30 at 5:07