장의 음영 문자

장의 음영 문자

이번 주에 나는 다음과 같은 말을 썼습니다.

\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}   

내 질문은: 동일한 방식으로 장과 섹션을 사용자 정의하려면 어떻게 해야 합니까? 어떤 통찰력이나 해결책이라도 감사하겠습니다.

답변1

부품이 없는 예비 버전입니다 \section. 장 제목에 확장할 수 없는 자료 대신 매크로가 포함되어 있으면 실패할 가능성이 높습니다.

\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}   

여기에 이미지 설명을 입력하세요

편집하다일부 개선된 버전

\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}   

여기에 이미지 설명을 입력하세요

나는 이것이 단지 해킹일 뿐이라는 것을 잘 알고 있습니다. 물론 더 나은 방법이 있을 것입니다. 대부분의 경우 토큰에 색상을 지정하고 입력의 각 문자를 식별하지 않는 것이 좋습니다.

관련 정보