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?

15
  • 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? Commented Aug 21, 2020 at 9:49
  • It seems that \a is also predefined but redefining it \renewcommand{\a}{\text{a}} does not makes any error!!!
    – user108724
    Commented Aug 21, 2020 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
    Commented Aug 21, 2020 at 10:53
  • 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.
    – user108724
    Commented Aug 21, 2020 at 10:58
  • 2
    physics isn't really loved, see e.g. tex.stackexchange.com/a/470842/2388 Commented Aug 21, 2020 at 11:35

1 Answer 1

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.

4
  • 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
    Commented Aug 21, 2020 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.
    – user108724
    Commented Aug 21, 2020 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
    Commented Aug 21, 2020 at 13:52
  • Ok. i will edit my answer. Thank you.
    – user108724
    Commented Aug 21, 2020 at 13:57

You must log in to answer this question.

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