4

I was recently required by a journal to getting rid of \def in the definitions of my personal macros. It turns out to be not-so-easy and the naive replacement of \def by \newcommand does not always work. Is there a standard way of doing that?

Let me give two examples:

(1) \def\res{\texttt{Res}\left(#1\right)} I cannot replace def by newcommand

(2) \def\io{\infty} I can replace def by newcommand

8
  • 5
    I think your question will be improved if you show one or a few of the ones you have difficulties with.
    – mickep
    Jan 22 at 20:24
  • 2
    You can insert \expandafter\let \expandafter\getridofdef \csname def\endcsname and replace all occurrences of \def by \getridofdef. Now, Your document includes no \def at all.
    – wipet
    Jan 22 at 20:39
  • 2
    If \newcommand doesn;t work, \renewcommand should. Better uet, use another name for the macro, one that isn't alreacy being used. If you intend to change an existing definition, don't do it! Jan 22 at 21:23
  • 5
    your first example is wrong anyway (if it is a standalone definition.). Apart from this: are you sure the journal will accept \newcommand instead? Jan 22 at 21:32
  • 2
    If the document is modified by my comment above, there is no \def. I wanted to point out that the rule "no \def in the document" is absurd. Journal needs a skilled editor who know TeX well. No to give absurd rules. The example about \def\c is somewhat historical. Now, we have Unicode TeX engines, so Turkish coauthor should write “Ş” directly. If not then the editor will correct it or ask the author not to use such historical macros. LaTeX needs to free itself from the burden of history.
    – wipet
    Jan 23 at 6:54

1 Answer 1

9

In a submission there should be no \def, because the copy editors are afraid tha a user does things such as

\def\c{\gamma}

so making it impossible to typeset a paper by a Turkish coauthor whose name contained “Ş”. It really happened.

You may possibly use a few \renewcommand instructions, but mark them clearly. I'm thinking to something quite safe like

\renewcommand{\epsilon}{\varepsilon}

but you should be certain not to modify important commands.

Your definition of \res is wrong anyway, because you're using a parameter in the replacement text without announcing it. Possibly

\newcommand{\res}[1]{\operatorname{\mathtt{Res}}(#1)}

I discourage you from

\newcommand{\io}{\infty}

because the standard command is semantic, yours isn't and the gain is really not worth the pain of remembering another command.

In any case, if using \newcommand returns an error about the command being already defined, avoid switching to \renewcommand unless you precisely know what you're doing (like in the \epsilon case, but not in the \c case).

4
  • Very good explanation. Sometimes what we "can" do is not what we "should" do.
    – rallg
    Jan 22 at 22:27
  • I vaguely recall someone asking a question saying that they tried \newcommand\box, then after seeing the error message they did \renewcommand\box and wondered why everything was running havoc :-)
    – campa
    Jan 23 at 7:54
  • @campa Redefining \box or \fi are two of my favorite examples when teaching LaTeX.
    – egreg
    Jan 23 at 8:08
  • Thanks, that’s very helpful.
    – Bazin
    Jan 23 at 21:10

You must log in to answer this question.

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