0

I've added a hook to lstlisting to do some special highlighting. Now I've got it to highlight %-prefixed variables just fine, but I'd like to handle the special case "%this" in another way.

Unfortunately when lstlisting find a keyword followed by a comma, it gives me this\unhbox \voidb@x \kern \z@ which I have a hard time parsing.. Essentially I just need to check if it is a "this" keyword, this has proved tricky however.

Just to be a little more specific, I can't just do a substring because %thisVal should not be accepted, only %this.

I tried the Sanitizer from another thread but had no success.

If the token didn't have all that other stuff appended, all I needed to do is:

    \ifnum\pdf@strcmp{\@restTestChar}{this}=0%
    \def\lst@thestyle{\color{thisColor}}%
    \else
    \def\lst@thestyle{\color{variableColor}}%
    \fi

I was thinking that any way to just remove anything after the first \ should work, but I can't figure out how to do this as it is not a string per se.

Edit: To give a little more context, I'm trying to make an extension to a lstlisting-based SyntaxHighlighlighter such that %this is highlighted in red and not the same color that other %-prefixed variables are highlighted in. I have a working sample that shows the issue. The lst-hook just checks whether the token is "%this" and doesn't handle the case where it is %this\unhbox \voidb@x \kern \z@ which is what lst gives me for some reason. I need to handle both cases.

LukasPJ
  • 121
  • Some more context is needed. – egreg Dec 03 '14 at 09:43
  • The addition is useless, sorry. – egreg Dec 03 '14 at 10:48
  • Can you elaborate on why? I'm not sure what you need, theres a full working sample and a precise description on what goes wrong?

    It is this comparison \ifnum\pdf@strcmp{\@restTestChar}{this}=0% that I need to change such that it takes into account the case where %this isfollowed by the 4 control sequences as described in the question.

    – LukasPJ Dec 03 '14 at 12:07

0 Answers0