拡大?汚い手口?

拡大?汚い手口?

考慮する

\documentclass{article}
\usepackage{titlesec}

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

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

コメント アウトされた行の目的は、\section{\bl 3 a 21}各セクションで \bl を入力しなくても と同等の結果を生成することでしたが、エラーが発生しました。意図した結果を得るために何かできることはありますか?

答え1

引数を に渡す前にキャプチャする必要があります。以下では、 に渡す前に\blを使用してキャプチャします。\@bl\bl

ここに画像の説明を入力してください

\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}

答え2

パッケージなしでも実行できます。ポイントは、引数が\section中括弧で囲まれたグループとしてコードの最終部分に渡されることです。そのため、その部分が引数を取るマクロで終わる場合、セクション タイトルが表示されますが、まず中括弧を削除する必要があります。3 つの引数を持つ内部マクロを定義すると、最後のピリオドを簡単に追加できることに注意してください。

\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}

ここに画像の説明を入力してください

答え3

これは「汚い」と言えるかもしれません:

\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. 本文。

関連情報