我正在写一本拉丁文诗集(摘自恩尼乌斯的年鉴)。
我定义了一些命令和一个环境来对它们进行编号,但我无法自动将最后一节居中。我知道重新定义命令\par
并不是一个好主意,问题肯定出在这里。
这是MWE:
\documentclass[a4paper, 12pt, latin]{minimal}
\usepackage[latin]{babel}
% Convert arabic number to roman number
\newcommand{\Romannum}[1]{%
\MakeUppercase{%
\ifnum#1<1
\ifnum#1=0
o%
\else
-\romannumeral -#1%
\fi
\else
\romannumeral #1%
\fi}}
% Fragment number
\newcounter{frammento}
\newcommand{\framm}{%
\stepcounter{frammento}%
\centering\Romannum\theframmento
}
% Environment for fragments
\newenvironment{frammpar}{%
\smallskip
\def\par{%
\vspace{1em}%
\pdfprimitive\par\framm%
\pdfprimitive\par\centering%
}%
}%
{%
\newline%
}
\begin{document}
\begin{frammpar}
Musae quae pedibus magnum pulsatis Olympum
Musas quas memorant, nosce nos esse \textit{Camenas}
Nam latos populos res atque po\"emata nostra cluebant
somno leni placidoque revinctus
\end{frammpar}
\end{document}
问题是什么?解决该问题的最佳方法是什么?
答案1
我会避免\par
完全重新定义:
\documentclass[a4paper, 12pt, latin]{article}
\usepackage[latin]{babel}
% Fragment number
\newcounter{frammento}
\newcommand{\framm}{%
\par
\refstepcounter{frammento}%
\addvspace{1em}%
\centering
{\everypar{}\Roman{frammento}\par\noindent}
}
% Environment for fragments
\newenvironment{frammpar}{%
\par
\smallskip
\centering
\everypar{\framm}%
}%
{%
\par
}
\begin{document}
\begin{frammpar}
Musae quae pedibus magnum pulsatis Olympum
% note multiple blank lines
Musas quas memorant, nosce nos esse \textit{Camenas}
Nam latos populos res atque po\"emata nostra cluebant
somno leni placidoque revinctus
\end{frammpar}
\end{document}
答案2
最后你需要用 a\pdfprimitive\par
来代替 the 。\newline
\documentclass[a4paper, 12pt, latin]{minimal}
\usepackage[latin]{babel}
% Convert arabic number to roman number
\newcommand{\Romannum}[1]{%
\MakeUppercase{%
\ifnum#1<1
\ifnum#1=0
o%
\else
-\romannumeral -#1%
\fi
\else
\romannumeral #1%
\fi}}
% Fragment number
\newcounter{frammento}
\newcommand{\framm}{%
\stepcounter{frammento}%
\centering\Romannum\theframmento
}
% Environment for fragments
\newenvironment{frammpar}{%
\smallskip
\def\par{%
\vspace{1em}%
\pdfprimitive\par\framm%
\pdfprimitive\par\centering%
}%
}%
{%
%\newline%
\pdfprimitive\par
}
\begin{document}
\begin{frammpar}
Musae quae pedibus magnum pulsatis Olympum
Musas quas memorant, nosce nos esse \textit{Camenas}
Nam latos populos res atque po\"emata nostra cluebant
somno leni placidoque revinctus
\end{frammpar}
\end{document}
答案3
\par
在调用时保存原始定义frammpar
,然后使用它来关闭环境。
\documentclass[a4paper, 12pt, latin]{minimal}
\usepackage[latin]{babel}
% Convert arabic number to roman number
\newcommand{\Romannum}[1]{%
\MakeUppercase{%
\ifnum#1<1
\ifnum#1=0
o%
\else
-\romannumeral -#1%
\fi
\else
\romannumeral #1%
\fi}}
% Fragment number
\newcounter{frammento}
\newcommand{\framm}{%
\stepcounter{frammento}%
\centering\Romannum\theframmento
}
% Environment for fragments
\newenvironment{frammpar}{%
\smallskip
\let\oldpar\par%
\def\par{%
\vspace{1em}%
\pdfprimitive\par\framm%
\pdfprimitive\par\centering%
}%
}%
{%
\oldpar%
}
\begin{document}
\begin{frammpar}
Musae quae pedibus magnum pulsatis Olympum
Musas quas memorant, nosce nos esse \textit{Camenas}
Nam latos populos res atque po\"emata nostra cluebant
somno leni placidoque revinctus
\end{frammpar}
\end{document}