Esta semana escrevi esta palavra:
\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}
minha pergunta é: se eu quiser personalizar capítulos e seções da mesma maneira, como posso fazer isso? Qualquer visão ou solução será apreciada
Responder1
Uma versão preliminar, sem \section
peças. Provavelmente irá falhar se o título do capítulo contiver macros em vez de material não expansível.
\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}
EditarAlguma versão melhorada
\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}
Estou bem ciente de que isso é apenas um hack. Deve haver maneiras melhores, é claro. Provavelmente, é melhor colorir os tokens e não tentar identificar cada caractere na entrada.