Article View: comp.text.tex
Article #2236Re: penalty inside a macro, problems with punctuation
From: Richard Beigel
Date: Sat, 15 Aug 1992 16:31
Date: Sat, 15 Aug 1992 16:31
38 lines
2241 bytes
2241 bytes
In article <1992Aug12.195354.13725@cs.yale.edu>, I wrote
>I would like to discourange line breaks inside a certain macro.
Donald Arseneau sent me a really nice solution which prevents
non-explicit hyphenation and sets a penalty of 500 for line breaks
between words. Here is his solution, followed by his explanations
(slightly edited):
{\obeyspaces%
\gdef\machine{\begingroup\obeyspaces% change catcode of spaces before reading
\let =\pensp\Machine}% the parameter with \machine
}
\def\Machine#1{\rm machine\null~[\null#1\null]\endgroup}
\def\pensp{\leavevmode\ifdim\lastskip=0pt{\null\penalty500 } \fi}
This makes spaces "active" in the parameter text and defines them
to be a \null, a penalty, and a space, but avoiding multiple spaces.
(\ignorespaces only ignores ordinary spaces.)
The \null macro is just an empty \hbox{}; it prevents hyphenation because
TeX won't try to hyphenate something that isn't a plain word.
Note that increasing the interword penalty above the value of \tolerance
has no greater effect than setting it to \tolerance (unless it is 10000).
If you are tolerating lines with badness of 500, then a penalty of 500 makes
sense.
This will still leave easy breakpoints wherever there is a dash or hyphen
in the parameter text. Make this harder by increasing the value of
\exhyphenpenalty to 500. This will be in effect for the whole paragraph,
but I don't find that to be a probalem.
--
Richard Beigel telephone: (203)432-1268
Dept. of Computer Science email: beigel-richard@cs.yale.edu
P.O. Box 2158, Yale Station campus mail: A. K. Watson Hall
New Haven, CT 06520-2158 51 Prospect Street
Technical Details
Message-ID:
<1992Aug15.163144.19208@cs.yale.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!caen!nigel.msen.com!yale.edu!cs.yale.edu!beigel-richardShow Full Headers
Complete Article Headers
Newsgroups: comp.text.tex Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!caen!nigel.msen.com!yale.edu!cs.yale.edu!beigel-richard From: beigel-richard@CS.YALE.EDU (Richard Beigel) Subject: Re: penalty inside a macro, problems with punctuation Message-ID: <1992Aug15.163144.19208@cs.yale.edu> Summary: how to discourage line breaks inside a macro Sender: news@cs.yale.edu (Usenet News) Nntp-Posting-Host: beech.theory.cs.yale.edu Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Date: Sat, 15 Aug 1992 16:31:44 GMT Lines: 38