TransWikia.com

LaTeX Overwriting colored text

TeX - LaTeX Asked by ZHUANG on December 19, 2020

In LaTeX, usually I use

default color {color{blue}changed color.}

enter image description here

or

default color textcolor{blue}{changed color.}

to change the color of a certain part of the text. Now I want to change the color of the whole sentence to a determined color, say red, as follows

enter image description here

I tried

textcolor{red}{default color {color{blue}changed color.}}

but it just has effect on the uncolored text:

enter image description here

For certain reasons, I need to keep "textcolor{blue}{changed color.}" in the origial text. Is there any way of overwritting the colored text?

3 Answers

Building upon David Carlisle's answer, you can define a macro that will be even nestable (is that a word?) ---

documentclass{article}

usepackage{color}
newcommand{absolutetextcolor}[2]{%
    textcolor{#1}{%
        renewcommandcolor[2][]{}%
    #2}%
}

begin{document}

absolutetextcolor{red}{default color {color{blue}changed color.}}

absolutetextcolor{red}{default color {absolutetextcolor{blue}{changed color.}}}
end{document}

enter image description here

Correct answer by Rmano on December 19, 2020

It would be much better not to add the nested color or to add it as a locally defined command such as mycolor that you could define to be a color, or nothing in different places, but if you really need this you can locally define color to do nothing.

enter image description here

documentclass{article}

usepackage{color}
begin{document}

textcolor{red}{renewcommandcolor[2][]{}default color {color{blue}changed color.}}
end{document}

Answered by David Carlisle on December 19, 2020

enter image description here

documentclass[10pt,a4paper]{article}

usepackage{tikz}
begin{document}
    default color {color{blue}changed color.}\
    textcolor{red}{default color {color{blue}changed color.}}\
    textcolor{red}{default color {changed color.}}
end{document}

Answered by js bibra on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP