Skip to content

Instantly share code, notes, and snippets.

@minad
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minad/6c8c22eea565766cca77 to your computer and use it in GitHub Desktop.
Save minad/6c8c22eea565766cca77 to your computer and use it in GitHub Desktop.
LaTeX to generate keyslips, derived from gpg-key2latex, change the \Key and execute with pdflatex -shell-escape keyslip.tex
\documentclass[a4paper]{article}
\usepackage{fancyvrb}
\usepackage[export]{adjustbox}
\usepackage{graphicx,calc}
\usepackage{inconsolata}
\usepackage[margin=5mm]{geometry}
\def\Key{2693CA43}
\def\Columns{3}
\newlength\MaxWidth
\newlength\Width
\newlength\Margin
\setlength\Margin{4pt}
\setlength\Width{31em}
\setlength\MaxWidth{\textwidth/\Columns - \Margin*\Columns - 1pt*(\Columns-1)}
\immediate\write18{LANG=C gpg --list-keys --fingerprint \Key | perl -pe '$_="" if /^$/; s/ +/ /g; s/ Key fingerprint =/fp/;' > \jobname.key}
\pagestyle{empty}
\begin{document}
\setlength\parindent{0pt}
\expandafter\newsavebox\csname key\endcsname
\expandafter\savebox\csname key\endcsname{%
\begin{adjustbox}{minipage=\Width,valign=t,max width=\MaxWidth,margin=\Margin}%
\VerbatimInput{\jobname.key}
\end{adjustbox}%
}
\makeatletter
\newtoks\toks@table
\newtoks\toks@row
\newtoks\toks@cell
\newcounter{n@column}
\def\free@space{\textheight}
\newlength\Row@Height
\newlength\Cell@Height
\toks@table = {}
\toks@cell = {\expandafter\usebox\csname key\endcsname}
\loop {
\setcounter{n@column}{0}
\setlength\Row@Height{0pt}
\toks@row = {}
% generate a single row
\loop \ifnum \value{n@column} < \Columns
\settototalheight\Cell@Height{\the\toks@cell}
\ifnum \Cell@Height>\Row@Height \global\Row@Height=\Cell@Height \fi
\ifnum \value{n@column} > 0 \toks@row = \expandafter{\the\toks@row & } \fi
\global\toks@row = \expandafter{\the\toks@row\the\toks@cell}
\stepcounter{n@column}
\repeat
}
\edef\free@space{\number \numexpr \free@space - \Row@Height \relax}
\ifnum \free@space > 0
\toks@table = \expandafter{\the\toks@table\the\toks@row \\ \hline}
\repeat
\begin{center}
\begin{tabular}{@{}|*\Columns{@{}l@{}|@{}}}\hline%
\the\toks@table
\end{tabular}
\makeatother
\end{center}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment