4

I find a strange conflict between scrbook and dynkin-diagrams, here is the code

\documentclass{scrbook} 
\usepackage{dynkin-diagrams} 
\begin{document} 
\chapter{One}
Here is one \dynkin A2
\end{document}

An error message "Command \do undefined." is showing.

However, if I use

\documentclass{scrbook} 
\usepackage{dynkin-diagrams} 
\begin{document} 
Here is one \dynkin A2
\end{document}

Then it works.

I wonder what cause it and how to fix this bug?

3
  • In the code for \chapter, it seems scrbook is setting the definition of \do to \relax (put \meaning\do after \chapter then see what happens when you remove \chapter). The \dynkin command does \renewcommand{\do}{...} which throws an error because it expects \do to be defined.
    – mbert
    Commented May 16, 2023 at 3:50
  • I've reported an issue to KOMA-Script. In the discussion the KOMA-Script author states, that KOMA-Script's tocbasic is not the only package, that has \let\do\relax and shows an example with the same error without using KOMA-Script. So you should report the issue to the dynkin-diagrams maintainer (AFAIK to the email address in the sty file).
    – cabohah
    Commented May 16, 2023 at 7:53
  • The issue seems to be fixed with KOMA-Script 3.41.4057.
    – cabohah
    Commented May 17, 2023 at 14:46

2 Answers 2

4

The style file dynkin-diagrams.sty uses LaTeX's \renewcommand when it defines a temporary macro \do because it supposes that \do was defined already by previous macros. This is almost always a correct assumption but not when the \chapter macro from scrbook.cls is used. This macro re-defines \do and finally does \let\do=\relax. Then the following \renewcommand\do invoked from \dynkin fails.

It will be more correct if dynkin-diagrams.sty does \def\do and no \renewcommand\do, but we are not author of this macro file.

One obscure workaround should be as follows:

\documentclass{scrbook} 
\usepackage{dynkin-diagrams}
{\catcode`\@=11 \expandafter\gdef\expandafter\dynkin@save
   \expandafter{\dynkin@save \let\do=\LaTeX}} % :)
\begin{document} 
\chapter{One}
Here is one \dynkin A2
\end{document}
6
  • This is an incorrect way to cope with a command defined with \NewDocumentCommand.
    – egreg
    Commented May 16, 2023 at 15:21
  • 1
    No, this is an obscure way to modify this macro, as I mentioned in my answer :).
    – wipet
    Commented May 16, 2023 at 15:44
  • Not “obscure”, but wrong.
    – egreg
    Commented May 16, 2023 at 16:51
  • 1
    Not "wrong", but obscure.
    – wipet
    Commented May 16, 2023 at 17:28
  • 2
    Note, there is no simple correct solution, because the core of the problem is in the fact that some style files for LaTeX uses \renewcommand instead \def when they (re)define \do macro (designed by Knuth as a special temporary macro). The only correct solution is to replace all \renewcommand\do to \def\do in all LaTeX style files where is the wrong declaration.
    – wipet
    Commented May 16, 2023 at 17:37
3

UPDATE 2023-05-20

The new release of dynkin-diagrams released on 2023-05-18 has fixed the issue, by prefixing every usage of \renewcommand{\do}[1]{...} by \providecommand{\do}{}.

ORIGINAL ANSWER

For historical reasons, at the start of a document (that is, after \begin{document} is processed), \do has the meaning \noexpand.

There have been discussions about removing this “hidden feature”, but it was thought that preserving this is important, because it has been so for about 30 years and packages might use it.

And indeed do, as you discovered. If you look in the documentation of etoolbox, you'll find several examples of

\renewcommand{\do}[1]{...}

and dynkin-diagrams makes extensive usage of etoolbox for list processing. It could dispense with it, by choosing expl3 instead of mixing a few of it with etoolbox and xstrings.

As a consequence, no class or package should ever issue \let\do\relax, because, as far as \renewcommand is concerned, something equivalent to \relax is seen as undefined. Unfortunately, scrbook does it.

You can use a workaround. When starting a diagram, the package issues \dynkin@save and you can hook in it to provide a definition for \do.

\documentclass{scrbook}
\usepackage{dynkin-diagrams}

\AddToHook{cmd/dynkin@save/before}{\providecommand{\do}{}}

\begin{document}
\chapter{One}
Here is one \dynkin A2
\end{document}
3
  • The version of the dynkin-diagrams package released on 2023/05/18 fixes the issue with no need to do patches.
    – egreg
    Commented May 20, 2023 at 19:59
  • Is expl3 preferable to etoolbox for list processing? Is xstrings a bad idea for a package to handle input strings? Commented May 24, 2023 at 9:56
  • @BenjaminMcKay Definitely, I'd say.
    – egreg
    Commented May 24, 2023 at 10:13

You must log in to answer this question.

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