# Why do routines of plain TeX standard insert get broken when using \mark in the midst of running text?

I use Edmac in plain XeTeX for typesetting scholarly editions, and for the first time have come across a problem that may be intractable. The text in question has frequently changing section numbers, which can occur either at the start of paragraphs or within the body of paragraphs. These are given as bold numerals, which ideally should be picked up by a \mark (or rather \marks) command so that they can be given in the running headlines, along with other changing elements.

The problem is that within text that is line-numbered by Edmac all of plain TeX's standard insert routines are broken. A \mark in the midst of running text causes the line to burst apart, so that the only thing that's right is the headline - everything else is messed up. Any suggestions as to how this might be overcome? I vaguely thought of \write, but I don't think it can be used to do the necessary - viz. in the left headline place the section number that is in operation in the first line of that page and in the right headline place the section number that is in operation in the last line of the page. I think I'm going to have to do these manually once the pagination has settled down. Or is there another solution?

• did not you receive the email I send to you when you wrote to me with this question? – Maïeul Sep 16 '18 at 20:34

This answer is not fully completed, especially because you didn't provide any MWE.

The problem is not caused but the modification of the output routine, but by the fact that edmac (and its derivateds ledmac, eledmac and reledmac) use \vsplit to split the content of each \pstart...\pstart in individual line in order to add line number and to manage critical notes and so on, add do also some addition. I don't know where exactly.

The solution is indeed to use \write. More precisly

1. Instead of directly call \mark{content}, write it inside the numbered auxiliary file, wraped in your own command. In your numebred auxiliary file, you should get something like this

\@l \@insidethislinehook{\mark{content}} \@l  You can use \unexpanded to help you with the problem of expansion. \@l is written by edtex at each line, and, at secund run, it increase line counter.

2. When reading the .1 file, \@insidethislinehook would store its argument in a macro which name includes line number (\absline@num, to define such macro, use \csname)
3. \do@line must be redefined to call the command defined on step 2 in one of the hbox. I don't know well edmac, as I started to work with ledmac, but I think it should be at the begining of this hbox \hbox to \hsize{\affixline@num{.

That is the method I used for reledmac, cf https://github.com/maieul/ledmac/commit/14aaca05ff72c9adf1ab35923df36fdb2173b6bb

of course, this code as content which does not interest you, as it is specific to reledmac. But see l. 9063 (step 1); l. 9075 (step 2) and 8919 (step 3).