6

Does not matter whether I use lualatex or pdflatex. MWE:

\documentclass{article}
\begin{document}
\textit{Hello\par World.}
\end{document}

As expected the above provides an error message Runaway argument which says: Paragraph ended before \text@command was complete. This is because \textit cannot include a paragraph break. I realize that {\itshape ... } can include paragraph breaks, but that is not my question.

Now, someone might ask, "What \text@command are you talking about? I did not type any \text@command". But of course, the reason is that the definition of \textit has \text@command within it.

I go to texmf-dist and `grep for "ended before". No Joy. I also try "ended~before". No joy. So the error message must originate somewhere in the binaries (which are not inside my texmf-dist directory).

But if I hunt through the code for \textit and the various other macros that it calls (and those that they call, and so forth) I do not find anything that explicitly asks for an error.

My question: Exactly how does TeX know that it is supposed to throw an error there? And more specifically, how can I re-define that error message using my own macro codes?

Why I ask: I like to pre-screen user input before it is processed, if possible. For example, instead of user-level \setlength I have a macro such as \somesize which stores the argument, checks that (as string) it can be intepreted as a a length value, check its bounds, and if successful sets the length. If unsuccessful, it get an error message from me, specific to the situation, and leaves the length unchanged from its default (not zero). So I would like to pre-screen \textit. Currently, I re-define \textit so that it will accept \par, but that is brute force.

4
  • don't you use luatex? Mar 1 at 2:10
  • \suppresslongerror = 1 in luatex (only) just disables this error condition Mar 1 at 2:13
  • commands do not accept \par in their arguments by default. they need to be defined by \long\def to allow \par. \text@command is not defined with \long so it is explicitly defined to throw an error on \par. Mar 1 at 2:17
  • @DavidCarlisle I will see if \suppresslongerror=1 helps. I have other Lua code that can intercept certain TeX errors. Perhaps they will play nicely together (or not).
    – rallg
    Mar 1 at 2:32

1 Answer 1

7

The web (pascal) source of tex is in the texlive sources but not distributed by default.

That message comes from line 8085 of tex.web

@<Report a runaway argument and abort@>=
begin if long_state=call then
  begin runaway; print_err("Paragraph ended before ");
@.Paragraph ended before...@>
  sprint_cs(warning_index); print(" was complete");
  help3("I suspect you've forgotten a `}', causing me to apply this")@/
    ("control sequence to too much text. How can we recover?")@/
    ("My plan is to forget the whole thing and hope for the best.");
  back_error;
  end;

https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/tex.web#L8085

It is not customisable from TeX macros (or anything else). The text is in the compiled program so can only be changed by changing the sources with a change file (which would mean you would fail the trip test and could not call the resulting program "TeX").

If you are using lualatex you can set

\suppresslongerror = 1 

Any non zero value causes this error condition not to be checked so macros are still \long or not \long but \par in an argument never raises the error shown.

3
  • Thanks. Investigation shows that the simple solution (suppress) does what I need in lualatex. I can absorb the consequences with my other code. Another example of why lualatex is so good.
    – rallg
    Mar 1 at 2:41
  • The suppression works when I set it to 1 without the following i. Does the i do something more, or is that a typo?
    – rallg
    Mar 1 at 16:16
  • 1
    @rallg see the comment I originally put under the question it said in luatex... and I picked up an i when copying.... Mar 1 at 17:12

You must log in to answer this question.

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