Is there a convenient way within a Lua block to determine the current file name and line number of the source file being processed by ConTeXt?

For example: (test.tex)
---------------------------------
\def\ShowLineNumber{%
   \ctxlua{print('current line number:', tex.current_line_number())
              print('current file:', tex.current_file_name())}}
\starttext
a line
\ShowLineNumber
another line

\ShowLineNumber
\stoptext
---------------------------------

With the following displayed:
---------------------------------
current line number: 6
current file: test.tex
current line number: 9
current file: test.tex
---------------------------------

I've considered hooking into the open_read_file callback and tracking the file name and line number (via reader) myself. But that seems a bit heavy handed if the file name and line number information are available more directly. And since that information is needed for error reporting, I'm thinking there's a good chance it is accessible.

(Just in case you're interested, the purpose of this is to be able to assemble code segments during the ConTeXt processing into external files with #line directives ala the C preprocessor. That way if the subsequent compilation of the external file results in an error, the error message can refer back to the line of code in the ConTeXt source file. This is part of the literate programming module that Kevin Robbins has been describing in another thread.)

Thanks,
Tad
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to