0

I'm trying to make a string manipulation by using xstring package.

Fore example \myparam equals to this: 1.1 Optimal solution of RNASP

But string functions doesn't work. For example \StrLeft{\myparam}{10} gives this error: Missing control sequence inserted. ...RNASP.\relax }}{10}{figure.caption.8}

I set this: \def\myparamDet{\detokenize{myparam}}

\myparamDet equals to this: \hyper@linkstart {link}{\Hy@tocdestname }{\numberline {1.1}{\ignorespaces Optimal solution of RNASP.\relax }}\hyper@-linkend

After detokenize this works: \StrLeft{\myparamDet}{10} and result is \hyper@lin

So I need two things:

  • Getting 1.1 from myparam and setting it to a new variable
  • Removing 1.1 from myparam
  • With the \detokenize, you discover what \myparam really equals, and it is not a string, but rather a hyperlink macro with various arguments set. Can you indicate whether the intended use will always be for such hyperlinks? – Steven B. Segletes Jun 4 '18 at 18:53
  • 2
    You really need to provide a small compiling example that highlights the issue. – Steven B. Segletes Jun 4 '18 at 18:57
  • Is result of detokenize not sufficient ? I suppose it is an escaped version of the hyperlink macro. Yes this manipulation will only be used for this type of strings. – Mark Jun 4 '18 at 19:06
2

With the \detokenize, you discover what \myparam really equals, and it is not a string, but rather a hyperlink macro with various arguments set. So you need to set up helper macros to grab the right argument and subargument from the list.

\documentclass{article}
\usepackage{hyperref}
\makeatletter
\def\myparam{\hyper@linkstart {link}{\Hy@tocdestname }{\numberline {1.1}{\ignorespaces Optimal solution of RNASP.\relax }}\hyper@linkend}
\newcommand\getmystring[1]{\expandafter\argfouroffive#1}
\newcommand\argfouroffive[5]{\xdef\NL{\argtwoofthree#4}\xdef\Mys{\argthreeofthree#4}}
\newcommand\argtwoofthree[3]{#2}
\newcommand\argthreeofthree[3]{#3}
\makeatother
\begin{document}
\getmystring\myparam

Number is \NL

String is \Mys
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.