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 5 '16 at 9:17
  • 2
    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 '16 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. – Guido Jorg Mar 5 '16 at 14:18
  • 2
    @GuidoJorg: If you use etoolbox you can apply \robustify\mycommand and it will be robust after that. – user31729 Mar 6 '16 at 7:46
1

`` 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.