I'm trying to improve the readability of my \drawHoshis macro by creating variables for the x and y coordinates, besides also running a calculation with a minus inside parentheses (e.g. x * (y - 1)). I don't know why but I just can't seem to make TeX work with it. I think it's something related to the array from the TikZ/PGF \foreach:
\foreach \sloc in {{3, 3}, {3, 7}, {7, 3}, {7, 7}, {5, 5}}{
% This is what I'm tryig to improve:
\filldraw (#3 * {\sloc}[0] - #3, #3 * {\sloc}[1] - #3)
circle [radius=#3 / 10];
}
I'm trying to make it look more like this:
\newlength{\hoshiCoordX}
\newlength{\hoshiCoordY}
% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 3: step
%
% Example: A 19x19 board with size 10cm x 10cm: `\drawHoshis{10}{19}{\step}'
\newcommand{\drawHoshis}[3]{
\ifthenelse{#2 = 9} {
\foreach \sloc in {{3, 3}, {3, 7}, {7, 3}, {7, 7}, {5, 5}}{
\setlength{\hoshiCoordX}{\dimexpr #3 * ({\sloc}[0] - 1) \relax}
\setlength{\hoshiCoordY}{\dimexpr #3 * ({\sloc}[1] - 1) \relax}
\filldraw (\hoshiCoordX, \hoshiCoordY)
circle [radius=#3 / 10];
}
}{}
}
Here's the complete working example:
\documentclass{article}
\newlength{\step}
% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
%
% Example: A 19x19 board with size 10cm x 10cm: `\gogrid{10}{19}'
\newcommand{\goGrid}[2]{
\setlength{\step}{\dimexpr #1cm / (#2 - 1) \relax} % chktex 1
\draw[step=\step] (0, 0) grid (#1, #1);
\drawHoshis{#1}{#2}{\step}
}
% Parameters
%
% 1: dimension (in cm)
% 2: board size (square)
% 3: step
%
% Example: A 19x19 board with size 10cm x 10cm: `\drawHoshis{10}{19}{\step}'
\newcommand{\drawHoshis}[3]{
\ifthenelse{#2 = 9} {
\foreach \sloc in {{3, 3}, {3, 7}, {7, 3}, {7, 7}, {5, 5}}{
% This is what I'm tryig to improve:
\filldraw (#3 * {\sloc}[0] - #3, #3 * {\sloc}[1] - #3)
circle [radius=#3 / 10];
}
}{}
}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht]
\begin{center}
\begin{tikzpicture}
\goGrid{10}{9}
\end{tikzpicture}
\caption{Goban 1}\label{my_goban_1}
\end{center}
\end{figure}
\end{document}
I've tried many variations of this but none have worked so far (I did try without \dimexpr as well). Is anyone able to spot what I'm missing?

\filldraw (#3 * {\sloc}[0] - #3, #3 * {\sloc}[1] - #3)? – Jasper Habicht Feb 06 '24 at 02:05\setlength{\step}{\dimexpr #1cm / (#2 - 1) \relax}with\pgfmathsetmacro{\step}{#1 / (#2 - 1)}and delete\newlength{\step}. And I'd probably just use\ifnum#2=9\relax ... \fiinstead of the\ifthenelsecommand which requires an additional package. – Jasper Habicht Feb 06 '24 at 02:070and1. That was a typo. The indices inside the desired example were correct though. – psygo Feb 06 '24 at 11:20