6

I'm pretty new to LaTeX, completely new actually, and there is one thing I can't quite understand.

I get the error "Display math should end with $$" when writing an equation like this:

\begin{equation}

$R_{2}$=$\frac{U_{R_2}}{I_2}$=$\frac{2,95\, \mathrm{V}$}{$0,03*10^{-3}\, \mathrm{A}$} = 7,10\,\mathrm{k}\Omega \,.

\label{eq:Bsp_OhmsLaw}\end{equation}

I tried a lot of things, I also skimmed these forums. Nothing seemed to help :-(

Thanks in advance!

3
  • 11
    Welcome to the site! You shouldn't use all of those $ symbols within the equation environment; remove them, and the blank lines, and you should get closer to a working piece of code :)
    – cmhughes
    Commented Mar 29, 2014 at 15:57
  • 2
    Please post complete compilable code as this makes it much easier to understand and answer your question.
    – cfr
    Commented Mar 29, 2014 at 16:00
  • Also, $$ is from plain TeX and has been replaced in LaTeX with a host of options, including \[ and \]. Commented Mar 29, 2014 at 16:04

2 Answers 2

13

In addition to removing the $ as cmhughes suggested, the blank lines in the equation environment confuse things. This may be why you added the dollar signs - with the blanks, LaTeX otherwise complains about missing $ symbols in the code.

Here's a working version:

\documentclass{article}

\begin{document}

\begin{equation}
  R_{2}=\frac{U_{R_2}}{I_2}=\frac{2,95\, \mathrm{V}}{0,03*10^{-3}\, \mathrm{A}} = 7,10\,\mathrm{k}\Omega \,.
  \label{eq:Bsp_OhmsLaw}
\end{equation}

\end{document}

equation

5
  • Thank's so much! It may sound odd, but my professor never really expained why and how to properly use the $ signs, so I just use them before and after every term that isn't just text.. worked fine so far, but I can see it leads to the first problems already.
    – user48884
    Commented Mar 29, 2014 at 16:20
  • 2
    Bascially, equation already tells TeX it is in maths mode. That's why you need e.g. \mathrm{} to get something text-like. If you are in a maths environment like that, don't use $ signs. Normally, you'd use $ signs if you wanted to typeset some maths inline i.e. in the middle of a paragraph or in the cell of a table or something like that.
    – cfr
    Commented Mar 29, 2014 at 16:43
  • 1
    @cfr Or, even better than $...$, you can use \(...\).
    – jub0bs
    Commented Apr 11, 2014 at 12:25
  • You could also change * to \times to get a properly typeset multiplication symbol, and even though it is obvious from context in this case, * is used for other operations in mathematics.
    – Ahlqvist
    Commented Apr 11, 2014 at 12:59
  • I'd also like to mention that it's generally a good idea to not use several equals signs in the same line.
    – 1010011010
    Commented May 16, 2014 at 22:32
5

Use the siunitx package for typesetting physical quantities:

\documentclass{article}

\usepackage{amsmath}
\usepackage[
  locale = DE % comma as decimal mark
]{siunitx}

\begin{document}

\begin{equation}
\label{eq:Bsp_OhmsLaw}
  R_{2}
  = \frac{U_{2}}{I_{2}}
  = \frac{\SI{2.95}{\volt}}{\SI{0.03e-3}{\ampere}}
  = \SI{7.10}{\kilo\ohm}.
\end{equation}
Ohm's law is used in equation~\eqref{eq:Bsp_OhmsLaw}.

\end{document}

output

Note that cfr has given the answer to why the initial code isn't compiling.

Update

You can make the code a bit shorter by use abbreviations for the physical units:

\documentclass{article}

\usepackage{amsmath}
\usepackage[
  locale = DE % comma as decimal mark
]{siunitx}

\begin{document}

\begin{equation}
\label{eq:Bsp_OhmsLaw}
  R_{2}
  = \frac{U_{2}}{I_{2}}
  = \frac{\SI{2.95}{\V}}{\SI{0.03e-3}{\A}}
  = \SI{7.10}{\kohm}.
\end{equation}
Ohm's law is used in equation~\eqref{eq:Bsp_OhmsLaw}.

\end{document}

(See page 37 of the manual.)

5
  • Wouldn't it be more instructive to write out \V and \A as it was done with \kiko\ohm. Also unless really really required to, I'd recommend using . as the decimal point, not comma. Otherwise one will have to wrap all non unit numbers in \num{...} which is a big hassle if one have not done so from the beginning.
    – daleif
    Commented Apr 11, 2014 at 10:55
  • @daleif Regarding \V and \A: I guess. (The reverse case: Do you know if there is an abbreviation for \kiko\ohm?) The comma is because that is how it is in the question. Commented Apr 11, 2014 at 12:21
  • abreviations \kohm
    – daleif
    Commented Apr 11, 2014 at 12:24
  • @daleif You could also use the icomma package to get properly spacing if comma is used a decimal separator.
    – Ahlqvist
    Commented Apr 11, 2014 at 13:01
  • In that case I'd rather use the siunitx approach and not have globally active math comma
    – daleif
    Commented Apr 11, 2014 at 13:18

You must log in to answer this question.

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