13

I'm in the process of transcribing an old French engineering text (circa 1890) that uses a somewhat non-standard section numbering. As I am attempting to make a more-or-less verbatim copy, it is important to me that I keep the structure of the new document the same as the original.

The general section numbering uses a numeric sequence (1, 2, 3, etc.). However, there are some sections that were inserted last-minute prior to printing, so the typesetter at the time (I assume) used the Latin suffixes "bis" and "ter" for inserting the new sections (1 bis, 1 ter, etc.) in lieu of renumbering the entire text. Please note that the suffixes are also in italics.

I've found Questions where the user asked about adding alpha characters to the end of numeric section numbers, but this isn't quite applicable.

Since the section numbering is pretty much set, I could manually adjust the few sections where this is needed. However, I would like to learn the TeX workaround for future reference and to get to know the program better.

Please see the MWE below for an example of my code that uses manual section numbering. This gives the desired result but does not have the automatic section numbering which is a major feature of TeX. I'd like to duplicate this result using some sort of automatic sectioning scheme.

\documentclass{book}

\usepackage{titlesec}
\titleformat{\section}[block]{\normalfont\large\normalfont\filcenter}{\thesection. ---}{0.5em}{}
\renewcommand\thesection{\arabic{section}}
\usepackage{lipsum}

\begin{document}

\tableofcontents

\section{First Section Header}
\lipsum[1]

\section{Second Section Header}
\lipsum[2]

\section*{2 \textit{bis}. --- Third Section Header}\addcontentsline{toc}{section}{2 \textit{bis}    Third Section Header}
\lipsum[3]

\section{Fourth Section Header}
\lipsum[4]

\end{document}

Rendering below.

Working example with Manual Numbering

grfrazee
  • 969
  • In your screenshot, the additions are not in italics –  Jul 07 '15 at 15:47
  • Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jul 07 '15 at 15:55
  • I have updated the original post with your requests. Apologies, I'm new here. – grfrazee Jul 07 '15 at 18:03

2 Answers2

8

Here's a semiautomatic version, where you have to add the suffix by hand.

\documentclass{article}

\makeatletter
\newcommand{\numpar}[1][]{%
  \par\addvspace{\medskipamount}%
  \if\relax\detokenize{#1}\relax
    \refstepcounter{numpar}%
    \def\thisnumpar{\thenumpar}%
  \else
    \edef\@currentlabel{\thenumpar\noexpand~#1}%
    \def\thisnumpar{\thenumpar~#1}%
  \fi
  \everypar{\thisnumpar.\hspace{\parindent}\everypar{}}%
}
\makeatother
\newcounter{numpar}


\begin{document}

\numpar This is the first paragraph. Let's make it longer
so it wraps. Maybe this suffices, but just in case we
add some more words.

\numpar[bis]\label{1bis} This has been added. Let's make it longer
so it wraps. Maybe this suffices, but just in case we
add some more words.

\numpar[ter] This also has been added and refers to the previous one~\ref{1bis}.
Let's make it longer so it wraps. Maybe this suffices, but just in case we
add some more words.

\numpar This is numbered normally and refers to the previous one~\ref{1bis}.
Let's make it longer so it wraps. Maybe this suffices, but just in case we
add some more words.

\end{document}

The trick with \everypar allows not to worry about spaces after \label.

enter image description here

egreg
  • 1,121,712
  • This is almost getting me there. Please see the updates to the original post with a code snippet and rendered output.

    I will need the section numbering to show up in the TOC as well.

    – grfrazee Jul 07 '15 at 18:01
4

Original solution Here is a solution using enumitem and enumerate environments.

Not sure wether it's really what you asked for, since you mentioned a numbering of sections.

However, with this solution, all your regularly numbered items must be in a (first level) enumerate environment, and when you need bis, ter, etc, then you can use a nested enumerate environment. Keep in mind that the first \item of this environment will be numbered bis, the second will be numbered ter, etc

\documentclass{article}
\usepackage{xparse}
\usepackage{enumitem}

\ExplSyntaxOn \seq_new:N \bislist \seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies} \NewDocumentCommand {\bisprint} {m} { \seq_item:Nn \bislist {#1} } \ExplSyntaxOff

\setlist[enumerate,1]{leftmargin=0pt,labelwidth=!,label=\arabic*.,align=left} \setlist[enumerate,2]{leftmargin=0pt,labelwidth=!,label=\arabic{enumi} \bisprint{\arabic{enumii}}.,align=left}

\begin{document} \begin{enumerate} \item First item \item Second item \begin{enumerate} \item First bis item \item First ter item \end{enumerate} \end{enumerate}

\end{document}

Which produces this kind of results : enter image description here

Maybe, another option to avoid conflicts with other nested enumerate environments would be to create a bis environment this way :

\documentclass{article}
\usepackage{xparse}
\usepackage{enumitem}

\ExplSyntaxOn \seq_new:N \bislist \seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies} \NewDocumentCommand {\bisprint} {m} { \seq_item:Nn \bislist {#1} } \ExplSyntaxOff

\setlist[enumerate,1]{leftmargin=0pt,labelwidth=!,label=\arabic*.,align=left}

\newlist{bis}{enumerate}{1} \setlist[bis]{leftmargin=0pt,labelwidth=!,label=\arabic{enumi} \bisprint{\arabic{bisi}}.,align=left}

\begin{document} \begin{enumerate} \item First item \item Second item \begin{bis} \item First bis item \item First ter item \end{bis} \end{enumerate}

\end{document}

This produces the exact same result than the previous code.

Note that if you have 10 or more items in the bis environment, then the numbering will fail (essentially because I have no idea of what follows decies). But I hope your original text does not need to go that far ;-) (however, it seems that certain french laws use decies, and maybe the few next ones...)

Edit : solution working with \section

Here is a solution using \section and \section*. Caution : by redefining these two commands, you will not be able to use them for anything else in the rest of your document (I think you were aware of this, but just in case, now it's clear).

The idea here is to use \section{} to begin a regularly numbered section, and \section*{} for a bis numbered section.

\documentclass{article}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\ExplSyntaxOn \seq_new:N \bislist \seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies} \NewDocumentCommand {\bisprint} {m} { \seq_item:Nn \bislist {#1} } \ExplSyntaxOff

\newcounter{bis} \stepcounter{bis} \titleformat{\section}[runin]{\normalfont}{\arabic{section}.}{0pt}{}[\setcounter{bis}{1}] \titleformat{name=\section,numberless}[runin]{\normalfont}{\arabic{section} \bisprint{\arabic{bis}}.}{0pt}{}[\stepcounter{bis}] \titlespacing{\section}{\parindent}{\baselineskip}{\parindent}{}

\begin{document}

\section{} \lipsum[1] \section{} \lipsum[2] \section{} \lipsum[3] \section{} \lipsum[4] \section{} \lipsum[5] \section{} \lipsum[6] \section{} \lipsum[7] \section{} \lipsum[8]

\end{document}

If the formatting is not exactly the one you wanted, you can change the parameters of \titleformat and \titlespacing (for example, changing \normalfont to \bfseries will produce bolded numbers).

Update : with the table of contents Here is a last update with the \section* appearing in the table of contents (and this time using book document class as you wanted and with the title formatting you were using in your MWE).

\documentclass{book}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{totcount}

\ExplSyntaxOn \seq_new:N \bislist \seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies}

\NewDocumentCommand {\bisprint} {m} { \seq_item:Nn \bislist {#1} } \ExplSyntaxOff

\newtotcounter{bismax} \newcounter{bis} \stepcounter{bis} \setcounter{bismax}{1}

\newcommand{\bisadd}{\stepcounter{bis} \setcounter{bismax}{\minof{4}{\maxof{\thebismax}{\thebis-1}}}}

\AtBeginDocument{\newlength{\bislength} \settowidth{\bislength}{\textit{\bisprint{\totvalue{bismax}}}} \addtolength{\bislength}{1.5em}}

\titleformat{\section}[block]{\normalfont\large\normalfont\filcenter}{\thesection. --- #1}{0.5em}{}[\setcounter{bis}{1}]

\renewcommand\thesection{\arabic{section}}

\titleformat{name=\section,numberless}[block]{\normalfont\large\normalfont\filcenter}{\arabic{section} \textit{\bisprint{\arabic{bis}}}. --- #1}{0.5em}{}[ \addcontentsline{toc}{section}{\protect\numberline{\arabic{section} \textit{\bisprint{\arabic{bis}}}}#1} \bisadd{}]

\makeatletter \renewcommand*\l@section{@dottedtocline{1}{1.5em}{\bislength}} \makeatother

\begin{document}

\tableofcontents

\section{First section header} \lipsum[1] \section{Second section header} \lipsum[2] \section{Third section header} \lipsum[3] \section{Fourth section header} \lipsum[4] \section{Fifth section header} \lipsum[5] \section{Sixth section header} \lipsum[6] \section{Seventh section header} \lipsum[7] \section*{Eighth section header} \lipsum[8]

\end{document}

The space between the numbers and the section titles in ToC is now automatically computed so that it is enough to display the longest "bis number" (i.e. the space will be smaller if you just have to print bis or ter than if you need to print quiquies). You can enlarge or reduce this space by changing the value currently set to 1.5em.

mvienney
  • 986
  • I appreciate the response, but this does not appear to work with Section numbering. I've tried a couple ways to modify your syntax for Sections, but to no avail. – grfrazee Jul 08 '15 at 15:24
  • OK, maybe it can be useful for someone else later ;-) – mvienney Jul 08 '15 at 16:11
  • @grfrazee : I updated my answer, tell me if it's what you were expecting. – mvienney Jul 09 '15 at 07:35
  • Maybe this solution is not compatible with the TOC, but we can work on it ! – mvienney Jul 09 '15 at 09:06
  • When I put the comment \tableofcontents into the document to generate the TOC, I get a weird artifact at the beginning of the TOC. Also, I haven't been able to figure out how to get the TOC to populate with the "bis" numbered sections without using the \addcontentsline command, followed by manually entering the section number. This kind of defeats the purpose of the automatic numbering :-/ Any ideas? – grfrazee Jul 13 '15 at 17:46
  • I updated my code so that the bis sections appear in the toc. It's not clear in your question wether or not you want to give a title to your sections, so I assume you do not. – mvienney Jul 15 '15 at 07:25
  • I updated the Question to hopefully clarify exactly what I'm looking for. Sorry I wasn't as clear the first time - I'm quickly finding out that one has to state exactly what one is looking for to get the best Answer. – grfrazee Jul 15 '15 at 13:49
  • Your latest edit is so close to being exactly it, all I'm missing is the italicized "bis." I can't for the life of me figure out where to edit your code to accomplish that. – grfrazee Jul 15 '15 at 13:56
  • I updater my answer (probably for the last time), and we are almost there, there is still a little alignment problem, but I do not know how to fix this right now and will ask this in a separate question. – mvienney Jul 15 '15 at 14:36
  • This is it! Now I just need to figure out why it errors out when I paste the syntax into my document (works fine just copy/pasting into a new document). – grfrazee Jul 15 '15 at 15:07
  • Last (minor update) : the spacing problem is now solved, an I used totcount package to automatically set the length in ToC, so that you don't need anymore to specify what is the maximum "bis numer" you are using. – mvienney Jul 17 '15 at 05:45