2

I'm a complete beginner to pstricks. I'd like to modify this image so the qdisk will have labels with letters (a-z for the sake of the example) inside. Could someone explain how can I achieve it?

\newpsstyle{gridstyle}
{
    gridlabels=0,
    gridwidth=6pt,
    subgriddiv=1,
    gridcolor=gray,
}
\begin{document}
\begin{pspicture}(8,8)
    \psframe*(8,8)
    \psgrid[style=gridstyle]
    \psset{linecolor=white}
    \multips(0,1)(0,1){7}{\multips(1,0)(1,0){7}{
    
    \qdisk(0,0){4.242pt}    
    } 
    }
\end{pspicture}
\end{document}

2 Answers 2

3

You can use (nested) \multido to replace the \multips loops.

In \multido you can use a loop variable with an increment. Importantly, the first letter of the name of the loop variable determines the variable type. Integers start with \i (or \I), for example \ia and \ib.

The syntax of \multido is

\multido{variable name=start value+increment}{number of repetitions}{loop body}

Separately you can use a normal LaTeX counter to keep track of which letter you are printing. This counter can be used together with \symbol{n} to print the symbol associated to the number n. The capital letter A is number 65 and Z is 90. When you are at Z you can reset the counter.

MWE (with a bit bigger circles to see the letters better):

\documentclass{article}
\usepackage{auto-pst-pdf} % compile with pdflatex --shell-escape
                          % this package is not needed when compiled with xelatex or lualatex
\usepackage{pstricks}
\usepackage{multido}
\newpsstyle{gridstyle}
{
    gridlabels=0,
    gridwidth=6pt,
    subgriddiv=1,
    gridcolor=gray,
}
\newcounter{currletter}
\setcounter{currletter}{65}
\begin{document}
\begin{pspicture}(8,8)
    \psframe*(8,8)
    \psgrid[style=gridstyle]
    \psset{linecolor=white}
    \multido{\ia=1+1}{7}{%
       \multido{\ib=1+1}{7}{%
         \qdisk(\ia,\ib){8.242pt}
         \rput(\ia,\ib){\symbol{\thecurrletter}}
         \stepcounter{currletter}
         \ifnum\value{currletter}=91\setcounter{currletter}{65}\fi
       }
    }
\end{pspicture}
\end{document}

Result:

enter image description here

2

The same solution with lualatex:

\documentclass{article}

\usepackage{pstricks}
\usepackage{multido}
\usepackage{luacode}
\newpsstyle{gridstyle}{gridlabels=0,subgriddiv=1,gridwidth=6pt,gridcolor=gray,}

\def\QDisk(#1,#2){\qdisk(#1,#2){8.242pt}
    \rput(#1,#2){\directlua{tex.print(getChar())}}}
\begin{luacode*}
letterNo = 0
function getChar()
  letterNo = letterNo % 26 + 1
  return string.char(64+letterNo)
end
\end{luacode*}

\begin{document}
\begin{pspicture}(8,8)
    \psframe*(8,8)
    \psgrid[style=gridstyle]
    \psset{linecolor=white}
    \multido{\ia=1+1}{7}{%
        \multido{\ib=1+1}{7}{\QDisk(\ia,\ib)}}
\end{pspicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .