# Controlling the numbering of section titles

Now i need to attach an endnote to the number of the beginning of section 16, and naive manipulations like \section{\endnote{$\pi=3.14$}} will make a big gap between the number 16 (which is automatically generated) and the mark of the endnote, therefore I changed it to \section*{16\endnote{$\pi=3.14$}} which consequently makes the number of the next section (which is section 17) 16. I don't want to adjust following sections' titles manually, so is there a way to attach the endnote/footnote? Or generally is there a way to control the sequence of numbering of the titles?

A minimal example

\documentclass{article}
\begin{document}
\section*{1\footnote{In this section we take $c=0$}}%This one being the title of the first section.
This is the material of the first section.
\section{}%This is the title of the supposedly second section
This is what is contained in the second section.
\end{document}

• If you want help, please provide a minimal example, meta.tex.stackexchange.com/q/228. Then we know what you are starting out from and also have something to start debugging on. – daleif Jul 11 '14 at 12:51
• Where does \endnote come from. From the equally named package? – user31729 Jul 11 '14 at 13:31
• @ChristianHupfer aye. – Wilson of Gordon Jul 12 '14 at 10:38
• @daleif Is has been done so. – Wilson of Gordon Jul 12 '14 at 10:42
• @ChristianHupfer - I think the footnote/endnote thing is a red herring: If the endnotes package is loaded, normal footnotes (i.e., those created by \footnote) are converted to endnotes automatically. The major issue seems to be the OP's attempt to attach a footnote (or endnote) marker directly to the section's number. Of course, I may not have understood the objective correctly. – Mico Jul 12 '14 at 11:19

Here's a solution, where \@seccntformat is hijacked to add an endnote marker. The endnote text is provided as a trailing optional argument to \Section.

\documentclass{article}

\usepackage{xparse,endnotes}

\NewDocumentCommand{\Section}{somo}{%
\gdef\thissectionnote{}% reinitialize
\IfValueT{#4}{\gdef\thissectionnote{#4}}% set up the endnote
\IfBooleanTF{#1}
{\section*{#3}} % starred section
{\IfNoValueTF{#2} % unstarred section
{\section{#3}} % no optional argument
{\section[#2]{#3}}% optional argument
}%
}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
\csname the#1\endcsname
\ifcsname #1@seccntformat\endcsname
\ifx\thissectionnote\@empty
\else
\unexpanded{\makebox[0pt][l]{\endnotemark}}%
\noexpand\endnotetext{\unexpanded\expandafter{\thissectionnote}}%
\fi
\fi
}
\def\section@seccntformat{}
\makeatother

\begin{document}

\Section{A title}

This is a normal section

\Section{Another title}[In this section we take $c=0$]

This section has an endnote.

\Section[Short title]{Long title}

This is another section.

\theendnotes

\end{document}


If you need to use \section because the text is automatically generated, you can save the meaning of \section: just the part with \NewDocumentCommand needs a change.

\let\latexsection\section
\RenewDocumentCommand{\section}{somo}{%
\gdef\thissectionnote{}% reinitialize
\IfValueT{#4}{\gdef\thissectionnote{#4}}% set up the endnote
\IfBooleanTF{#1}
{\latexsection*{#3}} % starred section
{\IfNoValueTF{#2} % unstarred section
{\latexsection{#3}} % no optional argument
{\latexsection[#2]{#3}}% optional argument
}%
}

• I have an idea: \phantom{\section}. If we can start a section whose title does not appear but the number counts, the next section's number will automatically be adjusted at the right place, and it works. But the cmd gives error message (albeit that it works) – Wilson of Gordon Jul 15 '14 at 9:31
• @WilsonofGordon I have added the workaround for being able to use \section instead of a new command. – egreg Jul 15 '14 at 9:31
• (continue) the error message reads – Wilson of Gordon Jul 15 '14 at 9:32
• ! Missing } inserted. <inserted text> } l.4 \phantom{\section} ? ! Too many }'s. \makeph@nt ...color@begingroup #1\color@endgroup } \finph@nt l.4 \phantom{\section} ? [1 – Wilson of Gordon Jul 15 '14 at 9:32
• Thanks for the lengthy response, but I feel myself failed to understand it. What is the package xparse for? – Wilson of Gordon Jul 15 '14 at 9:41