2

I have defined a \blue command which I often use with subscripts, e.g.

\newcommand{\blue}[1]{{\color{blue} \textup{\textbf{#1}}}}
\blue{v}_{\blue{ij}}

Question: Is there a way to define \blue in such a way that I can simply write

\blue{v}_{ij}

to get the same result as for \blue{v}_{\blue{ij}}, without changing the behavior of \blue{v}?

1
  • 1
    why do use use \text... comands (so the text fonts not the math fonts) here? Nov 22, 2023 at 11:08

1 Answer 1

4

Personally I don't really like this kind of construct which hides its behaviour under an apparently easier syntax, but here you go:

\documentclass{article}

\usepackage{color}
\NewDocumentCommand{\blue}{me{_}}{\mathcolor{blue}{\mathbf{#1}\IfValueT{#2}{_{\mathbf{#2}}}}}

\begin{document}
See $\blue{v}$ or $\blue{v}_{ij}$, but $\blue{v}^a$
\end{document}

enter image description here

2
  • 1
    Why not \mathcolor?
    – egreg
    Nov 22, 2023 at 12:45
  • 1
    @egreg Because I keep forgetting that it's in the kernel now... :-)
    – campa
    Nov 22, 2023 at 12:49

You must log in to answer this question.

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