4

Consider the following MWE:

\documentclass{article}

\usepackage{amsmath} \renewcommand{\d}{\text{d}} \usepackage{hyperref}

\begin{document}

$\d x$

$\text{d} x$

\end{document}

If hyperref is loaded after the redefinition of \d, then the first expression is rendered as an upright x with a dot below, just as if the macro had not been redefined. Additionally, I get the warning

LaTeX Warning: Command \d invalid in math mode on input line 12.

On the other hand, if I do not load hyperref or load it before the redefinition of \d, everything works as expected.

Why does this happen?

  • 2
    well if you redefine existing commands lots of curious things can happen. Are you absolutely sure that none of the other commands and inputs you will use in your document will rely on \d as it is meant to be? – Ulrike Fischer Aug 21 '20 at 09:49
  • It seems that \a is also predefined but redefining it \renewcommand{\a}{\text{a}} does not makes any error!!! –  Aug 21 '20 at 10:39
  • 2
    Unrelated: using \text{d} to make an upright d is wrong, (1) it is a text d not math d, (2) it will be italic if the text outside of math is italic. Use \mathrm{d} instead. – daleif Aug 21 '20 at 10:53
  • Redefining short commands is very dangerous. When you'll be citing some Indian or Arabic author, you'll know why. Don't do it. – egreg Aug 21 '20 at 10:55
  • 1
    On page 49 of hyperref manual, there is a command \DeclareTextCompositeCommand{\d}{PU}{a}{\9036\241} that produce 1EA1;LATIN SMALL LETTER A WITH DOT BELOW;... and the error is because of this maybe. –  Aug 21 '20 at 10:58
  • @C.F.G The macro \a is needed in a tabbing environment to get accents. But I would advise against redefining commands without knowing what they do and hoping for the best. – campa Aug 21 '20 at 11:02
  • @UlrikeFischer: I know it can be risky to redefine existing commands. However, in this case, I accept that risk. These are exercise sheets for my students where I will most certainly not use the original meaning of \d. The advantage in having a short command outweighs the risk. I might switch to \dd{x} from the physics package; did not know that, when I first used this macro ~15 years ago. – Philipp Imhof Aug 21 '20 at 11:19
  • @egreg You are completely right and the comment is valuable for future reference. In this specific use case, there is no risk. I will never cite Indian or Arabic authors in a maths worksheet :) – Philipp Imhof Aug 21 '20 at 11:22
  • @PhilippImhof the problem is, that you don't really know if you will use the original meaning, as the use can be hidden in other commands. And if I may say so: you are putting a bad example for your students here. What will you do if one of them asks for the tex source? Refuse to show it? Edit first? – Ulrike Fischer Aug 21 '20 at 11:27
  • @C.F.G Would you mind turning this into an answer so I can accept it? – Philipp Imhof Aug 21 '20 at 11:27
  • @UlrikeFischer I would show them and be honest about it. Teachers do not have to be perfect. :) As my students do not know nor use LaTeX, that is not going to happen very soon, though. This is not university level, but higher secondary education. But you are right. I will keep it in legacy documents, but use physics in new (and larger) documents. – Philipp Imhof Aug 21 '20 at 11:32
  • 2
    physics isn't really loved, see e.g. https://tex.stackexchange.com/a/470842/2388 – Ulrike Fischer Aug 21 '20 at 11:35
  • @UlrikeFischer Good to know, thanks. What would you recommend? Simply use \newcommand{\dd}{\mathrm{d}} ? – Philipp Imhof Aug 21 '20 at 11:40
  • @daleif You are right. It is a legacy definition. In some newer documents, I use \mathrm instead of \text. I think, I did not yet know about (or pay attention to) those details ~15 years ago. And there was no tex.stackexchange.com :) – Philipp Imhof Aug 21 '20 at 11:41
  • It is just something at least I'm very vocal about since we see of students and beginners use it wrongly. So better not have it in various questions to tempt them. – daleif Aug 21 '20 at 12:33

1 Answers1

3

I am not an expert and I don't know the reason of error completely. You are not allowed to use (and probably redefine) the followings after of hyperref package:

  • (backslash+ ` )
  • \^
  • \~
  • \"
  • \r
  • \v
  • \.
  • \c
  • \=
  • \b
  • \d

and the error is because of this maybe, as explained in comments and other answer it is better to use other command or you can use diffcoef package instead. See for instance here and this comment.

  • The manual is describing how to define additional composites; that particular definition in the manual is there as example and is not part of the PU encoding, the re-definition of \d happens before that. – campa Aug 21 '20 at 13:18
  • You are right but BTW in that file, there are another commands\DeclareTextCompositeCommand{\d}{PD1}{\@empty}{\textdotbelow} and \DeclareTextCompositeCommand{\d}{PD1}{\ }{\textdotbelow} as i wrote, but my reference is wrong. –  Aug 21 '20 at 13:49
  • Yes, that's why I said "additional" composites. Some composites are defined by default like the ones you quoted. However, those do not define \d: they are "exceptions" to what \d usually does, but the redefinition of \d is the one I posted in my answer. – campa Aug 21 '20 at 13:52
  • Ok. i will edit my answer. Thank you. –  Aug 21 '20 at 13:57