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?

8
  • 3
    A good starting point: What is the difference between Fragile and Robust commands? and On pitfalls of robust commands.
    – Werner
    Commented Mar 5, 2016 at 1:35
  • 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 Commented Mar 5, 2016 at 9: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. Commented Mar 5, 2016 at 9: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. Commented Mar 5, 2016 at 14:18
  • 2
    @GuidoJorg: If you use etoolbox you can apply \robustify\mycommand and it will be robust after that.
    – user31729
    Commented Mar 6, 2016 at 7:46

1 Answer 1

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.

You must log in to answer this question.

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