# Using the titlesec package with dgruyter style gives “Error: Entered in horizontal mode”

I'm trying to use the titlesec package with the dgruyter style from this page, and I get a compilation error "Error: Entered in horizontal mode." Many questions already exist for this error, but none of the answers seem to apply: this error usually arises when using the package commands with e.g. the wrong number of arguments, here, it doesn't matter which commands I use, and even if I don't use any commands, compilation still fails.

Repro steps:

• Unzip it: unzip popets.zip && cd popets
• In the directory, create a new file repro.tex
• Fix the error mentioned here: sed -e '/ngerman/ s/^%*/%/' -i dgruyter_NEW.sty
\documentclass[USenglish,oneside,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[big]{dgruyter_NEW}
\usepackage[compact]{titlesec}

\begin{document}
\section{section}
content
\end{document}

• Try to compile it: pdflatex repro. This returns the error ! Package titlesec Error: Entered in horizontal mode.

Which part of the .sty file should I try removing or modifying to fix this? Alternatively, is there a way to reduce spacing before/after headings that doesn't involve the titlesec package? (This is all I want to do.)

dgruyter_NEW is not really compatible with titlesec and one should not use it except for submissions to DeGruyter journals: in such a case, one should not modify the appearance.

Keep also in mind that dgruyter_NEW does a very dangerous setting, which can trigger weird errors.

If you want to risk rejection of your manuscript, you can patch \section before loading titlesec.

\documentclass[USenglish,oneside,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[big]{dgruyter_NEW}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\section}
{\leavevmode\vrule\@width\z@\@height\dimexpr\topskip+6.5\p@\relax\@depth\z@}
{}
{}{}
\makeatother

\usepackage[compact]{titlesec}

\begin{document}
\section{section}
content
\end{document}


Here is the alternative way to reduce the space before and after \section command

\documentclass[USenglish,oneside,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgffor}
\usepackage{fancyhdr}
\usepackage{lipsum}
%\usepackage[big]{dgruyter_NEW}
%\usepackage[compact]{titlesec}

\let\oldsection\section
\let\oldleftmark\leftmark

\let\oldmyaboveskip\myaboveskip%
\let\oldmybelowskip\mybelowskip%
\foreach \arg[count =\i from 1] in {#1}
{%
\ifnum\i=1
\global\def\myaboveskip{\vspace*{\tempdist}}%
\else
\global\def\mybelowskip{\vspace*{\tempdist}}%
\fi
}%
}

\def\OldSkips{%
\let\myaboveskip\oldmyaboveskip%
\let\mybelowskip\oldmybelowskip%
}

\makeatletter
\def\section{%
\@ifstar{\StarredSection}{\NonStarredSection}%
}
\def\StarredSection{%
\@ifnextchar[
{\StarredSectionWith}%
{\StarredSectionWithout}%
}
\def\NonStarredSection{%
\@ifnextchar[
{\NonStarredSectionWith}%
{\NonStarredSectionWithout}%
}
\def\StarredSectionWith[#1]#2{%
\@ifnextchar[
{\StarredSectionWithWith[#1]#2}%
{\StarredSectionWithWithout[#1]{#2}}%
}
\def\StarredSectionWithout#1{%
\@ifnextchar[
{\StarredSectionWithoutWith#1}%
{\StarredSectionWithoutWithout{#1}}%
}
\def\NonStarredSectionWith[#1]#2{%
\@ifnextchar[
{\NonStarredSectionWithWith[#1]#2}%
{\NonStarredSectionWithWithout[#1]{#2}}%
}
\def\NonStarredSectionWithout#1{%
\@ifnextchar[
{\NonStarredSectionWithoutWith#1}%
{\NonStarredSectionWithoutWithout{#1}}%
}
\def\StarredSectionWithWith[#1]#2[#3]{%
\let\oldleftmark\leftmark%
\renewcommand{\leftmark}{#1}%
\oldsection*{#2}%
\mybelowskip%
\OldSkips%
}
\def\StarredSectionWithoutWith#1[#2]{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection*{#1}
\mybelowskip%
}
\def\StarredSectionWithWithout[#1]#2{%
\myaboveskip%
\let\oldleftmark\leftmark%
\renewcommand{\leftmark}{#1}
\oldsection*{#2}
\mybelowskip%
}
\def\StarredSectionWithoutWithout#1{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection*{#1}
\mybelowskip%
}
\def\NonStarredSectionWithWith[#1]#2[#3]{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection[#1]{#2}
\mybelowskip%
\OldSkips%
}
\def\NonStarredSectionWithoutWith#1[#2]{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection{#1}
\mybelowskip%
\OldSkips%
}
\def\NonStarredSectionWithWithout[#1]#2{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection[#1]{#2}
\mybelowskip%
}
\def\NonStarredSectionWithoutWithout#1{%
\let\leftmark\oldleftmark%
\myaboveskip%
\oldsection{#1}
\mybelowskip%
}

\begin{document}
\pagestyle{fancy}
\tableofcontents
\section{section A}
\lipsum[1-2]
\section*{section B}
\lipsum[1-3]
\section[test C]{section C}
\lipsum[1-2]
\section*[test D]{section D}
\lipsum[1-3]
\section{section E}[0.5cm,10mm]
\lipsum[1-2]
\section*{section F}
\lipsum[1-3]
\section[test G]{section G}[-3mm]
\lipsum[1-2]
\section*[test H]{section H}
\lipsum[1-5]
\section*{section I}
\lipsum[1-5]
\end{document}


The code is from this answer of mine and takes care of:

1. A global reducing on spacing before and after section.
2. An optional additional argument after section command to reduce or increase the skips before or after (or before and after) the section.
3. An optional argument before the starred section to be used as \leftmark

There is a problem with \leavevmode in line 796 of your .sty file. You can try to suppress it, this makes your example compile normally:

sed -e '796s/.*/\Large/' -i dgruyter_NEW.sty


(I used \tracingmacros=2 to debug that)