directlua 내부의 lua 코드에서 잘못된 이스케이프 시퀀스 오류가 발생합니다.

directlua 내부의 lua 코드에서 잘못된 이스케이프 시퀀스 오류가 발생합니다.

lualatexPDF의 일부 생성을 자동화하는 데 활용하려고 합니다 . 내 최소 작업 예제의 디렉터리 트리는 다음과 같습니다.

│   lua_escaping_issue.tex
└───a_folder
        first_file.tex
        fourth_file.tex
        second_file.tex
        third_file.tex
  • a_folder/first_file.tex"안녕하세요"라는 텍스트가 포함되어 있습니다.
  • a_folder/second_file"World"라는 텍스트가 포함되어 있습니다.
  • a_folder/third_file"!. How are"라는 텍스트가 포함되어 있습니다.
  • a_folder/fourth_file"당신?"이라는 텍스트가 포함되어 있습니다.

를 사용하여 lua"HelloWorld!.How are you?"라는 텍스트를 생성하고 싶습니다. 그래서 나는 lua_escaping_issue.tex다음을 포함하는 글을 썼습니다.

\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}

불행히도 컴파일할 때 latexmk -lualatex lua_escaping_issue.tex오류가 발생합니다.

[\directlua]:1: '"a\p' 근처의 잘못된 이스케이프 시퀀스

\directlua나는 모든 것이 확장될 것이므로 LaTeX에서 인식할 수 있는 명령을 이스케이프해야 한다는 아이디어를 믿습니다 . 나는 이미 이 작업을 수행했으며 순수하게 내 파일을 테스트했는데 lua 제대로 작동하는 것 같습니다. 그래서 내가 여기서 뭘 잘못하고 있는지 잘 모르겠습니다.

답변1

\\예방 하고 ~확대하는 것이 필요합니다 . 앞에 wih를 붙이면 \그렇게 되지 않습니다:

\documentclass{article}

\begin{document}
    \directlua{
% no   require 'lfs'
                
        for file in lfs.dir("a_folder") do
           if file \string~= "." and file \string~= ".." then
              tex.sprint( "\string\\input{a_folder/" .. file .. "}" )
           end 
        end

    }   
\end{document}

관련 정보