LaTeX-Utilities
LaTeX-Utilities copied to clipboard
fix(texdef): improve error handling, set CWD, and add `--tex` config
Fixes #407. For reproduction steps, see #407 and texdef-fontspec-repro.
Before and After
| Before | After |
|---|---|
Description
While investigating why texdef couldn’t resolve macros defined in .cls files within the same folder, I manually ran the logged texdef command and confirmed it worked as expected. However, in the extension, the spawned process exited immediately without any output.
Debugging revealed the following issues:
- Issue 1: We were listening on
stdout.on('error'), but error messages fromtexdefare emitted viastderr.on('data'), so errors were never caught.
https://github.com/tecosaur/LaTeX-Utilities/blob/a3265cc6827bd383eac4945ea8b914c0b4896fa0/src/providers/macroDefinitions.ts#L105-L108 - Issue 2: The spawned process did not have the correct working directory (
cwd), which prevented it from accessing files in the workspace folder.- Based on testing, the default
cwdon macOS is/, while on Windows, it defaults to the VS Code directory. - https://github.com/tecosaur/LaTeX-Utilities/blob/a3265cc6827bd383eac4945ea8b914c0b4896fa0/src/providers/macroDefinitions.ts#L96
- Based on testing, the default
- Issue 3: Some packages (e.g.,
fontspec) require an engine likexelatex, buttexdefdefaults tolatex.
Summary of Changes
- Fixed error handling by switching from
stdout.on('error')tostderr.on('data'), sincestdoutandstderrcan appear simultaneously (confirmed by testing), so no early return onstderr. - Added
cwdtospawnoptions to ensuretexdefruns in the correct context. - Introduced a new configuration option
latex-utilities.texdef.texto set the--texargument.
Future Improvements
- Automatically detect the correct engine based on the project context.
- Provide user feedback if
texdeffails due to an incompatible engine. - Should we cache the result of
texdef?