# [XeTeX] Overfull \hbox when using inline math scripts

Daniel Greenhoe dgreenhoe at gmail.com
Sat Dec 17 08:49:03 CET 2011

2011/12/16 Zdenek Wagner <zdenek.wagner at gmail.com>:
> Generally speaking, paragraph breaking is controlled by a few
> registers, the most important is \tolerance. \sloppy sets \tolerance
> to 10000 which then looks ugly. You should start with \tolerance=9999.
> In such a case you should not have overfull boxes (if you still have
> them, some changes in the text may be needed). After this run you find
> the highest badness of the underfull box. Set \tolerance to this value
> and \hbadness to one less and run LaTeX again. You should see just one
> underfull box in your log. Now you can decrease \tolerance (and
> value of \tolerance and set \hbadness to the same value. If you have a
> paragraph with an overfull box, then set locally for  that paragraph
> \emergencystretch=1em. (This algorithm appeared years ago in an
> article by Phil Taylor and I use it since then)

> One possible solution for the particular example you posted (see below) is
> to allow line breaks at commas in inline maths. The solution I use for this
> is:
> \mathchardef\breakingcomma\mathcode\,
> {\catcode,=\active
> \gdef,{\breakingcomma\discretionary{}{}{}}}
> \newcommand{\mathlist}[1]{$\mathcode\,=\string"8000 #1$}

think maybe I can use the Philip/Zdenek solution for most cases, and
the Conrad solution for problems that still may persist after that.

Thanks again,
Dan

> Dan,
>
> One possible solution for the particular example you posted (see below) is
> to allow line breaks at commas in inline maths. The solution I use for this
> is:
>
> \mathchardef\breakingcomma\mathcode\,
>
> {\catcode,=\active
>
> \gdef,{\breakingcomma\discretionary{}{}{}}
>
> }
>
>
> \newcommand{\mathlist}[1]{$\mathcode\,=\string"8000 #1$}
>
>
> which I took from the answer by egreg to the following stackexchange
> question:
>
> http://tex.stackexchange.com/questions/19094/allowing-line-break-at-in-inline-math-mode-breaks-citations
>
>
> You could use this as "Let the tuple $(\mathlist{X, Y, Z, A, B, C, +, x, -, > !, \#})$" in your example.
>
>
> There are some other solutions in that post and the other it links to.
>
>
> All my best,
>
> On 12/16/2011 01:55 AM, Daniel Greenhoe wrote:
>
> I have a rather long document involving mathematics that sometimes has
> the "Overfull \hbox" problem when I use inline mathematical scripts.
> Before I go hacking up the document with newline and \raggedright
> commands, is there any more elegant solution currently available?
>
> \documentclass[12pt]{book}
> \usepackage{fontspec}
> \usepackage{unicode-math}
> \usepackage{geometry}
> \geometry{
>   paper=a4paper,margin=20mm,
>   showframe
>   }
> \setmainfont{texgyrepagella-regular.otf}
> \setmathfont{xits-math.otf}
> \setlength{\parindent}{0pt}
> \begin{document}%
> \thispagestyle{empty}%
> %\sloppy
> %\raggedright
> Theorem 1.1 (The Theorem That Has This Rather Long Title)
> Let the tuple $(X, Y, Z, A, B, C, +, x, -, !, \#)$
> be some useful mathematical structure.
> Then, \ldots
> \end{document}%
>
> Dan
>
>
>
>
>
> --------------------------------------------------
> Subscriptions, Archive, and List information, etc.:
>   http://tug.org/mailman/listinfo/xetex
>
>
>
>
>
> --------------------------------------------------
> Subscriptions, Archive, and List information, etc.:
>  http://tug.org/mailman/listinfo/xetex
>