3

I am using reledmac to create a custom environment typesetting poems with numbered lines and some other features. I managed to apply custom numbering and reset it to the previous state in order not to interfere with other numbered sections.

However, I don't know how to do the same with the formatting I apply through

\AtStartEveryPstart{\itshape}

All I managed so far is resetting it to empty at the end of the environment, but what is needed is storing the current command at the beginning and reapplying it at the end.

The first thing that came to mind is the usual

\let\tmp\currentMacro

step but of course that doesn't work because I don't want to store away the macro but the value passed to it.

Looking in the reledmac manual I found that the value seems to be stored in \@at@start@every@pstart, but I failed at storing/retrieving that value (due to my lack of understanding how to deal with the more hidden terms here.

This is a MWE reduction of what I have so far. Any suggestions or solutions appreciated:

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world 
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\AtStartEveryPstart{}
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}
  • i don't understand. if you want to have automatically \AtStartEveryPstart{\itshape}\itshape} for each \beginnumbering...\endnumbering, why calling it inside you environnement definition, and not globally in the preamble? – Maïeul Jun 18 at 13:48
  • Basically what I want is to write an environment with its own numbering parameters and formatting (for poems with numbered verses) that does not interfere with other numbered sections. So the \itshape must only affect the numbered section inside the poem environment and has to be reset afterwards. So far I can only reset it to "empty" but not to an arbitrary value it may have been assigned otherwise. – uli_1973 Jun 19 at 5:52
  • sorry, I didn't understand that you have both \itshape and \bfseries depending of the context. – Maïeul Jun 19 at 9:12
1

You have two problems in your question.

  1. You real problem : how to alternate between \itshape and \bfseries for \AtStartEveryPstart
  2. Your real question (bis): how to have italic for poem and bold for prose.
  3. You technical question: how to retrieve automatically the value passed to \AtStartEveryPstart

How to alternate between \itshape and \bfseries

Instead of made \AtStartEveryPstart{} at the end of poem environment, just do \AtStartEveryPstart{\bfseries}

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\AtStartEveryPstart{\bfseries}
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

How to have stanza in italic and verse in bold

Instead of using multiple time \AtEveryStartPstart, just use ifinstanza inside \AtStartEveryPstart{\ifinstanza\itshape\else\bfseries\fi}.

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\ifinstanza\itshape\else\bfseries\fi}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

How to retrieve automatically the value passed to \AtStartEveryPstart

As you noticed well, \AtStartEveryPstart just store the argument value inside \@at@start@every@pstart. As you may noticed, this command name contains @. That means that is an internal command, which can't be (normally) accessed in a .tex file, but only in a .sty file.

However, you can, inside a .tex file, use \makeatletter and \makeatother hack to access / define command with @. This \maketaletter...\makeatother must wrap your entire definition of poem environnement, that is the time TeX read the lines. Using that, you could backup the \@at@start@every@pstart in a backup macro.

A second problem you have to deal with is that you don't want to pass to \AtStartEveryPstart the backup macro, but the expansion of the backup macro. Otherwise, you will have an infinite loop. So you will have to deal with \expandafter.

So

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\makeatletter
\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
\global\let\@at@start@every@pstart@old\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\expandafter\AtStartEveryPstart\expandafter{\@at@start@every@pstart@old}
%Or just do \global\let\@at@start@every@pstart\@at@start@every@pstart@old
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\makeatother
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}
0

I don't find how to withdraw a question, so I'm answering it instead (basically marking it "invalid").

However it escaped me in the first place (I did try something similar) it is possible to achieve what I want by simply putting \itshape in the opening of the environment like

...
\setline{4}
\itshape
\stanza
...

For some reason my test resulted in only the first verse being in italics, so I ended up trying the paragraph hook. The code above will apply the italics to the whole numbered section without affecting anything outside, which is what I want.

I would still be interested in knowing how to retrieve the value stored via \AtStartEveryPstart{}, but that would of course be a totally different question.

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.