- #1
Ackbach
Gold Member
MHB
- 4,155
- 92
During an interaction on TeX.SE, egreg there posted some truly awesome code for doing unit vectors in $\LaTeX$:
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.
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.