I have a custom underlining command \cleverul{text}
proposed by @Jinwen here.
I would like to be able to pass the command inside a redefinition of the \@makechapterhead
macro, as a formatting value whose function is to beautifully underline the output of {\@chapapp{} \thechapter}
(could also be used for the name of the chapter, i.e. ##1
).
The solution that comes to my mind is to create a variant involving a \small
-style syntax.
Question is, is there a simple way to convert my underlining command \cleverul{text}
into a {\coolclevul text}
command?
Or, do you see a way to pass the \cleverul
command with its current syntax?
MWE
\documentclass{report}
\usepackage{etoolbox}
\usepackage{contour}
\usepackage{fp}
\usepackage[normalem]{ulem}
% Cool underlining. \cleverul
\contourlength{0.8pt}
\makeatletter
\newcommand{\cleverul}[1]
{%
\FPmul\cleverul@temp{\f@size}{0.15}%
\setlength{\ULdepth}{\cleverul@temp pt}%
\FPdiv\cleverul@temp{\f@size}{15}%
\renewcommand{\ULthickness}{\cleverul@temp pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}%
}%
% Formatting Chapter-word and Chapter title
\NewDocumentCommand{\chapterformat}{m}{%
\ifdef{\chapter}{%
\renewcommand{\@makechapterhead}[1]{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \reset@font
\ifnum \c@secnumdepth >\m@ne
{#1 \@chapapp{} \thechapter}% => Want to be able to pass my \cleverul command in formatting {\@chapapp{} \thechapter}.
\par
\vskip 20\p@
\fi
{\Huge\bfseries ##1} % Title formatting.
\par\nobreak
\vskip 180\p@}}
}{}
}
\makeatother
\begin{document}
\chapterformat{\fontsize{60}{90}\selectfont\bfseries} % => Want to be able to pass my \cleverul command.
\chapter{Cool Underlining}
\Huge\bfseries\cleverul{I love \LaTeX.}
\end{document}
Question Solved
I end up using two different keys, chapterformat
and titleformat
for standard formatting commands, chapterstyle
and titlestyle
for commands that involve delimiters around their argument.
Using @Skillmon's expkv-cs
package as shown here, creating my own key=value
-style custom command was kid stuff. This variant also includes vertical spacing.
\documentclass{report} % The report style has Chapters.
\usepackage{fontspec} % Allows me to switch to a "bold small caps"-compliant font.
\usepackage{etoolbox} % Provides \ifdef LaTeX wrapper.
\usepackage{contour} % Required for the \cleverul command.
\usepackage{fp} % Required for the \cleverul command.
\usepackage[normalem]{ulem} % Required for the \cleverul command.
\usepackage{expkv-cs}
\setmainfont{Times New Roman}
\newcommand{\giant}{\fontsize{72}{108}\selectfont}
% Cool underlining. \cleverul
\makeatletter
\newcommand{\cleverul}[1]
{%
\contourlength{0.04ex}
\FPmul\cleverul@temp{\f@size}{0.12}% The higher, the farther from the text. (font size multiplied by x)
\setlength{\ULdepth}{\cleverul@temp pt}%
\FPdiv\cleverul@temp{\f@size}{16}% The higher, the thinner. (font size divided by x)
\renewcommand{\ULthickness}{\cleverul@temp pt}%
\uline{\phantom{#1}}%
\llap{\contour{white}{#1}}%
}%
\NewDocumentCommand{\chapterformat}{mmmmmmm}{
\ifdef{\chapter}{
\renewcommand{\@makechapterhead}[1]{%
\vspace*{#5\p@}% Vertical Space before "ChapterX" (50)
{\parindent \z@ \raggedright \reset@font
\ifnum \c@secnumdepth >\m@ne
{#3#1{\@chapapp{}~\thechapter}}
\par
\vskip #6\p@ % Vertical Space after "Chapter X" (20)
\fi
{#4#2{##1}}
\par\nobreak
\vskip #7\p@}} % Vertical Space after Title (180)
}{}
}
\makeatother
\ekvcSplitAndForward\coolchap\chapterformat % Defining \coolchap as a split version of \chapterformat, using explkv package.
{
chapstyle = \relax,
titlestyle = \relax,
chapformat = \Huge\bfseries,
titleformat = \Large,
befchap = 50,
afchap = 20,
aftitle = 180
}
\begin{document}
\coolchap{chapstyle=\cleverul,titlestyle=\textsc,chapformat=\giant\bfseries,titleformat=\Huge\bfseries,afchap=40}
\chapter{Cool Underlining}
\Huge\bfseries\cleverul{I love \LaTeX.}
\end{document}