10

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.

  • 1
    you can try with \the\hyphenpenalty to check the value inside and outside block – touhami Dec 18 '16 at 18:26
  • 2
    You are missing a \par at the end of your group. – Ulrike Fischer Dec 18 '16 at 18:26
  • @touhami thanks for pointing this out, very useful! – Tasos Papastylianou Dec 18 '16 at 18:38
13

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.