Scrbook redefining sections without titlesec package

package-writingscrbooksectioningtitlesec

I am editing a package (which I did not write myself) where the titlesec package was used in combination with the scrbook document class. This produces an error, as explained in this post: Conflict between titlesec package and scrbook class after most recent update of TeXLive2019. I wish to fix this error, and get rid of the error message. I realize one must use the commands in the KOMA-class, but I don't know exactly how. Here is a minimal exaple:

Package:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage} 
\RequirePackage[T1]{fontenc}
\RequirePackage[explicit]{titlesec}
\titleformat{\section}
  {\normalfont}{\thesection}{0pt}{\phantomsection\fontsize{18pt}{20pt} \sffamily\center\MakeUppercase{#1}}
\titleformat{\subsection}
  {\normalfont}{\thesubsection}{0pt}{\fontsize{14pt}{16pt} \sffamily\center\MakeUppercase{#1}}
\titleformat{\subsubsection}
  {\normalfont}{\thesubsubsection}{0pt}{\scshape{\textbf{\normalsize #1}}}
% {left}{top}{below}{right}
\titlespacing*{\section}{0pt}{0pt minus 0.5em}{0pt}
\titlespacing*{\subsection}{0pt}{-2em plus 0.3em minus 0.3em}{-0.4em plus 0.2em minus 0.2em}
\titlespacing*{\subsubsection}{0pt}{-0.5em plus 0.2em}{-0.8em plus 0.5em minus 0em} 
\setcounter{secnumdepth}{0} 

The document:

\documentclass[fontsize=13pt,a4paper,openany,parskip=half,DIV=calc]{scrbook}
\usepackage{mypackage}
\begin{document}
\section{Section}
    Some text.
\subsection{Subsection}
    More text.
\subsubsection{Subsubsection}
    Text.
\end{document}

So the challenge is redefining the commands section, subsection and subsubsection as intended by the author of this class without using the titlesec package.

Best Answer

I see no way to apply \MakeUppercase to section titles with komascript methods. But it can be done.

\RequirePackage{fix-cm}
\documentclass[fontsize=13pt,a4paper,openany,parskip=half,DIV=calc]{scrbook}

\usepackage{lipsum} % for nonsense text

\RedeclareSectionCommand[
  style=section,
  level=1,
  runin=false,
  font=\fontsize{18}{20}\sffamily\centering,
  beforeskip=10pt,
  afterskip=5pt,
]{section}
\RedeclareSectionCommand[
  style=section,
  level=2,
  runin=false,
  font=\fontsize{14}{16}\sffamily\centering,
  beforeskip=6pt,
  afterskip=3pt,
]{subsection}
\RedeclareSectionCommand[
  style=section,
  level=3,
  runin=false,
  font=\normalfont\normalsize\scshape,
  beforeskip=6pt,
  afterskip=3pt,
]{subsubsection}
\setcounter{secnumdepth}{0}

\NewCommandCopy{\scrsection}{\section}
\NewCommandCopy{\scrsubsection}{\subsection}

\NewDocumentCommand{\uppercasesection}{msom}{%
  \IfBooleanTF{#2}{%
    #1*{\MakeUppercase{#4}}
  }{%
    \IfNoValueTF{#3}{%
      #1{\MakeUppercase{#4}}%
    }{%
      #1[#3]{\MakeUppercase{#4}}%
    }%
  }%
}
\RenewDocumentCommand{\section}{}{\uppercasesection\scrsection}
\RenewDocumentCommand{\subsection}{}{\uppercasesection\scrsubsection}

\begin{document}

\lipsum[1][1-3]

\section{Section}

\lipsum[1][1-3]

\subsection{Subsection}

\lipsum[1][1-3]

\subsubsection{Subsubsection}

\lipsum[1][1-3]

\end{document}

Adjust the spacing and font parameters to your taste.

enter image description here

Related Question