Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random lists of different lengths are not supported #1033

Closed
AndrewMathas opened this issue Jul 24, 2021 · 2 comments
Closed

Random lists of different lengths are not supported #1033

AndrewMathas opened this issue Jul 24, 2021 · 2 comments

Comments

@AndrewMathas
Copy link

AndrewMathas commented Jul 24, 2021

When more than one random list is defined using \pgfmathdeclarerandomlist PGF seems to assume that all random lists have the length of the longest list with the result that \pgfmathrandomitem can return a list item that is not defined.

Minimal example

\documentclass{article}
\usepackage{pgfmath,pgffor}
\begin{document}
\parindent=0pt

  \pgfmathdeclarerandomlist{short}{{A}{B}{C}{D}}
  \pgfmathdeclarerandomlist{middle}{{a}{b}{c}{d}{e}{f}}
  \pgfmathdeclarerandomlist{long}{{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}}

  \foreach \c in {1,...,40} {
    \pgfmathrandomitem{\short}{short}
    \pgfmathrandomitem{\middle}{middle}
    \pgfmathrandomitem{\long}{long}
    \typeout{short = \short, middle = \middle, long = \long.}
    short = \short, middle = \middle, long = \long.
  }

\end{document}

The resulting PDF file shows that several list items are not defined. More revealingly, the log file contains lines like:

short = \pgfmath@randomlist@short@9 , 
middle = \pgfmath@randomlist@middle@9 , 
long = 8.

that show PGF is trying to assign list items that are not defined.

@muzimuzhi
Copy link
Member

Currently, after \pgfmathrandomitem{\short}{short}, \short is defined as \csname pgfmath@randomlist@short@\pgfmath@randomtemp\endcsname, where \pgfmath@randomtemp is the chosen list index. If the \pgfmath@randomtemp is then changed by following use of \pgfmathrandomitem before \short is used, the strange behavior occurs.

I've changed it so that \short will be defined as \pgfmath@randomlist@short@<index>.

@ilayn
Copy link
Member

ilayn commented Jul 25, 2021

It's much easier to track if you merge a PR regardless of how trivial so that github does the clean up and you don't need to mention the issue number in a commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants