Changes

Jump to navigation Jump to search
2,674 bytes added ,  23:28, 5 October 2023
no edit summary
</context>
</ref>
 
=== Workaround with soft hyphens ===
As a workaround, a simpler way to break SHA sums in lines, but without any character would be (abusing both {{cmd|handletokens}} and {{cmd|softhyphen}}):
ef6fab6fa1aeb845cc257a410ab1b914bc399b4293f%
31c76fc2c73e5be5ea4d329f9e6820984688efec2}
\stopTEXpage
</context>
 
=== 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">
\startluacode
require("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
end
end
\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">
\startluacode
require("util-sha")
function document.coloniter(str)
local n = 0
for c in str:gmatch("..") do
if n > 0 then
context((":%s"):format(c))
else
context(c)
end
n = n + 1
end
end
\stopluacode
 
\unexpanded\def\hsa[#1]%
{{\tt\hyphenatedurl%
{\ctxlua{document.coloniter(utilities.sha2.hash512("#1"))}}}}
 
\unexpanded\def\hsafile[#1]%
{\doiffileelse{#1}{{\tt\hyphenatedurl
{\ctxlua{document.coloniter(utilities.sha2.hash512(io.loaddata("#1")))}}}}
{{\bfd\color[red]{\type{#1} not available!!!}}}}
 
\setupbodyfont[24pt]
 
\startTEXpage[offset=1dk]
This is a sequence: \hsa[This is a sequence].
\blank
This is a file: \hsafile[\jobname.tex]
\stopTEXpage
</context>
== Example DNA sequences ==
This is an adoption from Wolfang Wolfgang using Lua:
<context source="yes">
\startluacode
93

edits

Navigation menu