I use the currfile
package to help keep track of the source of my latex files. I use Linux, and the full path of the file looks like this:
/home/username/(various directories)/project-one/proposal/FIRST.tex
If I use
\usepackage[abs]{currfile}
\currfilename
then it displays the full path. If I use
\usepackage{currfile}
then I only see FIRST.tex
.
Question: Is there a way to display
project-one/proposal/FIRST.tex
(it does not matter if there is a backslash in front of the path).
In case this matters, I use TeXlive in Linux.
Best Answer
In the following code, once
\defineKnownPrefixes
has been called:\currFileAbsPathWithoutPrefix
expands in one step to the desired thing (string'ified path with one instance of the prefix removed if possible, if it is among those specified with\defineKnownPrefixes
);\stripPrefixFrom{⟨balanced text⟩}
recursively expands to same thing, but using ⟨balanced text⟩ as input instead of the “contents” of\currfileabspath
.\stripPrefixFrom
is restricted-expandable: it can be used inside\edef
,\xdef
,\write
,\typeout
,\message
, etc.\defineKnownPrefixes
assigns the list of prefixes\l_uflow_prefixes_seq
and the resulting\currFileAbsPathWithoutPrefix
locally (in other words, it respects TeX's grouping rules).As reminded below, the
\currFileAbsPathWithoutPrefix
setting requires the document to be compiled with the-recorder
option of the TeX engine (see the documentation of currfile).