3

As LaTeX requires eTeX now it would be much easier to replace all the definitions of robust commands with \DeclareRobustCommand[*]... by \protected[\long]\def..., wouldn't it?

Which advatages come along with the the complicated definition of \DeclareRobustCommand? It should be also mentioned that it is immpossible to find out the definition of a command defined this way by using \show or \meaning. Example: When you write \meaning\TeX you get macro:->\protect \TeX which seems to be nonsense as a command always expanding to itselt lets TeX crash. Please help me understandig this.

MWE:

\documentclass{article}

\begin{document}

% latex.ltx contains
% \DeclareRobustCommand\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
\meaning\TeX% macro:->\protect \TeX % This is useless.

\TeX

% define \TeX by \protected\def
\protected\def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
\meaning\TeX% The real definition is shown.

\TeX

\end{document}
  • 3
    On \meaning\TeX, the expansion has a command containing a space: that's the entire trick of \DeclareRobustCommand. It might look the same, but it's not. – Joseph Wright Apr 08 '20 at 12:31
  • 2
    More widely, you are asking two questions: why not use e-TeX for everything, and how does the 'classical' mechanism work – Joseph Wright Apr 08 '20 at 12:32
  • The main difference is that the definition of \protect can be changed. That means that you can get different behaviour in different contexts, see e.g. https://tex.stackexchange.com/a/161006/2388 – Ulrike Fischer Apr 08 '20 at 12:44
  • Try \expandafter\show\csname TeX\space\endcsname. Note that \DeclareRobustCommand was introduced long before LaTeX required e-TeX. This comment might be relevant: https://tex.stackexchange.com/questions/513337/expandable-test-for-an-empty-token-list-methods-performance-and-robustness#comment1298131_513337 :-) – Phelype Oleinik Apr 08 '20 at 13:44
  • Thanks @PhelypeOleinik, so there are historical reasons. – Weißer Kater Apr 08 '20 at 13:53
  • 1
    @user125730 Yes. We are moving some commands to e-TeX \protected (for example: https://github.com/latex3/latex2e/issues/203), but moving all of them would break LaTeX everywhere. Also there's the advantage that Ulrike mentioned that \protect can have different meanings, while a \protected macro has the same protection everywhere. – Phelype Oleinik Apr 08 '20 at 14:18
  • @PhelypeOleinik: But could you give an example where the protection by \protected would fail and where \DeclareRobustCommand is really necessary? – Weißer Kater Apr 08 '20 at 15:29
  • I mean "fail" in the sense that \protected\def cannot substitute \DeclareRobustCommand to get the desired result. – Weißer Kater Apr 08 '20 at 15:34
  • @user125730 One obvious problem are packages that rely on commands having their \DeclareRobustCommand meaning. Other than that, try \protected\def\end#1{\csname​ end#1​\endcsname\@checkend​{#1}\expandafter\endgroup​\if​@endpe​\@doendpe​\fi\if​@ignore​\@ignorefalse\ignorespaces​\fi​} and then use \begin{tabular}{|cc|}a&b\end{tabular}. – Phelype Oleinik Apr 08 '20 at 16:30
  • @PhelypeOleinik: OK, this is an argument, as a Plain TeX user I didn't think about packages. But when I insert your definition of \end (but without the tabular no output is produced: LaTeX Error: \begin{document} ended by \end{​}. (job aborted, no legal \end found) – Weißer Kater Apr 08 '20 at 17:25
  • 1
    @user125730 Well, there are packages for Plain. Not as many, sure, and definitely not so dependent on how the format is defined, so the impacts of a change like that are smaller. \end{}? Seems like you have a typo somewhere. Try this: \documentclass{article}\begin{document}\makeatletter\protected\def\end#1{\csname end#1\endcsname\@checkend{#1}\expandafter\endgroup\if@endpe\@doendpe\fi\if@ignore\@ignorefalse\ignorespaces\fi}\begin{tabular}{|cc|}a&b\\\end{tabular}\end{document}. Also, in my tabular example it was missing a \\. It doesn't throw an error, but the output is wrong. – Phelype Oleinik Apr 08 '20 at 19:28
  • 2

0 Answers0