I made myself a smallish template for practice writing some characters, see below. The objective for me was to have an easy way to enter a couple of characters, set the parameters (how many pre-drawn characters, how many columns, etc.) and then get a print-ready PDF.
It's written against TikZ and LuaLaTeX (I'm not sure it will run with other configurations), but I'm only using TikZ features, no Lua (yet).
I'm looking for feedback especially regarding maintainability, feature configuration (at the moment I'm simply editing the file, but it's not really convenient; I'm thinking more of how to do this easily from the command line?) and ease of use (the dimensions are manually specified - how should I structure this to have it usable for a multi-page setup without too much hassle?) - I've also been thinking of how to drive this from a web service, passing in options file paper size etc. since not everyone might use A4.
What's not added yet is settings with respect to. the drawing style (I'd possibly like to toggle some of the background grid lines) — are there established conventions how to do the background grid, not manually, basically? Note that I'm overdrawing significantly in order to keep the logic simple.
Small edit: I'd be especially grateful for advice explaining how to get rid of the horrible equations — defining new names for simply subtracting a number is, uh, awful.
\documentclass[a4paper]{article}
\usepackage[cm]{fullpage}
\usepackage{fontspec}
\usepackage[utf8]{luainputenc}
\usepackage{fontenc}
\usepackage{lmodern}
\usepackage[german]{babel}
\usepackage{luatexja-fontspec}
% https://ctan.org/tex-archive/fonts/fandol?lang=en
\setmainjfont{FandolKai}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{xstring}
\begin{document}
\def\c{gray!50}
\def\chars{我,你,您,也,很,他,们,好,吗,再,见,是,累,俄,渴,不,谢,用,爱,咖,啡,这,欧,雅,福}
\def\w{17}
\def\wFull{1}
\def\wHalf{2}
\StrCount{\chars}{,}[\h]
\pgfmathsetmacro{\h}{\h+1}
\pgfmathsetmacro{\hMinusOne}{\h-1}
\pgfmathsetmacro{\wMinusOne}{\w-1}
\pgfmathsetmacro{\wFullMinusOne}{\wFull+1}
\pgfmathsetmacro{\wAll}{\wFull+\wHalf}
\pgfmathsetmacro{\wPlusH}{\w+\h}
\begin{center}
\begin{tikzpicture}
\draw[step=1cm,dashed,gray,thin] (0,0) grid (\w,\h);
\foreach \x in {0,...,\wMinusOne}
{
\pgfmathsetmacro{\a}{\x+0.5}
\draw[dashed,\c,very thin] (\a,0) -- (\a,\h);
}
\foreach \y in {0,...,\hMinusOne}
{
\pgfmathsetmacro{\a}{\y+0.5}
\draw[dashed,\c,very thin] (0,\a) -- (\w,\a);
}
\begin{scope}
\clip(0,0) rectangle(\w,\h);
\foreach \x in {1,...,\wPlusH}
{
\pgfmathsetmacro{\xh}{\x-\h}
\draw[dashed,\c,very thin] (\xh,\h) -- (\x,0);
}
\foreach \x in {0,...,\wPlusH}
{
\pgfmathsetmacro{\xMinusH}{\x-\h}
\pgfmathsetmacro{\xh}{\x+\h}
\draw[dashed,\c,very thin] (\xMinusH,0) -- (\x,\h);
}
\end{scope}
\newcounter{counter}\setcounter{counter}{0}
\foreach \char in \chars
{
\pgfmathsetmacro{\y}{\h-1-\thecounter+0.55}
\foreach \x in {0,...,\wFullMinusOne}
{
\pgfmathsetmacro{\xo}{\x+0.5}
\node at (\xo,\y) {\huge\char};
}
\foreach \x in {\wFull,...,\wAll}
{
\pgfmathsetmacro{\xo}{\x+0.5}
\node[gray] at (\xo,\y) {\huge\char};
}
\stepcounter{counter}
}
\end{tikzpicture}
\end{center}
\end{document}
luainputenc
. \$\endgroup\$