2

I want to have a special symbol for the imaginary unit i, but I also need the usual character for the letter i in the same context. So, I tried to change the style of the imaginary unit by setting

\def \i{\begingroup\mathgroup=0 i\endgroup}

This is supposed to return a different symbol for i when typing \i in math-mode, but it refuses to do so! I get the error message:

Command \i invalid in math mode

Why is that and what can I do to obtain a different i for my complex numbers?

Jim
  • 535
  • Don't use one-letter command names, use longer names. – Johannes_B Dec 12 '15 at 17:04
  • It is a bad idea to use \i which has a pre-existing meaning, use any other name, (\newcommand rather than def would have warned you of that) – David Carlisle Dec 12 '15 at 17:05
  • What's wrong with \imath? –  Dec 12 '15 at 17:06
  • why use all these low level commands \def, \mathgroup, \begingroup etc. It seems you want \newcommand\imagi{\mathrm{i}} then use \imagi – David Carlisle Dec 12 '15 at 17:07
  • I am new to Latex and I wasn't aware neither of \mathrm{•} nor \imath. However, what is \i supposed to do normally? @David By the way, thank you very much for your replies. – Jim Dec 12 '15 at 17:15
  • \i is the command for getting the “dotless i”. It's best not to redefine it. – egreg Dec 12 '15 at 17:26
  • 4
    If you are new where did you learn of \mathgrouo (or \def) I wouldn't expect any such commands, which are used to define latex internals, being mentioned in any tutorial. – David Carlisle Dec 12 '15 at 17:31
  • copy - paste I made some research. – Jim Dec 12 '15 at 18:33

2 Answers2

9

\i is a standard latex command for dotless i, you should not redefine it.

This is why \latex has a \newcommand command, and you should not use \def except in internal package command where efficiency is more important. \newcomand would have given an error that it was redefining an existing command.

It seems that you want an upright i so

\newcommand\imagi{\mathrm{i}} 

then use \imgi (or use any other free name of your choice)

David Carlisle
  • 757,742
5

Here's a suggestion which may, at first, seem a bit complicated; however, in the longer run it will almost certainly save you a lot of time and effort: Load the siunitx package and make a habit of encasing numbers -- real, imaginary, and complex -- in \num{...} wrappers. The \num macro works in both text and math mode.

The siunitx package lets you customize the appearance of the symbol for the imaginary unit; in the example below, I've selected

\sisetup{output-complex-root = \mathbf{i}}

to use a bold upright "i" as the symbol; the default is an ordinary (non-bold) upright "i".

enter image description here

\documentclass{article}
\usepackage{siunitx}
\sisetup{output-complex-root = \mathbf{i}} % just for this example

\begin{document}
\num{2.71}, \num{-i}, \num{0.717\pm0.717i}

$\num{2.71}$, $\num{-i}$, $\num{0.717\pm0.717i}$
\end{document}
Mico
  • 506,678
  • +1 Yep. This also has a bunch of other advantages, like \num{0.123456i} will display with a thin space (\,) between the 3 and the 4, etc. – wchargin Dec 12 '15 at 23:12