0

Please can someone explain to me why I'm getting the following compiling error

LaTeX3 Error: Command '\sc' already defined!

\documentclass[10pt]{book}
  \NewDocumentCommand{\ch}{om}{
    \IfNoValueTF{#1}{
       \chapter{#2}
    }{ 
       \chapter{#2}\label{ch:#1}
          
    }
}
\NewDocumentCommand{\sc}{om}{
    \IfNoValueTF{#1}{
       \section{#2}
    }{ 
       \section{#2}\label{sc:#1}
          
    }
}

\begin{document}

\ch{AAA}
\sc{BBB}

\end{document}
5
  • 7
    Because \sc is already defined in the book class (it's the deprecated version of \scshape). You can redefine it with \RenewDocumentCommand Feb 15, 2022 at 20:40
  • 9
    P.S.: don' use these “shortcuts” for such common commands. They only seem to make your life easier, but you are actually shooting yourself on the foot. Quick example: how do you do \section*{title} or \section[short]{long} with those shortcuts? Feb 15, 2022 at 20:47
  • Thank you so much for your response
    – user547654
    Feb 15, 2022 at 20:53
  • 3
    I second @PhelypeOleinik's advice. Is there any real advantage in \sc[label]{title} over \section{title}\label{sc:label}? Maybe, but just as a far possibility, if you have over 100 sections, but you lose in generality and semantic nonetheless.
    – egreg
    Feb 15, 2022 at 20:55
  • 1
    apart from the error from \sc you are adding lots of white space tokens in these macros. Feb 15, 2022 at 21:10

1 Answer 1

3

\sc is a legacy font command based on \scshape that is used in the book class for compatibility with LaTeX2.09. You could use another name such as \Sc but beware such shorthands make it harder to use standard section features such as the * form for the unnumbered variant, and the optional argument for the table of contents version of the header.

Also as you are adding a lot of white space (in a standard context not in \ExplSyntaxOn) these space tokens can affect the output, consider

\documentclass[10pt]{book}
  \NewDocumentCommand{\ch}{om}{
    \IfNoValueTF{#1}{
       \chapter{#2}
    }{ 
       \chapter{#2}\label{ch:#1}
          
    }
}
\NewDocumentCommand{\Sc}{om}{
    \IfNoValueTF{#1}{
       \section{#2}
    }{ 
       \section{#2}\label{sc:#1}
          
    }
}

\begin{document}

\ch{AAA}


aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a
\Sc{BBB}

aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a {} {}
\section{BBB}

aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a
\section{BBB}

\end{document}

Which produces

enter image description here

Where the \Sc version is producing the heading as if the previous paragraph ended with additional space as shown in section 2 as opposed to the intended layout produced by \section in section 3.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .