Changes

Jump to navigation Jump to search
3,397 bytes added ,  23:28, 5 October 2023
no edit summary
Very long continuous strings (such as SHA512 keys or DNA sequences) might have to be broken after any character irrespective of , independent from the current hyphenation scheme.
== Example Line breaking with SHA512 sums ==This is Hans' trick from the list for SHA512 keys
Hans provided a way of breaking SHA512 sums in lines (now being checked).<texcoderef>There might be an issue with the custom hyphenator that needs to be reviewed, since the first characters in the new line are missing. <context source="yes">
\startluacode
\showframe
\starttextstartTEXpage[offset=3em]
\setupalign[tolerant,stretch]
}
\stopTEXpage
</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}}):
 
<context source="yes">
\define[1]\SHA{{\tt\handletokens #1\with\SHABreak}}
\define[1]\SHABreak{#1\softhyphen\hskip 0pt}
\startTEXpage[offset=1em, width=15em]
SHA sum \SHA{8b2f3c087046c3943ace0dc4f958ef2138e58a51b40e%
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
</texcodecontext> 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">\startluacoderequire("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 endend\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].\blankThis is a file: \hsafile[\jobname.tex]\stopTEXpage</context>
== Example DNA sequences ==
This is an adoption from Wolfang Wolfgang using Lua:
<context source="yes">
\startluacode
<context source="yes">
\define[1]\DNA{\handletokens #1\with\DNAspacer}
\define[1]\DNAspacer{#1\hskip 2.3pt plus .1pt}
== Help from ConTeXt-Mailinglist/Forum ==
 
All issues with:
{{Forum|SHA512}}
{{Forum|Linebreak after x characters}}
== Footnotes ==
[[Category:Basics]]
93

edits

Navigation menu