0

Maybe there is a way to catch when the paragraph breaks by something, for example a formula to insert some code after the break of the paragraph. The command \everypar allows us to catch when the paragraph is started, but it can also be a way to catch when the paragraph breaks by something, such as a formula with [] to insert some code after the break of the paragraph.

Yes, in lua exists a callback post_linebreak_filter which solves this problem, but I need the same for LaTeX/lualatex to insert some LaTeX commands.

Is it possible and if so, how does it work?

6
  • Why can't the formula insert the code? Nov 22, 2019 at 15:22
  • Because i must to understand,if formula now inside of the paragraph,or outside. @David-Carlisle If i redefine \everymathdisplay,will i get an error when,for example,i will use equation environment,or not? Because when i before redefine this for solving of problem with $$ and $,i had an errors,when i used it for example with equation environment. In fact,i need in hook,which catch breaking of paragraph by something,not only formula,which will works in all or in most cases. Nov 22, 2019 at 16:13
  • You can test for the current tag (\tagpdfget{mc_tag}), if it is P you know you are in a paragraph (assuming that your paragraph code is doing the right thing). Nov 22, 2019 at 18:55
  • @Ulrike Fischer But i need in catching when paragraph breakes to close mc and struct tag and open another tag depending of situation. Yes,i can create variable in expl3 which shows me,if i in par or not and for formulas with [] close mc and struct tags,if i in par,and after that open another tag,but i asked this question with hope,that exists best solution,which allow me to catch,if paragraph breaks by formula,description,itemize,enumerate,etc,to insert my code,when paragraph breaks by something. Nov 22, 2019 at 21:51
  • all list environment issue a \par, so should work like any new paragraph command. And for formula you could simply accepts that it is in the par and allow the structure to be a kid of the paragraph. Nov 22, 2019 at 22:02

1 Answer 1

1

Not every context that triggers TeX's linebreaking algorithm has a reasonable hook.

The most common cases are the end of a paragraph, so \par, and a math display mid-paragraph (which you can detect with \everydisplay) but the tricky case is end of a vbox, if you have \vbox (or a wrapper such as a \parbox or tabular p column) then in a context like

\vbox{
\hsize = 1cm
one two three four five}

the line breaker is triggered directly by the end of box (unlike say)

one two three four\vskip 2cm

where the \vskip inserts a \par token to(hopefully) end the paragraph, so if you hav edefined \par to insert your code it will catch this case.

Even in e-TeX there is no user controllable hook that can catch end of vbox, unless you redefine \vbox (and \vtop etc) to insert code at the end, but redefining \vbox while not breaking existing code is hard.

You must log in to answer this question.

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