TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following example:


Line One Line One \\ %
Line Two Line Two \\ %
Line Three Line Three \\ %
Line Four Line Four  %


Here is multi-line: \myMultiLineText ...


In the document, I'd like to insert something like:

Here is single-line: \doSingleLine{\myMultiLineText} ...

... where the \doSingleLine{} macro would basically remove the line-breaks (\\) from the text stored in \myMultiLineText (so its contents would be rendered on a single line).

Could someone provide an example of such a macro?

share|improve this question
up vote 8 down vote accepted

EDIT: As pointed by egreg, this does not take care of the optional argument of \\. Here is an alternative implementation that handles \\* and \\[10pt]:





Note that one cannot directly use \@ifstar as it will gobble the space at \\.

share|improve this answer
Many thanks for your answer, @Aditya - it seems to work fine! Cheers! – sdaau Sep 28 '11 at 7:51
Beware that this will fail if the optional argument to \\ or its *-form is used. – egreg Sep 28 '11 at 7:59
@egreg: See the modified answer. – Aditya Sep 28 '11 at 8:34

put it into a \mbox

share|improve this answer
Many thanks for your answer, @Herbert - however, since the \makebox command creates a box to contain the text specified, if the text lines are a little longer (just edited the OP, so the example shows that), then \mbox will create just a single unbreakable line... Cheers! – sdaau Sep 28 '11 at 7:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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