What is needed to make a new sectioning command which outputs a correct entry in the TOC?
For example, a command \foo
which outputs something similar to \subsection
in the TOC (and in the main document). After a few trial and error, I thought that just copying the definition of \subsection
and defining the needed commands (the foo
counter, \thefoo
command, \addfootocentry
, \foomarkformat
, \foomark
). But it seems that it's not enough.
Here is a minimal (non) working example.
\documentclass[DIV12]{scrartcl}
\makeatletter
\newcommand*{\foonumdepth}{\tw@}
\newcounter{foo}[section]
\renewcommand*{\thefoo}{\thesection.\@arabic\c@foo}
\newcommand*\foomarkformat{\thefoo\autodot\enskip}
\newcommand*{\addfootocentry}[2]{%
\addtocentrydefault{foo}{#1}{#2}%
}
\newcommand\foomark[1]{\markright{#1}}
\newkomafont{foo}{\normalfont\normalsize}
\newcommand\foo{%
\@startsection{foo}%
{\foonumdepth}%
{\z@}%
{-\baselineskip}%
{\baselineskip}%
{\ifnum \scr@compatibility>\@nameuse{scr@[email protected]}\relax
\setlength{\parfillskip}{\z@ plus 1fil}\fi
\raggedsection\normalfont\sectfont\nobreak\size@subsection\usekomafont{foo}}%
}
%\def\foo#1{}
\makeatother
\begin{document}
\tableofcontents
\noindent\hrulefill
\section{One}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\subsection{SubOne}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\foo{FooOne}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\subsection{Two}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
More and more
Added: I think this belongs to the same question, because it's, in a way, what I'm trying to achieve: how can I create a sectioning command \@startsection
named section
but on a different level (If I change \sectionlevel
command… I still get the same output in the table of contents: it's like this command does not influence in anything).
And this is probably a different question… but is there a way to tell KOMA-Script that I want to include in the TOC only the levels until \subsection
unnumbered (\setcounter{secnumdepth}{2}\setcounter{tocdepth}{2}
) but I want, e.g., numbered \subsubsection
s (which are not in the TOC)?
EDIT
I'm not sure if this needs to be clarified… but I'm thinking that this might be an XY Problem. I came across this question because I'm writting a document where are certain points which I need to address:
- I want to make a document which has four sectioning levels. Part, Foo (and Bar), Section and Subsection.
- As you see, the second level has two different commands. Each Foo or Bar, has it's own Sections or Subsections (i.e., they restart the counter).
- Part, and Foo and Bar, should not be numbered. And Section and Subsection should be numbered.
- Moreover, Part should add a line to the TOC with the style of the default
\section
(I thought that just changing the\@startsection{…}{\@ne}…
would suffice, but It seems not), and Foo/Bar should add a line to the TOC with the style of the default\subsection
.
Of course, I can address this with what I consider “hackish”. And I came trough this question. E.g., is it possible to create a parallel sectioning command to \subsection
which behaves correctly? How can I make it?
foo
section level supposed to do so differently compared tosubsection
? And the numbering of sections/subsections shall be turned off in TOC only, not in the rest of the document?\section
and\subsection
). And then I would redefine\section
and\subsection
to be numbered but in a deeper level so they don't add anything to the TOC.