2

This week I have wrote this word :

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[15]{MONVERT}
\begin{document}

\chapter{Test}
  \Huge
\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVER
T!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}
\end{document}   

my question is : if I want to customise chapter's and section's with the same way, How can I do this ? Any insight or solution will be appreciated

Aviroum
  • 1,504
  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Apr 23 '15 at 21:43
  • Sorry I have a problem with my PC ! – Aviroum Apr 23 '15 at 22:03
  • You know, you could just say \textcolor{MONVERT!!+}{PsychoPathology}...but frankly I don't know the purpose behind doing that. – Sean Allred Apr 23 '15 at 22:16
  • My problem is how can do the same color in all my chapter's or section's – Aviroum Apr 23 '15 at 22:19
  • @Haouam: I think you should clearify your question. What should be coloured? The chapter/section titles? –  Apr 23 '15 at 22:21
  • in my example psychopathology is colored in shaded color if i want to color all my chapter's(test in the example) at the same way how can do this? – Aviroum Apr 23 '15 at 22:31
  • Is it clear now ? – Aviroum Apr 23 '15 at 22:41
  • @Haouam: I think, I have some idea what you mean –  Apr 23 '15 at 22:44
  • @Haouam: In my point of view, the term shade is misleading. You are requesting a colour gradient –  Apr 23 '15 at 22:52
  • This is a duplicate of http://tex.stackexchange.com/questions/45744/how-to-put-color-gradient-to-desired-text-only and the answer to you question is there. – R. Schumacher Apr 24 '15 at 00:08

1 Answers1

4

A preliminary version, without \section parts. It will fail most probably, if the chapter title will contain macros instead of unexpandable material.

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[50]{MONVERT}

\usepackage{xpatch}

\usepackage{pgffor}

\usepackage{xstring}

\usepackage{xparse}

\NewDocumentCommand{\shadetitle}{+m}{%
  \StrLen{#1}[\titlelength]
  \foreach \x in {1,...,\titlelength} {%
    \textcolor{MONVERT!!+}{\StrChar{#1}{\x}}%
  }%
}

\makeatletter
\xpatchcmd{\@makechapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\makeatother
\begin{document}



\chapter{Test it with a very long title}
  \Huge
  \textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}
\end{document}   

enter image description here

Edit Some improved version

\documentclass{book}
\usepackage{xcolor}

\definecolor{Monvert}{RGB}{229,36,36}

\definecolorseries{MONVERT}{rgb}{last}{Monvert}{black}

\resetcolorseries[100]{MONVERT}

\usepackage{xpatch}
\usepackage{pgffor}
\usepackage{xstring}
\usepackage{xparse}
\usepackage{blindtext}

\NewDocumentCommand{\shadetitle}{+m}{%
  \StrLen{#1}[\titlelength]%
  \foreach \x in {1,...,\titlelength} {%
    \textcolor{MONVERT!!+}{\StrChar{#1}{\x}}%
  }%
}

\makeatletter

%\xpatchcmd{\@ssect}{\hskip #1\relax #5}{#4{\hskip #1\relax \shadetitle{#5}}}{\typeout{Patch success}}{\typeout{Patch failure}}

% Does not work so far :-(
%\xpatchcmd{\@ssect}{\@svsechd{#4{\hskip #1\relax #5}}}{\@svsechd{#4{\hskip #1\relax \shadetitle{#5}}}}{\typeout{Patching ssect}}{}


% Patching the section header command
\xpatchcmd{\@sect}{\def\@svsechd{%
    #6{\hskip #3\relax
      \@svsec #8}%
  }}{%
    \def\@svsechd{%
      #6{\hskip #3\relax
        \@svsec \shadetitle{#8}}%
    }}{}{}
\xpatchcmd{\@sect}{\interlinepenalty \@M #8\@@par}{          \interlinepenalty \@M \shadetitle{#8}\@@par}{}{}
\xpatchcmd{\@makechapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\xpatchcmd{\@makeschapterhead}{\Huge \bfseries #1\par\nobreak}{\Huge \bfseries \shadetitle{#1}\par\nobreak}{}{}
\xpatchcmd{\@makechapterhead}{\huge\bfseries \@chapapp\space \thechapter}{\huge\bfseries \shadetitle{\@chapapp}\space \shadetitle{\thechapter}}{}{}

\makeatother
\begin{document}



\chapter{Test it with a very  title}
\section{And a shorter title}
  \Huge
  \textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{s}\textcolor{MONVERT!!+}{y}\textcolor{MONVERT!!+}{c}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{P}\textcolor{MONVERT!!+}{a}\textcolor{MONVERT!!+}{t}\textcolor{MONVERT!!+}{h}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{l}\textcolor{MONVERT!!+}{o}\textcolor{MONVERT!!+}{g}\textcolor{MONVERT!!+}{y}

\chapter*{Some other chapter}
\section*{Some other section}
\end{document}   

enter image description here

I am pretty aware, that this is a hack only. There must be better ways, of course. Most likely, it's better to colorize the tokens and not trying to identify each character in the input.