I would like to typeset text (a link) at the end of the current line, like this

1 Text.                                                  [Link]

2 More text, that is unfortunately too long to fit the link.  

3 Text that goes over two lines just places the link at the end
  of the last line, if it fits.                          [Link]

4 If it doesn't fit into the second line, because the text is
  just too long, put it flushright on the next line, as in 2.

I don't want to break the [Link] into two lines.

Update. Thank you for all your answers. The code from the accepted answer on the "duplicate" question works best:



(Not tested.)

enter image description here


\newcommand*\link[1]{\hspace*{0em plus 1fill}\makebox{[#1]}}

\textwidth=.5\textwidth % Just for this example

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. \link{whatever}

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. \link{another}

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. \link{this}

Excepteur sint occaecat cupidatat non pro ident, sunt in culpa qui officia
deserunt mollit anim id est laborum. \link{that}
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.