1

I got "Undefined control sequence." message, but from ...sdir{\directlua{tex.sprint(lfs.currentdir())} I do not understand, on which control sequence LuaLaTeX refers:

enter image description here

How can I explore it?

The MWE is

\documentclass[a4paper, twoside]{ltjsarticle}

\usepackage{luatexja-fontspec}

\edef\currfileabsdir{\directlua{tex.sprint(lfs.currentdir())}/}

\begin{document}
    done
\end{document} 
  • 1
    Your file compiles without errors for me (TL 2018). – Alan Munn Mar 29 '19 at 00:47
  • @AlanMunn, Thank you for try. Did you compile by LuaLaTeX? It's interesting, what I missed. I'll upload a screencast later. – Gurebu Bokofu Mar 29 '19 at 01:11
  • Use tex.sprint(-2,lfs.currentdir()) to switch to verbatim catcodes. – Henri Menke Mar 29 '19 at 02:30
  • @HenriMenke, Thank you for the comment. Unfortunately, It will delete path separators, and C:Users/me/Documents/TeX/LuaLaTeX_Development/fonts/HGS_Mincho/HGRMB.ttc becomes to C:UsersmeDocumentsTeXLuaLaTeX_Development/fonts/HGS_Mincho/HGRMB.ttc. – Gurebu Bokofu Mar 29 '19 at 13:53

2 Answers2

5

The undefined control sequence is \Users which is part of the path. Even though here \ is meant to be the path separator, LuaTeX doesn't know that and just feeds the path with the currently active catcodes back to TeX, where \ happens to be the escape characters. Luckily, you can tell tex.sprint to use a different catcode table using an optional argument. To use verbatim catcodes (everything is catcode 12, except space which retains catcode 10) use the catcode table with number -2.

\edef\currfileabsdir{\directlua{tex.sprint(-2, lfs.currentdir())}/}
Henri Menke
  • 109,596
  • That why I did not understand... You have the deep understanding. Thank you for the answer! – Gurebu Bokofu Mar 29 '19 at 03:25
  • I checked your solution. Unfortunately, it will delete path separators, and C:Users/me/Documents/TeX/LuaLaTeX_Development/fonts/HGS_Mincho/HGRMB.ttc becomes to C:UsersmeDocumentsTeXLuaLaTeX_Development/fonts/HGS_Mincho/HGRMB.ttc. – Gurebu Bokofu Mar 29 '19 at 13:55
  • @GurebuBokofu You probably need another font. Try \texttt{\currfileabsdir}. – Henri Menke Mar 29 '19 at 18:55
2

The undefined control sequence is the thing just before the line break:

\documentclass{article}
\begin{document}
\quad\acommandthatdoesntexist\quad
\end{document}

Has the output:

! Undefined control sequence.
<*> \quad\acommandthatdoesntexist
                    \quad

In your case, that appears to be \Users, which may suggest that TeX is trying to read a Windows path and interpreting the \ as beginning a command. You'll probably need a package that can navigate Windows directories.

Teepeemm
  • 6,708
  • Side note, there are some special cases where the thing just before line break is not the undefined control sequence. See https://tex.stackexchange.com/a/627520/250119 – user202729 Mar 26 '22 at 23:46