Math & ScienceBreaking math expression

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

Breaking math expression

Post by Singularity »

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

I have (well, had) \everymath{\displaystyle}.

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

Code: Select all

\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}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Breaking math expression

Post by Johannes_B »

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.

Code: Select all

\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: 156
Joined: Sat Jan 22, 2011 9:55 pm

Breaking math expression

Post by Singularity »

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: 156
Joined: Sat Jan 22, 2011 9:55 pm

Breaking math expression

Post by Singularity »

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.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Breaking math expression

Post by Johannes_B »

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.

Code: Select all

\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 
$\displaystyle
R=\{\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: 156
Joined: Sat Jan 22, 2011 9:55 pm

Breaking math expression

Post by Singularity »

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
(16.14 KiB) Downloaded 969 times
I can't attach the image files, they are too big.

Thanks,
J
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Breaking math expression

Post by Johannes_B »

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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Breaking math expression

Post by Stefan Kottwitz »

Long equations even with left and right delimiters can be broken automatically, if you would use a dmath environment of the breqn package.

Stefan
LaTeX.org admin
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

Re: Breaking math expression

Post by Singularity »

Good info, thanks.
Post Reply