## LaTeX forum ⇒ Math & Science ⇒ Breaking math expression Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm

### Breaking math expression

How can I get a long expression to break across lines within a paragraph?

I have a long line that I do not want to put on its own line
Given the relation $R$ on $A=\set{1,2,3,4,5,6,7,8}$ defined by $R=\set{(1,1),(1,2),(1,4),(1,8),(2,2),(2,4),(2,8),(3,3),(3,6),(4,4),(4,8),(5,5),(6,6),(7,7),(8,8)}$, determine whether it is
(a) etc....

The relation R is too long to fit on a line and prints right through the margin and on thin air.

I have tried inserting a \\.
I have tried turning off the \everymath command.
I have tried \textstyle{R={...}}.

I've also tried replace \set with \{ and \}.
But nothing seems to make it break.

MWE
\documentclass[fleqn,addpoints,answers]{exam}\usepackage{amsfonts,amsmath,amssymb,amsthm,mathtools,commath} %\everymath{\displaystyle}\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip} \begin{document} Given the relation $R$ on $A=\set{1,2,3,4,5,6,7,8}$ defined by $\textstyle{R=\set{(1,1),(1,2),(1,4),(1,8),(2,2),(2,4), \\ (2,8),(3,3),(3,6),(4,4),(4,8),(5,5),(6,6),(7,7),(8,8)}}$, determine whether it is\begin{enumerate}	\item Reflexive	\item Antisymmetric	\item Transitive	\item A partial ordering on $A$\end{enumerate} \end{document}

Tags:

Johannes_B
Site Moderator
Posts: 3602
Joined: Thu Nov 01, 2012 4:08 pm
In the middle i wasn't sure if you want a matrix. Do you want a matrix? Usually, displayed formulas are used for big equations.
\documentclass[fleqn,addpoints,answers]{exam}\usepackage{amsfonts,amsmath,amssymb,amsthm,mathtools,commath,showframe} %\everymath{\displaystyle}\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip} \begin{document}Given the relation $R$ on $A=\set{1,2,3,4,5,6,7,8}$ defined by $R=\{(1,1),(1,2),(1,4),(1,8),(2,2),(2,4),\linebreak (2,8),(3,3),(3,6),(4,4),(4,8),(5,5),(6,6),(7,7),(8,8)\}$ determine whether it is Given the relation $R$ on $A=\set{1,2,3,4,5,6,7,8}$ defined by $R=\begin{Bmatrix}(1,1),(1,2),(1,4),(1,8),(2,2),(2,4), \\ (2,8),(3,3),(3,6),(4,4),(4,8),(5,5),(6,6),(7,7),(8,8)\end{Bmatrix},$ determine whether it is\begin{enumerate}	\item Reflexive	\item Antisymmetric	\item Transitive	\item A partial ordering on $A$\end{enumerate} \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm
Thanks. Not looking for a matrix. In math terms (if you're curious), it's a set of ordered pairs, which is not the same as a matrix. Your first solution is what I want.

I see you used \linebreak. This is good for the time being. Is there a way to automate it, so that LaTeX chooses an appropriate linebreak (like it does for everything else)?

Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm
It seems that when I turn \everymath{\displaystyle} back on, it blocks the \linebreak.

Is there a way to turn off \displaystyle temporarily? I've tried \textstyle but no luck. If not, I can probably get away without it this (and most) documents (mostly, I hate the displaystyle \sigma and \int, etc.

Johannes_B
Site Moderator
Posts: 3602
Joined: Thu Nov 01, 2012 4:08 pm
I don't experience any difficulties with \displaystyle, though using it everywhere is a bad thing. I think i have said that multiple times by now.

There is also a way to split at commas, the following is adapted directly from egreg's answer at TeX.SX.

\documentclass[fleqn,addpoints,answers]{exam}\usepackage{amsfonts,	amsmath,	amssymb,	amsthm,	mathtools,	commath,	showframe} \everymath{\displaystyle}\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip}  \newcommand{\splitatcommas}[1]{%	\begingroup	\begingroup\lccode~=, \lowercase{\endgroup		\edef~{\mathchar\the\mathcode, \penalty0			\noexpand\hspace{0pt plus 1em}}%		}\mathcode,="8000 #1%	\endgroup} \begin{document}Given the relation $R$ on $A=\set{1,2,3,4,5,6,7,8}$ defined by $\displaystyleR=\{\splitatcommas{(1,1),(1,2),(1,4),(1,8),(2,2),(2,4),(2,8),(3,3),(3,6),(4,4),(4,8),(5,5),(6,6),(7,7),(8,8)}\}$determine whether it is\begin{enumerate}	\item Reflexive	\item Antisymmetric	\item Transitive	\item A partial ordering on $A$\end{enumerate} \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm
I can't figure out why it won't work in my file. I'm posting the whole thing here -- even though it's not exactly an MWE -- hoping someone can help me.

The \linebreak is on line 275 (with wordwrap turned off). It will be question 7 in the output.

Test 2 (Sets, Fcns, Combinatorics).tex

I can't attach the image files, they are too big.

Thanks,
J

Johannes_B
Site Moderator
Posts: 3602
Joined: Thu Nov 01, 2012 4:08 pm
It is the \left{ \right} pair. That always means: unbreakable.

There is a reason i substituted the \set command. It uses the same mechanism, resulting in an unbreakable box.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Stefan Kottwitz
Posts: 8598
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Long equations even with left and right delimiters can be broken automatically, if you would use a dmath environment of the breqn package.

Stefan