2
\documentclass[pstricks,border=\dimexpr355pt/113\relax,12pt]{standalone}

\def\obj{%
    \pscircle[linecolor=yellow](.5,.5){12pt}
    \pscircle[linecolor=cyan](.5,.5){11pt}}
    
\begin{document}
\foreach \k in {%
    {0/0},
    {0/0,2/3},
    {0/0,2/3,4/4}
    }{%
\begin{pspicture}(8,8)
    \psframe[dimen=i,linewidth=\dimexpr355pt/113\relax,linecolor=brown](8,8)
    \multips(0,0)(0,2){4}{%
        \multips(0,0)(2,0){4}{%
            \multips(0,0)(1,1){2}{\psframe*(1,1)}}}
    \foreach \i/\j in \k {\rput(\i,\j){\obj}}
\end{pspicture}}
\end{document}

A bonus question:

Is there any trick to simplify the following

{0/0},
{0/0,2/3},
{0/0,2/3,4/4}

into just a single {0/0,2/3,4/4} but the outer loop still works as if it is still working on

{0/0},
{0/0,2/3},
{0/0,2/3,4/4}

?

  • I don't find \dimexpr355pt/113 particularly fun. Use border=3 and you'll have less problems. – egreg Jul 3 at 16:27
  • @egreg: I am very impressed with the ratio 355/113. :-) – Artificial Stupidity Jul 3 at 16:49
1

The main problem is that \foreach buries each cycle inside a group.

\documentclass[pstricks,border=3,12pt]{standalone}

\newcommand\obj{%
  \pscircle[linecolor=yellow](.5,.5){12pt}%
  \pscircle[linecolor=cyan](.5,.5){11pt}%
}

\begin{document}

\let\CUMULATIVE\undefined
\foreach \k in {0/0,2/3,4/4}{
  \xdef\CUMULATIVE{\ifdefined\CUMULATIVE \CUMULATIVE,\fi \k}%
  \begin{pspicture}(8,8)
    \psframe[dimen=i,linewidth=3pt,linecolor=brown](8,8)
    \multips(0,0)(0,2){4}{%
      \multips(0,0)(2,0){4}{%
        \multips(0,0)(1,1){2}{\psframe*(1,1)}%
      }%
    }
    \foreach \i/\j in \CUMULATIVE {\rput(\i,\j){\obj}}
  \end{pspicture}%
}
\end{document}

I used an uncommon command name just to ensure that nothing important gets redefined.

| improve this answer | |
2

Just spitballing here, I don't have a LaTeX installation handy at the moment, but perhaps something along the lines of

\newcounter{foo}
\foreach \k in {1,2,3}{
  \setcounter{foo}{0}
  \foreach \j in {{(0,0)},{(2,3)},{(4,4)}}{
     \stepcounter{foo}
     \ifnum\value{foo}<\k
        do stuff with \j
     \fi
  }
}

I offer no guarantees about off by one errors or whether the wrapping (a,b) in braces will work (but it should and I'm pretty sure my math is right. You could also do

\ifnum\value{foo}=\k
   \breakforeach
\fi
do stuff with \j

which would be mildly more efficient but feels kind of 1980s code to me.

| improve this answer | |
2
\documentclass[pstricks,border=\dimexpr355pt/113\relax,12pt]{standalone}
\usepackage{pst-tools,multido}
\def\obj{%
    \pscircle[linecolor=yellow](.5,.5){12pt}
    \pscircle[linecolor=cyan](.5,.5){11pt}}    

\psRegisterList{No}{{0,0},{2,3},{4,4}}

\begin{document}
\multido{\iA=1+1}{3}{%
  \begin{pspicture}(8,8)
    \psframe[dimen=i,linewidth=\dimexpr355pt/113\relax,linecolor=brown](8,8)
    \multips(0,0)(0,2){4}{%
        \multips(0,0)(2,0){4}{%
            \multips(0,0)(1,1){2}{\psframe*(1,1)}}}
  \multido{\iB=1+1}{\iA}{\rput(\No{\iB}){\obj}}
\end{pspicture}}

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.