If I redefine a command that has a starred variant, will this always effectively disable the starred variant, as a side effect of redefining the unstarred variant?
A related question: Do starred commands eat up space after them? (The information contained therein strongly suggests a "yes", but it'll be good to hear a confirmation from an expert.)
Notes:
- This question was meant to be generic.
- I mean the redefining act per se. That is, let's assume that I might not include a starred variant in my redefinition.
- Some examples I had in mind (for which it would actually make sense to redefine the starred version with them, unless one is short of time and doesn't need to for one's local document):
- I was thinking of redefining
\hspace
or\vspace
to be visible (for draft compilation runs). - In some earlier drafts of documents of mine,
\chapter
was redefined to contain a call to\pagestyle
.
- I was thinking of redefining
Best Answer
There are basically two ways of defining commands with a *-variant.
Traditional way
where
\@sfoo
and\@foo
may have arguments; the names are arbitrary, of course: they are two other commands. Many variations are encountered; here's an example:In the second example, the lookup for a following * is delegated to
\secdef
.In many cases,
\newcommand{\foo}{...}
is changed into\DeclareRobustCommand{\foo}{...}
to avoid problems with\foo
in moving arguments; the auxiliary macros\@sfoo
or\@foo
can be still defined with\newcommand
(or\def
, if one prefers).xparse
waywhere
...
stands for other argument types, possibly none.Redefining
If you have
\foo
defined in one of those ways, sayingwill of course remove any possibility that
\foo*
works as before, because the new\foo
doesn't check for a * following it, which is in any case the key for a *-variant to work.Thus, if you want to redefine a command with a *-variant, you should know how it was defined in the first place. In the most common case, with
\@ifstar
choosing between two different commands, just redefine the one you need, so\@foo
or\@sfoo
. The same applies for the\chapter
example, where you can work on\@schapter
or\@chapter
. It would be more difficult in the\if@tempswa
case, but one should know what the intention is.If you want to redefine
\section
, then you find yourself in a more complicated situation, then the problem is more difficult; the definition is usually in terms of\@startsection
which is the macro doing the\@ifstar
test, so the approaches outlined above don't work. In this case a simple way out is to sayand to define
\mynewsection
for the "non *" case, probably in terms of\latexsection
.Watch out, though, and always check how the command is defined: in case of doubt, the
\let
should be replaced with\LetLtxMacro
from theletltxmacro
package.Redefining
xparse
based commands should be done with\RenewDocumentCommand
and the proper argument types. Don't use\let
or\LetLtxMacro
in this case.Just for fun, here are some patches that make glue inserted with
\hspace
,\vspace
or\addvspace
"visible". However they are not guaranteed to always work and to give the same breaks.