1

I have a small problem with the package currfile and the command \currfileabspath. When compiling the file using (pdf|xe)latex I get the expected result, but if I use lualatex it adds ./ to the absolute path of the file. I'm using TeXLive 2018 (updated) in Fedora 29, the working directory looks like this:

[pablo@fedora forum] $ pwd
/home/pablo/forum
[pablo@fedora forum] $ ls -lha
total 12K
drwxrwxr-x.  2 pablo pablo 4,0K feb 17 13:11 .
drwx------. 43 pablo pablo 4,0K feb 17 13:10 ..
-rw-rw-r--.  1 pablo pablo  187 feb 17 13:03 test.tex

My MWE (test.tex) is this:

\documentclass{article}
\usepackage[abspath]{currfile}
\setlength{\parindent}{0pt} 
\begin{document}
\texttt{\jobname.pdf} created from file \texttt{\currfileabspath}%
\end{document}

I use the following line to compile it:

$ pdflatex -recorder test.tex

with which I obtain:

test.pdf created from file /home/pablo/forum/test.tex

which is correct, but if I change it to:

$ lualatex -recorder test.tex

I get

test.pdf created from file /home/pablo/forum/./test.tex

How can I solve this? regards

  • 1
    It is easy to remove the ./ e.g. with a regex from expl3, but imho the best would be a feature request to the author of currfile. – Ulrike Fischer Feb 17 at 17:01
  • @UlrikeFischer In my mind I think it's a "bug", remove the . / is an option :) , I'll try something using l3regex, thanks. – Pablo González L Feb 17 at 17:16
3

Removing the period is easy:

\documentclass{article}
\usepackage[abspath]{currfile}
\usepackage{expl3}
\ExplSyntaxOn
\regex_replace_once:nnN{\.\/}{}\currfileabspath
\ExplSyntaxOff
\setlength{\parindent}{0pt}
\begin{document}
\texttt{\jobname.pdf} created from file 
\currfileabspath%
\end{document}

But imho it would be better if currfile would do this, when lualatex is used, as the period and the slash is also in other commands.

2

You can easily get the absolute path in LuaTeX using the FFI and a platform-dependent function. On POSIX-based systems you can use the realpath() function, on Windows you would use _fullpath (I think).

Because it uses the FFI you have to enable --shell-escape.

In tex.sprint I use the first argument -2 to switch to verbatim catcodes, in case the path contains any characters which are treated special by TeX, such as {}$%#.

\documentclass{article}
\directlua{
local ffi = assert(require"ffi")

ffi.cdef[[
char *realpath(const char *path, char *resolved_path);
]]

function realpath(path)
    return ffi.string(ffi.C.realpath(path, ffi.NULL))
end
}

\def\currfileabspath{%
  \directlua{tex.sprint(-2, realpath(status.filename))}%
}

\begin{document}
\currfileabspath
\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.