[Tex/LaTex] Math mode problem

math-mode

I'm completely new to LaTeX, and I'm just learning how to type math equations. Can someone tell me what I'm doing wrong here?

The position of an object is given by
$\textbf{r} = (\emph{ct - bt^3}) \textbf{\hat{i}}$ + 
$\emph{dt^2}/textbf${\hat{j}}$, with constants \emph{c} = 6.7 m/s,
\emph{b} = 0.81 m/s^3, and \emph{d} = 4.5 m/s^2.

Best Answer

Welcome, to the site and to LaTeX!

Well, the number one thing I cannot stress enough is not to skip in and out of math mode. This is a very common mistake, so don't feel bad about it, but math mode ($ ... $) doesn't mean 'mathify' this, and it isn't primarily a way of getting special characters (although many commands only work in math mode). It's designed for typesetting the entire mathmatical object. Thus all of this:

$\textbf{r} = (\emph{ct - bt^3}) \textbf{\hat{i}}$ + 
$\emph{dt^2}/textbf${\hat{j}}$

Should be within one pair of $ ... $. LaTeX's math mode is designed to give you the correct spacing around operators such as + and =, don't circumvent this.

I don't know if /textbf${\hat{j}} is a typo for \textbf${\hat{j}} (i.e. you have / but you meant \) or whether you left out the \: /\textbf${\hat{j}}

$ must not come between \textbf and {.

Using \textbf{} in math mode is not exactly wrong in this case, but it is a bit counter-intuitive. Try \mathbf{}

Using \emph within math mode is definitely wrong. \emph{} is used within text to emphasise it. By default, \emph{} italicises text, but it is not an all-purpose italicisation command. $ ... $ italicises characters by default and the usual problem people have is making things not italicised! It is also a text mode command, which means math mode commands like ^ will not work within \emph{} unless you enter math mode again, totally circumventing the \emph{} in this circumstance, i.e.: \emph{foo $bar^{baz}$}.

\hat{i} will give you an i with a hat over the tittle. Having it bold, and dotless, and with a hat, is a much more difficult task than it may look. Ordinarily, you'd want to use \hat{\imath}, but then it would not be bold. Using \mathbf{} won't make it bold, but loading the bm package and using \bm{\hat{\imath}} will make it bold, but then it won't be upright, it'll be italic.

So, I used this question:

Bold upright i-hat and j-hat for vector notation

As mentioned above, ^ must be used in math mode. \emph{b} = 0.81 m/s^3 will fail.

Also, avoid using \emph{} for variables, use math mode.

What I guess you want:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\ihat}{\boldsymbol{\hat{\textbf{\i}}}}
\newcommand{\jhat}{\boldsymbol{\hat{\textbf{\j}}}}

\begin{document}

The position of an object is given by
$\mathbf{r} = (ct - bt^{3}) \ihat + dt^{2}\jhat$, with constants
$c = 6.7~\mathrm{m}/\mathrm{s}$, $b = 0.81~\mathrm{m}/\mathrm{s}^{3}$,
and $d = 4.5~\mathrm{m}/\mathrm{s}^{2}$

\end{document}

enter image description here

Although you should maybe look into the siunitx package for typesetting units more easily.

The siunitx way. Note the use of \usepackage[per-mode=symbol]{siunitx} in the preamble to give you the solidus for "per", as opposed to, e.g. m s-3

\documentclass{article}
\usepackage{amsmath}
\newcommand{\ihat}{\boldsymbol{\hat{\textbf{\i}}}}
\newcommand{\jhat}{\boldsymbol{\hat{\textbf{\j}}}}
\usepackage[per-mode=symbol]{siunitx}

\begin{document}

The position of an object is given by
$\mathbf{r} = (ct - bt^{3}) \ihat + dt^{2}\jhat$, with constants
$c = 6.7~\si{\metre\per\second}$,
$b = 0.81~\si{\metre\per\cubic\second}$, and
$d = 4.5~\si{\metre\per\square\second}$
Related Question