# When is Synctex file written?

When is the syncTeX file written and is there a way to get a callback in to lua after it occurs? I would like to read it at the end of the compilation process rather than have to compile twice to get at it.

I could potentially run an external script or wrap the compilation process to accomplish this task but that is much more work than necessary.

finish_pdffile occurs before synctex is written so it is no good ;/

Here is a list of all the callbacks, I believe, I don't see anything that will help.

local callbacktypes = callbacktypes or {
find_write_file    = exclusive,
find_font_file     = data,
find_output_file   = data,
find_format_file   = data,
find_vf_file       = data,
find_map_file      = data,
find_enc_file      = data,
find_sfd_file      = data,
find_pk_file       = data,
find_data_file     = data,
find_opentype_file = data,
find_truetype_file = data,
find_type1_file    = data,
find_image_file    = data,
find_cidmap_file   = data,
process_input_buffer  = data,
process_output_buffer = data,
process_jobname       = data,
contribute_filter      = simple,
buildpage_filter       = simple,
pre_linebreak_filter   = list,
linebreak_filter       = list,
append_to_vlist_filter = list,
post_linebreak_filter  = list,
hpack_filter           = list,
vpack_filter           = list,
hpack_quality          = list,
vpack_quality          = list,
pre_output_filter      = list,
process_rule           = list,
hyphenate              = simple,
ligaturing             = simple,
kerning                = simple,
insert_local_par       = simple,
mlist_to_hlist         = list,
pre_dump             = simple,
start_run            = simple,
stop_run             = simple,
start_page_number    = simple,
stop_page_number     = simple,
show_error_hook      = simple,
show_warning_message = simple,
show_error_message   = simple,
show_lua_error_hook  = simple,
start_file           = simple,
stop_file            = simple,
finish_pdffile = data,
finish_pdfpage = data,
define_font = exclusive,
}


I'm also not sure of a pure lua way or if the synctex file is written after all lua code is finished.

Looking at the source the synctex file is closed as the really last thing after all callbacks

    /* Close {\sl Sync\TeX} file and write status */
synctexterminate(log_opened_global);       /* Let the {\sl Sync\TeX} controller close its files. */
free_text_codes();
free_math_codes();
if (log_opened_global) {
wlog_cr();
selector = selector - 2;
if ((selector == term_only) && (callback_id == 0)) {
tprint_nl("Transcript written on ");
tprint_file_name(NULL, texmf_log_name, NULL);
print_char('.');
print_ln();
}
lua_a_close_out(log_file);
}
}


which is the end of close_files_and_terminate and the only thing called after that is do_final_end(); which just sets the error status and stops.

So I don't think the synctex data is reliably available during the current run.

• Ok, kinda sucks but I should be able to work around it. Where does one go to do a feature request for lualatex? Also, is synctex part of the lualatex engine(include as source) or a separate build? It would be nice to have a few hooks for lualatex as synctex is doing it's thing. I'm having to extract page numbers and line numbers to do what I want, but having to jump through many hoops to do so... – AbstractDissonance Feb 13 '17 at 14:09
• @AbstractDissonance that was the source of luatex that I showed. You could ask on luatex list for feature requests (luatex at tug dot org) but I would guess you would need to supply a lot more coherent use case than you have so far posted here. Not my call though: I have no write access to those sources:-) – David Carlisle Feb 13 '17 at 14:33