DumBeX: Dumb B to LaTeX translation

Some of the small programs I wrote on my spare time. They are Free Software, and written mostly in OCaml.
Post Reply
User avatar
Vincent
Posts: 3077
Joined: Fri Apr 07, 2006 12:10 pm
Location: Schtroumpf
Contact:

DumBeX: Dumb B to LaTeX translation

Post by Vincent » Sat Dec 20, 2008 12:48 pm

Out of date:

SUPERCEDED BY ZapoTeX



Download:
(note: up-to-date version in next post)
DumBeX.tar.gz
Source code distribution
(12.62 KiB) Downloaded 6796 times
dumbex_binaries.tar.gz
Linux and Windows binaries
(293.13 KiB) Downloaded 6838 times
Language: Objective Caml License: GNU GPL OS: Any

Description:
DumBeX is a filter, taking lines of B notation on STDIN, and churning out corresponding LaTeX code on STDOUT. This is useful if you are using the B method and need to embed some code in a report: translate just what you need on demand or whole source files automatically.

Examples:
dumbex1.png
excerpt of "showcase" in verbatim mode. Pink = B notation, black = LaTeX translation
showcase.pdf
This file shows all B constructs supported by DumBeX
(57.52 KiB) Downloaded 9215 times
showcase-verb.pdf
same as showcase.pdf, but there DumBeX is in verbatim mode, showing input B notation in pink
(83.46 KiB) Downloaded 7073 times
Usage:
It is a filter. So

Code: Select all

dumbex < file.B > file.B.tex
will do the translation. Note that file.B.tex won't compile on its own: it is meant to be integrated into a LaTeX document, typically through an \input command. I recommend writing

Code: Select all

\definecolor{Bcomment}{rgb}{0.2,0.2,0.6}
\definecolor{Bkeyword}{rgb}{0.3,0,0}
\definecolor{Bverbatim}{rgb}{0.9,0.3,0.3}

\def\loadB#1{{\sffamily \noindent\input{#1.tex}}}
before \begin{document} and then using

Code: Select all

\loadB{file.B}
to integrate your translated B file into the document.
If you have several files, feel free to use some shell script to make it easier:

Code: Select all

for i in *.b; do
  dumbex < $i  > $i".tex" 2> /dev/null
done
Note that the color definitions can be ommited if you specify predefined colors on the command-line of DumBeX. For instance

Code: Select all

dumbex cc blue
will put comments in blue instead of using the Bcomment color. See source code, function cl, for more information on command-line arguments.

Notes and restrictions: (in no particular order)
  • I called it "dumb" because it is a simple regexp script, the initial version of which was hacked in rougly an hour, because I wanted a program to do the job now and didn't have time or motivation to do anything more subtle. There may be other such translators out there, but I couldn't find one on the net when I needed it. 'B' is such a dreadful keyword for internet search...
  • I used my first afternoon of vacations to extend it to support most B operators.
  • It is not a parser for B notation. Consequently, while it does the job in most cases, there are things it will never do: for instance, it will never be able to tell the difference between IF-the-keyword and IF-the-set-you-just-defined.
  • It outputs the LaTeX code for each symbol directly. A more elegant solution would be to output commands defined in an external package, so as to allow the user to redefine some of them in her document. Until then, if you want different symbols, you'll have to change the source code.
  • If you need any help with it, you are welcome to post here (avoid sending me a mail though).
END_OF_FILE :)
{ Vincent Hugot }

User avatar
Vincent
Posts: 3077
Joined: Fri Apr 07, 2006 12:10 pm
Location: Schtroumpf
Contact:

Re: DumBeX: Dumb B to LaTeX translation

Post by Vincent » Mon Mar 09, 2009 5:05 am

Since I need to write another report with B notations in it, I have made some small updates to DumBeX:
  • Now variable names such as k0, k1,... will come out as k_0, k_1,... (subscript).
  • Integer intervals now detect variable names: previously the notation only worked between integers.
  • Integer intervals now detect expressions composed of variable names, + and -. so PX+1..N-1 correctly becomes [| PX+1, N-1|]
  • keywords SYSTEM and ASSERTIONS have been added.
dumbex.ml.gz
updated source file
(3.32 KiB) Downloaded 6679 times
{ Vincent Hugot }

User avatar
Olivier FINOT
Membre projet CRT
Posts: 136
Joined: Mon Sep 22, 2008 7:22 pm

Re: DumBeX: Dumb B to LaTeX translation

Post by Olivier FINOT » Mon Dec 21, 2009 5:20 pm

Salut Vincent,

j'ai voulu utiliser ton DumBeX pour le rapport de projet GL de fred mais
j'ai un soucis.

Lorsque j'essaie de compiler le fichier obtenu j'obtiens l'erreur suivante :

Code: Select all

\verb ended by end of line
, d'après ce que j'ai pu voir cela à un rapport avec verbatim, mais ne
maitrisant pas ton code je ne vois pas comment résoudre ce soucis.

Ce n'est apparemment pas très important vu que le pdf généré semble correct
mais tout de même ça m'embête un peu.

Donc si tu pouvais y jeter un œil (de préférence dans l'après midi), ça
m'arrangerait.

Merci d'avance

Je te joins la machine ainsi que le fichier généré.
Last edited by Vincent on Mon Dec 21, 2009 5:21 pm, edited 1 time in total.
Reason: (reçu par mail)
En effet le rire n'est jamais gratuit, l'homme donne à pleurer, mais il prête à rire. (Desproges)

User avatar
Vincent
Posts: 3077
Joined: Fri Apr 07, 2006 12:10 pm
Location: Schtroumpf
Contact:

Re: DumBeX: Dumb B to LaTeX translation

Post by Vincent » Mon Dec 21, 2009 5:25 pm

Ligne 379 du fichier généré:


\hspace*{28ex} \textbf{{\color{Bkeyword} ANY}} uu \textbf{{\color{Bkeyword} WHERE}} uu $\in$ dom(fct\_usager\_velo|> $\{$velo$\}$) \textbf{{\color{Bkeyword} THEN}}

Attention: | est le symbole de verb inline.

L'opérateur de restriction de codomaine n'a pas été séparé du reste par des espaces, et donc Dumbex ne l'a pas vu et l'a recopié tel-quel. C'est lui qui provoque l'erreur.

Solution: rajouter un espace ligne 190 de la source: ANY uu WHERE uu : dom(fct_usager_velo|> {velo}) THEN
{ Vincent Hugot }

User avatar
Olivier FINOT
Membre projet CRT
Posts: 136
Joined: Mon Sep 22, 2008 7:22 pm

Re: DumBeX: Dumb B to LaTeX translation

Post by Olivier FINOT » Mon Dec 21, 2009 6:31 pm

Ok, effectivement je l'avais complètement zappé celui-là lors de ma chase aux espaces autour des opérateurs et j'avais pas fait le rapprochement avec l'erreur.

Merci
En effet le rire n'est jamais gratuit, l'homme donne à pleurer, mais il prête à rire. (Desproges)

GeorgesMariano
Posts: 1
Joined: Tue Jan 26, 2010 12:24 pm

Re: DumBeX: Dumb B to LaTeX translation

Post by GeorgesMariano » Tue Jan 26, 2010 12:31 pm

Bonjour,

Même si l'approche suivie est moins directe que celle de l'outil DumBeX, je signale que par l'utilisation des outils libres BRILLANT (écrits en OCaml) il est possible d'obtenir une transcription de code B en LaTeX sur la base d'un véritable parser. (certes, incomplet pour raisons théoriques).

La démarche proposée est une conversion B->XML, puis XML->LaTeX par style XSL. Cela laisse la possibilité à l'utilisateur de paramétrer complètement sa conversion.

http://gna.org/projects/brillant


Cordialement

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests