I'm working on a package to simplify writing my homework and assignments. Unfortunately, not all of my professors assign problem sets with sequential numbering. Thus, I'd like to optionally be able to manually override the automatic numbering of sections.
My goals:
A syntax that resembles
\section[12(e)]{Fermat's Last Theorem}
, where the custom number is in brackets. I'm imagining that I'd ignore the normal section counters and simply define my own macro to contain the manually specified number. In the absence of an optional argument, this macro would simply mirror\thesection
.The ability to reference my custom number in headings and footers. I'd like to say something like "Question 12(e) continued on next page…" instead of referencing the whole section name.
And, finally, I want to have all of this work in a table of contents and the hyperref package.
Is this possible? Has it been done already? I'm not tied down to a particular document class; I've attempted hacking this onto both article
and Memoir's article mode.
This gets me close:
\documentclass[article]{memoir}
\newcommand*{\theproblem}{}
\renewcommand*{\cftchaptername}{Problem\space}
\renewcommand*{\chaptername}{Problem\space}
\setcounter{tocdepth}{2}
\newcommand*{\problem}[2][\thechapter]{%
\addtocounter{chapter}{1}
\setcounter{section}{0}
\phantomsection
\addcontentsline{toc}{chapter}{\numberline {\cftchaptername#1}#2}
\chapter*{\chaptername#1\quad#2}
\renewcommand*{\theproblem}{#1}
}
\newcommand*{\subproblem}[2][\thesection]{%
\addtocounter{section}{1}
\phantomsection
\addcontentsline{toc}{section}{\numberline {#1}#2}
\section*{#1\quad#2}
\renewcommand*{\theproblem}{#1}
}
Unfortunately, it doesn't account for longer-than-anticipated numbers in the table of contents. Also, I initially started trying to directly redefine \chapter
and \section
; this is definitely not necessary, but it would be quite nice (and now I'm curious if it could be possible). And, finally, this is my first bit of package hacking, so I'm not entirely confident I'm doing things in a reasonable manner.