I'm trying to generate a vigenere square using expl3. My aim is to provide an easy interface for different alphabets and different scaling. Therefore I chose a tabular-based approach which seemed very easy to customize.
Points I would especially appreciate feedback to:
- Is using tabular a good idea or might it be very bad (e.g. when the user customizes array stretches)?
- Am I abusing expl3 at any point (local vs. global)?
- the user interface in general (key-value approach)
Code:
\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{xparse}
\ExplSyntaxOn
\keys_define:nn { vigenere }
{
font .code:n = { \cs_set_eq:NN \__vigenere_font: #1 },
font .default:n = { \small },
font .initial:n = { \small },
tabcolsep .dim_set:N = \l__vigenere_tabcolsep_dim,
tabcolsep .initial:n = { 3pt },
alphabet .tl_set:N = \l__vigenere_alphabet_tl,
alphabet .initial:n = { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }
}
\NewDocumentCommand { \printvigeneretabular } { O{} }
{
\group_begin:
\keys_set:nn { vigenere } { #1 }
\clist_set:NV \l_tmpa_clist \l__vigenere_alphabet_tl
\clist_clear:N \l_tmpb_clist
\tl_clear:N \l_tmpa_tl
\int_step_inline:nnnn { 1 } { 1 } { \clist_count:N \l_tmpa_clist }
{
\tl_put_right:Nx \l_tmpa_tl { c| }
}
\__vigenere_font:
\dim_set_eq:NN \tabcolsep \l__vigenere_tabcolsep_dim
\expandafter\tabular\expandafter{\expandafter|\l_tmpa_tl}
\hline
\bool_while_do:nn { \int_compare_p:n { \clist_count:N \l_tmpa_clist > 0 } }
{
\clist_use:Nnnn \l_tmpa_clist { & } { & } { & }
\clist_if_empty:NF \l_tmpb_clist
{ & \clist_use:Nnnn \l_tmpb_clist { & } { & } { & } }
\clist_gpop:NN \l_tmpa_clist \l_tmpa_tl
\clist_gput_right:NV \l_tmpb_clist \l_tmpa_tl
\\\hline
}
\endtabular
\group_end:
}
\ExplSyntaxOff
\begin{document}
\printvigeneretabular\par
\printvigeneretabular[font=\tiny,alphabet={1,2,3,4,5,6,7,8,9,10},tabcolsep=1pt]
\end{document}