I am trying to typeset a exam subject with the same numbering as this document by Concours CentraleSupélec.
Sections are numbered with Roman, subsections are numbered with Alph and questions are numbered within each subsection with arabic : that is, question number 2 within subsection A of section I has number I.A.2.
I know how to do this with ntheorem and KOMA scrartcl : it suffices to do
\renewcommand\thesection{\Roman{section}}
\renewcommand\thesubsection{\thesection.\Alph{subsection}}
\newtheorem{question}{Question}[subsection]
And this works.
However, not all sections have subsections. In this case, questions are numbered within the section and with Alph, not arabic. So the third question in a section IV that does not have subsections is numbered IV.C, not IV..3.
I know I can do
\theoremnumbering{Alph}
\renewtheorem{question}{Question}[section]
I am trying to automate this. Clearly, it is not possible, when encountering a new section, to know whether there will be a subsection or not, so one has to change the numbering at each section and again at each subsection (or at least each first subsection within a section).
I could not find a AtBeginSection
or AtBeginSubsection
in the KOMA-script manual. Is there some hook that I can use to execute some code at each section/subsection without hacking the whole thing ?
\AtBeginSection
and\AtBeginSubsection
arebeamer
commands, I don't know whether there is a package that does provide them to KOMA. Though one could useetoolbox
's\pretocmd
(as I did) or\apptocmd
.