Changes

Jump to navigation Jump to search
1,557 bytes added ,  19:09, 5 October 2023
more complex sample
=== Another workaround interleaving colons ===
Another workaround that also helps to improve readability are interleaved colons every two characters. Of course you might change the number of chars without colons adding single dots to <code>str:match("..")</code>. Please, keep in mind that this will make line wrapping not easier in some places. Of course, there is also a way to shorten the hash string.<ref>A richer sample could set a smaller string length, another interval and a different character. <context source="yes">\startluacoderequire("util-sha")function document.coloniter(str,long,inter,sep) local n = 0  long = tonumber(long) inter = tonumber(inter)  if inter == "" then inter = 2 end if sep == "" then sep = ":" end  if long ~= nil and long > 0 then if long % inter > 0 then long = long + (inter - (long % inter)) end str = str:sub(0,long) end  for c in str:gmatch(("."):rep(inter)) do if n > 0 then context(("%s%s"):format(sep,c)) else context(c) end n = n + 1 endend\stopluacode \unexpanded\def\hsa[#1][#2][#3][#4]% {{\tt\hyphenatedurl {\ctxlua{document.coloniter(utilities.sha2.hash512("#1"),"#2","#3","#4")}}}} \unexpanded\def\hsafile[#1][#2][#3][#4]% {\doiffileelse{#1}{{\tt\hyphenatedurl {\ctxlua{document.coloniter(utilities.sha2.hash512(io.loaddata("#1")),"#2","#3","#4")}}}} {{\bfd\color[red]{\type{#1} not available!!!}}}} \setupbodyfont[24pt] \starttext\startTEXpage[offset=1dk]This is a sequence: \hsa[This is a sequence][10][3][]. This is a file: \hsafile[\jobname.tex][23][5][-].\stopTEXpage\stoptext</context> In this sample, the four arguments are the string (or the file) to be hashed, the length of the hash string, how many characters each interval has, and the interleaved character. Consider that not all chars break lines with {{cmd|hyphenatedurl}} -</ref>
<context source="yes">
{{\bfd\color[red]{\type{#1} not available!!!}}}}
\starttextsetupbodyfont[24pt] 
\startTEXpage[offset=1dk]
This is a sequence: \hsa[This is a sequence].
139

edits

Navigation menu