I have some string in variable \somevar, eg. foo\\bar. How can I force LaTeX to ignore newline in \somevar. When I write content of the variable there should be

foo bar

and not

  • 1
    Why do you store a newline in your variable if you don't want to display it? Maybe you need to make a wrapper around your macro to split the usage? – ℝaphink May 10 '11 at 12:23
  • 1
    The variable is in document class. Content of the variable comes from user's document and user can put newlines there. One time I can print the variable with newline and another time the newlines are not acceptable but this is still the same text. – jesper May 10 '11 at 12:28
  • How about providing an option like \chapter does? You can write \chapter[alternative title]{title} where one can have newlines and the other can't. – ℝaphink May 10 '11 at 12:30

Within the group that you are expanding the macro you can do


This will temporarily neuter the effect of \\.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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