initial import
[sbp.git] / src / edu / berkeley / sbp / tib / TibDoc.java
1 // Copyright 2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package edu.berkeley.sbp.tib;
6 //import org.ibex.util.*;
7 //import org.ibex.io.*;
8 import java.util.*;
9 import java.io.*;
10
11 public class TibDoc {
12     /*
13     public static enum Style { H, UL, TT, SO, IT, Q, B, PRE, LIST, EMDASH; }
14
15     public static AST h(AST a)      { return new Gather(a, Style.H); }
16     public static AST ul(AST a)     { return new Gather(a, Style.UL); }
17     public static AST tt(AST a)     { return new Gather(a, Style.TT); }
18     public static AST so(AST a)     { return new Gather(a, Style.SO); }
19     public static AST it(AST a)     { return new Gather(a, Style.IT); }
20     public static AST q(AST a)      { return new Gather(a, Style.Q); }
21     public static AST b(AST a)      { return new Gather(a, Style.B); }
22     public static AST pre(AST a)    { return new Gather(a, Style.PRE); }
23     public static AST list(AST a)   { return new Gather(a, Style.LIST); }
24     public static AST emdash()      { return new Gather(Style.EMDASH); }
25
26     public static AST seq(AST a) { return new Gather(a); }
27
28     public static class Latex {
29         public static void emit(PrintWriter p, AST a) {
30             prefix(p);
31             emit(p, a, "");
32             suffix(p);
33         }
34         public static void emit2(PrintWriter p, AST ast, String head) {
35             for(AST a = ast.getFirstChild(); a != null; a = a.getNextSibling()) emit(p, a, head);
36         }
37         public static void emit(PrintWriter p, AST ast, String head) {
38             if (!(ast instanceof Gather)) {
39                 if (ast.getNumberOfChildren()==0) {
40                     p.print(ast.getText());
41                 } else {
42                     emit2(p, ast, head);
43                 }
44                 return;
45             }
46             Gather a = (Gather)ast;
47             if (a.style==null) {
48                 emit2(p, a, head);
49                 return;
50             }
51             switch(a.style) {
52                 case H:    p.println(); p.println(); p.print("\\"+head+"section{"); emit2(p, a, "sub"+head); p.println("}"); break;
53                 case B:    p.print("{\\bf{");                          emit2(p, a, head); p.print("}}"); break;
54                 case UL:   p.print("{\\ul{");                          emit2(p, a, head); p.print("}}"); break;
55                 case IT:   p.print("{\\it{");                          emit2(p, a, head); p.print("}}"); break;
56                 case TT:   p.print("{\\tt{");                          emit2(p, a, head); p.print("}}"); break;
57                 case SO:   p.print("{\\overstrike{");                  emit2(p, a, head); p.print("}}"); break;
58                 case Q:    p.print("``");                              emit2(p, a, head); p.print("''"); break;
59                 case EMDASH: p.print(" \\emdash "); break;
60                 case LIST: p.println(); p.println("\\startitemize[symbol]"); emit2(p, a, head); p.println("\\stopitemize"); break;
61                 case PRE:
62                     if (a.getFirstChild() != null) {
63                         p.println();
64                         p.println("\\begin{verbatim}");
65                         p.println(a.getFirstChild().getText());
66                         p.println("\\end{verbatim}");
67                     }
68             }
69         }
70         public static void prefix(PrintWriter p) {
71             p.println("% generated by TIBDOC");
72             for(int i=0; i<packages.length; i++) p.println("\\usemodule["+packages[i]+"]");
73             p.println("\\setuppapersize[letter]");
74             p.println("\\setuppagenumbering[location=]");
75             p.println("\\setupcolors[state=start]");
76             //"\\setupinteraction[title={Title},author={Me},"++
77             //"subtitle={Deez Nutz},keywords={blargh},color=blue]\n" ++
78             //"\\setuppublications[database={me},numbering=yes,sort=author]\n" ++
79             p.println("\\setuphead[section][style={\\ss\\bfa},number=no,before=\\blank\\hairline\\nowhitespace]");
80             p.println("\\definelayout[mypage][backspace=1.75in,cutspace=1.75in,width=5in]");
81             p.println("\\setuplayout[mypage]");
82             p.println("\\definetypeface[myface][rm][Xserif][Warnock Pro]");
83             p.println("\\definetypeface[myface][tt][Xmono][CMU Typewriter Text Regular][default]");
84             p.println("\\definetypeface[myface][ss][Xsans][Myriad Pro][default]");
85             p.println("\\usesymbols[uni]");
86             p.println("\\definesymbol[1][{\\USymbCharZapf{39}{164}}]");
87             p.println("\\setupbodyfont[myface, 11pt]");
88             p.println("\\setupwhitespace[7pt]");
89             p.println("\\def\\MyDroppedCaps%");
90             p.println("    {\\DroppedCaps");
91             p.println("        {} {Serif} {2\\baselineskip} {2pt} {1\\baselineskip} {2}}");
92             p.println("\\starttext");
93             p.println("\\switchtobodyfont[16pt]\\midaligned{\\ss\\bfa{Title}}\\switchtobodyfont[10pt]");
94             p.println("\\midaligned{Adam Megacz}\n\n\\nowhitespace\\midaligned{\\tt{adam@megacz.com}}");
95             p.println("\\blank[1cm,force]");
96             //p.println("\\defineparagraphs[mypar][n=2,before={\\blank},after={\\blank}");
97             //p.println("\\setupparagraphs[mypar][1][width=.45\\textwidth");
98             //p.println("\\setupparagraphs[mypar][2][width=.55\\textwidth");
99             //p.println("\\startmypa");
100             //p.println("\\switchtobodyfont[sma");
101         }
102
103         public static void suffix(PrintWriter p) {
104             p.println("\\stoptext");
105         }
106         static String[] packages = new String[] { "supp-fun", "bib", "href" };
107     }
108     */
109 }
110