Re: texworks crashes with a context mkiv example
Stefan Löffler <[email protected]> Sat, 21 Mar 2026 18:05:50 +0100
| Newsgroups | gmane.comp.tex.live,gmane.comp.tex.texworks |
|---|---|
| Message-ID | <[email protected]> |
Hi Bruno,
Am 21.03.26 um 15:25 schrieb Bruno Voisin:
> [...]
>
> I get no crash with Hello-world.tex in any configuration. I get a crash with example.tex and release TeXworks 0.6.11 when lmtx is used. Switching to the TeXworks development version you point to, there's no crash but no SyncTeX functionality either.
No crash is good ;). So Jérôme's patch (preventing a
null-pointer-dereference) worked.
> I assume the crash comes from the combination of two things:
>
> - example.tex is very peculiar, it includes no actual input of its own, just calls /usr/local/texlive/2026/texmf-dist/tex/context/sample/common/knuth.tex through
>
> \dorecurse{4}{
> \input knuth
> \page
> }
>
> So that's bound to be a challenge for SyncTeX.
>
> - mkiv, ie context with --luatex, and lmtx, ie context without --luatex, work differently with respect to SyncTeX: the former stores the full absolute path of the .tex source in the .synctex file, and nothing about the files read within it with \input; the latter stores the names of the source files and any \input file, not their paths.
At the moment, I don't think it is related to the paths. That might
cause further problems down the line (though Tw is somewhat lenient with
respect to paths, to try and gracefully handle situations were files are
moved from one folder to another (or even from one PC to another)). But
that should not crash the program (the worst thing that should happen is
an error message stating that the file can't be found).
From Jérôme's patch, it appears to me that the problem was/is that
under certain conditions, SyncTeX receives an invalid (null) node, and
trying to access data for that invalid node (in particular its tag)
causes the crash.
> Attached is an archive with the tests, including the .tex, .pdf and .synctex files. I copied over
>
> /usr/local/texlive/2026/texmf-dist/tex/context/sample/common/knuth.tex (used by example.tex)
> /usr/local/texlive/2026/texmf-dist/tex/context/sample/common/tufte.tex (used by Hello-world.tex)
>
> to the respective directories, so that TeXworks could jump from preview to them with SyncTeX.
>
> The *-parser variants are for TeXShop (adding "% !TEX useConTeXtSyncParser" at the beginning of the source file), they're irrelevant for TeXworks.
>
> To analyze what's in the .synctex files produced by ConTeXt, how they are interpreted, Hans provided a very useful command during the testing:
>
> mtxrun --script synctex --list <basename>.synctex
>
> So the verdict: to get SyncTeX to work with TeXworks, you need to use --synctex=repeat, not just --synctex, but this is already what the "ConTeXt (LuaTeX)" typesetting script does.
Thanks a lot for the test cases! I looked at the .synctex files
(particularly, Hello-world-lmtx.synctex and
Hello-world-lmtx-repeat.synctex), and they look substantially different.
The numerical values of the various boxes are the same, but
Hello-world-lmtx.synctex contains a vbox ("[") containing a long list of
void hboxes ("h"), while Hello-world-lmtx-repeat.synctex contains a vbox
("[") containing a long list of (non-void) hboxes ("(") each containing
a rule ("r"). I don't know enough about SyncTeX (and haven't dug into
the code much) to tell if that is significant in any way.
In TeXworks, I see the status message that the respective SyncTeX file
is loaded in both cases. However, for Hello-world-lmtx.synctex, TeXworks
gets a reference to the main vbox from SyncTeX (which is associated with
the file, but no specific line number) regardless of where I click.
Conversely, for Hello-world-lmtx-repeat.synctex, it gets different
box_bdry nodes, which also include line number information.
>
> Max Chernoff just modified the dedicated page on the ConTeXt wiki:
>
> https://wiki.contextgarden.net/Input_and_compilation/Text_editors/SyncTeX
>
> By the way, a suggestion: the "ConTeXt (LuaTeX)" typesetting script uses actually LuaMetaTeX now. There would need to be two:
>
> ConTeXt (LuaTeX)
> context
> --luatex
> --script=repeat
> $fullname
>
> ConTeXt (LuaMetaTeX)
> context
> --script=repeat
> $fullname
Thanks for the suggestion. I updated the defaults in the code
accordingly (though the new defaults will only apply for new
installations as for existing installations, the old engine settings are
not overwritten). I used --synctex=repeat, though, as described on
https://wiki.contextgarden.net/Input_and_compilation/Text_editors/SyncTeX
and as has been used so far.
All the best,
Stefan