[tug-summer-of-code] Simplifying TeX's \tracingall output

Will Robertson wspr81 at gmail.com
Thu Feb 19 15:16:04 CET 2009


Hi Jonathan,

I'm not sure we're achieving much but it's a fun discussion :)

On 19/02/2009, at 11:44 PM, J.Fine wrote:

> The relation with LaTeX3, in my view, is this: tools to support the
> migration of documents and styles from LaTeX2e to LaTeX3.

I think the tool that I'm thinking of, at least, is not even specific  
to LaTeX; it could be used on any TeX-based format, since we're just  
looking at the expansion of macros.

If there's anything that ties this to LaTeX3, I must have missed that  
part. Again, I think we're way too early to start talking about  
migrating anything to LaTeX3.

> Well, we can't get all that, but maybe what you're thinking of is
> stepping through the macros, as written in the source file.  Is this
> what you have in mind?

Yes, sorry that I was unclear earlier; the problem I was talking about  
wasn't shown in that example.

I'm sorry I don't have time to create the best example in the world,  
but here's something I've got right in front of me now:

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\group_begin:
\tracingall
   \tlist_map_inline:nn {abcdezyxvuw} {
     \tlist_if_eq:nnTF {#1} {z} {
       \tlist_map_break:w
     }{
       [#1]
     }
   }
\group_end:
\end{document}


The very first lines from the trace in this example show the  
definition of \tlist_map_inline:nn:

\tlist_map_inline:nn #1#2->\num_gincr:N \g_tlp_inline_level_num  
\cs_gset:cpn {t
list_map_inline_\num_use:N  
\g_tlp_inline_level_num :n}##1{#2}\exp_args:Nc \tlis
t_map_function_aux:Nn {tlist_map_inline_\num_use:N  
\g_tlp_inline_level_num :n}#
1\q_recursion_tail \q_recursion_stop \num_gdecr:N  
\g_tlp_inline_level_num
#1<-abcdezyxvuw
#2<-\tlist_if_eq:nnTF {##1}{c}{\tlist_map_break:w }{[##1]}


But obviously in the source we have something much more readable:

\cs_new:Npn \tlist_map_inline:nn #1#2{
   \num_gincr:N \g_tlp_inline_level_num
   \cs_gset:cpn {tlist_map_inline_ \num_use:N  
\g_tlp_inline_level_num :n}
   ##1{#2}
   \exp_args:Nc \tlist_map_function_aux:Nn
   {tlist_map_inline_ \num_use:N \g_tlp_inline_level_num :n}
   #1 \q_recursion_tail\q_recursion_stop
   \num_gdecr:N \g_tlp_inline_level_num
}


 From the tracing output, we can break this code listing into logical  
chunks of expanding pieces:

   \num_gincr:N \g_tlp_inline_level_num

   \cs_gset:cpn {tlist_map_inline_ \num_use:N  
\g_tlp_inline_level_num :n}
   ##1{\tlist_if_eq:nnTF {##1}{c}{\tlist_map_break:w }{[##1]}}

   \exp_args:Nc \tlist_map_function_aux:Nn
   {tlist_map_inline_ \num_use:N \g_tlp_inline_level_num :n}

   abcdezyxvuw \q_recursion_tail\q_recursion_stop

   \num_gdecr:N \g_tlp_inline_level_num


By selecting one of these chunks, we could repeat the process,  
drilling down into the expansion of a single chunk until it terminates.

So there's two main parts to this analysis:

  - identifying from the trace where the discontiguous expanding  
chunks are (this may be impossible in general, I don't know)

  - providing a friendly way of showing the expansion steps, like I  
illustrated in my previous email.


I don't know really how useful this would be in the real world; it  
would certainly be useful to learn how TeX expands macros and to learn  
how complex macros work.

But the level of scripting knowledge needed to do this is way beyond  
my level. I'm only a lowly mechanical engineer, see; programming isn't  
my forte.

Will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2415 bytes
Desc: not available
Url : http://tug.org/pipermail/summer-of-code/attachments/20090220/4852668e/attachment.bin 


More information about the summer-of-code mailing list