Re: Literate Executables

Tim Daly <[email protected]> Sun, 4 Dec 2022 03:14:43 -0500
Newsgroups gmane.comp.mathematics.axiom.devel
Message-ID <CAJn5L=+=mO2KQa=q-boK45aO3G1KDc1BHTH4ZMj3tDs2SH5RQw@mail.gmail.com>
--00000000000075f51805eefc2a75
Content-Type: multipart/alternative; boundary="00000000000075f51505eefc2a73"

--00000000000075f51505eefc2a73
Content-Type: text/plain; charset="UTF-8"

In fact, making your program 'literate' (aka, a book ) is easy.

The first steps (1)-(6) are only done once to get your program in book form.
Note that this works with any programming language. I normally use Lisp
but I'll illustrate it with C code.

The last step (7) will create a PDF and also execute your code.
You run step (7) which just requires typing 'make' any time you
want to see the book and run the code.

So now you're in a "hot loop", writing explanations and changing your
literate code, typing 'make' to remake the book and rerun the code while
continuing to create a literate program in a PDF.

To explain in detail, assume you have "hello.c" and want it literate.

(1) convert your program to a latex file. Copy hello.c to hello.tex.

Starting with the your hello.c:

====================================
#include <stdio.h>
int main() {
  printf("hello\n");
  return 0;
}
=====================================

At the command line type:
=====================================
cp hello.c hello.tex
=====================================

(2) wrap your code into latex using macros (attached below)

There is a latex macro pair (attached in a latex style file below called
chunk.sty) which defines \begin{chunk} and \end{chunk} that wrap anything
in a verbatim-style block. The \begin{chunk} takes an argument which is any
word or sentence, as in \begin{chunk}{int main}. So you walk your source
file(s)
inserting these macros around every function / struct / define, etc. So,
for hello.c
you create a copy, call it hello.tex which contains your C code with latex
blocks.
This is tedious but trivial.

Your hello.tex file looks like (the chunk name can be anything)
======================================================
\begin{chunk}{includes}
#include stdio.h
\end{chunk}

\begin{chunk}{main}
int main() {
  printf("hello\n"};
  return 0;
}
\end{chunk}
========================================================

(3) automate the extraction from your hello.tex to hello.c

Now you'd like to make it so your program can be extracted easily.
Make a new chunk using any name that collects your chunks: The
third macro, called getchunk, will insert the named chunk inline.

at the end of hello.tex add a new chunk:
===================================================
\begin{chunk}{all}
\getchunk{includes}
\getchunk{main}
\end{chunk}
====================================================

(4) check that you can recreate the original hello.c from hello.tex

The second too is a program called 'tanglec' which, given the name of a
chunk will extract it to stdout. So we ask for the whole program and put it
into
extracted.c with and check that it is byte compatible with hello.c:
(Note: tanglec is attached below. gcc -o tanglec tanglec.c)

at the command line type:
===========================================
./tanglec hello.tex all >extracted.c
diff -Naur extracted.c hello.c
===========================================

(5) make hello.tex into a PDF. Just add some trivial latex header/footer.
For example add a header: (Note: chunk.sty is attached below)

So now your hello.tex looks like:
============================================

\documentclass[dvipdfm]{book}
\usepackage{chunk}
\begin{document}
\title{A Literate Hello}
\author{Timothy Daly}
\maketitle

\chapter{We need includes}
\section{This is the usual one for printf}
\begin{chunk}{includes}
#include <stdio.h>
\end{chunk}

\chapter{This is where the magic happens}
\begin{chunk}{main}
int main() {
  printf("hello\n");
  return 0;
}
\end{chunk}
\begin{chunk}{all}
\getchunk{includes}
\getchunk{main}
\end{chunk}

\end{document}

=================================================

(6) create a trivial makefile (note that indented lines require TABS, not
spaces)

in a file called 'makefile'
===================================================
doit:
    latex hello.tex
    dvipdfm hello.dvi
    evince hello.pdf &
    tanglec hello.tex all >hello.c
    gcc -o hello hello.c
    ./hello
==================================================

(7)

At the command line
===============================================
make
================================================

WIN! Now you write all your explanation and your code in the latex file.
Then type 'make' which recreates the book and runs the code. The
explanation and the code are always in sync. Now your code is a book.

Now you can add pictures, URLs, a table of contents, an index,
cross references, a bibliography, and even a spiffy new cover!
Oh, and someone can actually read your explanation of your code.

Make Knuth happy! Win a Pulitzer prize!

Tim



On Sat, Dec 3, 2022 at 8:20 AM Tim Daly <[email protected]> wrote:

> Java code has the pseudo-ability to re-generate the original source
> through decompilation. Unfortunately given the size of any executable
> it would be years worth of work to reverse-engineer the understanding
> without explanation. I struggle to even understand the traceback of
> any Java failure :-)
>
> Open source, by definition, already has the source available.
> Only the URL of the github repository and the hash number corresponding
> to the current executable is needed.
>
> I haven't worked for IBM since 1995, the year IBM Research eliminated
> the math department, including me. My ground-breaking work in Artificial
> Intelligence has yet to be cited by anyone so their decision was probably
> wise.
>
> Tim
>
>
> On Sat, Dec 3, 2022 at 1:01 AM Terence Kelly <[email protected]>
> wrote:
>
>>
>> Hi Tim,
>>
>> Your observations seem sound.  Keep in mind, however, that we're not
>> confronted with an either/or choice.  The chicken/egg aspect of literate
>> executables means that, in your context, we can arrange for the PDF to
>> generate code *and* for the code to generate PDF.  Cyclic dependency
>> graphs take some getting used to, but one can learn to love them.
>>
>> If literate execution isn't right for Axiom, perhaps it can benefit other
>> IBM open source projects.  If you circulate the paper among your
>> colleagues I'd be interested to see if they find useful applications.
>>
>> _Queue_ readers are remarkably creative and routinely find uses for Drill
>> Bits ideas that I never anticipated.  I wonder what your colleagues will
>> come up with.
>>
>> Thanks.
>>
>> -- Terence
>>
>>
>> On Fri, 2 Dec 2022, Tim Daly wrote:
>>
>> > ...
>> >
>> > The above considerations leads me to the conclusion that the PDF is the
>> > thing that generates code rather than the code generating the PDF.
>>
>

--00000000000075f51505eefc2a73
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>In fact, making your program &#39;literate&#39; =
(aka, a book ) is easy.</div><div><br></div><div>The first steps (1)-(6) ar=
e only done once to get your program in book form.</div><div>Note that this=
 works with any programming language. I normally use Lisp</div><div>but I&#=
39;ll illustrate it with C code.<br></div><div><br></div><div>The last step=
 (7) will create a PDF and also execute your code.</div><div>You run step (=
7) which just requires typing &#39;make&#39; any time you <br></div><div>wa=
nt to see the book and run the code.</div><div><br></div><div>So now you&#3=
9;re in a &quot;hot loop&quot;, writing explanations and changing your<br><=
/div><div>literate code, typing &#39;make&#39; to remake the book and rerun=
 the code while</div><div>continuing to create a literate program in a PDF.=
</div><div><br></div><div>To explain in detail, assume you have &quot;hello=
.c&quot; and want it literate.<br></div><div><br></div><div>(1) convert you=
r program to a latex file. Copy hello.c to hello.tex.</div><div><br></div><=
div>Starting with the your hello.c:</div><div><br></div><div>=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D<br></div><div>#include &lt;stdio.h&gt;</div><div>int =
main() {</div><div>=C2=A0 printf(&quot;hello\n&quot;);</div><div>=C2=A0 ret=
urn 0;</div><div>}</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div><di=
v><br></div><div>At the command line type:</div><div>=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D<br></div><div>cp hello.c hello.tex</div><div>=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br></div><div><br></div><div>(2) wrap your code in=
to latex using macros (attached below)<br></div><div><br></div><div>There i=
s a latex macro pair (attached in a latex style file below called</div><div=
>chunk.sty) which defines \begin{chunk} and \end{chunk} that wrap anything<=
/div><div>in a verbatim-style block. The \begin{chunk} takes an argument wh=
ich is any</div><div>word or sentence, as in \begin{chunk}{int main}. So yo=
u walk your source file(s)</div><div>inserting these macros around every fu=
nction / struct / define, etc. So, for hello.c</div><div>you create a copy,=
 call it hello.tex which contains your C code with latex blocks.</div><div>=
This is tedious but trivial.<br></div><div><br></div><div>Your hello.tex fi=
le looks like (the chunk name can be anything)<br></div><div>=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
<br></div><div>\begin{chunk}{includes}</div><div>#include stdio.h</div><div=
>\end{chunk}</div><div><br></div><div>\begin{chunk}{main}</div><div>int mai=
n() {</div><div>=C2=A0 printf(&quot;hello\n&quot;};</div><div>=C2=A0 return=
 0;</div><div>}</div><div>\end{chunk}</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></div=
><div><br></div><div>(3) automate the extraction from your hello.tex to hel=
lo.c<br></div><div><br></div><div>Now you&#39;d like to make it so your pro=
gram can be extracted easily.<br></div><div>Make a new chunk using any name=
 that collects your chunks: The</div><div>third macro, called getchunk, wil=
l insert the named chunk inline.<br></div><div><br></div><div>at the end of=
 hello.tex add a new chunk:<br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></div><div>\begin{chunk}{a=
ll}</div><div>\getchunk{includes}</div><div>\getchunk{main}</div><div>\end{=
chunk}</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br></div><div><br></div><div>(4) check that you ca=
n recreate the original hello.c from hello.tex<br></div><div><br></div><div=
>The second too is a program called &#39;tanglec&#39; which, given the name=
 of a</div><div>chunk will extract it to stdout. So we ask for the whole pr=
ogram and put it into</div><div>extracted.c with and check that it is byte =
compatible with hello.c:</div><div>(Note: tanglec is attached below. gcc -o=
 tanglec tanglec.c)<br></div><div><br></div><div>at the command line type:<=
br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></=
div><div>./tanglec hello.tex all &gt;extracted.c</div><div>diff -Naur extra=
cted.c hello.c</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D<br></div><div><br></div><div>(5) make hello.tex into a PDF. Just add=
 some trivial latex header/footer.</div><div>For example add a header: (Not=
e: chunk.sty is attached below)</div><div><br></div><div>So now your hello.=
tex looks like:<br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D<br></div><div><br></div>\documentclass[dvipdfm]{book}<br>\usep=
ackage{chunk}<br>\begin{document}<br>\title{A Literate Hello}<br>\author{Ti=
mothy Daly}<br>\maketitle<br><br>\chapter{We need includes}<br>\section{Thi=
s is the usual one for printf}<br>\begin{chunk}{includes}<br>#include &lt;s=
tdio.h&gt;<br>\end{chunk}<br><br>\chapter{This is where the magic happens}<=
br>\begin{chunk}{main}<br>int main() { <br>=C2=A0 printf(&quot;hello\n&quot=
;); <br>=C2=A0 return 0; <br>}<br>\end{chunk}<br>\begin{chunk}{all}<br>\get=
chunk{includes}<br>\getchunk{main}<br>\end{chunk}<br><br>\end{document}<br>=
<div><br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D<br></div><div><br></div><div>(6) create a trivial makefi=
le (note that indented lines require TABS, not spaces)<br></div><div><br></=
div><div>in a file called &#39;makefile&#39; <br></div><div>=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></div>do=
it:<br></div><div>=C2=A0=C2=A0=C2=A0 latex hello.tex<br>=C2=A0=C2=A0=C2=A0 =
dvipdfm hello.dvi<br>=C2=A0=C2=A0=C2=A0 evince hello.pdf &amp;<br>=C2=A0=C2=
=A0=C2=A0 tanglec hello.tex all &gt;hello.c<br>=C2=A0=C2=A0=C2=A0 gcc -o he=
llo hello.c<br><div>=C2=A0=C2=A0=C2=A0 ./hello</div><div>=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></div><div><br=
></div><div>(7) <br></div><div><br></div><div>At the command line</div><div=
>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div>=
<div>make</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D<br></div><div><br></div><div>WIN! Now you write all your ex=
planation and your code in the latex file.</div><div>Then type &#39;make&#3=
9; which recreates the book and runs the code. The</div><div>explanation an=
d the code are always in sync. Now your code is a book.</div><div><br></div=
><div>Now you can add pictures, URLs, a table of contents, an index,</div><=
div>cross references, a bibliography, and even a spiffy new cover!</div><di=
v>Oh, and someone can actually read your explanation of your code.<br></div=
><div><br></div><div>Make Knuth happy! Win a Pulitzer prize!<br></div><br><=
/div>Tim<br><div><div><br></div><div><br></div></div></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Dec 3, 2022 =
at 8:20 AM Tim Daly &lt;<a href=3D"mailto:[email protected]">axiomcas@gmai=
l.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex"><div dir=3D"ltr"><div>Java code has the pseudo-ability to re-generate =
the original source</div><div>through decompilation. Unfortunately given th=
e size of any executable</div><div>it would be years worth of work to rever=
se-engineer the understanding</div><div>without explanation. I struggle to =
even understand the traceback of</div><div>any Java failure :-)</div><div><=
br></div><div>Open source, by definition, already has the source available.=
</div><div>Only the URL of the github repository and the hash number corres=
ponding</div><div>to the current executable is needed.<br></div><div><br></=
div><div>I haven&#39;t worked for IBM since 1995, the year IBM Research eli=
minated</div><div>the math department, including me. My ground-breaking wor=
k in Artificial</div><div>Intelligence has yet to be cited by anyone so the=
ir decision was probably wise.<br></div><div><br></div><div>Tim</div><div><=
br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gma=
il_attr">On Sat, Dec 3, 2022 at 1:01 AM Terence Kelly &lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank">[email protected]</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Hi Tim,<br>
<br>
Your observations seem sound.=C2=A0 Keep in mind, however, that we&#39;re n=
ot <br>
confronted with an either/or choice.=C2=A0 The chicken/egg aspect of litera=
te <br>
executables means that, in your context, we can arrange for the PDF to <br>
generate code *and* for the code to generate PDF.=C2=A0 Cyclic dependency <=
br>
graphs take some getting used to, but one can learn to love them.<br>
<br>
If literate execution isn&#39;t right for Axiom, perhaps it can benefit oth=
er <br>
IBM open source projects.=C2=A0 If you circulate the paper among your <br>
colleagues I&#39;d be interested to see if they find useful applications.<b=
r>
<br>
_Queue_ readers are remarkably creative and routinely find uses for Drill <=
br>
Bits ideas that I never anticipated.=C2=A0 I wonder what your colleagues wi=
ll <br>
come up with.<br>
<br>
Thanks.<br>
<br>
-- Terence<br>
<br>
<br>
On Fri, 2 Dec 2022, Tim Daly wrote:<br>
<br>
&gt; ...<br>
&gt; <br>
&gt; The above considerations leads me to the conclusion that the PDF is th=
e <br>
&gt; thing that generates code rather than the code generating the PDF.<br>
</blockquote></div>
</blockquote></div>

--00000000000075f51505eefc2a73--

--00000000000075f51805eefc2a75
Content-Type: text/x-csrc; charset="US-ASCII"; name="tanglec.c"
Content-Disposition: attachment; filename="tanglec.c"
Content-Transfer-Encoding: base64
Content-ID: <f_lb92ehx10>
X-Attachment-Id: f_lb92ehx10

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHVuaXN0ZC5o
PgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxzeXMvc3RhdC5oPgojaW5jbHVkZSA8c3lz
L21tYW4uaD4KI2luY2x1ZGUgPGZjbnRsLmg+CgovLyBzZXQgdGhpcyB0byAzIGZvciBmdXJ0aGVy
IGluZm9ybWF0aW9uCiNkZWZpbmUgREVCVUcgMAoKLyogZm9yd2FyZCByZWZlcmVuY2UgZm9yIHRo
ZSBDIGNvbXBp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hbWUpOyB9CiAgICAgIHJldHVybihrKzEyKTsKICAgIH0gZWxz
ZSB7CiAgICAgIGlmIChERUJVRz09MikgeyAKICAgICAgICBwcmludGYoIj09PT09PT09IHByaW50
Y2h1bmsgZWxzZSAlZCAlZFxuIixrLGxpbmVsZW4pOyAKICAgICAgfQogICAgICBwcmludGxpbmUo
ayxsaW5lbGVuKTsKICAgICAgaz1rK2xpbmVsZW4rMTsKICAgIH0KICB9fQogIGlmIChERUJVRz09
MikgewogICAgIHByaW50ZigiPT09PT09PT09PT09PT09PT1cXG91dHslc30gJWRcbiIsY2h1bmtu
YW1lLGspOyAKICB9CiAgcmV0dXJuKGspOwp9CgovKiBmaW5kIHRoZSBuYW1lZCBjaHVuayBhbmQg
Y2FsbCBwcmludGNodW5rIG9uIGl0ICovCmludCBnZXRjaHVuayhjaGFyICpjaHVua25hbWUpIHsK
ICBpbnQgaTsKICBpbnQgbGluZWxlbjsKICBpbnQgY2h1bmtsZW4gPSBzdHJsZW4oY2h1bmtuYW1l
KTsKICBpZiAoREVCVUc9PTMpIHsgcHJpbnRmKCJnZXRjaHVuayglcylcbiIsY2h1bmtuYW1lKTsg
fQogIGZvciAoaT0wOyAoKGxpbmVsZW49bmV4dGxpbmUoaSkpICE9IC0xKTsgKSB7CiAgICBpZiAo
REVCVUc9PTIpIHsgCiAgICAgIHByaW50ZigiLS0tLSIpOyBwcmludGxpbmUoaSxsaW5lbGVuKTsg
cHJpbnRmKCItLS0tXG4iKTsgCiAgICB9CiAgICBpZiAoKGxpbmVsZW4gPj0gY2h1bmtsZW4rMTUp
ICYmIChmb3VuZGNodW5rKGksY2h1bmtuYW1lKSA9PSAxKSkgewogICAgICBpZiAoREVCVUc9PTIp
IHsKICAgICAgICAgZnByaW50ZihzdGRlcnIsIj09PT09PT09PT09PT09PT09XFxnZXRjaHVuaygl
cylcbiIsY2h1bmtuYW1lKTsgCiAgICAgIH0KICAgICAgaT1wcmludGNodW5rKGksbGluZWxlbixj
aHVua25hbWUp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CiAgfQogIGlmIChhcmdjID09IDIpIHsKICAgIGdldGNodW5rKCIqIik7CiAgfSBl
bHNlIHsKICAgIGdldGNodW5rKGFyZ3ZbMl0pOwogIH0KICBjbG9zZShmZCk7CiAgcmV0dXJuKDAp
Owp9Cgo=
--00000000000075f51805eefc2a75
Content-Type: text/x-tex; charset="US-ASCII"; name="chunk.sty"
Content-Disposition: attachment; filename="chunk.sty"
Content-Transfer-Encoding: base64
Content-ID: <f_lb92fmf91>
X-Attachment-Id: f_lb92fmf91

JSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUl
JSUlJSUlJSUlJSUlJSUlJSUKJSUgVGhpcyBkZWZpbmVzIHRoZSBUZVggc3VwcG9ydCBmb3IgQXhp
b20uCgolJSBMYXRleCBDaHVuayBzdXBwb3J0CiUlIFRoaXMgaXMgdGhlIGNodW5rIGVudmlyb25t
ZW50IHRoYXQgcmVwbGFjZXMgdGhlIHVzZSBvZiB3ZWItbGlrZSB0b29scwolJQolJSBcYmVnaW57
dmVyYmF0aW19CiUlIFRvIHVzZSB0aGUgY29tbWFuZCB5b3Ugd291bGQgd3JpdGUKJSUgICAgXGJl
Z2lue2NodW5rfXtzb21lIHJhbmRvbSBzdHJpbmd9CiUlICAgIHJhbmRvbSBjb2RlIHRvIGJlIHZl
cmJhdGltIGZvcm1hdHRlZAolJSAgICBcZW5ke2NodW5rfQolJSAKJSUgIFRoaXMgdmVyc2lvbiBw
cmludHMgCiUlICAgICAgICAgICAgICAgICAgICAgLS0tIHNvbWUgcmFuZG9tIHN0cmluZyAtLS0K
JSUgICAgcmFuZG9tIGNvZGUgdG8gYmUgdmVyYmF0aW0gZm9ybWF0dGVkCiUlICAgICAgICAgICAg
ICAgICAgICAgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KJSUgXGVuZHt2ZXJiYXRpbX0KCiUl
JSUlJSUlJSUlJSUlJSUlJSUlJSUl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b2x1bW4gMQogClxuZXdlbnZpcm9ubWVudHtjaHVu
a31bMV17JSAgIHdlIG5lZWQgdGhlIGNodW5rbmFtZSBhcyBhbiBhcmd1bWVudAp7XCB9XG5ld2xp
bmVcbm9pbmRlbnQlICAgICAgICAgICAgICAgICAgICBtYWtlIHN1cmUgd2UgYXJlIGluIGNvbHVt
biAxCiV7XHNtYWxsICRcYmFja3NsYXNoe30kYmVnaW5ce2NodW5rXH1ce3tcYmYgIzF9XH19JSBh
bHRlcm5hdGUgYmVnaW4gbWFyawpcaGJveHtcaHNraXAgMi4wY219e1xiZiAtLS0gIzEgLS0tfSUg
ICAgICBtYXJrIHRoZSBiZWdpbm5pbmcKXHZlcmJhdGltfSUgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgc2F5IGV4YWN0bHkgd2hhdCB3ZSBzZWUKe1xlbmR2ZXJiYXRpbSUgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgcHJvY2VzcyBcZW5ke2NodW5rfQpccGFye30lICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICB3ZSBhZGQgYSBuZXdsaW5lClxub2luZGVudHt9JSAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXJ0IGluIGNvbHVtbiAxClxoYm94e1xoc2tpcCAy
LjBjbX17XGJmIC0tLS0tLS0tLS19JSAgICAgIG1hcmsgdGhlIGVuZAolJFxiYWNrc2xhc2h7fSRl
bmRce2NodW5rXH0lICAgICAgICAgICAgICBhbHRlcm5hdGUgZW5kIG1hcmsgKGNvbW1lbnRlZCkK
XHBhciUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW5kIGEgbmV3bGluZQpc
bm9ybWFsc2l6ZVxub2luZGVudH0lICAgICAgICAgICAgICAgICAgICBhbmQgcmV0dXJuIHRvIHRo
ZSBkb2N1bWVudAoKJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUl
JSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUKJSUlIFRoaXMgZGVjbGFyZXMgdGhlIHBsYWNl
IHdoZXJlIHdlIHdhbnQgdG8gZXhwYW5kIGEgY2h1bmsKClxwcm92aWRlY29tbWFuZHtcZ2V0Y2h1
bmt9WzFdeyUKXG5vaW5kZW50JQp7XHNtYWxsICRcYmFja3NsYXNoe30kYmVnaW5ce2NodW5rXH1c
e3tcYmYgIzF9XH19fSUgbWFyayB0aGUgcmVmZXJlbmNlCgo=
--00000000000075f51805eefc2a75--