1

In the following example, I get unwanted line breaks for text "Dest-Addr". The result is correct for text "Hello-World". The result is also correct if I change font size to 10pt or 12pt.

\documentclass[11pt]{article}
\parindent=0pt
\begin{document}

\setbox0=\hbox{Hello-World}
\setbox2=\vbox{\hsize=\wd0 Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \centering Hello-World}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft Hello-World}  \box2

\setbox0=\hbox{Dest-Addr}
\setbox2=\vbox{\hsize=\wd0 Dest-Addr} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright Dest-Addr} \box2
\setbox2=\vbox{\hsize=\wd0 \centering Dest-Addr}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft Dest-Addr}  \box2

\end{document} 

enter image description here

  1. Where do these unwanted line breaks come from?
  2. How can I get rid of these line breaks?

I need to use \raggedleft, \centering and \raggedright since in my package I need to compare and get the minimal width of several text lines and put them in a vbox (similar to varwidth package). Also I can not put them in a hbox for some other reasons.

1
  • I get no linebreaks with pdftex texlive 2021 nor with luatex, but I do with xetex – David Carlisle Jun 5 at 9:45
1

This only happens with xetex it seems.

You can prevent hyphenation by setting the exhyphenpenalty to the maximumn

\documentclass[11pt]{article}
\parindent=0pt
\begin{document}

\setbox0=\hbox{Hello-World}
\setbox2=\vbox{\hsize=\wd0 Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright Hello-World} \box2
\setbox2=\vbox{\hsize=\wd0 \centering Hello-World}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft Hello-World}  \box2


\setbox0=\hbox{Dest-Addr}
\setbox2=\vbox{\hsize=\wd0 Dest-Addr} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright \exhyphenpenalty10000 Dest-Addr} \box2
\setbox2=\vbox{\hsize=\wd0 \centering   \exhyphenpenalty10000 Dest-Addr}   \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft  \exhyphenpenalty10000 Dest-Addr}  \box2



\end{document} 
5
  • Is it a bug of XeTeX? Are there any other solutions, since I need to handle short text lines and breakable long text lines in the same commands and \exhyphenpenalty10000 is not good for the latter case? – L.J.R. Jun 5 at 10:23
  • @L.J.R. I was away from cpmputer so didn't investigate further, it's certainly surprising behaviour, you could raise it on the xetex list, the xetex developers are not here, I suspect it's \rounding error in passing lengths between tex and harfbuzz, but I'm not sure., – David Carlisle Jun 5 at 11:44
  • @L.J.R. with \raggedright you don't (normally) get hyhpenation unless the word is longer than the text width so stopping hyphenation may not be an issue – David Carlisle Jun 5 at 11:45
  • looks like a bug in XeTeX. Add 1sp to the width of box 0 and no break happens. I think this should be discussed on xetex list. – Frank Mittelbach Jun 5 at 21:24
  • I have submit a bug here: sourceforge.net/p/xetex/bugs/185 – L.J.R. Jun 5 at 23:46

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.