In short: When debugging my lualatex files in VS Code with Local Lua Debugger, breakpoints in lua files are ignored if they lie outside the current working directory; for example, if they lie in the parent folder of the file to be compiled.
I successfully set up Visual Studio Code with all the required extensions as described here to be able to debug lualatex code.
My setting: I have a folder that I opened in VS Code. It contains the following three files:
- 'script.lua'
- 'latex/main.tex' (that is, 'main.tex' is lying in a subfolder called 'latex')
- .vscode/launch.json (the configuration file for the debugger)
script.lua (the content is not relevant for the issue):
for i=1,10 do
tex.print("Hello ")
end
main.tex:
% !TeX program = lualatex
\documentclass{article}
\directlua{%
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
package.loaded["lldebugger"] = assert(loadfile(os.getenv("LOCAL_LUA_DEBUGGER_FILEPATH")))()
require("lldebugger").start()
end}
\begin{document}
\directlua{require("../script.lua")}
\end{document}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Custom Lua Environment",
"type": "lua-local",
"request": "launch",
"stopOnEntry": false,
"program": {
"command": "lualatex"
},
"args": ["${file}"],
"cwd": "${fileDirname}"
}
]
}
Issue: When I put a breakpoint into script.lua (e.g., 2nd line), and press F5 (when main.tex is selected), then main.tex is compiled without errors, but the breakpoint is ignored.
Can I tell VS Code + Local Lua Debugger to pause at the breakpoints? Important: I want to keep the files where they are and I also do not want to change the path of script.lua in main.tex.
Observation 1:
The debugger correctly pauses at the breakpoint, when I change the penultimate line of main.tex to \directlua{require("script.lua")}
and either
- remove
"cwd": "${fileDirname}"
from launch.json, or - move script.lua into the folder latex.
Observation 2:
- The breakpoints work fine if the file in
require( )
is given by an absolute path, e.g.,require("c:/test/script.lua")
. - The breakpoints are ignored if the path is relative (to main.tex), e.g.
require("..\script.lua")
.
But as noted above, I look for a different solution than the ones of the observations. The reasons: On one hand, I have many files where I would need to carefully update the paths. The path structure is actually more complicated and I want to keep it relative to the respective tex files. On the other hand, I want to be able to compile the files directly from within their directories also without (using the configuration files of) VS Code, e.g., by just using the terminal.
If possible, I would prefer a solution where I have only to configure Local Lua Debugger in an appropriate way without changing the code at all.
Some ideas:
The description page of Local Lua Debugger mentions two options for the configuration file that sounded promising: scriptRoots
and scriptFiles
. However, I was not able to resolve the issue by using them. Maybe I used them wrongly.