# String parsing macro fails within a minipage environment? [closed]

I am trying to work with a string parsing macro, found in the answer of TeX capacity exceeded while parsing a date string - TeX - LaTeX.

Basically, I have strings num01, num02... num09 - from these, I would like to extract the last character; and this code, for instance, works (with pdflatex):

\documentclass{article}

\def\parseMyNumHelper num0#1\relax{\edef\MyNum{#1}}
\def\parseMyNum#1{\edef\temp{#1}%
\expandafter\parseMyNumHelper\temp\relax}

\begin{document}

\edef\myid{num01}

%   \begin{minipage}
\parseMyNum{\myid}
\typeout{ ======== \temp === \MyNum }
%   \end{minipage}

\end{document}


... resulting with this in the log output:

...
======== num01=== 1
(./a.aux) )
...


However, now just uncomment the begin/end {minipage} statements; the code immediately crashes with:

...
(./a.aux
)
! Missing number, treated as zero.
\edef
l.12     \parseMyNum
{\myid}
...


... and even if I proceed a bit with looking at \parseMyNum, I cannot see anything strange:

? i
insert>\show\parseMyNum
! Illegal unit of measure (pt inserted).
\show
l.12     \parseMyNum
{\myid}
? i
insert>\typeout{ \meaning\parseMyNum }
macro:#1->\edef \temp {#1}\expandafter \parseMyNumHelper \temp \relax
> \parseMyNum=macro:
#1->\edef \temp {#1}\expandafter \parseMyNumHelper \temp \relax .
<insert>  \show\parseMyNum

l.12     \parseMyNum
{\myid}


Any ideas why the parsing macro \parseMyNum fails when within a minipage environment - and how to have a similar string parsing macro, working both within and outside of minipage and other environments?

Cheers!

-
minipage looks for its argument: \begin{minipage}{width}... –  Ulrike Fischer May 23 '12 at 10:02
To confirm Ulrike's comment, if you put \begin{minipage}{\textwidth} then it works again. (Admittedly, this is far from obvious when looking at the log file! But a good debugging strategy is to also comment out the stuff you're trying to debug just to check that without it the document compiles okay.) –  Andrew Stacey May 23 '12 at 10:09
And indeed it is (looking for it argument) :) Many thanks for that @UlrikeFischer - would you mind posting your comment as an answer, so I can accept it? Cheers! –  sdaau May 23 '12 at 10:12

## closed as too localized by Frank Mittelbach, Marco Daniel, percusse, Count Zero, Tom BombadilAug 23 '12 at 19:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

minipage looks for its argument: \begin{minipage}{width}...
Many thanks for that, @UlrikeFischer - wish sometimes Latex would be able to give a message like "Error: environment minipage missing argument: \begin{minipage}..."; instead of: "Error: Missing number, treated as zero: \parseMyNum..." ... but thankfully, it's solved now :) Cheers! –  sdaau May 23 '12 at 10:21
@sdaau: The argument is not missing. minipage is using your parseMyNum as argument and tells you that it hasn't the correct content. You would get a similar error if you forget e.g. the slash before a width: \begin{minipage}{textwidth} –  Ulrike Fischer May 23 '12 at 10:35
Ah, I see - many thanks for that as well, @UlrikeFischer; I didn't come to the conclusion that "minipage is using your parseMyNum as argument" until now; it starts making a lot more sense. Could you also comment on why also forgetting the slash before a width would be similar? Is it that, not being a command, Latex will ignore the {textwidth}, and keep going until the next time it sees a backslash - a command, as demanded for minipage's argument? Thanks again - Cheers! –  sdaau May 23 '12 at 10:56
No minipage will not ignore {textwidth}. It's its argument and it will try to use it. But the argument of minipage should be a width – in the end (after expansion) it should be a number followed by an unit like cm or pt. So if the argument start with "t" minipage will complain Missing number. –  Ulrike Fischer May 23 '12 at 11:06