Portable shell escape dependency declaration for LaTeX packages
0 reputation · 23 Apr 2023, 22:21 UTC
0 reputation · 23 Apr 2023, 22:21 UTC
Package authors sometimes need to invoke external tools during compilation through \write18, but there is no widely adopted metadata mechanism to declare that dependency so engines and distributions can enforce or prompt for the correct permission level. While pdfTeX, XeTeX, and LuaTeX expose command-line flags to control shell escape, their default security postures differ, and the command whitelist available in restricted mode is not standardized across engines or distribution versions.
LuaTeX adds further ambiguity because its os.execute and io functions are governed by a security layer that does not align directly with the traditional \write18 restricted mode. A document that relies on shell escape may therefore behave differently depending on the engine and the local TeX installation, without any explicit warning to the user.
When a package genuinely requires shell escape—for example, to run a conversion tool at build time—the author cannot portably signal that requirement so the build system or user knows to adjust engine flags. This leaves the permission boundary implicit and dependent on distribution defaults.
Is there a documented or emerging convention for declaring shell escape dependencies in package metadata that works consistently across pdfTeX, XeTeX, and LuaTeX? How should authors reconcile LuaTeX's native os security layer with the engine-agnostic \write18 restricted mode? What configuration strategy keeps a project compilable when the local distribution defaults to restricted shell escape?
34775 reputation · 24 Apr 2023, 04:57 UTC
There is no standardized package-metadata field or engine-agnostic convention for declaring shell-escape requirements across pdfTeX, XeTeX, and LuaTeX. A \\sty file cannot force the engine to enable \\write18; the document or build system must pass the appropriate command-line flag. The portable approach is to check at load time, fail or degrade gracefully, and document the required flag.
Assumption: you are using a recent TeX Live or MiKTeX installation and can add pdftexcmds as a package dependency. If you cannot add dependencies, use the engine primitive directly where available.
Configure CI or Makefile targets to compile with each target engine using both --shell-escape and --no-shell-escape. This verifies that the package either works with the flag or degrades as intended without it. Do not rely on restricted mode for portability; its allowed-command list is not standardized.
pdftex --version lualatex --version xelatex --version
Then compile a minimal test document under each flag and print \\pdfshellescape or the pdftexcmds equivalent. In LuaTeX, run a harmless os.execute probe under the same flags to observe the native security layer.
Which TeX engine and distribution version are you targeting? If you are using LuaTeX exclusively, the check should focus on os.execute rather than \\write18; the recommendation otherwise stays the same.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.