I have searched the web to no avail trying to figure out how to redefine the section title format in a way that will be transmitted to the way that same chapter appears in the Table of Contents.
I would like to define a new environment that alters the colour of the text as well as the section titles as seen in the following minimal example:
\documentclass{article}
\usepackage{xcolor,titlesec}
\newcommand{\mystyle}{}
\titleformat{\section}{\normalfont\Large\bfseries\mystyle}{\thesection}{1em}{}
\newenvironment{myenv}
{\renewcommand{\mystyle}{\color{red}} \mystyle}
{\renewcommand{\mystyle}{}}
\begin{document}
\tableofcontents
\section{One}
Section one.
\begin{myenv}
\section{Two}
Section two.
\end{myenv}
\section{Three}
Section three.
\end{document}
This code gives me the below result, which only sets the colour of the section in the text.
However, what I would like to achieve, without modifying each section manually and without defining a new section command is to have the specific section name appear the same colour in the table of contents too, as seen below.
EDIT 1: This post is somewhat related, but it only works if the style of the section titles is changed across the entire document, therefore it does not solve my problem.
EDIT 2: Thanks very much for the really fast answers! However, I think I found the way that works best for me as described in my answer to myself below, inspired by this post.
Best Answer
Here is a solution. I will try to explain if needed.
Update I did not take care of subsection and so on (well that was not explicit in the question) so I think one should do