Menu

#185 Unwanted line break with \raggedleft, \centering or \raggedright

Future
open
nobody
None
5
2024-04-08
2021-06-05
Anonymous
No

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. Pdflatex and Luatex don't have this bug.

\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}

Discussion

  • Anonymous

    Anonymous - 2023-03-07

    A plaintex example

    \parindent=0pt
    \def\test#1{%
      \setbox0=\hbox{#1}
      \vbox{\hsize=\wd0 \leftskip0pt plus 1fil  #1} % emulate \raggedleft etc.
      \vbox{\hsize=\wd0 \rightskip0pt plus 1fil #1}
      \vbox{\hsize=\wd0 \leftskip0pt plus 1fil \rightskip\leftskip #1}
      \par
    }
    
    \font\1="[lmroman10-regular]" at 10pt \1
    \test{Dest-Addr} % ok
    
    \font\1="[lmroman10-regular]" at 10.95pt \1
    \test{Dest-Addr} % unwanted line breaks right after hyphen char
    % none of 10.94pt nor 10.96pt can reproduce the problem
    
    \font\1="[lmroman10-regular]" at 11pt \1
    \test{Dest-Addr} % ok
    
    \bye
    

    output
    The condition to reproduce the problem is so narrow that makes me guess it's caused by some rounding error.

     
  • Anonymous

    Anonymous - 2024-02-07

    This is a rounding issue where D2Fix rounds the double by addiing 0.5 before it converted into an integer, effectively rounding the number, rather than just truncating it. If the +0.5 is removed (so it just (int)(d * 65556.0) then this issue (and a number of issues I've had with tblr environments) goes away. I suspect (and this is a guess) that the rounding up exceding the size of the box calculated somewhere else.

     
  • karl berry

    karl berry - 2024-02-12

    Here is a version of the test document that runs under -ini, and also runs with both xetex and luatex. Reply posted to the thread following https://tug.org/pipermail/tex-live/2024-February/049883.html ...

     
  • Anonymous

    Anonymous - 2024-04-08

    Hello Karl,

    I noticed there is an error in your example where the problem size is 10.95pt but the example has 10.90pt, which works.

    \fi
    at 10.90pt
    \loggingall
    \1
    \test{Dest-Addr} % unwanted line breaks right after hyphen char
    % none of 10.94pt nor 10.96pt can reproduce the problem with xetex.

    I did find where a rounding error does happen in XeTeX_err.c.

    At 10.95pt in the function measure_native_mode (around line 2100)

                width = positions[totalGlyphCount].x;
    
    node_width(node) = D2Fix(width);
    

    This is less than sum(advances) by 1. Setting node_width(node) = sum(D2Fix(advances[i])) does result in the 10.95pt example no longer breaking. My test code if ugly but I could clean it up

    I've noticed if I'm not running without -ini it will break the line on the hypen regardless (tested with 10pt, 10.95pt and 11pt), tested on a new TL install on a CentOS 7 system. This behaviour is in line with pdftex (using cmr10 rather than lmr10).

     

Anonymous
Anonymous

Add attachments
Cancel