5

I'm trying to redefine \rule to make cleaner underscores, but my book file (in memoir class) is having problems with the following:

\RequirePackage{letltxmacro}
\LetLtxMacro{\oldrule}{\rule}
\renewcommand{\rule}[1]{\oldrule[0pt]{#1}{0.4pt}}

I get an "undefined control sequence" on \LetLtxMacro{\oldrule}{\rule}.

Marco Daniel
  • 95,681
jamaicanworm
  • 29,114
  • 5
    It's a very bad idea to redefine an important command of LaTeX, which is used in many places with a different syntax. – egreg Dec 02 '11 at 20:29
  • 1
    It was suggested to me here: [http://tex.stackexchange.com/a/36922/9757]. If there's a better way of doing this, though, that would be helpful too. Thanks! – jamaicanworm Dec 02 '11 at 20:30
  • 2
    The suggestion was bad. You won't be able to typeset footnotes, for example. Why not defining a command as I suggested you? \newcommand{\blank}[1]{\rule{#1}{0.4pt}} – egreg Dec 02 '11 at 20:36
  • 1
    @egreg: Note that in my answer to @ jamaicanworm's question there was no mention of using memoir. Moreover, the example given had no mention of the scope. Using something else (like your suggestion) would work fine. – Werner Dec 02 '11 at 20:38
  • 2
    @Werner It doesn't matter much what class is being used: don't ever advise to redefine kernel commands other than those that simply produce text; for instance \let\phi\varphi is OK, but redefining \parbox would be disastrous. – egreg Dec 02 '11 at 20:42
  • 1
    @egreg: Kernel commands, got it. – Werner Dec 02 '11 at 20:44
  • \newcommand{\blank}[1]{\rule{#1}{0.4pt}} works great. Thanks! – jamaicanworm Dec 02 '11 at 20:48

1 Answers1

9

The purpose of \newcommand in LaTeX is exactly to protect users from redefining a command that can be very important for the system.

For instance, if one tries to redefine \fi, all sorts of strange things will happen, starting from LaTeX throwing an error when finding \begin{document} and telling

Missing \begin{document}.

Really. :)

The command \rule is used in the LaTeX kernel when typesetting footnotes and redefining it will break the feature. Classes and packages may use \rule as well: it appears 14 times in memoir.cls.

In some cases it's good to redefine also kernel commands; Heiko Oberdiek's packages do it frequently and for this the package letltxmacro has been devised. However users should know precisely what they're doing, and never change the command syntax (the number and nature of arguments).

It's quite strange that you get an error, because your code works for me. However, don't use it. Rather define a personal command such as

\newcommand{\blank}[1]{\rule{#1}{0.4pt}}

You'll have only benefits from this: you give semantic value to your code.

Werner
  • 603,163
egreg
  • 1,121,712