How would I write a macro (to be placed immediately before every URL in a bibliography) whose effect is to tell TeX
- This is a good place to insert a line break, but breaking the line here is not required.
- If (and only if) you break the line here, insert a
\hfill(or maybe a\par, I'm not sure which makes more sense) immediately before the line break.
I tried \discretionary{\hfill}{}{}\penalty-500\relax which gave me a bunch of "Improper discretionary list" errors, and I also tried \discretionary{\par}{}{}\penalty-500\relax which didn't give me any errors but also didn't seem to have any effect.
(Also I'm not sure if \penalty is how you encourage a line break.)
(What I really want is for TeX to insert a paragraph break before the URL if and only if the URL doesn't fit onto the space remaining in the current line, but -- after that break happens -- not interfere with url.sty's intra-URL line breaking. But I suspect this is not even possible, whereas what I described above, I'm pretty sure is possible, I just don't know how to do it.)