10

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.

3
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jul 9, 2014 at 20:13
  • 2
    $\hat{\textbf{\j}}$ gives the desired result, so probably it is a problem with fonts in your installation. Your *.log file may help to find the reason. Jul 9, 2014 at 20:24
  • Yes, I just found out that including the times package causes the blobs. Jul 9, 2014 at 20:26

4 Answers 4

13

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

16
  • I think my solution is to not include the times package. Then my command works fine with \i and \j. Jul 9, 2014 at 20:34
  • 1
    @AdrianKeister I added a way to have Times and the dotless j.
    – egreg
    Jul 9, 2014 at 20:35
  • Excellent! I like that a tad better than without. The text is just a bit darker and easier to see. Jul 9, 2014 at 20:38
  • 1
    @AdrianKeister I just did a copy-paste from the file I produced the image with.
    – egreg
    Jul 9, 2014 at 20:45
  • 1
    @AdrianKeister Are you perhaps trying something like \uvec{\alpha}?
    – egreg
    Jul 9, 2014 at 20:48
9
\documentclass{article}
\usepackage{bm}
\newcommand{\uvec}[1]{\boldsymbol{\hat{\textbf{#1}}}}
\begin{document}
$\uvec{\i} \uvec{\j} \uvec{k}$
\end{document}

enter image description here

7
  • Excellent! The bm package fixed the problem nicely. I'll start including that now. Jul 9, 2014 at 20:20
  • 2
    Shouldn't it be \bm instead of \boldsymbol? However, try this in a theorem statement.
    – egreg
    Jul 9, 2014 at 20:22
  • Actually, it doesn't solve my problem. I'm still getting the blob. Let me see if I can figure out if there's a package problem... Jul 9, 2014 at 20:24
  • 1
    @AdrianKeister There are many good reasons not to use the times package, not least of which is the ugliness of Times. There's a question here somewhere on this site... But I'm guessing the \j glyph is not defined for that font package. Jul 9, 2014 at 20:28
  • 1
    @AdrianKeister Yes, I am reasonably sure that amsmath just loads the bm package, though I'm not 100% sure. Jul 9, 2014 at 20:37
1
\documentclass{article}    
\usepackage{bm}


\begin{document}

$\bm{\vec{a_{1}}}$ = a $\bm{\hat{\imath}}$

\end{document}

enter image description here

1
  • This is italic, not bold like I requested. Sep 2, 2020 at 15:59
-1

You can use your command but \uvec{\i} and \uvec{\j}. This will produce what you want.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .