3

Consider the output of texdef -t latex \flat

\flat:
\mathchar"15B

\the\flat: 347

I'd like to save the \flat command and then redefine it to work as binary symbol, for example, the same space around as \times.

I'm using this

\let\oldflat\flat 
\renewcommand{\flat}{\mathbin\oldflat}
\[ a\oldflat b \neq a\flat b \]

but I'd like to confirm here if this is the right way to to this.

Sigur
  • 37,330

1 Answers1

2

If you know that the symbol is ordinary, then

\mathchardef\oflat=\flat
\mathchardef\flat=\numexpr"2000+\oflat\relax

will do, because 2 is the class number for binary operation symbols. The trick is that a \mathchardef token can be used in the context of a <number>. It's necessary to first get an equivalent because when the number for \mathchardef\flat is being evaluated, \flat is temporary set equal to \relax, to avoid some problems that could arise from sloppy input.

\documentclass{article}

\mathchardef\oflat=\flat
\mathchardef\flat=\numexpr"2000+\oflat\relax

\begin{document}

\[ a\oflat b \neq a\flat b \]

\end{document}

enter image description here

egreg
  • 1,121,712
  • Sorry, I can not appreciate your elegant solution because my pour knowledge... lol but I'm sure that it is sophisticated. Do you have an example showing some possible difference between your solution compared with mine? – Sigur Feb 06 '17 at 23:03
  • 1
    @Sigur Try A_\flat with your code and with mine. ;-) – egreg Feb 06 '17 at 23:05
  • Mine is problematic. I got Missing { inserted. \[ A_\flat. Thanks. – Sigur Feb 06 '17 at 23:09