7

Is there a way to automatically set parameters when emergency stretch is required?

Here is my situation. After I implemented the solution chosen for unbreakable spaces in Bible verse references, I get some overfull boxes due to verse references at the end of lines. To fix these overfull lines, I can allow hyphenation between the book name and the chapter, as an exception (I don't want to allow it unless it is really necessary).

I've made myself two macros to make this easier. For example, I'll use:

(\BRallowhypbch\ibibleverse{Ac}(4:13)\BRforbidhypbch).

To allow hyphenation between Actes and 4.13 in Actes 4.13 as an exception.

I'm wondering if, when LaTeX gets down to use \emergencystretch (because other methods of justifications have failed), there is a way to trigger a hook that would call my two macros before and after the problematic paragraph (or line if possible) to fix it.

raphink
  • 31,894
  • Would you please make the question more clear? Do you want \BRallowhypbch activated when you set \emergencystretch? – egreg Jun 14 '11 at 15:10
  • @egreg: I fixed the explanation a bit... The question is whether, when LaTeX has to employ some "tougher" justification method, it is possible to trigger hooks to "help" it. – raphink Jun 14 '11 at 15:13
  • @Raphink Are you using microtype? – yannisl Jun 14 '11 at 15:32
  • @Yiannis: yes, the beta version for XeTeX. – raphink Jun 14 '11 at 17:18
  • @Raphink normally this should help. Can you post a small image with a sample paragraph? I think it will be best to rather box and unbox the full paragraph, or otherwise use egreg's solution or something similar. TeX goe through a paragraph three times and then if everything fails and emergencystretch>0 kicks in the last round. To hook into it, you will need to catch the whole paragraph, check for badness, change parameters and retry. – yannisl Jun 14 '11 at 18:49
  • @Yiannis: microtype does help already, and I've already set \tolerance=300 and \emergencystretch=1.7em, which solves 90% of my problems, but in some cases (say, 2 cases in 90 pages so far), a Bible reference will prevent proper hyphenation, and in this case, I would rather set an exception to allow hyphenation in the Bible reference. – raphink Jun 14 '11 at 20:08
  • By the way, I don't know if it's really a good idea to set \tolerance=300 and \emergencystretch=1.7em in the preamble, or if I should only do that for paragraphs that require it. – raphink Jun 14 '11 at 20:09
  • @Raphink Do a more reading at http://www.tex.ac.uk/cgi-bin/texfaq2html?label=overfull personally I never use \emergencystretch. – yannisl Jun 14 '11 at 20:18
  • Thanks @Yiannis, I had already read that :-) I'm not really sure still if \tolerance is better set for the whole document or for a specific paragraph (using an environment like in @egreg's answer for example). – raphink Jun 14 '11 at 20:35
  • @Raphink Always better to adjust tolerances on specific problematic paragraphs only, i.e, have a global value and only adjust for overfull cases see my example http://tex.stackexchange.com/questions/19178/whats-the-difference-between-tolerance-and-badness/19189#19189 – yannisl Jun 14 '11 at 20:55
  • @Yiannis: XeTeX doesn't indicate the badness in the logs: Overfull \hbox (4.45204pt too wide) in paragraph at lines 3--10 \EU1/LinuxLibertineO(0)/m/n/12 pleine, personnelle et sainement biblique avec D ieu lâ<80><99>Esprit-Saint,| [] How do I know how to adjust the \tolerance ? – raphink Jun 15 '11 at 08:24

1 Answers1

7

I would define a particular environment:

\newenvironment{specialpar}[1]{\par#1}{\par}

This allows to enclose the problematic paragraph and do experiments with the various methods, for example

\begin{specialpar}{\emergencystretch=3em \BRallowhypbch}
Problematic paragraph ...
\end{specialpar}

The settings in the argument will be in force only for this paragraph; if the argument is left empty, there will be no particular setting and the paragraph will be typeset with the default values.

egreg
  • 1,121,712