From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 5DA52820A1 for ; Mon, 2 Sep 2013 18:50:33 +0200 (CEST) Received-SPF: Neutral (mail2-smtp-roc.national.inria.fr: domain of simon.cruanes.2007@m4x.org does not assert whether or not 129.104.30.34 is permitted sender) identity=pra; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=+1CK=SO=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="simon.cruanes.2007@m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of SRS0=+1CK=SO=m4x.org=simon.cruanes.2007@bounces.m4x.org designates 129.104.30.34 as permitted sender) identity=mailfrom; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=+1CK=SO=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="SRS0=+1CK=SO=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@mx1.polytechnique.org designates 129.104.30.34 as permitted sender) identity=helo; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=+1CK=SO=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="postmaster@mx1.polytechnique.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AngBAKjAJFKBaB4inGdsb2JhbABaFoMmgx5aqnuSRIEpFg4BAQEBAQgUCTyCJAEBBQwXBEcLEAkCGA0dAgIhJBIGAQ0FEodeAw8ECItYm0yIKAMKiUaND4E3gTWCdIE0A5YMgWmBL4R9hguIUYFv X-IPAS-Result: AngBAKjAJFKBaB4inGdsb2JhbABaFoMmgx5aqnuSRIEpFg4BAQEBAQgUCTyCJAEBBQwXBEcLEAkCGA0dAgIhJBIGAQ0FEodeAw8ECItYm0yIKAMKiUaND4E3gTWCdIE0A5YMgWmBL4R9hguIUYFv X-IronPort-AV: E=Sophos;i="4.89,1008,1367964000"; d="scan'208,217";a="31214278" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 02 Sep 2013 18:50:32 +0200 Received: from [10.163.64.200] (unknown [37.160.56.91]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 5D844140C5BA7; Mon, 2 Sep 2013 18:50:31 +0200 (CEST) User-Agent: K-9 Mail for Android In-Reply-To: References: <5224B137.8070706@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----TWLARKGCA7UG6YZI12PTO4AI8V3FYG" From: Simon Cruanes Date: Mon, 02 Sep 2013 18:50:25 +0200 To: =?ISO-8859-1?Q?Rapha=EBl_Proust?= ,Jonathan Protzenko CC: OCaml Mailing List Message-ID: <0fb7c9b0-f46a-40c1-b7b2-d7fd2be75a73@email.android.com> X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Mon Sep 2 18:50:32 2013 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.020323, queueID=568DE140C5BAB X-Org-Mail: simon.cruanes.2007@polytechnique.org Subject: Re: [Caml-list] Literate (sort-of) programming in OCaml ------TWLARKGCA7UG6YZI12PTO4AI8V3FYG Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You may also try https://www.lri.fr/~filliatr/ocamlweb/ . Cheers "Raphaël Proust" a écrit : >On Mon, Sep 2, 2013 at 5:39 PM, Jonathan Protzenko > wrote: >> I am currently writing a big, mostly textual document in format blah >> (blah being of a course a meta-variable). Are there any tools that >> would allow me to interleave OCaml code with the contents of my >> document? >> >> More on my use-case. Creating this document requires me to perform >> various subtasks, such as: >> - write a code snippet in the document, >> - put the code snippet in a file, >> - call an external program on the file, >> - paste the output into the document. > >Current workflow I use involves: >- mkfile: a rule file for mk (Plan9's take on make, it has simple >escaping and a readable man page) to drive the whole thing, >- bar: a compiler for the language bar that includes a Latex pretty >printing mode >- inc/: a directory where I place all my code samples from language bar >- main.pdc: a pandoc file holding the source. > >Extracts from the mkfile: >~~~~~~~ >TARGET=main.pdf >SOURCE=${TARGET:%.pdf=%.pdc} > >INCLUDES=`{cat $SOURCE | grep '\\input{.*\.tex}' | sed >'s/^.*\\input{([^\$\\}]*\.tex)}.*$/\1/'} > >$TARGET: $SOURCE $INCLUDES > pandoc -o $TARGET $SOURCE > >%.pp.tex: %.bar bar.byte > OCAMLRUNPARAM=$OCAMLRUNOPT ./bar.byte -latex $stem.bar > $target > >%.pp.annot.tex: %.bar bar.byte >OCAMLRUNPARAM=$OCAMLRUNOPT ./bar.byte -latex -annot $stem.bar > $target >~~~~~~~ > >Extracts from bar.mli: >~~~~~~~ >module type PRINTER = sig > val t: annotations:bool -> t -> string >end >module LatexPP : PRINTER >~~~~~~~ > >Extracts from the main.pdc >~~~~~~~ >The annotation process, blahblah. Thus the program >$\input{inc/foo.pp.tex}$ >is annotated in the following way: $\input{inc/foo.pp.annot.tex}$ >~~~~~~~ > > >Known bugs and shortcomings: >- sed works line-wise so the mkfile INCLUDES variable is not set >properly when there are several \input on the same line. >- the passing of argument (using two rules with and two file >extensions) is hackish and would not scale. > > >Less painful than copy-pasting things and easier to keep everything in >sync. It's also nice to be able to do things such as: >\begin{align*} >\input{inc/function-application.pp.tex}\\ >\input{inc/function-declaration.pp.tex}\\ >\input{inc/if-then-else.pp.tex}\\ > >\end{align*} > >-- >______________ >Raphaël Proust > >-- >Caml-list mailing list. Subscription management and archives: >https://sympa.inria.fr/sympa/arc/caml-list >Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >Bug reports: http://caml.inria.fr/bin/caml-bugs -- Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté. ------TWLARKGCA7UG6YZI12PTO4AI8V3FYG Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit You may also try https://www.lri.fr/~filliatr/ocamlweb/ .

Cheers


"Raphaël Proust" <raphlalou@gmail.com> a écrit :
On Mon, Sep 2, 2013 at 5:39 PM, Jonathan Protzenko
<jonathan.protzenko@gmail.com> wrote:
I am currently writing a big, mostly textual document in format blah
(blah being of a course a meta-variable). Are there any tools that
would allow me to interleave OCaml code with the contents of my
document?

More on my use-case. Creating this document requires me to perform
various subtasks, such as:
- write a code snippet in the document,
- put the code snippet in a file,
- call an external program on the file,
- paste the output into the document.

Current workflow I use involves:
- mkfile: a rule file for mk (Plan9's take on make, it has simple
escaping and a readable man page) to drive the whole thing,
- bar: a compiler for the language bar that incl udes a Latex pretty
printing mode
- inc/: a directory where I place all my code samples from language bar
- main.pdc: a pandoc file holding the source.

Extracts from the mkfile:
~~~~~~~
TARGET=main.pdf
SOURCE=${TARGET:%.pdf=%.pdc}

INCLUDES=`{cat $SOURCE | grep '\\input{.*\.tex}' | sed
's/^.*\\input{([^\$\\}]*\.tex)}.*$/\1/'}

$TARGET: $SOURCE $INCLUDES
pandoc -o $TARGET $SOURCE

%.pp.tex: %.bar bar.byte
OCAMLRUNPARAM=$OCAMLRUNOPT ./bar.byte -latex $stem.bar > $target

%.pp.annot.tex: %.bar bar.byte
OCAMLRUNPARAM=$OCAMLRUNOPT ./bar.byte -latex -annot $stem.bar > $target
~~~~~~~

Extracts from bar.mli:
~~~~~~~
module type PRINTER = sig
val t: annotations:bool -> t -> string
end
module LatexPP : PRINTER
~~~~~~~

Extracts from the main.pdc
~~~~~~~
The annotation process, blahblah. Thus the program $\input{inc/foo.pp.tex}$
is annotated in the following way: $\input{inc/foo.pp.annot.tex}$
~~~~~~~


Known bugs and shortcomings:
- sed works line-wise so the mkfile INCLUDES variable is not set
properly when there are several \input on the same line.
- the passing of argument (using two rules with and two file
extensions) is hackish and would not scale.


Less painful than copy-pasting things and easier to keep everything in
sync. It's also nice to be able to do things such as:
\begin{align*}
<some math>\input{inc/function-application.pp.tex}<more math>\\
<more math>\input{inc/function-declaration.pp.tex}<more math>\\
<more math>\input{inc/if-then-else.pp.tex}<more math>\\
<etc.>
\end{align*}

--
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté. ------TWLARKGCA7UG6YZI12PTO4AI8V3FYG--