3

In my current document, the commands \k and \H are defined to be \PU-cmd\k\Pu\k and \PU-cmd\H\Pu\H, which seems to be part of the package hyperref. However, for the convenience, I redefined them as follows:

\def\k{\Bbbk}
\def\H{\mathbb{H}}

My question is, would these redefinitions cause serious trouble? It seems fine in my document, but I'm afraid if I have broken some important internal commands and the retribution shall come sooner or later.

Jinwen
  • 8,518

1 Answers1

2

When you cite a paper by “Erdős and Szczęsny”, you'll know why redefining \k and \H is a bad idea.

\begin{filecontents*}{\jobname.bib}
@article{test,
  author={Erdős, P. and Szczęsny, W.},
  title={Title},
  journal={Journal},
  year={2022},
}
\end{filecontents*}

\documentclass{article} \usepackage{amsmath,amssymb}

\renewcommand\k{\Bbbk} \renewcommand\H{\mathbb{H}}

\begin{document}

$\k+\H$ \cite{test}

\bibliographystyle{plain} \bibliography{\jobname}

\end{document}

The console after running LaTeX and BibTeX and LaTeX again:

! LaTeX Error: \mathbb allowed only in math mode.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.4 P.~Erdő s and W.~Szczęsny. ? ! Missing $ inserted. <inserted text> $ l.4 P.~Erdős and W.~Szczę sny.

egreg
  • 1,121,712
  • It is not bad idea to redefine sort control sequences at user level. It is bad idea to use them in laTeX as an internal control sequences. Moreover, it is only problem with old LaTeX, non-unicode LaTeX and non-Unicode Bibtex. With Unicode-ready software this problem is not occur. – wipet Apr 04 '22 at 15:57
  • @wipet Uh? Try and redefine \tenrm in plain TeX. Or \box. The latter is a very nice name for my command, isn't it? – egreg Apr 04 '22 at 16:18
  • Try to redefine \box or \fi or whatever in OpTeX. Nothing horrible happens. OpTeX will work without problems. – wipet Apr 04 '22 at 16:42
  • @wipet That's completely irrelevant. LaTeX users may not want to use XeTeX or LuaTeX and they may need to input Erd\H{o}s because they are not required to know how to use Unicode input. And there are thousands (or millions) of documents that need to be typeset without having to change them. That's not so small a difference, is it? – egreg Apr 04 '22 at 17:21
  • Please allow me to ask one more question, what if I define \k and \H to be my meaning in math mode while keep the original meaning in text mode, using \mode_if_math:TF? – Jinwen Apr 05 '22 at 20:57
  • @Jinwen It should work, but I wouldn't recommend it: uselessly confusing. I stand with my opinion that \kk and \HH are more semantic. – egreg Apr 05 '22 at 20:58
  • @egreg OK, thank you, that is indeed a good suggestion. – Jinwen Apr 05 '22 at 21:02