Expansion? dirty tricks?

You have to capture the argument before passing it to \bl. Below we capture it using \@bl before passing it to \bl:

enter image description here

\documentclass{article}
\usepackage{titlesec}

\makeatletter
\def\@bl#1{\bl#1}
\def\bl#1 #2 {#1\textsuperscript{#2}\,}
\titleformat{\section}[runin]{}{}{0pt}{\@bl}[. ]
\makeatother

\begin{document}
\section{3 a 21}
main text.
\end{document}

You can do it also without any package. The trick is that the argument to \section is passed as a braced group to the final part of the code, so if that part ends with a macro taking an argument, it will see the section title; but you first need to remove the braces. Note that defining the inner macro with three arguments we can easily add the final period.

\documentclass{article}
\usepackage{showframe}% just for the example

\makeatletter
\renewcommand{\section}{%
  \@startsection{section}{1}{\z@}%
    {-3.5ex \@plus -1ex \@minus -.2ex}%
    {-1em}%
    {\normalfont\process@section@title}%
}
\newcommand{\process@section@title}[1]{\process@section@title@aux#1\@nil}
\def\process@section@title@aux#1 #2 #3\@nil{%
  #1\textsuperscript{#2} #3.%
}
\makeatother

\setcounter{secnumdepth}{0}

\begin{document}

\section{3 a 21}
Some text for the section.

\section{4 a 42}
Some text for the section.

\end{document}

enter image description here


This might qualify as "dirty":

\documentclass{article}
\usepackage{titlesec}

\def\bl#1 #2 {#1\textsuperscript{#2}\,}
\titleformat{\section}[runin]{}{}{0pt}{}[. ]
\let\oldsect=\section
\def\section#1{\oldsect{\bl#1}}
\begin{document}
\section{3 a 21}
main text.
\end{document}

3a 21. main text.

Tags:

Expansion