TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

I have defined the following shortcut for some text

\newcommand{\sometext}{text\\text\\text}

Now I would like to use this in some other place but with the linebreaks removed. So is there an easy way to do it (e.g. something like "\remove_linebreaks{\sometext}")?

share|improve this question
up vote 9 down vote accepted

This will change \\ into a space:

\newcommand{\removelinebreaks}[1]{%
  \begingroup\def\\{ }#1\endgroup}

\removelinebreaks{\sometext}
share|improve this answer
    
\\ has an optional star and an optional argument. Something like \def\\{\@ifstar {\@gobbleopt}{\@gobbleopt}}\providecommand*\@gobbleopt[1][]{} would handle these too. – Schweinebacke Nov 23 '11 at 13:56

Your Answer

 
discard

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.