I have a syntax highlighting program that outputs LaTeX code. The generated code can be used in regular text or in a
tabular to do more advanced layouts.
The generated LaTeX output includes
\my@eol at the end of each line, which is essentially defined as
\par. Of course, this works in regular text but not in tables, so I'd like to conditionally use
\cr if I'm in a table.
How do I check if I'm currently in an alignment (tabular, array, halign, etc.)?
Originally I defined
my@eol in terms of
\\, which worked in tabular as well, but based on the comment of Barbara Beeton in When to use \par and when \\, \newline, or blank lines I changed to using
\par. Now I need to find a way to switch between
\cr as needed.
Here's what I've tried: I looked at the implementation of
tabular, and noticed that it redefined
\\ (the latter to
\@arraycr, which eventually expands to
\cr), so one solution would be to check whether
\par has been redefined, but that sounds very brittle. I read the documentation of
tabular as well.
Then I looked at various sources of documentation to see if TeX has any sort of conditional (like
\ifvmode) for alignments, but I couldn't find one.
Finally I also looked at the implementation of
\halign (it calls
init_align) in the source code of TeX, but I didn't manage to spot anything directly relevant (it seems to just change to
vmode and set up
align_state when entering an
halign, but I'm not sure how to access
align_state from TeX).