4

What is the primary reason to \protect new definitions or macros, or use \DeclareRobustCommand rather than just \def? (If it is primarily to do with better error messages, I personally can live with the Prolog ``No''. If it's better to start using it everywhere, which are the packages to load and best practices?)

WANTED: A one sentence answer I can give other people about why \DeclareRobustCommand is used somewhere but elsewhere there is \def.

MOTIVATION: Sometimes you base code on an existing macro and put in an article. \DeclareRobustCommand is sometimes used. Then a coauthor or an editor replies: Why do you need this complicated looking code? What do you tell them?

  • 3
  • 1
    \DeclareRobustCommand is defined in the latex format, not in a package. It's not the difference between good and bad error messages, but rather the difference between things working and getting an error message. But I think it's probably a duplicate of the questions Werner lists – David Carlisle Mar 05 '16 at 09:17
  • 3
    If you do not define a command to be robust then the user has to use \protect in front of the command in all moving arguments such as headings captions, writing to files etc, so the command is more complicated for the user. – David Carlisle Mar 05 '16 at 09:22
  • D.C., your last comment answers the question. Can you post it as an answer so I can checkmark it, closing the question? This was ultimately what I was looking for: a one sentence answer I can give other people about why \DeclareRobustCommand is used somewhere but elsewhere \def is used. – Gottfried William Mar 05 '16 at 14:18
  • By the way, if I'm a journal copy editor, I'd reject any document using \def, asking to use \newcommand or similar method; this includes \DeclareRobustCommand, but only if preceded by a \newcommand for checking definability of the command (unless comments explain why the author wants to redefine a command). – egreg Mar 05 '16 at 14:28
  • BTW, any reason to use something from the etoolbox package if working with robust commands? – Gottfried William Mar 05 '16 at 14:41
  • And I'd reject any document using \newcommand, asking to use \def or similar method. Because \newcommand doesn't work in plain TeX. – wipet Mar 05 '16 at 15:16
  • 2
    @GuidoJorg: If you use etoolbox you can apply \robustify\mycommand and it will be robust after that. –  Mar 06 '16 at 07:46

1 Answers1

3

`` If you do not define a command to be robust then the user has to use \protect in front of the command in all moving arguments such as headings captions, writing to files etc, so the command is more complicated for the user. – David Carlisle Mar 5 at 9:22''

This was ultimately what I was looking for: a one sentence answer I can give other people about why \DeclareRobustCommand is used somewhere.