Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.
<to be read again> 
                   \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).
<to be read again> 
                   \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?

Many thanks in advance for any answers,
Cheers!

share|improve this question
3  
minipage looks for its argument: \begin{minipage}{width}... –  Ulrike Fischer May 23 '12 at 10:02
2  
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
add comment

closed as too localized by Frank Mittelbach, Marco Daniel, percusse, Count Zero, Tom Bombadil Aug 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.

1 Answer

up vote 7 down vote accepted

minipage looks for its argument: \begin{minipage}{width}...

share|improve this answer
    
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
2  
@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
2  
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
add comment

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