[Tex/LaTex] Prevent a paragraph break after a section heading

sectioningsections-paragraphsspacingtitlesec

In my .cls file for my thesis, I have defined \subsection as follows:

\newcommand{\subsection}[1]{%
  \pagebreak[2]
  \refstepcounter{subsection}
  \addcontentsline{toc}{subsection}{
    {\protect\makebox[0.3in][r]{\thesubsection.} \hspace*{3pt}#1}}
  \noindent
  \textbf{\thesubsection\space\space{#1}. }
}

However, the thesis examiner has told me that the proper way to format subsection headings is to make the first paragraph continue on the same line as the subsection heading.

I can make this work if my document says

\subsection{A Subsection}
Lorem ipsum dolor sit amet...

typesets to

3.1.1 A Subsection.  Lorem ipsum dolor sit amet...

But if I have a blank line at the beginning of the subsection, I get a paragraph anyway.

\subsection{A Subsection}

Lorem ipsum dolor sit amet...

typesets to

3.1.1 A Subsection.
    Lorem ipsum dolor sit amet...

Is there any way to force this to typset like the first version, even if there's a blank line after the \subsection command? If not, is there at least a way to get a warning?

Best Answer

Use the titlesec package to redefine your sections: Here's an example of your subsection style:

\usepackage{titlesec} % or RequirePackage[loadonly]{titlesec} in a cls file
\titleformat{\subsection}[runin]{\normalfont\bfseries}{\thesubsection.}{3pt}{}

Note that if you do this in a class file, you will need to load titlesec with the [loadonly] option, and use titlesec to define all of the sectioning command your class will allow.