I'm having trouble tracking down an error that looks like a missing input error, but is occurring in a strange place. I'm trying to take a detokenized string (actually a macro in my actual doc) with an underscore in it and replace the detokenized underscore with a "cancelled" underscore (ie: \_
). I pass the result to \Result
and then attempt to print it to check if it worked. It doesn't. In fact the error is for line 13 rather than line 9 where the initial macro is.
If, however, I replace the \_
with any other non-control character then I receive no errors. Can anyone explain why I am having this error and how to fix it?
Error:
1 Tutorials/Example1/Example1.tex|13 error| Missing number, treated as zero.
2 Tutorials/Example1/Example1.tex|13 error| Missing number, treated as zero.
Example:
\documentclass{minimal} % EDIT: From answer, minimal shouldn't be used.
\usepackage[abspath]{currfile}
\usepackage{xstring}
%%% Set a fake return.
\def\theabsdir{\detokenize{/Users/Me/Example_with_underscore}}
\StrSubstitute[0]{\theabsdir}{\detokenize{_}}{\_}[\Result] % LINE 9
\begin{document}
Before: \theabsdir\\
After: \Result % LINE 13
\end{document}
This is the intended usage, but it doesn't work for a variety of reasons. Essentially pseudocode.
\documentclass{article}
\usepackage[abspath]{currfile}
\usepackage{xstring}
% Determine path of current file
\getabspath{Example.tex} % this provides \theabsdir, the file's directory.
% Delete folders up to the project's root directory.
\StrDel{\theabsdir}{path/to/project_root/}[\ProjectRoot]
% Add the location of custom packages
\def\StylePath{\ProjectRoot style_name}
% Load custom package
\usepackage[options]{\StylePath}
%%% End Preamble