1

I'm working with vectors, which I'm denoting with $\overrightarrow{a}$, where a is just the name of the vector, and thus is a variable that can take any value. I would like to redefine this as $\v{a}$, to save time and effort. How do I do this?

Apologies if this question is a duplicate - I did find some similar questions, but none that I thought directly answered this.

Edit: Question has been extensively answered in the comments. Thanks!

Newb
  • 365
  • 2
    \newcommand*{\V}[1]{$\overrightarrow{#1}$} Use it as \V{a} –  Nov 08 '13 at 09:42
  • Remark: if I'm already in math-mode, it's better to have the command as \newcommand*{\V}[1]{\overrightarrow{#1}} – Newb Nov 08 '13 at 09:49
  • @HarishKumar how would I do that? – Newb Nov 08 '13 at 09:57
  • \newcommand*{\V}[1]{\ensuremath\overrightarrow{#1}}. But use it only if you intend to apply in both modes. Otherwise, as you said \newcommand*{\V}[1]{\overrightarrow{#1}} is better. –  Nov 08 '13 at 10:00
  • If I end up only using it in one mode, why would the latter option be better than the first? – Newb Nov 08 '13 at 10:02
  • There is a question on when to use \ensuremath in the site. Now I am on mobile, so searching is difficult. –  Nov 08 '13 at 10:05
  • @Newb Use \newcommand{\V}[1]{\overrightarrow{#1}} and be happy. I used \ensuremath yesterday in an answer; I believe it's the first usage I made of it in a couple of months. – egreg Nov 08 '13 at 10:05
  • Here's the question @Harish mentioned: http://tex.stackexchange.com/questions/34830/when-not-to-use-ensuremath-for-math-macro – Torbjørn T. Nov 08 '13 at 10:25
  • Just adding another reference, about the use of one-letter macro names: http://tex.stackexchange.com/questions/19111/short-names-for-macros – Torbjørn T. Nov 22 '13 at 15:51

1 Answers1

3

LaTeX provides the semantic macro \vec to typeset a vector. This is short, clear and easy to understand for others. As Martin pointed out in Short names for macros there are several one letter macros that do accent stuff. It is also harder to read for others, once you submit your file for editing or proof reading.

As has been pointed out in the comments, you can do \newcommand*{\V}[1]{\overrightarrow{#1}} without automatic selecting math mode if necessary. Be sure to be the one who decides when math should be involved. You can read more about this in When not to use \ensuremath for math macro?

Now, how about efficiency and saving time to type? A general rule of thumb is, don't do it on the LaTeX side, use anassistent to help you, meaning a good text editor that can expand your often used macros with the hit of one button.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248