I need to parse a "commands" where each command is is a string of letters and numbers: a34b56c32alpha
Does xparse have any way to deal with the numbers?
I would like to specify it with something like { 'a' n 'b' n 'c' n m }
where n would be a number.
Basically this is to save having to use unnecessary delimiters (it's already more complex and I can't use ,).
I'm new to xparse and didn't see anything in the docs about being able to parse numbers.
\documentclass[11pt]{book} % use larger type; default would be 10pt
%\documentclass[11pt,a4paper,oneside]{report}
\usepackage{pgffor}
\usepackage{xparse}
\begin{document}
\DeclareDocumentCommand{\Dotparse}{o m}
{
#1
}
% Passes each value in the array to an xparse command.
\def\Dots#1
{
\foreach \n in {#1}{
\Dotparse{\n}
}}
\Dots{[3]f4s3,f12s5,s2f14,[5]e,f,g,1,2,3,4,5,6,7}
\end{document}
This code does not parse the optional commands
The above should display 3, , , 5, , , , ....
but I get No Value for all.
not sure what is going on.
In any case, what I want the output to be is for
\Dots{[3]f4s3,f12s5,s2f14,[5]e,f,g,1,2,3,4,5,6,7}
to parse into
[3](f + 4), s + 3, f + 12, s + 5, ...
where the the + does not mean addition BUT simply is a separator.
So #1 = 3, #2 = f, #3 = s, #4 = 4
(note, don't get confused by the array, it is irrelevant. I iterate over it and THEN pass the element to the xparser which is all I am concerned about now... e.g., I want to parse [3]f4s3 into it's it's tokens where f4s3 is actually 4 tokens. f43s35 would still be 4 since for my purposes)
for example, which such a parser I could write x353.43y32.435z345.3cgreen
to represent a 3d point with color. Obviously it looks more confusing than using commands or = signs but it is very compact which is what I'm after.
xparse, which is meant to define document command syntax in an ordered way. Complex parsing of structured input is not something we've aimed for, or would necessarily encourage (although the latter of course depends on the context). – Joseph Wright♦ Mar 16 '12 at 11:54x353.43y32.435z345.3cgreenand something like[3]f4s3,f12s5,s2f14,[5]e,f,g,1,2,3,4,5,6,7? It's quite difficult to understand. I would specify(354.43,32.435,345.3,green)which is clearer and more easily parsed or used. – egreg Mar 16 '12 at 12:44