# A LaTeX log analyzer application (visualizing TeX expansion)

Consider the following MWE, test.tex:

\documentclass[12pt]{article}

\begin{document}

\tracingassigns=1
\tracingmacros=1

\def\aaa{something}
\def\bbb{else \aaa, else}
\edef\ccc{third \bbb, level}

\tracingassigns=0
\tracingmacros=0

\end{document}


If you build this with pdflatex test.tex - then in the logfile, test.log, you get something like this (linebreaks added for legibility):

{into \tracingassigns=1}
{changing \tracingmacros=0}
{into \tracingmacros=1}

{changing \aaa=undefined}
{into \aaa=macro:->something}

{changing \bbb=undefined}
{into \bbb=macro:->else \aaa , else}

\bbb ->else \aaa , else

\aaa ->something

{changing \ccc=undefined}
{into \ccc=macro:->third else something, else, le\ETC.}

{changing \tracingassigns=1}


Now, this explains the expansion steps done by (La)Tex quite well for this short example - unfortunately, it becomes extremely hard to read (for me) once you have to deal with possibly hundreds of these expansions, some maybe dealing with typesetting procedures.

So I was thinking - it shouldn't be too extremely difficult to build an application, which would basically read the logfile line by line, and allow for "stepping" through the logfile; I'd imagine rightarrow keyboard key -> would step you forward through the log, and leftarrow key <- would step backwards; possibly, one could specify line number of the logfile as a starting point as well.

Then, the application would simply react on '^{changing', '^{into', and possibly '^\\(.*)->(.*)'; and would display the line, as well as the "current" token elsewhere on screen; so at the "changing" line, the extra portion of the screen would say \aaa=undefined; and upon "into" line, the snippet would change to \aaa=macro:->something.

I think just this facility would make visualizing and understanding the (La)Tex expansion process much more easy (especially in "real" documents). And in fact, such an application doesn't even need a full-blown GUI - I'd imagine a ncurses terminal application would do just as well (problems with display of long strings in limited width terminal notwithstanding).

So, I was wondering - is there any application similar to this out there?

-
As far as I know, nothing like this exists yet. Keeping track of definitions and other unexpandable commands is straightforward, as you describe. However, expansion can become nested very deeply. Consider for instance \def\a#1;{8#18}\expandafter\a\number\a2;; At first, a simple macro definition, then {\expandafter}, {\number}, \a #1;->8#18, #1<-2, \a #1;->8#18, #1<-828... Very hard to keep track of which \a is being expanded when. I suspect that the correct approach would be to modify the engine itself, but I still don't know how the expansion would be displayed. – Bruno Le Floch Jun 24 '12 at 9:04
Thanks for mentioning that, @BrunoLeFloch - I completely overlooked such cases when I was typing the question; now I can see better that even "just" reading the logfiles would not necessarily be straightforward.. Cheers! – sdaau Jun 25 '12 at 1:13
An answer I wrote to a question from Yiannis, tex.stackexchange.com/a/9340/2707 may be of interest for what you're trying to achieve. I tried several times to have a general solution, but it is very hard. – Bruno Le Floch Jun 25 '12 at 2:53
I have not tried it my self, but I think TeXStudio could help you. It has a built in log analizer. – Jonas Stein Oct 27 '12 at 10:52
Note that I'm working on a LaTeX package which could provide an aswer to this question. See the discussion in this chat room. It's not strictly an interactive application, but you get a lot of "interaction value" by lots of navigation links in the pretty-printed log file. – Stephan Lehmke Feb 11 at 8:01