Desculpe se dei a entender que havia algo de mágico com litl… o que realmente importava era que as partes que precisavam ser deslocadas tivessem sua própria marcação (mas, nesse caso, você altera o hook para ficar antes de qual for o marcador relevante).
Agora, o fato de \hfill (e \leaders) serem descartados quando há uma quebra de linha é um recurso muito útil, não um bug - isso impede que haja um espaço no início/fim de uma linha quebrada. Não é necessário tratar as coisas como exceções, apenas precisamos educar o TeX…
A pergunta que precisa ser respondida, no entanto, é: o que você gostaria que acontecesse?
- Nunca quebrar a linha antes do número (mesmo que o resultado seja horrível): altere o final do sethook para:
litl}{\penalty10000\hfill}
- Uma linha inteira em branco / uma linha de pontos antes do número:
litl}{\unskip\penalty500\hbox{}\penalty10000\hfill}
Em ambos os casos, se você estiver usando o \leaders, coloque a parte extra na frente dele.
Explicação:
O que esses comandos fazem é dar algumas instruções extras ao algoritmo de quebra de linha.
Também adicionei \unskip, que remove um espaço anterior, se houver - isso é mais útil para o código baseado em \leaders e impede que haja um espaço entre os pontos e a palavra anterior.
O \penalty 500 significa que a linha pode ser quebrada ali, mas está longe do ideal. E \hbox{} é apenas algo de largura zero que ele não pode descartar. \penalty10000 diz que o custo de quebrar a linha aqui é 'infinito'. Assim, em ambas as versões, o TeX não é permitido quebrar a linha em (logo antes do) fill, e, portanto, ele não pode ser descartado pelo processo normal.
Sorry if I implied there was something magic with litl… what was really important was that the bits that needed to be offset needed to have their own markup (but then you change the hook to be before whatever the relevant marker is.
Now, \hfill (and \leaders) getting discarded if there’s a line-break is a very useful feature, not a bug - it stops there being a space at the start/end of a broken line. There’s no need to treat things as exceptions, we just need to educate TeX…
The question that needs to be answered, though, is what would you like to happen?
- Never ever break the line before the number (even if the result is horrible): change the end of the sethook to be:
litl}{\penalty10000\hfill}
- A whole blank line / line of dots before the number:
litl}{\unskip\penalty500\hbox{}\penalty10000\hfill}
In both of these, if you are using the \leaders, put the extra bit in front of that instead.
Explanation:
What these are doing is giving the line-breaking algorithm some extra instructions.
I’ve also added \unskip which removes a preceding space if there is one - that’s more useful for the \leaders-based code, and stops there being a space between the dots and the preceding word.
The \penalty 500 means the line can be broken there, but it’s a long way from ideal. and \hbox{} is just a zero-width thing that it can’t discard. \penalty10000 says the cost of breaking the line here is ‘infinite’. Thus for both of these versions, TeX is not allowed to break the line at (just before) the fill, and thus it cannot be discarded by the normal process.