5

In a 2014 post of the XeTeX list, the Great Master David Carlisle gives the following code for obtaining the same result as with the \showhyphens command, but with OpenType fonts in XeTeX:

\catcode`\@=11
\def\showhyphenspace#1 {%
\ifx\valign#1\valign\else
#1\vadjust{\penalty\@ne} \expandafter\showhyphenspace
\fi}

\def\showhyphens#1{{%
\showboxbreadth\maxdimen
\showboxdepth\maxdimen
\pretolerance\m at ne\tolerance\m at ne
\setbox2\hbox{}%
\setbox0\vbox{%
\pretolerance\m at ne
\tolerance\m at ne\hbadness\z@
\parfillskip\z at skip
\hsize1sp
\noindent
\hskip\z@
\hfuzz\maxdimen
\hbadness\maxdimen
\showhyphenspace#1 {} \par
\loop
\count@\@ne
\ifnum1=\lastnodetype
 \setbox4\lastbox
 \setbox2\hbox{\unhbox4 \unhbox2}\count@\z@
\fi
\ifnum11=\lastnodetype\unskip\count@\z@\fi
\ifnum13=\lastnodetype
 \count2\lastpenalty
 \unpenalty\count@\z@
 \ifnum\count2=\@ne
 \setbox2\hbox{ \unhbox2}\count@\z@
 \fi
\fi
\ifnum\z@=\count@
\repeat
\hsize\maxdimen
\hfuzz\z@
\hbadness\z@
\par
\unhbox2
\par
}}}

When I run this code I get a lot of error messages such as

! Undefined control sequence.
\showhyphens ...xdepth \maxdimen \pretolerance \m 
                                                  at ne\tolerance \m at ne \...
l.129 }

and

! Undefined control sequence.
\showhyphens ...t ne\hbadness \z@ \parfillskip \z 
                                                  at skip \hsize 1sp \noinde...
l.129 }

and merely a third of the text that I wanted to see hyphenated.

Could you please tell me what to replace \z and \m with, so that it works in XeLaTeX?

7
  • 1
    You've got an oddly-formatted version: you want for example \m@ne not \m at ne
    – Joseph Wright
    Commented Apr 9, 2021 at 15:19
  • 2
    There's a problem in copy-pasting. All <space>at<space> bits should be @
    – egreg
    Commented Apr 9, 2021 at 15:19
  • Thank you so much! If only all problems were so easy to solve! (Please write an answer instead of a comment, so that I can validate it and you get the well-deserved credit!)
    – yannis
    Commented Apr 9, 2021 at 15:22
  • BTW, with a medium size text (~ 2,000 words) it works smoothly and produces an immediate result. With a 12,000-word text it takes ages and produces nothing. Am I doing something wrong? Or are there some limits not to cross?
    – yannis
    Commented Apr 9, 2021 at 15:39
  • note if you are using xelatex or lualatex then something equivalent to that is the default definition of \showhyphens you don't need any extra re-definition. Commented Apr 9, 2021 at 21:40

1 Answer 1

7

You are reading a version that has been mangled by a mail or website re-formatting changing @ to at to make email addresses safe from copying...

\m at ne is \m@ne ie -1

But you do not need this at all, the default definition of \showhyphens in XeLaTeX is the following slightly updated version of that code.

\DeclareRobustCommand\showhyphens[1]{%
  \setbox0\vbox{%
    \usefont{TU}{lmr}{m}{n}%
    \hsize 1sp %
    \hbadness\@M
    \hfuzz\maxdimen
    \tracingonline\z@
    \everypar={}%
    \leftskip\z@skip
    \rightskip\z@skip
    \parfillskip\z@skip
    \hyphenpenalty=-\@M
    \pretolerance\m@ne
    \interlinepenalty\z@
    \clubpenalty\z@
    \widowpenalty\z@
    \brokenpenalty1127 %
    \setbox\z@\hbox{}%
    \noindent
    \hskip\z@skip
    #1%
    \par
     \loop
     \@tempswafalse
     \ifnum\lastnodetype=11\unskip\@tempswatrue\fi
     \ifnum\lastnodetype=12\unkern\@tempswatrue\fi
     \ifnum\lastnodetype=13 %
      \count@\lastpenalty
      \unpenalty\@tempswatrue
    \fi
    \ifnum\lastnodetype=\@ne
     \setbox\tw@\lastbox\@tempswatrue
     \setbox0\hbox{\unhbox\tw@\unskip\unskip\unpenalty
                   \ifnum\count@=1127 \else\ \fi
                   \unhbox0}%
     \count@\z@
    \fi
    \if@tempswa
    \repeat
   \hbadness\z@
   \hsize\maxdimen
   \showboxdepth\z@
   \tolerance\m@ne
   \hyphenpenalty\z@
   \noindent\unhbox\z@
}}
1
  • I like very much your answer and the "Great Master David Carlisle" written by the user. :-) +1
    – Sebastiano
    Commented Apr 9, 2021 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .