LyX supports math-macros, but sadly when passed to the latex processor, they are defined by a \def
rather than a newcommand.
I have found overwriting commands (e.g. using \def\v{\mathbf{v}}
) to result in hard-to-debug errors, especially when BibTeX files entries introduce names, that require the original meaning of the command. Hence I'd like to change this behaviour -- asking for a change in LyX would however be unlikely to be successful (breaking backward compatibility) and at best require waiting for the next binary release (windows) or compiling it myself with a patch (linux).
Hence I was wondering if it is possible to (locally) overwrite \def
to call \newcommand
instead.
I tried
\documentclass[]{article}
\begin{document}
\begingroup % for locality of the redefinition
\let\odef\def
\renewcommand{\def}[1]{\newcommand{#1}{}\odef#1}
\def\xx{{\bf x}} \xx
\endgroup
\end{document}
but this fails with
! TeX capacity exceeded, sorry [input stack size=5000]. \@ifstar #1->\@ifnextchar *{\@firstoftwo {#1 }} l.18 \def\xx {{\bf x}} \xx
presumably related to \newcommand using \def internally.
\@ifdefinable
or\ifundefined
might help here.\bf
was deprecated 20 years ago...