I want to detect whether an input line contains a certain substring, similar to the problem discussed here: Check if a string contains a given character
The complicating problem is that the match strings look like these:
%* tex 1;
%* pgm 4;
The first step is to find whether I have a match. I'm trying to do this using the xstring package. The following code is my attempt to get started, just to test whether the string contains a % sign. It complains that the paragraph ended before \x was complete.
\begingroup
\catcode`\%=12\relax
\def\x#1{\def\dotest{\catcode`\%=12\relax\IfSubStr{#1}{%}{YES}{NO}}}
\expandafter\endgroup\x
The complete task is to read a line and:
- find whether there is match,
- what type it is (tex or pgm) and
- read the trailing number into a counter
- possibly pass the line to a verbatim environment or external file.
Basically I'm constructing a mini-language to be used as a code environment.