4
submitted 2 days ago* (last edited 12 hours ago) by evenwicht@lemmy.sdf.org to c/tex_typesetting@lemmy.sdf.org

Suppose I have a fingerprint to a public key like this:

b1946ac92492d2347c6235b4d2611184

If I just drop that verbatim in a doc, it’s obviously an ergonomic struggle for someone who has to verify those numbers against what they see in an app. So it should be presented as something like this:

b194 6ac9 2492 d234 7c62 35b4 d261 1184

But if we manually add a space every 4 chars, that’s embarrassing manual labor for a nerd. Self-respecting nerds make the tool do the work for us.

This code does the job:

\newcommand{\mkergo}[2][$\cdot$]{% The mandatory arg is a fingerprint; the optional arg is the delimiter between 4-char groups
  \StrLen{#2}[\fplen]
  \newcounter{ilpos} % internal left position
  \newcounter{irpos} % internal right position
  \setcounter{irpos}{4}

  \whiledo{\not\value{irpos}>\fplen}{%
    \setcounter{ilpos}{\value{irpos}-4}
    \wlog{lpos::rpos is [\arabic{ilpos}..\arabic{irpos}]}
    \StrLeft{#2}{\value{irpos}}[\left]
    \wlog{left is \left}
    \StrGobbleLeft{\left}{\value{ilpos}}[\segment]
    \wlog{segment → \segment}
    \noindent\hspace{-32pt}\segment\ifthenelse{\value{irpos}=\fplen}{}{#1}% WTF, why do we need neg hspace?!
    \addtocounter{irpos}{4}
    }
}

calling it looks like this:

\mkergo[\,]{b1946ac92492d2347c6235b4d2611184}

or

\newcommand{\fingerprint}{b1946ac92492d2347c6235b4d2611184}
\mkergo[\,]{\fingerprint}

It works but it’s still not something to be proud of because if the readable version of the fingerprint is needed in multiple places, that loop must run everywhere it is needed. It’s also really ugly that I had to add \hspace{-32pt} -- what the fuck for? Why is there a huge space between segments?

How can that code be improved? I tried creating a \prettyfp (short for pretty fingerprint) command and then having the loop extend that, so the \prettyfp can be used without rerunning the loop. But it’s got a logical error.. the last 4 chars just gets repeated over and over. This is the code:

\makeatletter
\newcommand{\spaceout}[2][$\cdot$]{% The mandatory arg is a fingerprint; the optional arg is the delimiter between 4-char groups
  \StrLen{#2}[\fplen]
  \newcounter{lpos} % internal left position
  \newcounter{rpos} % internal right position
  \setcounter{rpos}{4}

  \whiledo{\not\value{rpos}>\fplen}{%
    \setcounter{lpos}{\value{rpos}-4}
    \wlog{S/O lpos::rpos is [\arabic{lpos}..\arabic{rpos}]}
    \StrLeft{#2}{\value{rpos}}[\left]
    \wlog{S/O left is \left}
    \StrGobbleLeft{\left}{\value{lpos}}[\segment]
    \wlog{S/O segment → \segment}
    \g@addto@macro\prettyfp{\segment\ifthenelse{\value{irpos}=\fplen}{}{#1}}
    \addtocounter{rpos}{4}
    }
}
\makeatother

That was inspired by the 1st answer on this page.

What’s my problem?

How can this be improved?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here
this post was submitted on 23 Feb 2026
4 points (100.0% liked)

TeX typesetting

204 readers
1 users here now

A place to share ideas, resources, tips, and hacks for Donald Knuths typesetting software TeX. All variants and formats like OpTeX, LaTeX and ConTeXt are welcome.

founded 2 years ago
MODERATORS