2

I'm trying to define custom styles for the KOMA-Script title which is later inserted using the \maketitle command currently using a mix of the KOMA-Script \setkomafont command and the \patchcmd command from the etoolbox package.

To clear up any confusion, here's a short mwe.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[2015/12/07 mwe0.1]
\LoadClass[paper=a4, fontsize=11pt]{scrartcl}
\RequirePackage{etoolbox}

\ProcessOptions\relax

\setkomafont{subject}{\normalfont}
\setkomafont{title}{\normalfont\scshape}
\setkomafont{subtitle}{\normalfont}
\setkomafont{author}{\normalfont}
\setkomafont{date}{\normalfont}

\patchcmd{\@maketitle}{\huge}{\fontsize{32}{36}\selectfont}{}{}
\patchcmd{\@maketitle}{\@title}{\vspace{-18pt}\@title{}}{}{}
\patchcmd{\@maketitle}{\@subtitle}{\@subtitle{} \\ \@@subject{}}{}{} % this line apparently does not have any effect
%\patchcmd{\@maketitle}{\@subject}{}{}{} % if this line is commented out, the subject is hidden, not appended to the subtitle

\endinput

And the corresponding mwe.tex:

\documentclass{mwe}

\subject{Subject}
\title{Title}
\subtitle{Subtitle}
\author{Author}
\date{\today}


\begin{document}
\maketitle

Further content...
\end{document}

What I'm trying to achieve is that the subject is displayed after the subtitle - I'm not using \publisher or another built-in title command as a workaround to stay semantically correct.

To me it appears like patching the subtitle command does not succeed, probably because of a different internal processing name for the command, but I didn't find anything about it in the KOMA-Script documentation.

4
  • \patchcmd{\@maketitle}{\@subtitle}{\@subtitle{} \\ \@@subject{}}{\typeout{OK!}}{\typeout{Oh, no!}} will tell you for sure....
    – cfr
    Dec 8, 2015 at 0:46
  • ...("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\misc\etex.sty" Package: etex 2015/09/02 v2.4 eTeX basic definition package (PEB,DPC) \et@xins=\count88 ) \etb@tempcnta=\count89 ) OK! )... Apparently, the hook somehow works. The changes just don't make it into the document.
    – Big-Blue
    Dec 8, 2015 at 0:49
  • They do. They do exactly what you asked TeX to do. They just don't do what I think you think you asked TeX to do. This is probably because TeX is a computer programme and I am a human being, so I can guess that you didn't really want what you asked for whereas TeX blithely assumes that you intended exactly that. ;)
    – cfr
    Dec 8, 2015 at 1:24
  • I don't think patching is the right thing to do here. Just define \@maketitle the way you want the title to appear.
    – Johannes_B
    Dec 12, 2015 at 15:30

1 Answer 1

3

The patch is applied. Here is the line which your patch affects (from scrartcl.cls):

{\ifx\@subtitle\@empty\else\usekomafont{subtitle}\@subtitle\par\fi}%

So you will end up with

{\ifx\@subtitle{} \\ \@@subject{}\@empty\else\usekomafont{subtitle}\@subtitle\par\fi}%

which means that the \ifx conditional fails, so \@@subject{} etc. is never executed (because you told it to use this only if the test succeeded). So the \else bit is executed, which is identical to the original code.

You need to be more specific about what you want patched and where:

\patchcmd{\@maketitle}{\usekomafont{subtitle}\@subtitle\par\fi}{%
  {\usekomafont{subtitle}\@subtitle\par}\fi
  \vskip .5em
  {\ifx\@subject\@empty\else\usekomafont{subject}\@subject\par}\fi}{\typeout{OK!}}{\typeout{Oh, no!}} % this line apparently does not have any effect

Note that it is very important to use \par here. It may be that \\ is translated to a paragraph ending anyway, but it may not be. And you want a paragraph break to ensure correct vertical spacing and to avoid bad boxes. Since different parts of the title use different fonts and font sizes, the vertical spacing will be incorrect if you use a line break instead.

Subject below

Code:

\begin{filecontents}{\jobname.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{\jobname}[2015/12/07 \jobname0.1]
\LoadClass[paper=a4, fontsize=11pt]{scrartcl}
\RequirePackage{etoolbox}

\ProcessOptions\relax

\setkomafont{subject}{\normalfont}
\setkomafont{title}{\normalfont\scshape}
\setkomafont{subtitle}{\normalfont}
\setkomafont{author}{\normalfont}
\setkomafont{date}{\normalfont}

\patchcmd{\@maketitle}{\huge}{\fontsize{32}{36}\selectfont}{\typeout{OK! Title size changed!}}{\typeout{Oh, no! Title still huge!}}
\patchcmd{\@maketitle}{\@title}{\vspace{-18pt}\@title{}}{\typeout{OK! Moving up!}}{\typeout{Oh, no! Stuck down here!}}
\patchcmd{\@maketitle}{\@subject}{}{\typeout{OK! Subject eliminated!}}{\typeout{Oh, no! Subject persists!}}
\patchcmd{\@maketitle}{\usekomafont{subtitle}\@subtitle\par\fi}{%
  {\usekomafont{subtitle}\@subtitle\par}\fi
  \vskip .5em
  {\ifx\@subject\@empty\else\usekomafont{subject}\@subject\par}\fi}{\typeout{OK! Subject added!}}{\typeout{Oh, no! Could not add subject!}}

\endinput
\end{filecontents}
\documentclass{\jobname}
\subject{Subject}
\title{Title}
\subtitle{Subtitle}
\author{Author}
\date{\today}

\begin{document}
\maketitle

Further content\dots
\end{document}

Note that the use of the last two arguments in \patchcmd provides useful diagnostics. Each one should tell you what has been tried and whether it succeeded or not. If you use a common prefix (OK! or Oh, no!) then you can search the .log file for all successes or failures. For example grep OK <jobname>.log gives me

OK! Title size changed!
OK! Moving up!
OK! Subject eliminated!
OK! Subject added!
2
  • Thank you very much for this detailed answer. Nice not only to know how this works correctly, but why it didn't work before. I've also learned a bit more about the usage of \patchcmd - I knew it worked using substitution before, but apparently not exactly like I've imagined. I think you grabbed the relevant code from a file - may I ask which? I've tried browsing through the KOMA-Script files myself, but they're huge and I didn't succeed in finding anything relevant, neither in the files nor in the documentation.
    – Big-Blue
    Dec 8, 2015 at 1:49
  • I just looked in scrartcl.cls since that was what you were using and searched for e.g. @maketitle or @subtitle etc. Thanks for reminding me - I forgot the reference but have added it now.
    – cfr
    Dec 8, 2015 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .