3

OK, so I'm writing a lot of maths that includes a lot of vectors. Not every thing is a vector, but a lot of it is. Are there tools that can help me mark up a lot of my variables as being vectors without having to type \vec{} over and over again? (It slows me down a lot to do that.)

3 Answers 3

3

You could use tools like Autohotkey (https://autohotkey.com/), Autokey (https://github.com/autokey/autokey) for Linux, Textexpander for Mac or the built-in expansion of your editor (Texworks has one for example).

I am using for example the following autohotkey snippet

:*:s#::\section{{}{}}{LEFT}

so that whenever I type 's#' it becomes automatically expanded to \section{} with the cursor placed within the curly brackets.

2

In such situations, I simply define some macros in my preamble.

For example if you know you will use \vec{v} a lot of times add

\newcommand{\Vv}{\vec{v}}

in your preamble.

This way you can use \Vv instead \vec{v} every time you need it.

It is both shorter to type and also has the advantage of uncoupling what you mean from its rendering. Therefore if at some point of the writing you want to change the way you type vector, say with bold fonts instead of arrows, you just change the definition of \Vv by

\newcommand{\Vv}{\mathbf{v}}

instead or changing all of your \vec{v} in your possibly long document.

FYI : When using arrows for vectors I generally use the quite nice esvect package

1

This is a bit of a sledgehammer, but useful if used carefully. Make sure that you are not clobbering an already defined macro:

\documentclass{article}

\usepackage{pgffor}

%% Put what ever letters in the braces you want to use:
\foreach \x in {A,B,T,Z}{\expandafter\xdef\csname V\x\endcsname{\vec{\x}}}%

\begin{document}

Bla bla bla. $\VA \VB \VT \VZ$.

\end{document}

enter image description here

2
  • This is a nice snippet, I guess I cann apply this for other tasks as well. Apr 20, 2018 at 12:35
  • @UweZiegenhagen Absolutely. Just be judicious. I have seen \foreach \x in {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} with only a few (if any!) actually used. Drives journal production editors CRAZY ;).
    – sgmoye
    Apr 20, 2018 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .