3

I'm working on a collection of latin verses (from Ennius's Annales).

I defined some commands and an environment to number them, but I'm not able to center automatically the last verse. I know that redefining the \par command isn't such a good idea and the problem comes surely from there.

Here's the 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}

And then the result: Compiled result.

What's the problem and what's the best way to solve it?

  • 3
    redefining \par is almost certainly going to break something, It's also very fragile if done this way for example if you have two blank lines instead of one normally this is fine but here gives two headings) – David Carlisle Dec 4 '17 at 13:18
8

I woudl avoid redefining \par completely:

enter image description here

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

You need a \pdfprimitive\par instead of the \newline at the end.

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

enter image description here

1

Save the original \par definition at the invocation of frammpar and then use that to close out the environment.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.