# What is * doing for these commands and how to replicate?

I'm trying to get a project's root folder path for usage later on in the preamble. My latex knowledge is... limited... but I've gotten a solution working using a combination of the currfile, and xstring packages. Unfortunately I don't understand what the * is doing to the functions to make the function work.

My MWE, Example.tex, is located within /Users/Me/Tutorials/Example1/. I get the path to it's root directory using the currfile package and then I use xstring:\StrBefore* to cut out the folders I know exist (/Tutorials/Example1/).

As best I can tell it is an expansion trick of some kind - as I understand it \StrBefore* makes the first argument be correctly expanded and treated with the right character codes. But what exactly does that mean? If it is an expansion issue then why does it work without the * syntax for the \UnExpectedResult string?

Ideally I'd like to be understand how I might have achieved the same result using explicit expansion commands instead. Not because I think it would make things easier, but because the knowledge will certainly come in handy. There are a variety of related posts on this site, but I couldn't find any answers that were approachable to me. This might be due to of a lack of latex vocabulary.

MWE named Example.tex:

\documentclass{minimal}

\usepackage[parents,abspath]{currfile}
\usepackage{xstring}

%%% Get the MWE root location.
\getabspath{Example.tex}
% \theabsdir contains /Users/Me/Tutorials/Example1/

\newcommand{\WithStar}{\StrBefore*{\theabsdir}{Tutorials/}}
\newcommand{\WithoutStar}{\StrBefore{\theabsdir}{Tutorials/}}

%%% Create an example string
\newcommand{\ExampleRoot}{/Users/Me/Tutorials/Example1/Example.tex}
\newcommand{\UnExpectedResult}{\StrBefore{\ExampleRoot}{Tutorials/}}

\begin{document}
MWE:\\
theabspath: \theabspath\\
theabsdir: \theabsdir
WithStar: \WithStar\\
WithoutStar: \WithoutStar\\
UnExpectedResult: \UnExpectedResult

\end{document}


• According to the ctan xstring doc all the starred version does is detokenize the input before sending it to the standard commands (that's a bit of a simplification of course). I don't quite understand why that would affect this though. Perhaps catcodes come into play? All of the input looks to be normal text to me. I do know that \theabsdir only provides cat codes 10,11, and 12, because right now it is causing me an issue with a folder that has an underscore. Perhaps converting \theabspath back into standard catcode would have produced the same results? – Lagix Feb 6 at 23:20
• Perhaps tex.stackexchange.com/questions/20059/… will help. – John Kormylo Feb 7 at 16:48
• Ah ok, that looks like it is exactly what is happening. Is there such a thing as retokenize? – Lagix Feb 10 at 17:17
• I believe \def or \edef performs that function, whether you want it do or not. – John Kormylo Feb 10 at 22:50