In this paper, Daniel J. Bernstein used horizontally stretched lines (page 7). I was trying to do the same. I saw this question, but none of the answers could produce the desired result. Can anybody help?
3 Answers
Here's an implementation using LaTeX3 functions. I added also the simpler case of hexadecimal input.
\documentclass{article}
\usepackage{amsmath,xparse}
\newcommand\op[1]{\operatorname{#1}}
\newcommand\he[1]{\mathtt{0x#1}}
\ExplSyntaxOn
\NewDocumentCommand{\fl}{m}
{
\pushpen_fl:n { #1 }
}
\dim_new:N \l_pushpen_digit_dim
\seq_new:N \l_pushpen_input_seq
\seq_new:N \l_pushpen_output_seq
\cs_new_protected:Npn \pushpen_fl:n #1
{
\hbox_set:Nn \l_tmpa_box { 0 }
\dim_set:Nn \l_pushpen_digit_dim { 3\box_wd:N \l_tmpa_box }
\seq_set_split:Nnn \l_pushpen_input_seq { , } { #1 }
\seq_clear:N \l_pushpen_output_seq
\seq_map_inline:Nn \l_pushpen_input_seq
{
\seq_put_right:Nn \l_pushpen_output_seq { \makebox[\l_pushpen_digit_dim][r]{##1} }
}
\seq_use:Nn \l_pushpen_output_seq { , }
}
\ExplSyntaxOff
\begin{document}
\begin{align*}
\op{doubleround}(
&\he{00000001}, \he{00000000}, \he{00000000}, \he{00000000},\\
&\he{00000000}, \he{00000000}, \he{00000000}, \he{00000000},\\
&\he{00000000}, \he{00000000}, \he{00000000}, \he{00000000},\\
&\he{00000000}, \he{00000000}, \he{00000000}, \he{00000000})\\
=(
&\he{8186a22d}, \he{0040a284}, \he{82479210}, \he{06929051},\\
&\he{08000090}, \he{02402200}, \he{00004000}, \he{00800000},\\
&\he{00010200}, \he{20400000}, \he{08008104}, \he{00000000},\\
&\he{20500000}, \he{a0000040}, \he{0008180a}, \he{612a8020}).\\
\op{doubleround}(
&\he{de501066}, \he{6f9eb8f7}, \he{e4fbbd9b}, \he{454e3f57},\\
&\he{b75540d3}, \he{43e93a4c}, \he{3a6f2aa0}, \he{726d6b36},\\
&\he{9243f484}, \he{9145d1e8}, \he{4fa9d247}, \he{dc8dee11},\\
&\he{054bf545}, \he{254dd653}, \he{d9421b6d}, \he{67b276c1})\\
=(
&\he{ccaaf672}, \he{23d960f7}, \he{9153e63a}, \he{cd9a60d0},\\
&\he{50440492}, \he{f07cad19}, \he{ae344aa0}, \he{df4cfdfc},\\
&\he{ca531c29}, \he{8e7943db}, \he{ac1680cd}, \he{d503ca00},\\
&\he{a74b2ad6}, \he{bc331c5c}, \he{1dda24c7}, \he{ee928277}).
\end{align*}
Another example with decimal digits:
\begin{align*}
\op{Salsa20}(
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})\\
=(
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\\
&\fl{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}).\\
\op{Salsa20}(
&\fl{211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,191,187,234,136},\\
&\fl{ 49,237,179, 48, 1,106,178,219,175,199,166, 48, 86, 16,179,207},\\
&\fl{ 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113,238, 55,204, 36},\\
&\fl{ 79,201,235, 79, 3, 81,156, 47,203, 26,244,243, 88,118,104, 54})\\
=(
&\fl{109, 42,178,168,156,240,248,238,168,196,190,203, 26,110,170,154},\\
&\fl{ 29, 29,150, 26,150, 30,235,249,190,163,251, 48, 69,144, 51, 57},\\
&\fl{118, 40,152,157,180, 57, 27, 94,107, 42,236, 35, 27,111,114,114},\\
&\fl{219,236,232,135,111,155,110, 18, 24,232, 95,158,179, 19, 48,202}).
\end{align*}
\end{document}
A version with simplified syntax for inputting the values; similar ideas could be used for the hexadecimal output.
\documentclass{article}
\usepackage{amsmath,xparse}
\newcommand\op[1]{\operatorname{#1}}
\ExplSyntaxOn
\NewDocumentCommand{\fl}{m}
{
\pushpen_fl:n { #1 }
}
\dim_new:N \g_pushpen_digit_dim
\seq_new:N \l_pushpen_input_seq
\seq_new:N \l_pushpen_output_seq
\int_new:N \l_pushpen_step_int
\cs_new_protected:Npn \pushpen_fl:n #1
{
\hbox_set:Nn \l_tmpa_box { 0 }
\dim_gset:Nn \g_pushpen_digit_dim { 3\box_wd:N \l_tmpa_box }
\int_zero:N \l_pushpen_step_int
\seq_set_split:Nnn \l_pushpen_input_seq { , } { #1 }
\seq_clear:N \l_pushpen_output_seq
\seq_put_right:Nn \l_pushpen_output_seq { ( & } % initialize
\seq_map_inline:Nn \l_pushpen_input_seq
{
\int_incr:N \l_pushpen_step_int
\seq_put_right:Nn \l_pushpen_output_seq { \makebox[\g_pushpen_digit_dim][r]{##1} }
\int_compare:nTF { \l_pushpen_step_int == 64 } % we're doing the last item
{
\seq_put_right:Nn \l_pushpen_output_seq { ) }
}
{
\int_compare:nTF { \int_mod:nn { \l_pushpen_step_int } { 16 } == 0 } % end of row
{
\seq_put_right:Nn \l_pushpen_output_seq { , \\ & }
}
{
\seq_put_right:Nn \l_pushpen_output_seq { , }
}
}
}
\seq_use:Nn \l_pushpen_output_seq { }
}
\ExplSyntaxOff
\begin{document}
\begin{align*}
\op{Salsa20}
\fl{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}\\
=
\fl{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}.\\
\op{Salsa20}
\fl{
211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,191,187,234,136,
49,237,179, 48, 1,106,178,219,175,199,166, 48, 86, 16,179,207,
31,240, 32, 63, 15, 83, 93,161,116,147, 48,113,238, 55,204, 36,
79,201,235, 79, 3, 81,156, 47,203, 26,244,243, 88,118,104, 54
}\\
=
\fl{
109, 42,178,168,156,240,248,238,168,196,190,203, 26,110,170,154,
29, 29,150, 26,150, 30,235,249,190,163,251, 48, 69,144, 51, 57,
118, 40,152,157,180, 57, 27, 94,107, 42,236, 35, 27,111,114,114,
219,236,232,135,111,155,110, 18, 24,232, 95,158,179, 19, 48,202
}.
\end{align*}
\end{document}
-
carefully compare the space around the commas between "triplets" in this last example with the corresponding commas as shown in the original questions. in the original, there is no "extra" space following a comma between adjacent full triplets. this effect can be obtained by entering the commas as
{,}
; see the texbook, p.134. Commented Feb 1, 2014 at 16:11 -
For the array
-inclined, here's a regular implementation:
\documentclass{article}
\usepackage{amsmath,array}% http://ctan.org/pkg/{amsmath,array}
\begin{document}
\[
\settowidth{\dimen0}{$000$}% Capture widest element
\begin{array}{r@{}*{15}{>{\raggedleft}p{\dimen0}@{,{} }}>{\raggedleft\arraybackslash}p{\dimen0}@{}l}
\text{Salsa20}(& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & ) \\
{}=(& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & , \\
& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & ). \\
\text{Salsa20}(& 211 & 159 & 13 & 115 & 76 & 55 & 82 & 183 & 3 & 117 & 222 & 37 & 191 & 187 & 234 & 136 & , \\
& 49 & 237 & 179 & 48 & 1 & 106 & 178 & 219 & 175 & 199 & 166 & 48 & 86 & 16 & 179 & 207 & , \\
& 31 & 240 & 32 & 63 & 15 & 83 & 93 & 161 & 116 & 147 & 48 & 113 & 238 & 55 & 204 & 36 & , \\
& 79 & 201 & 235 & 79 & 3 & 81 & 156 & 47 & 203 & 26 & 244 & 243 & 88 & 118 & 104 & 54 & ) \\
{}=(& 109 & 42 & 178 & 168 & 156 & 240 & 248 & 238 & 168 & 196 & 190 & 203 & 26 & 110 & 170 & 154 & , \\
& 29 & 29 & 150 & 26 & 150 & 30 & 235 & 249 & 190 & 163 & 251 & 48 & 69 & 144 & 51 & 57 & , \\
& 118 & 40 & 152 & 157 & 180 & 57 & 27 & 94 & 107 & 42 & 236 & 35 & 27 & 111 & 114 & 114 & , \\
& 219 & 236 & 232 & 135 & 111 & 155 & 110 & 18 & 24 & 232 & 95 & 158 & 179 & 19 & 48 & 202 & ).
\end{array}
\]
\end{document}
array
is used for right-alignment within the cells, while amsmath
provides \text
.
-
It should be
\sbox{0}{$000$}
and\wd0
(odd numbered scratch registers should be used globally). Why not simply\settowidth{\dimen0}{$000$}
?– egregCommented Feb 1, 2014 at 18:37 -
This is using the under-development tabstackengine
package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align).
The package extends the stackengine
package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of the package. I apologize that I have been lax in completing the package and getting it out the door, so the only way to see it in action is by searching this site for tabstackengine
.
In this case, a tabbed long-understack allows a uniform gap between each column to be set, in this case, I set the tab to .5ex (the "long" means each row is of uniform baseline-to-baseline spacing, and the "under" means that the overall baseline is set at the top row of the stack). I did require several \rlap
s/\phantom
s as corrections for the closing parenthesis, and a \phantom
to widen a column with only 2 digits of data.
\documentclass{article}
\usepackage{tabstackengine}
\textwidth 6.5in
\begin{document}
\setstacktabbedgap{.5ex}
\noindent Salsa20
\tabbedLongunderstack[r]{
(211;&159;& 13;&115;& \protect\phantom{1}76;& 55;& 82;&183;& 3;&117;&222;& 37;&191;&187;&234;&136;\\
49;&237;&179;& 48;& 1;&106;&178;&219;&175;&199;&166;& 48;& 86;& 16;&179;&207;\\
31;&240;& 32;& 63;& 15;& 83;& 93;&161;&116;&147;& 48;&113;&238;& 55;&204;& 36;\\
79;&201;&235;& 79;& 3;& 81;&156;& 47;&203;& 26;&244;&243;& 88;&118;&104;& 54\rlap{):}\protect\phantom{;}
}\\
\makebox[\widthof{Salsa20}][r]{=}
\tabbedLongunderstack[r]{
(109;& 42;&178;&168;&156;&240;&248;&238;&168;&196;&190;&203;& 26;&110;&170;&154;\\
29;& 29;&150;& 26;&150;& 30;&235;&249;&190;&163;&251;& 48;& 69;&144;& 51;& 57;\\
118;& 40;&152;&157;&180;& 57;& 27;& 94;&107;& 42;&236;& 35;& 27;&111;&114;&114;\\
219;&236;&232;&135;&111;&155;&110;& 18;& 24;&232;& 95;&158;&179;& 19;& 48;&202\rlap{):}\protect\phantom{;}
}
\end{document}
-
I think the use of
\kern1.1ex
in column 5 should be replaced with\phantom{1}
. Also, why the final\kern
s?– Werner ♦Commented Feb 1, 2014 at 18:16 -
@Werner The final kern before the
&
makes sure the last number aligns with the last number in the row above, rather than with the semicolon. The final kern following the&
moves the paren to the left, so that there is no gap between the final number and the right paren. In column 5, I used a kern because it needed to be protected and\protect\phantom{1}
took more typing than a kern, but you are correct it should be that. I'll revise and correct the missing links, too. Commented Feb 1, 2014 at 18:22 -
1For the final
\kern
s, you could also use\rlap{):}\phantom{;}
(with some protection, perhaps). I think it's always good to use\phantom
s to have proper alignment, rather than using font-specific widths.– Werner ♦Commented Feb 1, 2014 at 18:24
\textwidth
, or do you just want the ability to add arbitrary space between the column elements?