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 02: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 02: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 02:18
  • @cfr: Then we are three, as it seems… :-) – GuM Mar 12 '17 at 02:19
  • @GustavoMezzetti 1/3 is going to bed now :). – Dr. Manuel Kuehner Mar 12 '17 at 02:20
  • @cfr Because I intend to use verb sometimes inside the macros. Unfortunately, the verbenvironment doesn't work inside macros; solving this is precisely the purpose of the cprotectpackage. – Matemáticos Chibchas Mar 12 '17 at 04:50
  • 1
    @cfr You are right, included now. – Matemáticos Chibchas Mar 12 '17 at 18:13
  • @MatemáticosChibchas: I have the impression that \cMakeRobust does not maintain the color stack –  Mar 12 '17 at 18:47
  • Thanks. I would suggest unaccepting the existing answer so people know the problem isn't solved. I don't see much point in a new question because there isn't really a different question here - we were just trying to get clear about what the problem you wanted help with was. – cfr Mar 12 '17 at 22:17
  • Related here is the multidef package, e.g. "\usepackage{multidef}\multidef[prefix=cal]{\ensuremath{\mathcal{#1}}}{G, O, Z}\multidef[noerr,nowarn]{\mathbb{#1}}{A-Z}" . See also https://tex.stackexchange.com/questions/25452/how-to-define-a-macro-to-create-a-new-macro-with-a-name-passed-as-its-argument – Watson May 08 '21 at 09:04

1 Answers1

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