I need to measure a number of characters in string, that I returned from label through \nameref command.
Here is my MWE:
\documentclass{article}
\usepackage{hyperref}
\usepackage{xstring}
\begin{document}
\protected\def\testStr{\nameref{testLabel}}
String content = \testStr
\par
\newlength\testStrWidth
\settowidth{\testStrWidth}{\testStr}
String width = \the\testStrWidth
\par
\StrLen{\testStr}[\testStrNumOfChars]
Number of characters in string = \testStrNumOfChars
\clearpage
\makeatletter
\edef\@currentlabelname{This is a somewhat long string}
\label{testLabel}
\makeatother
Here we have some text to make another page.
\end{document}
Here is the result:
MWE doesn't give any errors.
I'm using XeTeX, but it doesn't work in pdfLaTeX too. I've tried \edef, \def, \let instead of \protected\def, but nothing seems to work.
Of course, if I set tested string explicitly inside \StrLen command, everything will work as it should.
Any help would be much appreciated.


