;; Generate a LaTeX table of characters.scm
;;
;; This file is part of Beastie <https://purl.org/nxg/dist/beastie>
;; SPDX-FileCopyrightText: 2023 Norman Gray <https://nxg.me.uk>
;; SPDX-License-Identifier: BSD-2-Clause

(define charlist
  (with-input-from-file "characters.scm" read))

(printf #"""\documentclass{article}
%\usepackage{multicol}
\begin{document}
%\begin{multicols*}(3}
\begin{tabular}{ccc|ccc|ccc|ccc}""")

(let loop ((cl charlist)
           (col 1))
  (unless (null? cl)
    (let ((c (cadr (car cl)))
          (escape (cadddr (car cl))))
      (if (string=? escape "")
          (loop (cdr cl) col)
          (begin
            (printf "\\verb|~a| & \\~a & ~a" escape escape c)
            (if (= col 4)
                (begin
                  (printf "\\\\~%")
                  (loop (cdr cl) 1))
                (begin
                  (printf " & ~%")
                  (loop (cdr cl) (+ col 1)))))))))

(printf "\\end{tabular}\\end{document}~%")
