0

I introduced colour to a QED command, but the colour has side effect on the text that follows it. I want the colour to be restricted to the symbol only.

\documentclass[a4paper,12pt]{article}

\usepackage{xcolor}

\ExplSyntaxOn

\definecolor{dblue}{RGB}{0,0,139} \colorlet{celestk}{dblue}

\NewDocumentCommand{\wvQed}{O{celestk}o} { \IfNoValueTF{#2}{\color{#1}}{\color[#1]{#2}} \hfill\nabla }

\ExplSyntaxOff

\begin{document}

Tantra is an Expansion Device. \wvQed

The word appears in the hymns of the Rigveda such as in 10.71

\end{document}

Celest
  • 1
  • 1
    You are also missing $. As requested before, please make sure your code compiles and please link and attribute when you use code provided by others. Strictly speaking, this is a legal requirement of SE's licence. (Though I don't know how much would be considered subject to copyright.) – cfr Oct 16 '23 at 00:09
  • 1
    You have already been shown how to use a group or \textcolor to scope color, you would find it easier to find existing answers if you did not delete your account aftereach question – David Carlisle Oct 16 '23 at 09:43

1 Answers1

1

expl3 syntax isn't doing much for you here except saving the need to comment line endings. While that's convenient, I wouldn't change category codes for it.

You need $ to compile this. You need a group to limit the effect of the colour change.

\documentclass[a4paper,12pt]{article}

\usepackage{xcolor}

\definecolor{dblue}{RGB}{0,0,139} \colorlet{celestk}{dblue}

\NewDocumentCommand{\wvQed}{O{celestk}o} {% \begingroup \IfNoValueTF{#2}{\color{#1}}{\color[#1]{#2}}% \hfill$\nabla$% \endgroup }

\begin{document}

Tantra is an Expansion Device. \wvQed

The word appears in the hymns of the Rigveda such as in 10.71

\end{document}

limited colouration

cfr
  • 198,882