nrnrnr / noweb

The noweb tool for literate programming
BSD 2-Clause "Simplified" License
253 stars 27 forks source link

Mini-indices in the margins #25

Closed raghnysh closed 1 year ago

raghnysh commented 1 year ago

@nrnrnr Many thanks for this system for literate programming, and even more for your wonderful book Build, Prove, Compare. Can you please describe how to get mini-indices of identifiers as in the book?

nrnrnr commented 1 year ago

The mini-indices use a fair amount of custom engineering. To start at the back end, noweb generates an "MDB file" that contains all the marginal indices in one place. That file includes a LaTeX environment for each mini-index, something like this:

\begin{marginalindex}{25}
  \inchunk{mod}{NW3lf9Qy-1I7sVC-3}% 27f
\end{marginalindex}
\begin{marginalindex}{45}
  \autogen{\textrm{type} Def}%
  \inchunk{\textrm{type} Echo}{NW3PGINC-qYINM-3}% S293j
  \autogen{\textrm{type} Exp}%
  \autogen{\textrm{type} Func}%
  \inchunk{\textrm{type} Name}{NW3lf9Qy-qYINM-1}% 43d
  \inchunk{\textrm{type} Namelist}{NW3lf9Qy-qYINM-1}% 43d
  \autogen{\textrm{type} Userfun}%
  \inchunk{\textrm{type} Value}{NW3lf9Qy-32mcxO-1}% 43f
  \inchunk{\textrm{type} Valuelist}{NW3lf9Qy-32mcxO-1}% 43f
\end{marginalindex}

The environment is defined in mini-idx.sty.

The MDB file is generated by a Lua script that crawls three kinds of information:

Definition-use pairs can be obtained from the MLton compiler (for ML code), the rtags package (for C code), or a modified interpreter (for bridge-language code).

raghnysh commented 1 year ago

On 27 June 2023 22:36:48 GMT+05:30, Norman Ramsey @.***> wrote:

The mini-indices use a fair amount of custom engineering. To start at the back end, noweb generates an "MDB file" that contains all the marginal indices in one place. That file includes a LaTeX environment for each mini-index, something like this:

\begin{marginalindex}{25}
 \inchunk{mod}{NW3lf9Qy-1I7sVC-3}% 27f
\end{marginalindex}
\begin{marginalindex}{45}
 \autogen{\textrm{type} Def}%
 \inchunk{\textrm{type} Echo}{NW3PGINC-qYINM-3}% S293j
 \autogen{\textrm{type} Exp}%
 \autogen{\textrm{type} Func}%
 \inchunk{\textrm{type} Name}{NW3lf9Qy-qYINM-1}% 43d
 \inchunk{\textrm{type} Namelist}{NW3lf9Qy-qYINM-1}% 43d
 \autogen{\textrm{type} Userfun}%
 \inchunk{\textrm{type} Value}{NW3lf9Qy-32mcxO-1}% 43f
 \inchunk{\textrm{type} Valuelist}{NW3lf9Qy-32mcxO-1}% 43f
\end{marginalindex}

The environment is defined in mini-idx.sty.

The MDB file is generated by a Lua script that crawls three kinds of information:

  • The main .aux file for the book
  • A list of the primitives defined in each chapter, obtained by crawling the source code
  • Multiple lists of definition-use pairs for each chapter

Definition-use pairs can be obtained from the MLton compiler (for ML code), the rtags package (for C code), or a modified interpreter (for bridge-language code).

Thanks for the explanation. I'll see if I can implement all these steps, or alternatively try for a more LaTeX -oriented solution.

nrnrnr commented 1 year ago

If you want scripts, let me know, although they are a royal mess.

raghnysh commented 1 year ago

Yes, the scripts would be useful. I'll send you a request by email.

On 27 June 2023 11:03:12 pm IST, Norman Ramsey @.***> wrote:

If you want scripts, let me know, although they are a royal mess.

dbosk commented 1 year ago

I'm also interested in this. Please CC me at dbosk at kth dot se. Or just upload the scripts here in this thread, that would also work.

nrnrnr commented 1 year ago

Attached is a stack of scripts plus some sample .prim and .du files.

A partial list of how book.mdb is built is as follows:

   ./import-du -absolute -methods $BUILD/src/usmalltalk/newtests.bdu $BUILD/src/usmalltalk/transcript.bdu $BUILD/src/usmalltalk/exercises.bdu $BUILD/src/usmalltalk/tests.bdu $BUILD/src/usmalltalk/simscript.bdu $BUILD/src/usmalltalk/bignum.bdu > usmalltalk-book.du
   ./mlprim ./typesys.nw ./typesysa.nw > typesys.prim
   ./mlprim ./upr.nw ./upra.nw > upr.prim
   ./cprim ./gcs.nw ./gcsa.nw > gcs.prim
   ./mlprim ./adt.nw ./adta.nw > adt.prim
   ./mlprim ./tuscheme.nw ./tuschemea.nw > tuscheme.prim
   ./mlprim ./mcl.nw ./mcla.nw > mcl.prim
   ./mlprim ./ml.nw ./mla.nw > ml.prim
   ./mlprim ./haskell.nw ./haskella.nw > haskell.prim
   ./mlprim ./mlscheme.nw ./mlschemea.nw > mlscheme.prim
   ./cprim ./schemes.nw ./schemesa.nw > schemes.prim
   ./cprim ./scheme.nw ./schemea.nw > scheme.prim
   ./cprim ./impcore.nw ./impcorea.nw > impcore.prim
   ./mlprim ./usm.nw ./usma.nw > usm.prim
       # was dependend o $TEXFILES $AUXFILES 
./mini5 book.aux -prim typesys.prim upr.prim gcs.prim adt.prim tuscheme.prim mcl.prim ml.prim tuscheme.prim haskell.prim mlscheme.prim schemes.prim scheme.prim impcore.prim adt.prim tuscheme.prim gcs.prim usm.prim -du timpcore-mlton.du uprolog-mlton.du uscheme-copy-rtags.du uml-mlton.du tuscheme-mlton.du molecule-mlton.du nml-mlton.du uhaskell-mlton.du uscheme-ml-mlton.du uschemeplus-rtags.du uscheme-rtags.du impcore-rtags.du umlx-mlton.du uscheme-ms-rtags.du usmalltalk-mlton.du timpcore-book.du uscheme-copy-book.du uml-book.du nml-book.du uscheme-ml-book.du uscheme-book.du impcore-book.du uscheme-ms-book.du usmalltalk-book.du -used indexed.dus > book.mdb
raghnysh commented 1 year ago

Many thanks. I'll try these scripts.