As a full-stack developer and Linux enthusiast, I often find myself needing to properly typeset mathematical expressions involving vectors. Vectors are essential mathematical objects that appear across physics, engineering, and more. Being able to cleanly represent them in documents is key.
LaTeX provides powerful tools for typing up high-quality math. Its syntax and packages give fine-tuned control over vector symbols. In this comprehensive guide, I‘ll walk through the various techniques for wielding vectors in LaTeX.
Vector Basics
Let‘s quickly review some vector basics before diving into LaTeX.
A vector is a mathematical entity that has both magnitude and direction. Some examples are:
- Velocity – speed and course
- Force – strength and push/pull orientation
- Displacement – distance and direction of movement
We denote vectors with an arrow above variables like so:
The arrow conveys directionality. We use vectors instead of plain variables when that added context is meaningful.
Now let‘s see how to produce such vector symbols properly in LaTeX.
The Vec Command
The simplest way to denote something as a vector in LaTeX is by using the \vec{}
command. Inside the curly braces, insert the variable you want turned into a vector:
$\vec{v}$
This outputs:
You can use \vec{}
with any letter variable. The result is a boldfaced character with a small arrow above:
$\vec{F}$, $\vec{a}$, $\vec{\theta}$
Note that greek letters like θ work fine within the \vec{}
command.
Multi-Letter Vectors
Suppose you want a vector that spans multiple letters, like the displacement vector s:
$\vec{s}$
This unfortunately renders poorly:
Only the first letter gets the vector styling. For multi-letter scenarios, use the \mathbf{}
command instead to boldface the entire variable, along with \vec{}
before just the first letter:
$\vec{\mathbf{s}}$
With the output:
Vector Components
Vectors often split into component parts. For example, a 3D vector v breaks into:
vx, vy, vz
To typeset such components properly:
$\vec{v}_x$, $\vec{v}_y$, $\vec{v}_z$
Giving:
Note the subscripting, which is enabled by the underscore _
character in LaTeX math mode.
Vector Modification Commands
LaTeX‘s physics
package provides specialized vector commands for added stylistic control:
\usepackage{physics}
With this package imported, you can use:
\vv{v}
– Bold vector with extra large arrow\vw{v}
– Bold vector with small arrow\uv{v}
– Plain vector with extra large arrow\uw{v}
– Plain vector with small arrow
For example:
$\vv{F}$, $\vw{F}$, $\uv{F}$, $\uw{F}$
Renders as:
The physics
vectors come in handy when you want vectors that mesh well with other math symobls around them.
Vector Magnitude
The magnitude (or length) of a vector uses the modulus/absolute value notation:
$\lvert \vec{v} \rvert$
Which produces:
Use \lvert
and \rvert
to envelop the vector itself.
An alternative approach is to use plain text for the magnitude together with the \vert
command:
$|\vec{v}|$
Math mode handles spacing better with the former approach.
Unit Vectors
A unit vector has its length scaled to a magnitude of 1. This makes it‘s direction clear.
We denote unit vectors with a hat accent over the variable name:
$\hat{\vec{n}}$
Output:
Unit vectors assist when discussing directions conceptually without specific magnitudes.
Zero Vector
What about the zero vector – that is one pointing to the origin with no length? LaTeX handles it cleanly:
$\vec{0}$
Renders as:
The zero vector points the concept of directionality collapsing when magnitude becomes zero.
Vector Relationships
With these basics covered, let‘s look at typesetting vectors amidst other mathematical expressions.
For example, momentum p equals mass m times velocity v:
p = m * v
We properly vectorize this in LaTeX as:
$\vec{p} = m\vec{v}$
The output:
Note how the m mass term stays scalar, while p and v become vectorized.
LaTeX‘s math mode spacing eliminates the need to fuss over *‘s between terms. The spaces before and after \vec{}
also help guide the eye while reading.
Equations with vectors can quickly become complex across aerodynamics, electromagnetics, relativity, and quantum mechanics. Keep vectors always properly formatted amidst any symbols helps readers parse information cleanly.
For example, in a hydraulic system we might analyze pressure and viscosity like:
$\frac{\vec{F}}{\mu \vec{A}} = \vec{\nabla} P$
With sensible spacing between all components:
When to Use Boldface Vectors
Now you may be wondering – why use the arrow-accented variable like \vec{v}
rather than just boldfacing, like \mathbf{v}
?
The boldface approach is okay when juxtaposing vectors right next to other clearly-scalar quantities. For example:
\mathbf{F} = m\mathbf{a}
But when used in isolation, readers may confuse v as matrix notation instead of a vector. The arrow makes vectors undeniably explicit.
Thus use arrow vectors by default, and optionally drop down to boldface when vectors locally contrast clearly against scalar terms.
The same goes for using plain variables amidst messy equations – whileReadable Locally, ambiguity may emerge Globally. Err on the side of explicit notation.
When Not To Use Vectors
Also resist the temptation to over-vectorize everything in sight! Vectors carry conceptual meaning about directionality. Use them only when that context truly matters.
For example, while acceleration a often appears as a vector:
$\vec{a} = \frac{\Delta \vec{v}}{\Delta t}$
There are certain scenarios when its magnitude alone suffices. Treating acceleration as scalar may help simplify analysis when vector directionality can be assumed or isn‘t relevant.
Let logic and the situation at hand guide your judgement of when to vectorize variables versus using scalars. Vectorize where doing so aids understanding.
Further Vector Control
The tips in this guide cover the basics of typesetting vectors in LaTeX. The physics
and other packages provide further tweaks like dotted/dashed vector arrows if you need added customization.
You can also use LaTeX‘s \overrightarrow{}
command for alternative large vector arrows. Matrices like \mathbf{V}
represent special column vector notation.
With practice you‘ll soon find yourself fluently forming vectors amidst any mathematical typsetting scenario. Vectors will cleanly convey directionality and meaning wherever applied.
I hope you‘ve found these examples and guidelines useful! Let me know if you have any other questions.