2

I am now writing a file with many section, subsection, subsubsections. I wish to declare a new shorthand for this.


Perhaps something like: \s, \ss, \sss for section, subsection, susubsection, and with an n for the *-versions.

For example

  • \sssn{} = \subsubsection*{}
  • \ss{}= \subsection{}

How does one go about setting this?

2
  • Are you familiar with LaTeX's \newcommand macro?
    – Mico
    Commented Jul 3, 2020 at 4:48
  • 1
    To solve quickly: \let\foo\section , \let\bah\subsection, etc., but be completely sure that \foo and \bah are not already defined as \par or \emph, or the result could be amusing.
    – Fran
    Commented Jul 3, 2020 at 4:49

1 Answer 1

2

I can think of two distinct approaches to achieving your objective.

First, you could issue a number of \newcommand directives to create macros called \s, \ss, \sss, and their "starred" counterparts \sn, \ssn, and \sssn:

% Must un-define "\ss" first:
\let\ss\relax
% The unstarred commands take one optional argument:
\newcommand\s[2][]{\section[#1]{#2}}
\newcommand\ss[2][]{\subsection[#1]{#2}}
\newcommand\sss[2][]{\subsubsection[#1]{#2}}
% The starred commands take a single, mandatory argument:
\newcommand\sn[1]{\section*{#1}}
\newcommand\ssn[1]{\subsection*{#1}}
\newcommand\sssn[1]{\subsubsection*{#1}}

to write things like \s[abbr form]{full form} and \ssn{full form}.

Second, you could pursue an abbreviated setup via TeX's \let primitive:

% Must un-define "\ss" first:
\let\ss\relax
% Using TeX's "\let" primitive:
\let\s\section
\let\ss\subsection
\let\sss\subsubsection

to write things such as \s[abbr form]{full form} and \ss*{full form}.

Either way, it's essential to undefine an existing macro called \ss. If you have reason to believe that you may need to typeset the character ß in your document and don't have way to enter it directly on your keyboard, you should definitely save the default meaning of \ss via, say, \let\ssorig\ss before undefining it.

You must log in to answer this question.

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