# How to redefine the section symbol (§)?

I'm trying to redefine the section symbol (§) so that it automatically places a space after it. When inserting the symbol in text, I typically write \S{} Section Number which gets me the spacing between the § and the Section Number that I'm after. Since I do this every single time I figured I'd just redefine the command.

Here is my attempt:

\documentclass[12pt]{article}

\let\OldS\S
\renewcommand{\S}{\OldS{}}

\begin{document}

\S 13

\OldS 13

\S{} 13

\OldS{} 13

\end{document}


Unfortunately, it doesn't seem that I've changed the behavior of \S at all--- both \S and \OldS seem to behave identically.

Why doesn't my attempt produce the desired space between \S and the following text and how can I fix it?

-
Perhaps you want \renewcommand{\S}{\OldS\ }? –  Gonzalo Medina Feb 19 at 19:31
Possible duplicate: No space following macro without argument. You can use xspace, but also read Drawbacks of xspace. –  Werner Feb 19 at 19:31
@GonzaloMedina Works perfectly! If you turn that into an answer (maybe with a short explanation of why that works and my attempt doesn't, if possible) I'd be happy to accept so you get the credit. –  Dennis Feb 19 at 19:34
My guess is that the extra backslah stops the extra space at the end from being gobbled? –  Dennis Feb 19 at 19:35
@Dennis: If you mostly use \S with a space, you can use it as such and add \unskip wherever you want to remove the space (as in \S\unskip). If you mostly use \S without a space, then you can add the space manually. As a novice, I would suggest using xspace and see if it suits your needs. –  Werner Feb 19 at 19:43
show 3 more comments

The command \S is defined with \DeclareRobustCommand, so redefining it with \renewcommand is not the best strategy, see When to use \LetLtxMacro?

If you really want a space after \S (which is not usual, I should say), it's better to act at a lower level.

The kernel definition of \S is

% latex.ltx, line 1798:
\DeclareRobustCommand{\S}{\ifmmode\mathsection\else\textsection\fi}


so a better strategy would be

\usepackage{xspace}

\let\S\relax % to avoid spurious warnings
\DeclareRobustCommand{\S}{%
\ifmmode
\mathsection
\else
\textsection~%
\fi
}


You surely don't want a line break after §, do you? So ~ is necessary. Using \xspace doesn't guarantee that a line break is not taken at the space.

Note. With

\let\OldS\S
\renewcommand{\S}{\OldS\ }


an \S command that ends up in a caption or other moving argument will result in two spaces. Why?

When LaTeX writes in the .aux file a command \S 1 appearing in a figure caption, it will write

\protect \S \ 1

because the expansion of \OldS is still \protect\S. The same would be written out in the .lof file. When the .lof file is read in, \protect will be ignored, and \S will be interpreted normally as \OldS\; this means two spaces, because the following \ would still be there.

For having “double §”, you can do

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\NS}{%
\textsection\@ifnextchar\NS{}{~}%
}
\makeatother

\begin{document}

\NS 1 and \NS\NS 2--3

\end{document}


reserving \S for the cases where you don't want a space (I can't see when, though).

However, I believe that the simplest way is to type

\S~1 and \S\S~2--3

-
Your answers always teach me something new and interesting about how LaTeX does its magic. Thanks! –  Dennis Feb 19 at 21:17
Very instructive. In Norwegian statutes, every clause starts with a §, and when we refer to two or more clauses, we write §§, i.e. see §§ 5, 6 and 8. Is there a simple way to have the macro to check if the next character is a §, and in case not insert the hard space. Actually, a nice feature for your macro would be the possibility to define an exception list, like xspace does. –  Sveinung Feb 19 at 21:55
@Sveinung Kind of off-topic, but do you know if the use of §§ is idiosyncratic to Norwegian conventions? It reminds me of the convention to use pp. instead of p. when citing multiple pages, so now I'm thinking I might be citing multiple sections incorrectly. –  Dennis Feb 19 at 22:26
@Dennis: I don’t think it’s just a Norwegian thing. I’ve seen it in quite a few style guides (a mix of American and European ones, iirc). –  alexwlchan Feb 19 at 22:49
@Dennis I have seen it in Danish legal literature (Norway and Denmark was a union for 400 years) and German legal literature. I am not sure, but due to German influence om Danish and Norwegian jurisprudence, I would assume that this notation stems from German tradition, and may be Roman law. But I am not sure. –  Sveinung Feb 21 at 7:55

How about using the xspace package:

\documentclass[12pt]{article}
\usepackage{xspace}

\let\OldS\S
\renewcommand{\S}{\OldS\xspace}

\begin{document}

\S 13

\OldS 13

\S{} 13

\OldS{} 13

\end{document}


The advantage is that if you ever want to typeset \S before a full stop or comma, xspace automatically omits the additional space.

-
Ah, great! I was just about to ask why I would use xspace instead of Gonzalo's solution of \renewcommand{\S}{\OldS\ }, but you beat me to it! –  Dennis Feb 19 at 19:36
Won't this suppress the space if the § is followed by a punctuation mark? –  Mico Feb 19 at 19:38
Yes, that's the job of xspace. Normally if you define a command with a trailing space you get the space also in front of a full stop. Using the \xspace command the space is suppressed in front of sentence-closing symbols. –  Uwe Ziegenhagen Feb 19 at 19:42