4

I'm encountering an issue where I have \leaders that occasionally fall at the beginning of the line and as a result, there are no leaders appearing.

I have for example:

\hsize 9.2cm

Lorem ipsum dolor sit amet\leaders\hbox{.}\hfill 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit\leaders\hbox{.}\hfill 2

\end

and this produces:

Lorem ipsum dolor sit amet ............................ 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit
2

If I add \penalty0\hbox{}\penalty10000 before the \leaders, I get

Lorem ipsum dolor sit amet ............................ 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit
....................................................... 2

But what I really want is this:

Lorem ipsum dolor sit amet ............................ 1
Lorem ipsum dolor sit amet, consectetur adipiscing
elit .................................................. 2

I've tried adding \penalty and other things but nothing I try seems to give me the desired result. Am I overlooking something simple?

4
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Seamus
    Dec 18, 2015 at 15:59
  • 3
    @Seamus: I'm not using LaTeX.
    – dreamlax
    Dec 18, 2015 at 16:00
  • @dreamlax Compilable example is sufficient.
    – Manuel
    Dec 18, 2015 at 16:04
  • @dreamlax Sorry, that's just a stock block of text we use. Most people who need to be asked for a MWE will be using LaTeX.
    – Seamus
    Dec 18, 2015 at 16:12

1 Answer 1

12

Glue (and leaders) are removed at a line break; so your idea of adding \nobreak is good, but you spoil it with \penalty0 that introduces a feasible line break before the empty box and the leaders.

Just use \nobreak. I also add some fixed width so some dots are printed anyway and \raggedright.

\def\mydotfill{\unskip\nobreak\leaders\hbox{.}\hskip 4em plus 1fill\relax}

\hsize 8.5cm \raggedright

\noindent
Lorem ipsum dolor sit amet\mydotfill 1

\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit\mydotfill 2

\end

enter image description here

2
  • Excellent, thanks for that. It's currently 5:32 Saturday morning and I have been up all Friday night (that explains the \penalty0).
    – dreamlax
    Dec 18, 2015 at 16:33
  • Perhaps relevant explanation of the first statement by the same poster tex.stackexchange.com/a/443672/183051
    – 0fnt
    Apr 26, 2019 at 6:52

You must log in to answer this question.

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