LaTeXConstants.java
001 /*
002  *  LaTeXConstants.java
003  *  Copyright (c) 1998-2008, The University of Sheffield.
004  *
005  *  This code is from the GATE project (http://gate.ac.uk/) and is free
006  *  software licenced under the GNU General Public License version 3. It is
007  *  distributed without any warranty. For more details see COPYING.txt in the
008  *  top level directory (or at http://gatewiki.sf.net/COPYING.txt).
009  *  
010  *  Hamish Cunningham, 24th August 2006
011  */
012 
013 package gate.yam.translate;
014 
015 /**
016  * Constants used when translating LaTeX. One entry for each type of parse tree
017  * node. Each entry contains the node type name, the start constant and the
018  * end constant.
019  * <pre>
020  * constantsTable[CONSTANTNAME] is the node type name
021  * constantsTable[CONSTANTSTART] is the start string
022  * constantsTable[CONSTANTEND] is the end string
023  * </pre>
024  * A separate map is defined for predicates, and there are misc patterns for
025  * e.g. headings construction.
026  * @author Hamish Cunningham
027  */
028 public interface LaTeXConstants
029 {
030   /** Array mapping node type name to start/end strings. */
031   final String[][] latexConstantsTable = {
032 
033     // ordinary nodes
034     { "YamDocument",    "",             "\\end{document}"       },
035     { "Sep",            "",             ""                      },
036     { "Title",          "",             ""                      },
037     { "Text",           "",             ""                      },
038     { "Verbatim",       "\\begin{verbatim}", "\\end{verbatim}"  },
039     { "Word",           "",             ""                      },
040     { "Escape",         "",             ""                      },
041     { "Plain",          "",             ""                      },
042     { "Control",        "",             ""                      },
043     { "TargetControl",  "",             ""                      },
044     { "Hr",             "\\hrulefill",  ""                      },
045     { "Url",            "\\url{_X_}",   ""                      },
046     { "Anchor",         "\\label{_X_}", ""                      },
047     { "Br",             "\\\\",         ""                      },
048     { "Nbsp",           "~",            ""                      },
049     { "Unit",           "",             ""                      },
050     { "SectionHead",    "\n",             ""                    },
051     { "SectionText",    "",             ""                      },
052     { "Paragraph",      "",             ""                      },
053     { "List",           "",             ""                      },
054     { "ListItem",       "\\item ",      ""                      },
055     { "OList",          "\\begin{enumerate}", "\\end{enumerate}"},
056     { "UList",          "\\begin{itemize}", "\\end{itemize}"    },
057     { "Table",          "\\begin{table}", "\\end{table}"        },
058     { "Row",            "",             "\\\\"                  },
059     { "Column",         "",             " & "                   },
060     { "TableSep",       "",             ""                      },
061     { "Whsp",           "",             ""                      },
062     { "Contents",       "",             ""                      },
063     { "Predicate",      "",             ""                      },
064     { "TextOrTable",    "",             ""                      },
065     { "Skip",           "",             ""                      },
066 
067     // controls
068     { "*",              "{\\bf ",       "}"                     },
069     { "^",              "{\\tt ",       "}"                     },
070     { "_",              "{\\it ",       "}"                     },
071     { "__",             "{\\ul",        "}"                     },
072     { "<",              "<",            ""                      },
073     { "&",              "\\&",          ""                      },
074     { "%\"",            "\begin{quotation}", "\\end{quotation}" },
075 
076     // predicates
077     { "image",          "\\includegraphics{", "}"               },
078     { "footnote",       "\\footnote{",  "}"                     },
079     { "cite",           "\\cite{",      "}"                     },
080     { "include",        "",             ""                      },
081 
082     // misc useful constants
083     { "olistPara",      "\\n\\begin{enumerate}\\n",  "\\end{enumerate}\\n" },
084     { "ulistPara",      "\\n\\begin{itemize}\\n",  "\\end{itemize}\\n" },
085     { "anchorPattern",  "\\label{_X_}", ""                      },
086     { "linkPattern",    "\\href{_X_}{_Y_}", ""                   },
087     { "headingPattern", "\\_X_{_Y_}",   ""                      },
088     { "nbSpace",        "~",            ""                      },
089     { "headNumber",     "",             ""                      },
090     { "footnoteText",   "",             ""                      },
091     { "footnoteSection","",             ""                      },
092     { "comment",        "\\delete{",    "}",                    },
093 
094     // headings
095     { "1",              "section",      "",                     },
096     { "2",              "subsection",   "",                     },
097     { "3",              "subsubsection", "",                    },
098     { "4",              "paragraph",    "",                     },
099     { "5",              "subparagraph", "",                     },
100     { "6",              "subparagraph", "",                     },
101     { "7",              "subparagraph", "",                     },
102     { "8",              "subparagraph", "",                     },
103     { "9",              "subparagraph", "",                     },
104   };
105 
106   /** Attributes allowed on images. */
107   final String[] imageAttrs =
108     { " src=\"_X_\"", " alt=\"_X_\"", " width=\"_X_\"", " height=\"_X_\"",
109       " align=\"_X_\"", " border=\"_X_\"", };
110 
111   /** Attributes allowed on footnotes. */
112   final String[] footnoteAttrs = { "_X_" };
113 
114   /** HTML citation style. */
115   final String citationAttr = "\\cite{_X_}";
116 
117   /** Attributes allowed on citations. Ugly, I admit. */
118   final String[] citationAttrs = { citationAttr,
119     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
120     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
121     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
122     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
123     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
124     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
125     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
126     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
127     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
128     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
129     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
130     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
131     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
132     ", " + citationAttr, ", " + citationAttr, ", " + citationAttr,
133   };
134 
135   /** Attributes allowed on includes. */
136   final String[] includeAttrs = { "_X_" };
137 
138   /** Array mapping predicate type name to attributes. */
139   final Object[][] latexPredicatesTable = {
140     { "image",          imageAttrs },
141     { "footnote",       footnoteAttrs },
142     { "cite",           citationAttrs },
143     { "include",        includeAttrs },
144   };
145 
146 } // LaTeXConstants