# processkv or keyval package keys does not allow 0 key

Either the processkv or keyval package does not seem to allow the 0 key. When I do 0=val I get errors when trying to process the key but when I do 1=val everything works.

Any ideas? In parcolumns it processes the keyvalues using:

\expandafter\processkeyvalues\expandafter{\the\toks@}\pc@setsinglecolwidth%


and the key is simply defined as

\define@key{parcolumns}{colwidths}{\toks@{#1}}


Which calls calls the following macro to act on the key-value pairs:

\def\pc@setsinglecolwidth#1#2{%
\@ifundefined{pc@column@width@\number#1}{%
\PackageError{parcolumns}{#1' is not a valid column width number!}{\@ehc}%
}{%
\csname pc@column@width@\number#1\endcsname=#2\relax%
}%
}


The error message is from the package error. It is not creating the \pc@column@width@0 value for some reason but all other positive values work(well, up to the number of columns).

The way I understand the code is processkv simply processes each key-value pair and calls the macro, in this case \pc@setsinglecolwidth, on each key-value pair. Hence I see no reason why '0' doesn't work. Since I couldn't find anything in parcolumns that is treating 0 as special I see no reason why the error would be in parcolumns (hence the only other place would be processkv and keyval?

Works:

\begin{parcolumns}[nofirstindent,distance=0pt,colwidths={1=30pt}]{6}%


Doesn't Work:

\begin{parcolumns}[nofirstindent,distance=0pt,colwidths={0=30pt}]{6}%

-
Really you have asked enough questions to know the score by now, saying "I get errors" doesn't help, please cut and paste the exact error message you get, and show the code that produces the error. Historically since the beginning of computing the most common reason for getting an error just for 0 is that either the definition or use accidentally used O instead. –  David Carlisle May 12 '12 at 8:53
"Um, seriously? You do realize that tex does not give exact error messages 99%" you may think they are not exact, but you are mistaken. If you posted the error message many people would know exactly what bit of latex produced the message, even if the text does not appear relevant, knowing where in the code the error is generated is most often the largest part of debugging. –  David Carlisle May 12 '12 at 9:00
"Basically you want me to give you more information which I didn't really have until joseph said it worked for him" Joseph only had that information because he took the trouble to generate a minimal example that just set and used a 0 key. You should have generated that MWE. Often when constructing a MWE to ask a question you discover the problem goes away, which means that the problem is not where you thought it is, so that allows you to generate a different MWE that does show the problem, and ask a more useful question. –  David Carlisle May 12 '12 at 9:04
You haven't shown the error message you get and you haven't posted an example that anyone can run to test. –  David Carlisle May 12 '12 at 9:10
but presumably parcolumns labels its columns 1,2,3...s o why would you expect pc@column@width@0 to be defined? That is, it is presumably nothing to do with keys, just that a 2 column document has columns 1 and 2 I would guess. –  David Carlisle May 12 '12 at 9:14

It is nothing to do with the key mechanism. Just that the columns are labelled 1,2,3... so you can not set the width of column 0.

-
I don't undestand this. You say the columns are labelled 1,2,3 BUT where? I don't see parcolumns labeling or creating the column width registers before hand. They are programmatically created. I could create a key using "alpha=30" pt. and it should create a corresponding width register for it(it just won't be used later down the code... but I shouldn't get the packageerror in setcolumnwidth –  Uiy May 12 '12 at 9:23
You might be right because the ifundefined in setcolumnwidth is testing the register and it doesn't exist... but I never saw those registers being created. –  Uiy May 12 '12 at 9:26
@Uiy I guess David is looking at the parcolumns documentation where is says 'Sets the widths of the columns. The widths are specified as key-values, ⟨columnnumber⟩=⟨width⟩. Columns start at ‘1’. Note that in order to be ignored by the keyval package, the complete value has to be surrounded by braces, i.e. ‘colwidths={1=2cm,3=5cm,4=2cm}’ to set the first column to a width of 2 cm, the third to 5 cm and the fourth to 2 cm. (the second column is calculated)'. –  Joseph Wright May 12 '12 at 9:27
@JosephWright Yes, he is right!! ;/ Sorry. There is the alloccolumns that creates those registers using a counter, which doesn't start at 0. –  Uiy May 12 '12 at 9:27

(An extended comment, really.) With the somewhat hacked-up test file

\RequirePackage{keyval,processkv}
\makeatletter
\define@key{parcolumns}{colwidths}{\toks@{#1}}
\define@key{parcolumns}{nofirstindent}[true]{}
\define@key{parcolumns}{distance}{}
\def\pc@setsinglecolwidth#1#2{%
\@ifundefined{pc@column@width@\number#1}{%
\PackageError{parcolumns}{#1' is not a valid column width number!}{\@ehc}%
}{%
\csname pc@column@width@\number#1\endcsname=#2\relax%
}%
}
\newenvironment{parcolumns}[2][]{%
\setkeys{parcolumns}{#1}%
\expandafter\processkeyvalues\expandafter{\the\toks@}\pc@setsinglecolwidth%
}
{}
\expandafter\newdimen\csname pc@column@width@0\endcsname
\expandafter\newdimen\csname pc@column@width@1\endcsname
\begin{parcolumns}[nofirstindent,distance=0pt,colwidths={0=30pt}]{6}%
\expandafter\showthe\csname pc@column@width@0\endcsname
\expandafter\showthe\csname pc@column@width@1\endcsname
\end{parcolumns}

\begin{parcolumns}[nofirstindent,distance=0pt,colwidths={1=30pt}]{6}%
\expandafter\showthe\csname pc@column@width@0\endcsname
\expandafter\showthe\csname pc@column@width@1\endcsname
\end{parcolumns}


I see no difference in behaviour other than the expected difference in assignment. As I've commented on the question, my suspicion here is an issue with using the scratch toks \tok@, but it's hard to be sure without a full example where I could trace the register through.

-
I've modified the tokens but same problem. David maybe right... I'll have to look through the code to find out where those registers are being generated. –  Uiy May 12 '12 at 9:25