# Reledmac: How to store and retrieve the argument of \lemma?

We are preparing a critical edition with reledmac. For some of the texts, we provide a collation.

The relevant critical notes (\Afootnote) provide: first, the last word common to all witnesses, as a catchword – this we put into \lemma; then, the variants, which we enter into \Afootnote proper. Each variant starts with the catchword again.

The problem: This way, we have to repeat the catchword manually for each new witness. We would like to automate the process (and maybe make it customizable along the way, add nice props around the catchword, f.i. \textbullet~#1\enskip).

Is there a way to temporarily store the argument of \lemma and repeat it at will (within one footnote)? This information should be specific to each footnote – the next footnote will have a different \lemma argument.

I have tried, to no avail, to define a new command \repeatlemma; I made a conditional \ifinfoot that is true iff within a footnote (using \Xwrapcontents); but then I got lost in the complicated hook system of reledmac.

Here's a MWE:

\documentclass{article}

\usepackage[series={A},noend,nofamiliar,noeledsec]{reledmac}
\Xarrangement[A]{paragraph}
\Xnolemmaseparator[A]
\Xinplaceoflemmaseparator[A]{0.5em}

\begin{document}
\beginnumbering
\pstart
%
Lorem ipsum dolor,
%
\edtext{quod erat demonstrandum.}{%
\lemma{quod}\Afootnote{%        % \lemma prints "quod" in the apparatus
erat demonstrandum \textit{A}\quad  % 1st witness
%
%\repeatlemma\              % should print "quod" again
quod                            % this would be made superfluous by \repeatlemma
demonstrandum est \textit{B}}}  % 2nd witness
%
\pend
\endnumbering
\end{document}


And here's the desired output if \repeatlemma was implemented (an example from our latest volume):

For consistency reasons, it would be great if this didn't require a new, dedicated series of Xfootnotes, or a new user-level command (\AfootnoteCollation), but rather if we could stick to the usual \Afootnote; we're OK with hacking the definition of Xfootnote or modifying some other internals, though.

Any help would be appreciated.

(In case it is relevant: we always write the argument of \lemma{} explicitly, we don't let it inherit argument #1 of \edtext{}.)

• The main problem I see with your approach, is : how do you deal with nested footnote ? which lemma do you keep ? – Maïeul Mar 25 at 19:29
• \edtext has 3 args: \edtext{#1}{\lemma{#2}\Afootnote{#3}}. To "nest" a footnote is to put another \edtext{...\Afootnote{...}} into arg #1, right? But the command I'm looking for would print #2, which is the direct argument of \lemma{}, and not arg #1. So there would be no overlap with the other footnote, right? Also, FWIW: in a critical footnote, we always write \lemma{}, even if we leave it empty (for style reasons). So in our case, #2 never defaults to #1 (arg #1 of \edtext). So if \repeatlemma prints #2, it should be safe. – marquinho Mar 25 at 22:01
• No, edtext has two arguments : - one contening the default lemma - second contening both the overriding lemma and the footnote, as specific macro – Maïeul Mar 26 at 10:12

1. Thanks for the FULL MWE example and the expect output.
2. It is a very bad idea to hack some internal macros of reledmac, they are very sensitive. It is to avoid such hack that we implement "the complicated hook system of reledmac". There are a lot, I know, but it should allow you to do what you want.
3. But in your case, the hooks won't be useful, as they are applied when footnote argument is already read
4. But it is very easy. Ok, you need to patch (but NOT redefine) \lemma in order to store its argument in your macro \repeatlemma.
5. The main problem is that the notes are inserted, by reledmac, after all the paragraph has been splitted into lines, so if you just store it in a macro, this macro will get you the last value in the paragraph
6. But reledmac have to deal with this problem in internal code, and provides an (not documented) insertion point for that : \@beforeinsertofthisedtext

So :

\documentclass{article}

\usepackage[noend,noeledsec,series={A}]{reledmac}
\makeatletter
\apptocmd{\lemma}{%
\global\appto\@beforeinsertofthisedtext{\def\repeatlemma{#1}}%
}{}{}
\makeatother
\begin{document}
\beginnumbering
\pstart
\edtext{s}{\lemma{REPETED LEMMA}\Afootnote{Entry1 \repeatlemma Entry2}}

\edtext{s}{\lemma{ANOTHER REPETED LEMMA}\Afootnote{Entry1 \repeatlemma Entry2}}
\pend
\endnumbering
\end{document}

• Thanks for the help – I know it's a lot of questions. Thanks for the warnings, I'll promise I'll be careful :) The MWE is improved now. There's a problem: as it stands, \repeatlemma prints the same catchword for every footnote in the document (it's the \lemma arg of the very last footnote). But \repeatlemma should be specific for every footnote, bc the catchword is immer different. Try adding a second critical footnote to your MWE \edtext{foo baz bar}{\lemma{foo}\Afootnote{baz bar}}: it changes \repeatlemma to "foo", everywhere. Maybe this has to do with \global\def? – marquinho Mar 25 at 22:06
• I correct myself: the problem is that \repeatlemma prints the same catchword for every footnote in the paragraph, not the whole document. – marquinho Mar 25 at 23:37
• ah yes. Of course. It is still a problem of when the arguments of footnote are parsed. I will try something and let you know. – Maïeul Mar 26 at 10:19
• The new version of my answer deal with this problem. – Maïeul Mar 26 at 10:42
• nice ! it was easier than expected. (I did'nt remember the existence of @beforeinsertofthisedtext !) – Maïeul Mar 26 at 12:36