Page 1 of 1

DumBeX: Dumb B to LaTeX translation

Posted: Sat Dec 20, 2008 12:48 pm
by Vincent
Out of date:


(note: up-to-date version in next post)
Source code distribution
(12.62 KiB) Downloaded 6242 times
Linux and Windows binaries
(293.13 KiB) Downloaded 6275 times
Language: Objective Caml License: GNU GPL OS: Any

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.

excerpt of "showcase" in verbatim mode. Pink = B notation, black = LaTeX translation
This file shows all B constructs supported by DumBeX
(57.52 KiB) Downloaded 8599 times
same as showcase.pdf, but there DumBeX is in verbatim mode, showing input B notation in pink
(83.46 KiB) Downloaded 6432 times
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


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

Code: Select all

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
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).

Re: DumBeX: Dumb B to LaTeX translation

Posted: Mon Mar 09, 2009 5:05 am
by Vincent
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.
updated source file
(3.32 KiB) Downloaded 6101 times

Re: DumBeX: Dumb B to LaTeX translation

Posted: Mon Dec 21, 2009 5:20 pm
by Olivier FINOT
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

Merci d'avance

Je te joins la machine ainsi que le fichier généré.

Re: DumBeX: Dumb B to LaTeX translation

Posted: Mon Dec 21, 2009 5:25 pm
by Vincent
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

Re: DumBeX: Dumb B to LaTeX translation

Posted: Mon Dec 21, 2009 6:31 pm
by Olivier FINOT
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.


Re: DumBeX: Dumb B to LaTeX translation

Posted: Tue Jan 26, 2010 12:31 pm
by GeorgesMariano

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.