# Emergency stretch hook

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.

-
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. –  ℝaphink Jun 14 '11 at 15:13
@Raphink Are you using microtype? –  Yiannis Lazarides Jun 14 '11 at 15:32
@Yiannis: yes, the beta version for XeTeX. –  ℝaphink 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. –  Yiannis Lazarides Jun 14 '11 at 18:49

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.

-