
고려하다
\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
중괄호 그룹으로 코드의 마지막 부분에 전달되므로 해당 부분이 인수를 취하는 매크로로 끝나는 경우 섹션 제목이 표시된다는 것입니다. 하지만 먼저 교정기를 제거해야 합니다. 세 개의 인수로 내부 매크로를 정의하면 마지막 마침표를 쉽게 추가할 수 있습니다.
\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}