I'm trying to make use of lualatex to automate generation of some part of a pdf. The directory tree for my minimal working example looks like the following:
│ lua_escaping_issue.tex
│
└───a_folder
first_file.tex
fourth_file.tex
second_file.tex
third_file.tex
a_folder/first_file.texcontains the text "Hello"a_folder/second_filecontains the text "World"a_folder/third_filecontains the text "!. How are"a_folder/fourth_filecontains the text "you?"
Using lua, I'd like to generate the text "HelloWorld!.How areyou?". So I wrote lua_escaping_issue.tex which contains the following:
\documentclass{article}
\begin{document}
\directlua
{
require 'lfs'
for file in lfs.dir("a\_folder") do
if file ~= "." and file ~= ".." then
tex.print("\\input\{" .. "a\_folder/" .. file .. "\}")
end
end
}
\end{document}
Unfortunately when I compile with latexmk -lualatex lua_escaping_issue.tex I get an error:
[\directlua]:1: invalid escape sequence near '"a\p'
I believe the idea of \directlua is that everything will be expanded, therefore commands susceptible to be recognized by LaTeX should be escaped. I've already done this, and also tested my file in pure lua and it seems to work. So I'm not sure what I'm doing wrong here.