]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/matex/TeXOutput.ml
MaTeX
[helm.git] / matita / components / binaries / matex / TeXOutput.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 module L = List
13 module P = Printf
14 module S = String
15
16 module X = Ground
17 module T = TeX
18
19 (* internal functions *******************************************************)
20
21 let special = "\\{}$&#^_~%" (* LaTeX reserves these characters *)
22
23 let special = [
24    '_', "\\_";
25 ]
26
27 let quote s c = try s ^ L.assoc c special with
28    | Not_found -> s ^ S.make 1 c 
29
30 let rec out_item och = function
31    | T.Free s  -> P.fprintf och "%s" s
32    | T.Text s  -> P.fprintf och "%s" (X.fold_string quote "" s)
33    | T.Macro s -> P.fprintf och "\\%s%%\n" s
34    | T.Group t -> P.fprintf och "{%a}%%\n" out_text t
35    | T.Note s  -> P.fprintf och "%% %s\n" s
36
37 (* interface functions ******************************************************)
38
39 and out_text och t = 
40    L.iter (out_item och) t