12

I'm writing a paper and I used \vec{} to express all vectors. Now, I changed my mind and want to write them in bold letters using \bf{} for instance. Is there a fast way to change all that's been written \vec{} to \bf{} without doing it for every single vector?

  • To change the appearance of an element globally is actually the key point of using a markup language over WYSIWYG software. In latter case you have to go through all vectors by hand. In the first case you could do this. But even though a search and replace routine will speed up this process there is no actual reason to do so. – Ruben Aug 1 '15 at 22:32
20

First, I have to recall that \bf is a plain TeX macro. It is not bad practice to use it but it isn't needed anymore since \bfseries was intoduced with LaTeX and its syntax is exactly the same as for good old \bf.

Second, don't change your markup! (by exploiting a search and replace routine). If you wrote \vec in your manuscript you did it because the element that you want to typeset is a vector and not because the \vec macro puts a nice little arrow above your letter.

You don't break anything if you redefine \vec since it is a simple macro that invoces \mathaccent. In fact redefining it is best practice. The shortest and most efficient way to accomplish this in your case would be

\renewcommand\vec{\mathbf}

If you want to use the original form of the \vec macro next to the redefined one you should put \let\arrowedvec=\vec (pick any name you want instead of "arrowedvec") before the line with \renewcommand\vec{\mathbf} and use \arrowedvec of course when you need the original version of \vec. Alternatively you could also define the macro directly: \def\arrowedvec{\mathaccent"017E}. The only difference here concerns memory usage which nowadays mostly isn't an issue anymore.

Addendum

I recommend to read the post Separate content from formatting - i.e., "just type". It contains a brief discussion on logical markup.

  • 1
    i'd be inclined to first \let\oldvec\vec, just in case i ever wanted to put an arrow over some symbol and didn't remember the "long" version of the code. – barbara beeton Aug 2 '15 at 8:15
  • @barbarabeeton -- Good point! I'll add a remark... – Ruben Aug 2 '15 at 10:09
11

The proper way of doing this would be to use a search-and-replace command in your text editor in connection with a custom macro, e.g. \myvec.

However, if you insist on having a quick solution inside your document (which I discourage), you could add the following to your document's preamble:

\let\oldvec=\vec
\renewcommand{\vec}[1]{\oldvec{\mathbf{#1}}}

If you wish to have the letter printed in bold face without the vector accent on top of it, use

\renewcommand{\vec}[1]{\mathbf{#1}}

instead

11

You could change meaning of \vec, but that would be very bad pratice. What I would do:

  1. Define new command with style like: \newcommand{\vectorstyle}[1]{\mathbf{#1}}
  2. Use Find and Replace feature of your text editor/IDE to replace \vec{ for \vectorstyle{
  3. In the event of next chage, just replace the definiton of the \vectorstyle

P.S. Do not use \bf. It's bad pratice. You can use \bfseries instead.

  • 2
    changing the meaning of \vec isn't bad practice at all (see also my answer.) – Ruben Aug 1 '15 at 22:12
  • 3
    \bf is not bad practice: it's deprecated and it's existence cannot be relied upon. (Also it doesn't have an argument...) – clemens Aug 2 '15 at 4:59
5

First, {\bf ...} is obsolete. Instead it you should use \mathbf{...} or \boldsymbol, depending on which packages you use. For replacing you have two possibilities:

  • By means of the editor the 'Replace' function replaces \vec{ with for example mathbf{.
  • Redefine \vec with \renewcommand (this gives easy way to change your mind again ...:) )
  • 8
    and even before \bf became obsolete, it was properly used as {\bf ...}, not \bf{...}. – barbara beeton Aug 1 '15 at 13:24
4

I use this macro in many of my papers:

\renewcommand{\vec}[1]{\boldsymbol{\mathrm{#1}}}

It can always be commented out, of course, if the original definition is preferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.