[Tex/LaTex] Remove newline *before* \section

sectioningtitlesec

I have searched a lot to find an answer to this question, but I could only find how to remove a newline after \section (or \chapter).

How can one remove the newline before \section, as defined by book class?

Basically, looking at the MWE below, I am looking to a way to have:

Text before. Section heading

MWE:

\documentclass[12pt]{book}        
\usepackage{titlesec}    
\titleformat{\section}[hang]{\normalfont}{\thesection.}{0pt}{}

\titlespacing{\section}
   {0pt}% left
   {0pt}% before
   {0pt}% after

\begin{document}
Text before. \section*{Section heading} Text after
\end{document}

I can't find any option with titlesec and I would not want to enter the esoteric intricacies of TeX class redefinitions.

I would be grateful for any hint or pointer on how to deal with this kind of problem.

Best Answer

enter image description here

\documentclass[12pt]{book}        
\makeatletter
\renewcommand\section{\@ifstar\mystarsec\mynostarsec}
\makeatother

\newcommand\mystarsec[1]{%
\ifhmode\unskip\fi\quad\textbf{#1}}
\newcommand\mynostarsec[1]{%
\ifhmode\unskip\fi\refsetepcounter{section}\quad\textbf{\thesection. #1}}

\begin{document}
Text before. \section*{Section heading} Text after
\end{document}
Related Question