[Tex/LaTex] the scope of \hyphenpenalty

hyphenation

What is the scope of the \hyphenpenalty command? E.g.

\hyphenpenalty=0
Dear hyphens! You are welcome here! Welcome! 

{ 
  \hyphenpenalty=100000
  We don't want no pesky hyphens inside dis here block! Dey tuk r jurrbs!
}

I sure hope those inner-block bigots haven't scared away 
those poor hyphens out here too!

Are hyphens still welcome after the inner block? 🙂


For context: I'm trying to write stuff in the margin in places where I've highlighted corrections in my thesis, and I'd appreciate aggressive hyphenation to make more use of limited available margin space. Aesthetics don't really matter too much because it's to point out what a correction was for, so it will be removed in the official document. I want to make sure that having a hyphenpenalty inside a marginpar won't affect the rest of my document.

Best Answer

Hyphens are also welcome in the inner block. \hyphenpenalty=100000 does not have an effect. Hyphenation is done at the end of the paragraph, when TeX tries to fit and break the text into lines. But the end of the paragraph is at the empty line (causing \par) after the block with \hyphenpenalty=0 in force.

Fixed example:

\hyphenpenalty=0
Dear hyphens! You are welcome here! Welcome! 

{ 
  \hyphenpenalty=100000 % local assignment
  We don't want no pesky hyphens inside dis here block! Dey tuk r jurrbs!
  \par
}

Now, hyphens are again welcome.    

The setting to \hyphenpenalty is local to the current group. The assignment can be made global by prefixing it with \global:

\global\hyphenpenalty=100000 % global assignment

For quick testing, \textwidth can be set to a very small value (even zero) to force hyphenation.