From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 61ECD820A1 for ; Mon, 2 Sep 2013 18:39:42 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of raphlalou@gmail.com) identity=pra; client-ip=209.85.217.172; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of raphlalou@gmail.com designates 209.85.217.172 as permitted sender) identity=mailfrom; client-ip=209.85.217.172; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lb0-f172.google.com) identity=helo; client-ip=209.85.217.172; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="postmaster@mail-lb0-f172.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AocBAEm+JFLRVdmsm2dsb2JhbABahAEMgye9P4EhCBYOAQEBAQEGCwsJFCiCJAEBBSMEGQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMIh2cBAw+bNYt/UYMFhAgKGScNZIhcAQUMgR2LZoI9MweCaYE0A5YMgWmMN4NGGCmESjo X-IPAS-Result: AocBAEm+JFLRVdmsm2dsb2JhbABahAEMgye9P4EhCBYOAQEBAQEGCwsJFCiCJAEBBSMEGQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMIh2cBAw+bNYt/UYMFhAgKGScNZIhcAQUMgR2LZoI9MweCaYE0A5YMgWmMN4NGGCmESjo X-IronPort-AV: E=Sophos;i="4.89,1008,1367964000"; d="scan'208";a="31213119" Received: from mail-lb0-f172.google.com ([209.85.217.172]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Sep 2013 18:39:41 +0200 Received: by mail-lb0-f172.google.com with SMTP id x18so4107446lbi.17 for ; Mon, 02 Sep 2013 09:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=EocA/4ZfyeLuwYthnGfpVSqIX9oup5oaN/62hw4fUKs=; b=welIX+xNj/H8OCamF2GPyAm14YEnNAn6+wUvhy/7AYZrkHEMVrSWIunMVWMmU4Wy0E ZPkT6EGXt0SVjZFRa7bH9F1IMkD5YC4l4xoaxee/IzfXDtYgMH6oifkDZI11w76LbIOc NEaxgGXRNqSHk3zj/wcfxXJUDbjWezyZufNn1Z2ZCHCSNJGmjplIPAnO6uPxk/gHw7By YnDZMFYm+HoHqx/GO1lBWa4HRr+3Kb5JFNbhprRL+YgAegC5w49Pe+ufP8rB+DqongTT 7BrC/dKBTkAz2AwEAhgcud3lfZdRv8gVL0Ebc1309AVXobvITJwpcRR3cgxlaUXkuuLu 8Sxg== MIME-Version: 1.0 X-Received: by 10.112.167.3 with SMTP id zk3mr21538197lbb.23.1378139981155; Mon, 02 Sep 2013 09:39:41 -0700 (PDT) Received: by 10.112.125.164 with HTTP; Mon, 2 Sep 2013 09:39:41 -0700 (PDT) In-Reply-To: <5224B137.8070706@gmail.com> References: <5224B137.8070706@gmail.com> Date: Mon, 2 Sep 2013 18:39:41 +0200 Message-ID: From: =?UTF-8?Q?Rapha=C3=ABl_Proust?= To: Jonathan Protzenko Cc: OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Literate (sort-of) programming in OCaml 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=3Dmain.pdf SOURCE=3D${TARGET:%.pdf=3D%.pdc} INCLUDES=3D`{cat $SOURCE | grep '\\input{.*\.tex}' | sed 's/^.*\\input{([^\$\\}]*\.tex)}.*$/\1/'} $TARGET: $SOURCE $INCLUDES pandoc -o $TARGET $SOURCE %.pp.tex: %.bar bar.byte OCAMLRUNPARAM=3D$OCAMLRUNOPT ./bar.byte -latex $stem.bar > $target %.pp.annot.tex: %.bar bar.byte OCAMLRUNPARAM=3D$OCAMLRUNOPT ./bar.byte -latex -annot $stem.bar > $= target ~~~~~~~ Extracts from bar.mli: ~~~~~~~ module type PRINTER =3D 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*} --=20 ______________ Rapha=C3=ABl Proust