Math & ScienceNew Line in Equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
gremlint
Posts: 16
Joined: Tue Oct 09, 2012 6:04 am

New Line in Equation

Post by gremlint »

LaTeX is not giving me two lines, and I have no idea why.

Code: Select all

\[
6. \quad f(x) = \frac {1} {1+9x^2} \\
f(x) = x^2
\]
That puts everything together on one line.

Why? The manual claims that a \\ will instruct the program to create a new line.
Last edited by localghost on Mon Nov 05, 2012 10:00 am, edited 1 time in total.

Recommended reading 2024:

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

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

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

New Line in Equation

Post by localghost »

gremlint wrote:[…] The manual claims that a \\ will instruct the program to create a new line.
Which manual exactly do you mean? And does it tell you that for text or math mode? Can you give a link where to find this manual?

Multi-lined equations are usually typeset by respective environments from amsmath like align, multline or split. The package manual should help you on in this regard. In case the package is installed in your TeX system, you have direct access by the command line.

Code: Select all

texdoc amsmath

Further reading:

Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10344
Joined: Mon Mar 10, 2008 9:44 pm

New Line in Equation

Post by Stefan Kottwitz »

Additionally, here are direct links:
A minimal example how your equation(s) could be typeset:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
  f(x) &= \frac {1} {1+9x^2} \\
       &= x^2
\end{align}
\end{document}
Here you can see, you can align at relation symbols if you mark the position by an ampersand symbol &. In those amsmath multi-line environments, you can break the line by \\.

Another remark: instead of writing unnumbered equations by \[ ... \] and manually numbering (6. \quad) I would let LaTeX do the numbering automatically. This allows automatic references if you use \label and \ref, or \eqref from amsmath.

Stefan
LaTeX.org admin
gremlint
Posts: 16
Joined: Tue Oct 09, 2012 6:04 am

New Line in Equation

Post by gremlint »

localghost wrote:Which manual exactly do you mean?
I'm using the manual that came with the software, "More Math into LaTeX," by George Gratzer.

Stefan — I tried your suggestion, and it didn't work.

This is the example file.

Code: Select all

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}

\begin{document}

\begin{align}
	f(x) &= \frac {1} {1+9x^2} \\
	&= x^2
\end{align}

\end{document}
And this is the obtained error message.

Code: Select all

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
 restricted \write18 enabled.
entering extended mode
(./Alignment Test 2.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, 
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
 polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, 
welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2012/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/parskip/parskip.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2012/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsopn.sty))
(./Alignment Test 2.aux)
*geometry* driver: auto-detecting./Alignment Test 2.tex:11: Missing $ inserted.
<inserted text> 
                $
l.11 
     
? 
*geometry* detected driver: pdftex
(/usr/local/texlive/2012/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifluatex.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2012/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/umsb.fd)
Runaway argument?
 
./Alignment Test 2.tex:11: Paragraph ended before \align was complete.
<to be read again> 
                   \par 
l.11 
     
?
Last edited by localghost on Sat Nov 10, 2012 10:50 am, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

New Line in Equation

Post by localghost »

Your example works flawlessly (TeX Live 2012 here).


Further reading:
gremlint
Posts: 16
Joined: Tue Oct 09, 2012 6:04 am

New Line in Equation

Post by gremlint »

localghost wrote:Your example works flawlessly.
No, that's incorrect. The sample file returned errors, as one can plainly see above.
gremlint
Posts: 16
Joined: Tue Oct 09, 2012 6:04 am

New Line in Equation

Post by gremlint »

Stefan_K wrote:A minimal example how your equation(s) could be typeset:
I modified the example slightly in my second attempt, and there were still errors.

Code: Select all

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}

\begin{document}

\begin{align}
\[
	f(x) &= \frac {1} {1+9x^2} \\
	&= x^2
\]
\end{align}
\end{document}

Code: Select all

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
 restricted \write18 enabled.
entering extended mode
(./Alignment Test 2.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, 
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
 polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, 
welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2012/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/parskip/parskip.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2012/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsmath/amsopn.sty))
(./Alignment Test 2.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/local/texlive/2012/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/ifluatex.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2012/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2012/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2012/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/umsa.f./Alignment Test 2.tex:15: Extra }, or forgotten \endgroup.
<template> }
            $}\ifmeasuring@ \savefieldlength@ \fi \set@field \endtemplate 
l.15 \end{align}
                
? d)
(/usr/local/texlive/2012/texmf-dist/tex/latex/amsfonts/umsb.fd)

./Alignment Test 2.tex:15: LaTeX Error: Bad math environment delimiter.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.15 \end{align}
Last edited by cgnieder on Sat Nov 10, 2012 8:33 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

New Line in Equation

Post by cgnieder »

gremlint wrote:I modified the example slightly in my second attempt, and there were still errors.

Code: Select all

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}

\begin{document}

\begin{align}
\[
	f(x) &= \frac {1} {1+9x^2} \\
	&= x^2
\]
\end{align}
\end{document}
This modification can't work! Both \begin{align} and \[ shift to math mode which effectively means that the second one ends the math mode! Stefan's example is correct and compiles flawlessly. Did you by any chance insert an empty line inside the {align} environment? That would cause the first error you reported. Empty lines are forbidden in the {align} environment.

Regards
site moderator & package author
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

New Line in Equation

Post by localghost »

gremlint wrote:No, that's incorrect. The sample file returned errors, as one can plainly see above.
Perhaps I should have written that it works for me on my system. So you shouldn't simply claim that my statement is not true. I understood this as a hint that you might face a systematical problem. So a follow-up question might have been suggestive.
gremlint
Posts: 16
Joined: Tue Oct 09, 2012 6:04 am

New Line in Equation

Post by gremlint »

cgnieder wrote:Did you by any chance insert an empty line inside the {align} environment?
No, I did not, but thanks for asking. See my first reply to Stefan.

Does LaTeX only work correctly on a PC? I'm using a Macintosh.
Post Reply