The best way to ask this question is to present two MWEs, one of which works and one of which does not. Naturally, I would like to get this into the second form, but I am at a loss as to what is happening. I believe this is an order-of-expansion issue. I tried this originally with the TeX primitives \csname
and \endcsname
and, failing that, went with the etoolbox
utility instead thinking that it would know what I was doing wrong and have built-in safeguards. But I am getting the same errors. Without further ado, why does
\documentclass[inline]{svmono}
\usepackage{xstring,etoolbox}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{TeX Gyre Termes}
\setsansfont[Scale=0.9,Mapping=tex-text]{TeX Gyre Heros}
\setmonofont[Scale=0.9]{Consolas}
\DeclareDocumentCommand{\extract}{m}{%
\edef\c{\detokenize{#1}}%
\StrCount{\c}{\string /}[\lastslash]%
\StrCount{\c}{\string .}[\lastdot]%
\StrBetween[\lastslash,\lastdot]{\c}{\string /}{\string .}[\temp]%
\csedef{\temp}{true}
}
\DeclareDocumentCommand{\mark}{m}{%
\csedef{\extract{#1}}{true}
}
\begin{document}
\extract{\input{../../Lyx/MacroMasterXeTeX.tex}}
\MacroMasterXeTeX
\end{document}
work, but (showing only changes)
\DeclareDocumentCommand{\extract}{m}{%
\edef\c{\detokenize{#1}}%
\StrCount{\c}{\string /}[\lastslash]%
\StrCount{\c}{\string .}[\lastdot]%
\StrBetween[\lastslash,\lastdot]{\c}{\string /}{\string .}[\temp]%
\temp
}
\DeclareDocumentCommand{\mark}{m}{%
\csedef{\extract{#1}}{true}
}
\begin{document}
\mark{\input{../../Lyx/MacroMasterXeTeX.tex}}
% \MacroMasterXeTeX
\end{document}
not work? (I commented out the last line in the document because that macro is never getting defined.) I would like to reuse the extraction code and would prefer to separate it from the "marking" process.
\mark
is a tex primitivexstring
latex has built in (expl3) functions for almost all that functionality, mostly with expandable variants where that is possible\temp
from the end of your extract and then use\temp
to expand in the csedef. (that is why xstring defines its command to return result in a specified csname, so you can do teh comamdn first and then use the result by expansion