I would like to parse a path in Lua in order to split it into its folder and file components. The goal is to create a macro that accepts an argument of the form myfolder/myfile
and be able to use myfolder
inside the lua block in order to put it into other macros.
The following does not work but is supposed to showcase what I seek:
\newcommand*{\splitme}[1]{\directlua{
local parts=split(#1,'[\\/]+');
tex.sprint("\graphicspath{",parts[1],"}");
}}
I checked out http://lua-users.org/wiki/SplitJoin but could not piece it together in LuaLaTeX. Is it possible though without too much hassle?
/
char? If so,string.match
is likely the way to go\filename@parse
which is used all over the graphics package to split a filename into directory, basename and extension parts.string.match
in his answer...\filename@parse
, but find it very hard to understand its usage.