Henning Hraban Ramm schrieb am 13.09.2019 um 18:51:
Hi, in an example document I’m trying to get pictures of random size and placement. Unfortunately the expansion is over my head:
%%%%%%%%%%%%%%%%% \useMPlibrary[dum] \usemodule[visual]
\startluacode
local locations = { 'top', 'bottom', 'left', 'right', }
function RandomLocation() context(locations[math.random(1,#locations)]) end
\stopluacode
\newdimen\PicWidth \PicWidth=\textwidth
\define[1]\Blindbild{ \getrandomnumber\imgH{1}{9} \PicWidth=\textwidth \doif{#1}{left}{\PicWidth=.4\textwidth} \doif{#1}{right}{\PicWidth=.4\textwidth} \startplacefigure[location={#1},title={#1 \fakewords{3}{20}}] \externalfigure[place #1][width=\PicWidth,height=\dimexpr\textheight * \imgH / 10 \relax] \stopplacefigure } Put the value of the random location in a macro.
\define[1]\Blindbild {\edef\PicLocation{#1}% \getrandomnumber\imgH{1}{9}% \PicWidth=\textwidth \doifinset{\PicLocation}{left,right}{\PicWidth=.4\textwidth}% \startplacefigure[location={\PicLocation},title={\PicLocation\space\fakewords{3}{20}}] \externalfigure [place \PicLocation] [width=\PicWidth, height=\dimexpr\textheight * \imgH / 10 \relax] \stopplacefigure} Wolfgang