考慮する
\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
答え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}