2

I would like to define these commands:

\newcommand{\green}[1]{\textcolor{green}{#1}}
\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}

When I try to use \green the output corresponds to the command \red. This shows that, other than the last one, the previous definitions are being ignored or replaced by the last one, perhaps because all are based on the same "basic" command, namely \textcolor.

EDIT

Thank you to all for your answers. Here is a MWE (rather a minimal "not-working" example hehe). It seems that there is indeed a problem with the cprotect package, which I need in order to be able to use the verb environment inside the macros. Not only the previous macro definitions are being ignored, but the vertical spacing is not being applied, too.

If the best course of action is to ask a separate question, don't hesitate to tell me.

\documentclass[border=5mm]{standalone}

\usepackage{xcolor,cprotect}

\newcommand{\green}[1]{\textcolor{green}{#1}}
\cMakeRobust\green
\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\cMakeRobust\blue
\newcommand{\red}[1]{\textcolor{red}{#1}}
\cMakeRobust\red

\begin{document}

\green{Huey $e^{\pi i}+1=0$ (math is OK)}\newline

\newline\blue{Dewey \verb|I'm using verbatim here $e^{\pi i}+1=0$|}
\\[3mm]\red{\textbf{Louie}}

\vspace{3mm}\green{Vertical spacing is not working, too.}

\end{document}

enter image description here

  • 1
    Please provide complete code. It makes no difference that your definitions are using the same command in their definitions. Unless you redefined \textcolor by mistake. You can use it in as many definitions as you wish. – cfr Mar 12 '17 at 2:15
  • 2
    I’ve wrapped your definitions in a standard preamble, with \usepackage{color}, and they work as expected. You should post a MWE that exhibits the problem you claim to have. – GuM Mar 12 '17 at 2:18
  • 2
    I just did the same as @GustavoMezzetti just to be absolutely sure. \documentclass{article} \usepackage{xcolor} \begin{document} \newcommand{\green}[1]{\textcolor{green}{#1}} \newcommand{\blue}[1]{\textcolor{blue}{#1}} \newcommand{\red}[1]{\textcolor{red}{#1}} \green{green} \blue{blue} \red{red} \red{green} \green{blue} \blue{red} \end{document} – cfr Mar 12 '17 at 2:18
  • @cfr: Then we are three, as it seems… :-) – GuM Mar 12 '17 at 2:19
  • 1
    @cfr You are right, included now. – Matemáticos Chibchas Mar 12 '17 at 18:13
1

Here's a complete code example (what is typically needed here). I do not see any problems.

\documentclass[border=5mm]{standalone}

\usepackage{xcolor}

\newcommand{\green}[1]{\textcolor{green}{#1}}
\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}

\begin{document}

\green{green} \blue{blue} \red{red}

\end{document}

enter image description here

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.