Best Unit Vectors in LaTeX for TeX.SE Interaction

In summary, egreg shared code on TeX.SE for creating unit vectors in LaTeX using the packages newtxtext, newtxmath, and amsmath. The code allows for the use of both Latin and Greek letters as unit vectors, with the Greek letters being displayed in an upright font. However, it may not be compatible with the times package and some journals may not accept the formatting of the unit vectors.
  • #1
Ackbach
Gold Member
MHB
4,155
89
During an interaction on TeX.SE, egreg there posted some truly awesome code for doing unit vectors in $\LaTeX$:

Code:
\usepackage{newtxtext}
\usepackage{newtxmath}
\usepackage{amsmath}
\usepackage{bm}
\newcommand{\uveci}{{\bm{\hat{\textnormal{\bfseries\i}}}}}
\newcommand{\uvecj}{{\bm{\hat{\textnormal{\bfseries\j}}}}}
\DeclareRobustCommand{\uvec}[1]{{%
  \ifcat\relax\noexpand#1%
    % it should be a Greek letter
    \bm{\hat{#1}}%
  \else
    \ifcsname uvec#1\endcsname
      \csname uvec#1\endcsname
    \else
      \bm{\hat{\mathbf{#1}}}%
     \fi
   \fi
}}

% for upright lowercase Greek; newtxmath hasn't an option for this
  \let\alpha\alphaup
  \let\beta\betaup
  \let\gamma\gammaup
  \let\delta\deltaup
  \let\epsilon\epsilonup
  \let\zeta\zetaup
  \let\eta\etaup
  \let\theta\thetaup
  \let\iota\iotaup
  \let\kappa\kappaup
  \let\lambda\lambdaup
  \let\mu\muup
  \let\nu\nuup
  \let\xi\xiup
  \let\pi\piup
  \let\rho\rhoup
  \let\sigma\sigmaup
  \let\tau\tauup
  \let\upsilon\upsilonup
  \let\phi\phiup
  \let\chi\chiup
  \let\psi\psiup
  \let\omega\omegaup
  \let\varepsilon\varepsilonup
  \let\vartheta\varthetaup
  \let\varpi\varpiup
  \let\varrho\varrhoup
  \let\varsigma\varsigmaup
  \let\varphi\varphiup

Comments:

1. This code is not compatible with the times package.

2. Usage: \uvec{i} or \uvec{\rho} or \uvec{\varphi}.

3. The Greek unit vectors are upright.

4. For \uvec{i} and \uvec{j}, this code will leave off the dots, letting the hat take their place. I think the result is highly satisfactory.
 
Physics news on Phys.org
  • #2
Some journals may not accept anything but ##\hat{i}##. But thanks for sharing, anyway.
 
  • Like
Likes Ackbach

1. What is a unit vector in LaTeX?

A unit vector in LaTeX is a mathematical notation that represents a vector with a magnitude of 1. It is commonly used in typesetting equations and mathematical expressions.

2. How do I insert a unit vector in my LaTeX document?

To insert a unit vector in your LaTeX document, you can use the command \hat{i} for the unit vector in the x-direction, \hat{j} for the unit vector in the y-direction, and \hat{k} for the unit vector in the z-direction. You can also use the notation \vec{v} to indicate a vector with a unit direction.

3. Can I customize the appearance of a unit vector in LaTeX?

Yes, you can customize the appearance of a unit vector in LaTeX by using different fonts, sizes, and colors. You can also use the command \overrightarrow{v} to add an arrow on top of the unit vector, or the command \widehat{v} to make the hat symbol wider.

4. Is there a shortcut for inserting unit vectors in LaTeX?

Yes, you can use the package "esvect" to easily insert unit vectors in LaTeX. Simply use the command \vv{} followed by the variable or vector you want to add a unit vector to. You can also use the command \unitvec{} to insert a unit vector with a specific direction.

5. Can I use unit vectors in other mathematical environments besides equations?

Yes, you can use unit vectors in other mathematical environments such as matrices, arrays, and even in text. Simply use the appropriate command for unit vectors (\hat{}, \vec{}, etc.) within the desired environment.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
14K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top