I'm currently adjusting the code shown in Test if a paragraph has a page break in it? to support underlining and highlighting using TikZ similar as shown in Cool Text Highlighting in LaTeX, but without the need of soul or any other package which influences the typesetting of the text.

For this I'm placing a TikZ coordinate (using overlay,remember picture) at the begin and end and use this to draw the lines. At the moment I simply calculate the baselines of the intermediate lines by adding \baselineskip to the Y-coordinate of the first marker (or subtracting it from the second of there is a page break between them). This works fine for normal text but leads to wrong positions if the line distance is not equal to \baselineskip, e.g. caused by an overly high element on the line.

Would it be possible to automatically place such a TikZ marker on every line TeX produces? I also might use \zlabel from the zref package in addition to that to determine the page. I searched a little through The TeXBook and had a look at the source code of lineno but both without success. It would be enough to add the marker only when the line is higher than normal. (My current funny ideaTM to solve this is to make some frequent letter active, but I try to avoid such trickery.)

2 Answers 2


I don't think this is possible in TeX, because of its way of building paragraphs. There's no \everyline parameter, unfortunately.

One might try to typeset the paragraph in a \vbox and then dismantling it, adding to each line the code, see this answer.

I believe this is solvable with LuaTeX.


I implemented something similar with in the gmdoc-enhance package to have leading % signs on each comment line. It makes the space character active and expand in principle to \discretionary{}{\gmde@kommentarStart}{}~, where \gmde@kommentarStart puts a \hbox with the contents I want to show.

The problem here is that \gmde@kommentarStart will be evaluated for every space, not only for those that create a line break - but only for those the box will actually occur in the output. And also, I have to make sure that no other line breaks occur, which destroys most of TeX's line breaking algorithm (i.e. I essentially need \raggedright and no word-breaking). This is acceptable for my use case, but might not be for your one.

I'm not sure how this works together with TikZ (never used it).

(The package's documentation is in German, if someone needs more details, please comment.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .