[texhax] pgf & dim & 1-element array-like structures

Neal H. Walfield neal at walfield.org
Tue Aug 2 14:13:11 CEST 2016


I'm trying to get the length a pgf array-like structure in a macro.
I'm using the "dim" function.  I want the caller to pass a list as

  \foo{"something", "another thing"}

Sometimes, only one string needs to be passed, in this case, the
following should be enough:

  \foo{"one thing"}

Here's a simplified version of some code that I've tried:

    dim(\array) = \pgfmathresult
    \def\array{{#1, ""}}
    dim(\array) = \pgfmathresult
  \foo{"xyz", "abc"}
  \bar{"xyz", "abc"}

The calls to \foo output:

  dim("xyz") = 3
  dim("xyz") = 1
  dim("xyz", "abc") = 2

The "bug" with single element arrays is apparently known.  To work
around it, I thought I'd just add an empty element to the array-like
structure, as shown in \bar above.  But, this results in the following

  ! Undefined control sequence.
  \pgfmath at token@stop ->\pgfmath at stop 
  l.25 \bar{"xyz"}
  ! Undefined control sequence.
  \pgfmath at token@stop ->\pgfmath at stop 
  l.27 \bar{"xyz", "abc"}

Does anyone have an idea what the problem could be?


:) Neal

More information about the texhax mailing list