1

I would not be surprised if this has been asked before, but my searches did not yield any results. Neither would it surprise me if this is not possible without doing some really dangerous hacking of the TeX kernel or something. But allow me to ask anyway.

I use the following code as a shortcut for bold letters in math mode as recommended here:

\documentclass{memoir}
\usepackage{amsmath,bm,amsfonts}

\def\*#1{\bm{\mathrm{#1}}}

\begin{document}
Let $\*v$ be a vector in $\mathbb R^n$ with $A\*v = \*v$.
\end{document}

This is nice and handy in most contexts, but it sometimes gets tedious to write \*v inside the argument of other commands. For instance, I may want to write the derivative of \*v as \dot{\*v}. I wonder if there is a way to avoid having to write the {}s. Concretely, what I want is to redefine the command \* so that

$\dot\*v$

or even

$\dot\*{longvector}$

can be parsed correctly.

Gaussler
  • 12,801
  • 1
    The problem isn't your definition of \*, but rather the definition of \dot, which takes 1 argument. Without braces, that argument is \*, which is not what you would desire. – Steven B. Segletes Mar 22 '14 at 16:19
  • amsfonts missing? – Sigur Mar 22 '14 at 16:19
  • @Sigur, oops, I must have forgotten. Will be corrected. – Gaussler Mar 22 '14 at 16:22
  • @StevenB.Segletes, yes, I know, but the question if it is possible to cheat LaTeX into parsing the command \* before \dot and with the argument. – Gaussler Mar 22 '14 at 16:25
  • And preferably, it should work not only with \dot, but in general with commands taking only one argument. – Gaussler Mar 22 '14 at 16:29
  • unrelated to your question but \let*\mathbf would be a vastly more stable definition of * \bm{\mathrm{...}} does vast amounts of work but will end up using the same font as as \mathbf – David Carlisle Mar 22 '14 at 18:50
  • For ordinary letters, indeed; I defined it that way in order to get a command that also works well for Greek letters. ;-) – Gaussler Mar 22 '14 at 19:11

1 Answers1

3

Maybe this is sufficient for your needs

\def\*#1{{\bm{\mathrm{#1}}}}
\let\olddot\dot
\def\dot{\expandafter\olddot}

Note the extra brackets around the body of your \* macro definition: this is to make the expansion of \* look like a single argument to \olddot:

\dot\*v -> \expandafter\olddot\*v -> \olddot{\bm{\mathrm{v}}}
Bordaigorl
  • 15,135
  • Sounds interesting, could you elaborate more on this automation? :-) – Gaussler Mar 22 '14 at 16:44
  • So I guess it means that there is no way around redefinition the individual commands to be used? Sure it does make everything simpler. ;-) – Gaussler Mar 22 '14 at 17:01
  • 2
    Well, this was to illustrate the point about needing to redefine \dot. It has to do with the fact that you cannot influence how tokens already consumed by tex are expanded..so, roughly speaking, you cannot change the expansion of \dot by calling something after it. – Bordaigorl Mar 22 '14 at 17:06