0

I have created a symbol with

\newcommand{\redx}[1][x]{\color{red}{\boldsymbol{#1}}}

This correctly colors the symbol red, but annoyingly it also colors the symbols after it red. How do I ensure only one symbol is colored.

2
  • 2
    \color{red} willl switch everything that follows, until the end of the group, to red. I does not have a second argument. What you are looking for is \textcolor{red}{something}.
    – Rmano
    Sep 20, 2020 at 11:00
  • 1
    I use it for mathematical symbols, but I see that \textcolor works in mathmode as well. This solves it.
    – Mike
    Sep 20, 2020 at 12:39

2 Answers 2

1

The command \color{red} is a declaration. It tells LaTeX to start typesetting in red and bracing the following text does not delimit the red text; only a brace or other grouping before the declaration will define a scope for the declaration.

You want \textcolor{red}{whatever} which, despite the name, also works in math mode and continues math mode for its second argument.

1

Hope that this will help you

\documentclass{article}
\usepackage{color}

\newcommand{\redx}[1]{{\color{red}#1}}

\begin{document}

    this is in \redx{red}.this is in black.
    
\end{document}

Its output is output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .