[Tex/LaTex] How to type a particular kind of unit vector

vector

I write unit vectors frequently. Right now, the best thing going for me is to define:

\newcommand{\uvec}[1]{\boldsymbol{\hat{\textbf{#1}}}}

and then do

\uvec{i}, \uvec{j}, and \uvec{k}. I like the results (they're clear enough), but I would prefer no dots for the i and j unit vectors. What's a nice, unified way to get that?

I tried \hat{\textbf{\i}}, and that works ok, as does \hat{\textbf{k}}. The problem is that \hat{\textbf{\j}} doesn't work for me. For some reason, I don't get a j, but some rectangular blob of ink.

\jmath and \imath don't work for me, because I don't want italics but bold-face.

So, to sum up:

  1. Want bold, not italic

  2. Want a hat over the unit vector

  3. Want no dot for the i or j unit vectors.

How best to get all this? Thanks very much for your time!

Here's a minimum working example:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\uvec}[1]{\boldsymbol{\hat{\textbf{#1}}}}
\begin{document}
$\uvec{i}, \uvec{j}, \uvec{k}$
\end{document}

Please feel free to suggest the inclusion of other packages.

Best Answer

You have to use \i and \j, which means you need to switch to text mode. However, there is a problem that text fonts in math mode inherit the attributes of the context, so, for example, $\textbf{\i}$ would give a bold italic dotless i in a theorem statement.

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}
\newcommand{\uveci}{{\bm{\hat{\textnormal{\bfseries\i}}}}}
\newcommand{\uvecj}{{\bm{\hat{\textnormal{\bfseries\j}}}}}
\DeclareRobustCommand{\uvec}[1]{{%
  \ifcsname uvec#1\endcsname
     \csname uvec#1\endcsname
   \else
    \bm{\hat{\mathbf{#1}}}%
   \fi
}}

\begin{document}
$\uveci\ne\hat{\imath}_{\uvec{i}}+\uvec{j}+\uvec{k}$
\end{document}

You can type both \uveci and \uvec{i} for uniformity, the same for a ā€œjā€.

enter image description here

You can't use the times package for this; first of all because it's obsolete, but even its substitute, that is mathptmx, doesn't provide a dotless j. You can use newtxtext and newtxmath:

\documentclass{article}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{bm}
\newcommand{\uveci}{{\bm{\hat{\textnormal{\bfseries\i}}}}}
\newcommand{\uvecj}{{\bm{\hat{\textnormal{\bfseries\j}}}}}
\DeclareRobustCommand{\uvec}[1]{{%
  \ifcsname uvec#1\endcsname
     \csname uvec#1\endcsname
   \else
    \bm{\hat{\mathbf{#1}}}%
   \fi
}}

\begin{document}
Some text for showing that Times is being used.

$\uveci\ne\hat{\imath}_{\uvec{i}}+\uvec{j}+\uvec{k}$
\end{document}

enter image description here


With newTX you also have the possibility of getting upright lowercase Greek letters. Here's how to do it; I also added the possibility of typing \uvec{\alpha}. Please, be aware of the fact that the argument of \uvec must be a single Latin character (not \i or \j, which are unnecessary and illegal for the macro) or a single Greek symbol.

\documentclass{article}
\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
%%

\begin{document}
Some text for showing that Times is being used.

$\uveci\ne\hat{\imath}_{\uvec{i}}+\uvec{j}+\uvec{k}$

$\uvec{\alpha}+\uvec{\Gamma}+A$
\end{document}

enter image description here


Note

The Times font is by no means necessary and the code works as well with the standard fonts.

\documentclass{article}
\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
}}

\begin{document}

$\uveci\ne\hat{\imath}_{\uvec{i}}+\uvec{j}+\uvec{k}$

$\uvec{\xi}+\uvec{\Gamma}+A$

\end{document}

enter image description here

Related Question