Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created December 5, 2018 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/9c856107d84f1a32db01cfc6dfba6297 to your computer and use it in GitHub Desktop.
Save zr-tex8r/9c856107d84f1a32db01cfc6dfba6297 to your computer and use it in GitHub Desktop.
To pass to the TeX command a file name containing dangerous characters
local ptn = '[\\{}#^~%%]' -- dangerous characters
local fa, c = arg[#arg]:gsub(ptn, '~\\%1')
if c > 0 then
arg[#arg] = [[\bgroup\escapechar-1\let~\string\xdef\x{]]..
fa..[[}\egroup\input\x\relax]]
end
arg[0] = nil
os.exec(arg)

Example:

texlua texfile.lua latex "%.tex"

texlua texfile.lua pdflatex -halt-on-error "ABC~"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment