I'm trying to generate a "word cloud" by using \mbox
es with random spaces around words.
In the code below I've removed stuff that change the font size, and I've replaced \mbox
es by \framebox
es for debug purpose.
\documentclass{article}
\usepackage[first=1, last=10]{lcg}
\newcommand*{\wordtag}[1]{%
\framebox{\vspace{3pt}\hspace{5pt}#1\vspace{1pt}\hspace{6pt}}%
}
\begin{document}
\rand
\wordtag{color}
\wordtag{animals}
\end{document}
When I replace length with \rand
(i.e. \vspace{\rand pt}
), I get the following error:
! Illegal unit of measure (pt inserted).
Does anyone know how to fix this error?
And why the \rand
at the beginning of the document doesn't print anything?
Is there a better way to produce a word cloud?
Best Answer
The manual of the
lcg
package states:So
\rand
is not expanding to a number and therefore doesn't typeset anything and can't be used in a length. You need to use it first and then can use therand
counter using\value{rand}
, e.g.\vspace{\value{rand} pt}
.You could also use the math engine of the
pgf
package. It provides\pgfmathrandom{x,y}
(also accessible using\pgfmathparse{random(x,y)}
and friends) and stores the result into\pgfmathresult
. Herex
andy
are the same numbers asfirst
andlast
withlcg
.