Math & ScienceCorrect Use of Math Mode for Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Nolin
Posts: 4
Joined: Thu Sep 27, 2012 2:29 pm

Correct Use of Math Mode for Equations

Post by Nolin »

Hi!

Second time I ask a question here, and thanks for the good respond last time.

I want to display a formula, and when I test it with LaTeX Online Equation Editor, it works, but when I try to compile it I get errors.

Don't know what it is, and I got some other equations that's work when I added $ before and after some math symbols. Not sure when or when not to use those.

This is my equation, thankful if someone could correct it and explain what I did wrong and when I need $ sign, before and after.

Code: Select all

\begin{equation}
\label{eq:dct}
F(u,v) = \left (\frac{2}{N}  \right )^{\frac{1}{2}} \left ( \frac{2}{M} \right )^{\frac{1}{2}} \sum_{i=0}^{N-1}\sum_{j=0}^{M-1} \Lambda(i,j)cos\left [ \frac{\pi u}{2 N}\left ( 2i +1 \right ) \right ]cos\left [ \frac{\pi v}{2 M}\left ( 2j +1 \right ) \right ] f(i,j)
\end{equation}
\textit{where}
\begin{equation}
\Lambda(i)\left\{\begin{matrix}
\frac{1}{\sqrt{2}} & for  \varepsilon = 0
\\ 1 & otherwise
\end{matrix}\right.\end{equation}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Correct Use of Math Mode for Equations

Post by localghost »

Please get used to always providing a proper, that is to say self-contained and minimal example. Nobody knows what you are doing beside the equation you posted.

If I supplement your loosely code snippet to a compete document, I have no major problem, only a warning about an overfull box caused by this wide equation.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\begin{document}
  \begin{equation}\label{eq:dct}
    F(u,v) = \left (\frac{2}{N}  \right )^{\frac{1}{2}} \left ( \frac{2}{M} \right )^{\frac{1}{2}} \sum_{i=0}^{N-1}\sum_{j=0}^{M-1} \Lambda(i,j)cos\left [ \frac{\pi u}{2 N}\left ( 2i +1 \right ) \right ]cos\left [ \frac{\pi v}{2 M}\left ( 2j +1 \right ) \right ] f(i,j)
  \end{equation}
  \textit{where}
  \begin{equation}
    \Lambda(i)\left\{
    \begin{matrix}
      \frac{1}{\sqrt{2}} & for  \varepsilon = 0\\
       1 & otherwise
    \end{matrix}\right.
  \end{equation}
\end{document}
But perhaps you should typeset it in a slightly different way.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
  \begin{align}\label{eq:dct}
    F(u,v) &= \left (\frac{2}{N}  \right )^{\frac{1}{2}} \left ( \frac{2}{M} \right )^{\frac{1}{2}} \sum_{i=0}^{N-1}\sum_{j=0}^{M-1} \Lambda(i,j)\cos\left [ \frac{\pi u}{2 N}\left ( 2i +1 \right ) \right ]\cos\left [ \frac{\pi v}{2 M}\left ( 2j +1 \right ) \right ] f(i,j)
    \intertext{where}
    \Lambda(i) &=
    \begin{dcases}
      \frac{1}{\sqrt{2}} & \text{for}\ \varepsilon = 0\\
       1 & \text{otherwise}
    \end{dcases}
  \end{align}
\end{document}
If you are struggling which such basics, you might need to do some basic reading. Useful information about advanced math typesetting can be found in the excellent »Math mode« document.


Thorsten
Nolin
Posts: 4
Joined: Thu Sep 27, 2012 2:29 pm

Correct Use of Math Mode for Equations

Post by Nolin »

My misstake!
But problem still contains. I dont get an error, just warnings but the problem is that my .pdf file is kinda empty. I had lots of text there before, added this and now it dosnt work at all. Is there some way to figure out what problem there is since i just get warnings.

Code: Select all

LaTeX Warning: Citation `david_l' on page 12 undefined on input line 312.

[12]
Overfull \hbox (22.48993pt too wide) in paragraph at lines 331--331
[] 
<dct2.jpg, id=69, 1450.41875pt x 343.2825pt> <use dct2.jpg>)
Runaway argument?
{Figure illustrates a MRI image of a phantom, where 1\label {fig:dct2\ETC.
! File ended while scanning use of \@xdblarg.
<inserted text> 
                \par 
<*> ...ropbox/exjobb_rapport/using/rapportmall.tex
                                                  
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Correct Use of Math Mode for Equations

Post by localghost »

You don't just get warnings, but concrete error messages. The problem is caused neither by the equation you posted nor by my examples. It's even not caused by an equation at all but by a figure caption. And the exact wording of this caption along with the corresponding line(s) where to find it is given in the error message you posted.

Please reduce the problem to a proper minimal example that exactly reproduces these error(s). Otherwise it will not be possible to help you.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Correct Use of Math Mode for Equations

Post by Stefan Kottwitz »

Hi Nolin,

have a look at Thorsten's link regarding an minimal example. That's useful information for now and for later. Better post an MWE ("minimal working example") instead of a code snippet you guess it may contain the error. An MWE is better and usually a guarantee to get a solution.

At least we got an error message now. Well, this and the code line let me guess, it may be caused by a missing brace, because we would get exactly this error

Code: Select all

! File ended while scanning use of \@xdblarg.

with code like

Code: Select all

\caption{text\label{labelname}
where the closing brace is missing.

Stefan
LaTeX.org admin
Post Reply