0

I have a simple command which creates coloured text. This works without any issues when there is a single paragraph without a line break. With a linebreak/new paragraph this does not work (commented code in MWE below produces this). The error that is given is

Too many }'s.
\tbn #1->\textcolor {blue}{{#1} }

A simple method is to use \tbn{} separately for each paragraph after line break. But can the command be redefined so that it works across paragraphs/line breaks?

\documentclass{article}
\usepackage{xcolor}

\newcommand{\tbn}[1]{\textcolor{blue}{{#1}}}

\usepackage{lipsum}

\begin{document}

\tbn{This works if there is no line break.}

% \tbn{This doesn't work if there is a line break.

% If there is a line break.}

\end{document}

Damitr
  • 1,889

1 Answers1

4

\textcolor doesn't accept paragraphs in its argument (just like all the other \text... commands like \textbf). Instead use an explicit group and \color:

\documentclass{article}

\usepackage{xcolor}

\newcommand{\tbn}[1]{\leavevmode{\color{blue}#1}}

\begin{document} \tbn{This works if there is no line break.}

\tbn{This doesn't work if there is a line break.

If there is a line break.} \end{document}

Skillmon
  • 60,462