27

Since 2015, \( \), \begin{math} etc. have been made robust. Aside from user-generated commands not created with \DeclareRobustCommand and out-of-date packages, are fragile commands still a thing in LaTeX these days? In other words, can I delete that section from my book for LaTeX users (not programmers)? (Discussing this in a later book for people programming LaTeX is a whole other thing.)

Bernard
  • 271,350
Don Hosek
  • 14,078

2 Answers2

18

Well not completely gone, but you have to try a lot harder to find a case, and if it's a really plausible case quite possibly we'd accept an enhancement request to make the command robust.

For example \begin has been robust (only since 2019, not 2015) so \begin{tabular} is robust, as is \\ (from 2015) but \cline is not, compare these two \typeout

\documentclass{article}

\begin{document}

\typeout{ \begin{tabular}{cc} a&b\ \cline{1-1} c&d \end{tabular}}

\typeout{ \begin{tabular}{cc} a&b\ \protect\cline{1-1} c&d \end{tabular}}

\end{document}

producing

 \begin {tabular}{cc} a&b\\ \omit \@multicnt 1\advance \@multicnt \m@ne \relax 
\def \iterate {}\iterate \let \iterate \relax \@multicnt 1\advance \@multicnt -
1\advance \@multicnt \@ne \relax \def \iterate {}\iterate \let \iterate \relax 
\leaders \hrule height\arrayrulewidth \hfill \cr \noalign {\vskip -\arrayrulewi
dth } c&d \end {tabular}

and

 \begin {tabular}{cc} a&b\\ \cline{1-1} c&d \end {tabular}

Of course \typeout here could be replaced by any command with moving argument such as caption or section hesdings.

David Carlisle
  • 757,742
  • 1
    Is there any reason why \cline hasn't been made robust? – Don Hosek Mar 23 '21 at 21:48
  • 2
    And I will add, that LaTeX's robustness strategy has broken my old-school debugging strategies for LaTeX. I used to use \texttt{\meaning\foo} liberally to see what the current definition of macros was in troublesome documents and now a lot of those troublesome macros won't talk to me. – Don Hosek Mar 23 '21 at 21:50
  • 8
    @DonHosek that's why we added \ShowCommand :-) – David Carlisle Mar 23 '21 at 21:51
  • 6
    @DonHosek no no reason I just found it by reverse engineering an example by flicking through latex.ltx looking for a plausible combination. actually there is a possible reason ( \protect\cline<space> won't work if \protect is \relax as it will mess up the \halign \omit. Internally it could be made robust in other ways though... – David Carlisle Mar 23 '21 at 21:55
  • Another example: ~ is expandable, it expands to \nobreakspace{} where \nobreakspace is robust -- although this is intentional according to texdoc source2e. – user202729 Dec 22 '22 at 06:16
6

There are still a number of kernel commands that have not been touched for one or the other reason but as David said, for most of them it is difficult to construct meaningful use cases where robustness matters in real life.

The situation is different though for major packages, e.g., amsmath, where many commands are still fragile but shouldn't really. But cleaning that up is rather difficult and the loose ends ended up as a task with rather low priority.

The current status can be found in the test file for github issues 123, e.g. amsmath robustness status and base LaTeX robustness status for those interested in the nitty gritty details. (You may have to also read the corresponding input file (.lvt) to make sense of some of the output).

  • Ooh, the AMS math stuff is a challenge since I'm covering a lot of "extended" stuff as part of the core material. I can still delete my fragile commands section, I think, but I will need to add a sidebar to cover the symbols that are dangerous. – Don Hosek Mar 31 '21 at 01:47