[Tex/LaTex] Hbox overfull: automatic linebreaks on spaces

automationline-breaking

I have a problem Overfull \hbox (13.62198pt too wide) in paragraph at lines 49--50. I read similar questions and all the solutions introduced a manual intervention directly into the text – e.g. using a linebreak, a command from another package surrounding the problematic text, etc. I would like to define some settings in the beginning of the document, e.g. linebreak upon space if you cannot decide. I would like to avoid as much manual work as possible.

My problematic lines of the text are:

\begin{itemize}
\item The language of enquiry $\mathcal{L}$ is given by $\mathcal{C}_o=\{milk, curry, rice\}$,$\mathcal{R}_o=\{TastesHot, IsWhite, ContainsSpice, ContainsSugar\}$, $\mathcal{F}_o=\{\}$.
\item Let the observational language $\mathcal{L}_o$ be $\mathcal{C}_o=\{milk, curry, rice\}$, $\mathcal{R}_o=\{TastesHot, IsWhite\}$, $\mathcal{F}_o=\{\}$
\item Let the hypothesis language $\mathcal{L}_h$ be $\mathcal{C}_h=\{milk, curry, rice\}$, $\mathcal{R}_h=\{TastesHot, IsWhite, ContainsSpice\}$, $\mathcal{F}_h=\{\}$.
\item $\mathcal{L}_h$-sentences are $\forall x. TastesHot(x) \implies ContainsSpice(x)$, $\forall x. IsWhite(x) \lor TastesHot(x)$.
\end{itemize}

Settings in the beginning of the document are:

\documentclass[a4paper,12pt,twoside]{report}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=3cm]{geometry}
\usepackage{amsthm}
\usepackage{amsmath}

And the template code:

\pagestyle{empty}

\setlength{\parskip}{2ex plus 0.5ex minus 0.2ex}
\setlength{\parindent}{0pt}

\makeatletter  %to avoid error messages generated by "\@". Makes Latex treat "@" like a letter

\linespread{1.5}
\def\submitdate#1{\gdef\@submitdate{#1}}

\def\maketitle{
  \begin{titlepage}{
    %\linespread{1.5}
    \Large University of London \\
    %\linebreak
    Imperial College of Science, Technology and Medicine \\
    %\linebreak
    Department of Computing
    \rm
    \vskip 3in
    \Large \bf \@title \par
  }
  \vskip 0.3in
  \par
  {\Large \@author}
  \vskip 2.9in
  \par
  Submitted in partial fulfilment of the requirements for the MEng Degree
  \linebreak
  in Computing (Artificial Intelligence) of Imperial College London
  \linebreak
  \@submitdate
  \vfil
  \end{titlepage}
}

\def\titlepage{
  \newpage
  \centering
  \linespread{1}
  \normalsize
  \vbox to \vsize\bgroup\vbox to 9in\bgroup
}
\def\endtitlepage{
  \par
  \kern 0pt
  \egroup
  \vss
  \egroup
  \cleardoublepage
}

\def\abstract{
  \begin{center}{
    \large\bf Abstract}
  \end{center}
  \small
  %\def\baselinestretch{1.5}
  \linespread{1.5}
  \normalsize
}
\def\endabstract{
  \par
}

\newenvironment{acknowledgements}{
  \cleardoublepage
  \begin{center}{
    \large \bf Acknowledgements}
  \end{center}
  \small
  \linespread{1.5}
  \normalsize
}{\cleardoublepage}
\def\endacknowledgements{
  \par
}

\newenvironment{dedication}{
  \cleardoublepage
  \begin{center}{
    \large \bf Dedication}
  \end{center}
  \small
  \linespread{1.5}
  \normalsize
}{\cleardoublepage}
\def\enddedication{
  \par
}

\def\preface{
    \pagenumbering{roman}
    \pagestyle{plain}
    \doublespacing
}

\def\body{
    \cleardoublepage    
    \pagestyle{uheadings}
    \tableofcontents
    \pagestyle{plain}
    \cleardoublepage
    \pagestyle{uheadings}
    \listoftables
    \pagestyle{plain}
    \cleardoublepage
    \pagestyle{uheadings}
    \listoffigures
    \pagestyle{plain}
    \cleardoublepage
    \pagestyle{uheadings}
    \pagenumbering{arabic}
    \doublespacing
}

\makeatother  %to avoid error messages generated by "\@". Makes Latex treat "@" like a letter

Notice, these have the spaces, I do not understand why the Latex complains. I am new to Latex, perhaps a simple setting would solve my problem.

Best Answer

you've already separated the different elements, providing spaces between the distinct equations comprising each language and separately coding these equations as math (even though the space between the first two is, probably inadvertently, omitted). unfortunately, these spaces don't fall in a place that is optimal for tex to break the line.

the ultimate goal is for what is presented to be understood.

there are two parts to this recommendation.

first, the words "milk, curry, rice" are, as you say, constants, and as such should be in a text font, preferably not italic in this context, even though they're part of the math expression. as coded in your original, they are typeset as strings of variables multiplied together. these could be coded as \mathrm{<word>}, but that doesn't help with line breaking. it also wouldn't leave spaces after the commas, although in this situation, whether spaces are visible there or not wouldn't be misunderstood by a reader.

another way to approach these is to recognize them as text, and input them as, for example,

$\mathcal{C}_o=\{\text{milk, curry, rice}\}$

but this doesn't help with line breaking either, since in this context, the only "allowable" break is after the equals sign.

so, second part of suggestion, take advantage of the fact that a reader isn't likely to misunderstand what is meant if a line is broken within that string of constants, and (temporarily) terminate the math after the opening brace, and reinstate it for the ending brace:

$\mathcal{C}_o=\{$milk, curry, rice$\}$

to illustrate, using a forced line break for the "all math" instance, compare these two lines:

enter image description here

here's the input that produced the image:

\begin{itemize}
\item The language of enquiry $\mathcal{L}$ is given by
$\mathcal{C}_o=\{milk, curry, rice\}$,\\
$\mathcal{R}_o=\{TastesHot, IsWhite, ContainsSpice, ContainsSugar\}$,
$\mathcal{F}_o=\{\}$.
\item The language of enquiry $\mathcal{L}$ is given by
$\mathcal{C}_o=\{$milk, curry, rice$\}$,
$\mathcal{R}_o=\{$TastesHot, IsWhite, ContainsSpice, ContainsSugar$\}$,
$\mathcal{F}_o=\{\}$.
\end{itemize}

(by the way, that's hardly a minimal example.)