LaTeX Best Unit Vectors in LaTeX for TeX.SE Interaction

AI Thread Summary
Egreg shared a LaTeX code snippet on TeX.SE for creating unit vectors, utilizing packages like newtxtext, newtxmath, and amsmath. The code defines commands for upright Greek letters and custom unit vector notation, allowing users to write vectors such as \uvec{i} and \uvec{\rho}. It is noted that this code is incompatible with the times package and that the resulting unit vectors for i and j replace dots with hats, which some may find visually appealing. However, it is mentioned that certain journals may require the traditional hat notation for unit vectors. Overall, the code provides a robust solution for typesetting unit vectors in LaTeX.
Ackbach
Gold Member
MHB
Messages
4,148
Reaction score
93
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
Some journals may not accept anything but ##\hat{i}##. But thanks for sharing, anyway.
 

Similar threads

Replies
10
Views
16K
Replies
3
Views
2K
Replies
4
Views
4K
Back
Top