3

I want to typeset the hyphens in the margin using plain TeX (I'm using the XeTeX engine, if that's important to you). For example:

Lorem ipsum dolor sit amet, consecte-
tuer adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum
sociis natoque penatibus  et  magnis
dis parturient montes, nascetur ridi-
culus mus. Donec quam felis, ultrici-
es  nec,  pellentesque  eu,  pretium
quis,  sem.  Nulla  consequat  massa
quis enim. Donec pede justo, fringil-
la vel, aliquet nec, vulputate eget,
arcu.

There is a similar question on this website Put hyphen on the margin, not in the text, but it only covers LaTeX and ConTeXt.

I think the way to go is to redefine \hypenchar so that it produces \discretionary{\rlap-}{}{}.

1

2 Answers 2

3

as in latex or context, you can enable the built in protrusion

enter image description here

\XeTeXprotrudechars=2
\font\rm=[lmroman10-regular.otf] \rm
\rpcode\font\XeTeXcharglyph\hyphenchar\font=350
\hsize=6.5cm
\parindent=0pt

Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Aenean commodo
ligula eget dolor. Aenean massa. Cum
sociis natoque penatibus  et  magnis
dis parturient montes, nascetur rididculus mus.
Donec quam felis, ultricies  nec,  pellentesque  eu,  pretium
quis,  sem.  Nulla  consequat  massa
quis enim. Donec pede justo, fringilla vel,
aliquet nec, vulputate eget,
arcu.

\bye
5
  • Thanks, do you know if there is a way to achieve a similar result without relying on XeTeX extensions? Just out of curiosity
    – user292932
    Commented May 17, 2023 at 11:21
  • 2
    no, basically you need to modify the linebreaker, all current engines have this, pdflatex originally @John Commented May 17, 2023 at 11:25
  • Good to know thanks
    – user292932
    Commented May 17, 2023 at 12:22
  • pdftex originally.
    – wipet
    Commented May 23, 2023 at 11:59
  • @wipet yes of course, it's an engine feature, I see my fingers added la by habit:-) Commented May 23, 2023 at 13:40
1

From the XeTeX manual §7:

\XeTeXprotrudechars ⟨integer⟩

Equivalent to \pdfprotrudechars in pdfTeX for controlling character protrusion or “margin kerning”. When set to zero (default), character protrusion is turned off. When set to one, it is activated but will not affect line-breaking. When set to two, line-breaking decisions will change as a result of the character protrusion.

Example:

\XeTeXprotrudechars=2
\font\rm="[texgyrepagella-regular.otf]"\relax
\rm
\rpcode\font\XeTeXcharglyph\hyphenchar\font=250
\hsize=20mm
a a a a a a a a a a abbabbabb aabbabbabb abbabb

enter image description here

See the pdfTeX documentation for further details.

\rpcode ⟨font⟩ ⟨char slot⟩ (integer, 𝑛)

Sets the right-side character protrusion value of the ⟨char slot⟩ in the specified ⟨font⟩ to n/1000 em. n is clipped to ±1000.

\lpcode ⟨font⟩ ⟨char slot⟩ (integer, 𝑛)

Sets the left-side character protrusion value of the ⟨char slot⟩ in the specified ⟨font⟩ to n/1000 em. n is clipped to ±1000.

2
  • Thanks, do you know if there is a way to achieve a similar result without relying on XeTeX extensions? Just out of curiosity
    – user292932
    Commented May 17, 2023 at 11:20
  • 1
    @John You could probably adjust the metrics of the hyphen character, but you'd need to modify .tfm files, which you can't do from within TeX. Commented May 17, 2023 at 22:32

You must log in to answer this question.