This is a sort-of follow-up to the question Create environment whose contents are passed to TikZ matrix, which did not reveal any solution to the specific question (but did make me aware of another package to try).
I need to create an environment to draw Sudoku grids, in which the syntax used is that of a tabular environment. That is, with cells delimited by & and new rows indicated by \\.
The following code is a solution using tabularray:
\documentclass[11pt]{article}
\usepackage{tabularray}
\usepackage{color}
\newenvironment{sudoku}[1][]{%
\begin{tblr}{
hline{1,4,7,10}={blue,2pt},
hline{2,3,5,6,8,9}={blue,0.5pt},
vline{1,4,7,10}={blue,2pt},
vline{2,3,5,6,8,9}={blue,0.5pt},
abovesep=3pt,
#1
}
}{%
\end{tblr}
}
\begin{document}
\begin{sudoku}
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
1&2&3&4&5&6&7&8&9\\
\end{sudoku}
\end{document}
This would be perfect, except for the following:
- It doesn't work at all on some devices (presumably something to do with the LaTeX 3 nature of the package)
- On devices where it does work, the time taken to compile a tex file with 20 or 30 of these sudoku grids in is getting seriously problematic. (See here for a related post.)
So, I need something less computationally intensive: it's just a 9x9 grid, after all! Can anyone replace the code in the definition of the sudoku environment above to render a similar/the same result?
Besides tabularray Here are some things I've looked - this is not to say that one of these doesn't have a solution, but I haven't been able to work one out.
Using
tikz-matrix. This was the subject of my earlier post.Using
nicematrix. I haven't found a way to specify (e.g.) that different\hlines can have different thicknesses.Using
sudoku. Perhaps something can be done withcatcodesto replace the normal syntax?
As a broader comment: we LaTeX users still seem to have to work with table-like structures in which the styling has to be embedded within the code for the table, rather than applied separately (if you're familiar with web-design, think of the distinction between the HTML and the CSS of a well-crafted page). That's why the tabularray is (almost) perfect.
Thanks in advance for any help!


foreachloop, reading a data set? – SebGlav May 03 '22 at 15:12sudokuenvironment must be regarded simply as a standard table. – rbrignall May 03 '22 at 15:18