(* * bibtex2html - A BibTeX to HTML translator * Copyright (C) 1997-2000 Jean-Christophe Filliâtre and Claude Marché * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License version 2 for more details * (enclosed in the file GPL). *) (*i $Id: latexmacros.ml,v 1.63 2007-07-16 14:34:08 filliatr Exp $ i*) (*s This code is Copyright (C) 1997 Xavier Leroy. *) open Printf open Options (*s Output functions. *) let out_channel = ref stdout let print_s s = output_string !out_channel s let print_c c = output_char !out_channel c (*s Actions and translations table. *) type action = | Print of string | Print_arg | Skip_arg | Raw_arg of (string -> unit) | Parameterized of (string -> action list) | Recursive of string (*r piece of LaTeX to analyze recursively *) let cmdtable = (Hashtbl.create 19 : (string, action list) Hashtbl.t) let def name action = Hashtbl.add cmdtable name action let find_macro name = try Hashtbl.find cmdtable name with Not_found -> if not !quiet then eprintf "Unknown macro: %s\n" name; [] ;; (*s Translations of general LaTeX macros. *) (* Sectioning *) def "\\part" [Print ""; Print_arg; Print "\n"]; def "\\chapter" [Print "

"; Print_arg; Print "

\n"]; def "\\chapter*" [Print "

"; Print_arg; Print "

\n"]; def "\\section" [Print "

"; Print_arg; Print "

\n"]; def "\\section*" [Print "

"; Print_arg; Print "

\n"]; def "\\subsection" [Print "

"; Print_arg; Print "

\n"]; def "\\subsection*" [Print "

"; Print_arg; Print "

\n"]; def "\\subsubsection" [Print "

"; Print_arg; Print "

\n"]; def "\\subsubsection*" [Print "

"; Print_arg; Print "

\n"]; def "\\paragraph" [Print "
"; Print_arg; Print "
\n"]; (* Text formatting *) def "\\begin{alltt}" [Print "
"];
def "\\end{alltt}" [Print "
"]; def "\\textbf" [Print "" ; Print_arg ; Print ""]; def "\\mathbf" [Print "" ; Print_arg ; Print ""]; def "\\texttt" [Print "" ; Print_arg ; Print ""]; def "\\mathtt" [Print "" ; Print_arg ; Print ""]; def "\\textit" [Print "" ; Print_arg ; Print ""]; def "\\mathit" [Print "" ; Print_arg ; Print ""]; def "\\textsl" [Print "" ; Print_arg ; Print ""]; def "\\textem" [Print "" ; Print_arg ; Print ""]; def "\\textrm" [Print_arg]; def "\\mathrm" [Print_arg]; def "\\textmd" [Print_arg]; def "\\textup" [Print_arg]; def "\\textnormal" [Print_arg]; def "\\mathnormal" [Print "" ; Print_arg ; Print ""]; def "\\mathcal" [Print_arg]; def "\\mathbb" [Print_arg]; def "\\mathfrak" [Print_arg]; def "\\textin" [Print ""; Print_arg; Print ""]; def "\\textsu" [Print ""; Print_arg; Print ""]; def "\\textsi" [Print "" ; Print_arg ; Print ""]; (* Basic color support. *) def "\\textcolor" [ Parameterized (function name -> match String.lowercase name with (* At the moment, we support only the 16 named colors defined in HTML 4.01. *) | "black" | "silver" | "gray" | "white" | "maroon" | "red" | "purple" | "fuchsia" | "green" | "lime" | "olive" | "yellow" | "navy" | "blue" | "teal" | "aqua" -> [ Print (Printf.sprintf "" name); Print_arg ; Print "" ] (* Other, unknown colors have no effect. *) | _ -> [ Print_arg ] )]; (* Fonts without HTML equivalent *) def "\\textsf" [Print "" ; Print_arg ; Print ""]; def "\\mathsf" [Print "" ; Print_arg ; Print ""]; def "\\textsc" [Print_arg]; def "\\textln" [Print_arg]; def "\\textos" [Print_arg]; def "\\textdf" [Print_arg]; def "\\textsw" [Print_arg]; def "\\rm" []; def "\\cal" []; def "\\emph" [Print "" ; Print_arg ; Print ""]; def "\\mbox" [Print_arg]; def "\\footnotesize" []; def "\\etalchar" [ Print "" ; Raw_arg print_s ; Print "" ]; def "\\newblock" [Print " "]; (* Environments *) def "\\begin{itemize}" [Print "

"]; def "\\begin{enumerate}" [Print "

    "]; def "\\end{enumerate}" [Print "
"]; def "\\begin{description}" [Print "

"]; def "\\end{description}" [Print "
"]; def "\\begin{center}" [Print "
"]; def "\\end{center}" [Print "
"]; def "\\begin{htmlonly}" []; def "\\end{htmlonly}" []; def "\\begin{flushleft}" [Print "
"]; def "\\end{flushleft}" [Print "
"]; (* Special characters *) def "\\ " [Print " "]; def "\\\n" [Print " "]; def "\\{" [Print "{"]; def "\\}" [Print "}"]; def "\\l" [Print "l"]; def "\\oe" [Print "œ"]; def "\\OE" [Print "Œ"]; def "\\o" [Print "ø"]; def "\\O" [Print "Ø"]; def "\\ae" [Print "æ"]; def "\\AE" [Print "Æ"]; def "\\aa" [Print "å"]; def "\\AA" [Print "Å"]; def "\\&" [Print "&"]; def "\\$" [Print "$"]; def "\\%" [Print "%"]; def "\\_" [Print "_"]; def "\\slash" [Print "/"]; def "\\copyright" [Print "(c)"]; def "\\th" [Print "þ"]; def "\\TH" [Print "Þ"]; def "\\dh" [Print "ð"]; def "\\DH" [Print "Ð"]; def "\\ss" [Print "ß"]; def "\\'" [Raw_arg(function "e" -> print_s "é" | "E" -> print_s "É" | "a" -> print_s "á" | "A" -> print_s "Á" | "o" -> print_s "ó" | "O" -> print_s "Ó" | "i" -> print_s "í" | "\\i" -> print_s "í" | "I" -> print_s "Í" | "u" -> print_s "ú" | "U" -> print_s "Ú" | "'" -> print_s "”" | "c" -> print_s "ć" | "y" -> print_s "ý" | "Y" -> print_s "Ý" | "" -> print_c '\'' | s -> print_s s)]; def "\\`" [Raw_arg(function "e" -> print_s "è" | "E" -> print_s "È" | "a" -> print_s "à" | "A" -> print_s "À" | "o" -> print_s "ò" | "O" -> print_s "Ò" | "i" -> print_s "ì" | "\\i" -> print_s "ì" | "I" -> print_s "Ì" | "u" -> print_s "ù" | "U" -> print_s "Ù" | "`" -> print_s "“" | "" -> print_s "‘" | s -> print_s s)]; def "\\~" [Raw_arg(function "n" -> print_s "ñ" | "N" -> print_s "Ñ" | "o" -> print_s "õ" | "O" -> print_s "Õ" | "a" -> print_s "ã" | "A" -> print_s "Ã" | "" -> print_s "˜" | s -> print_s s)]; def "\\c" [Raw_arg(function "c" -> print_s "ç" | s -> print_s s)]; def "\\^" [Raw_arg(function "a" -> print_s "â" | "A" -> print_s "Â" | "e" -> print_s "ê" | "E" -> print_s "Ê" | "i" -> print_s "î" | "\\i" -> print_s "î" | "I" -> print_s "Î" | "o" -> print_s "ô" | "O" -> print_s "Ô" | "u" -> print_s "û" | "U" -> print_s "Û" | "" -> print_c '^' | s -> print_s s)]; def "\\hat" [Raw_arg(function "a" -> print_s "â" | "A" -> print_s "Â" | "e" -> print_s "ê" | "E" -> print_s "Ê" | "i" -> print_s "î" | "\\i" -> print_s "î" | "I" -> print_s "Î" | "o" -> print_s "ô" | "O" -> print_s "Ô" | "u" -> print_s "û" | "U" -> print_s "Û" | "" -> print_c '^' | s -> print_s s)]; def "\\\"" [Raw_arg(function "e" -> print_s "ë" | "E" -> print_s "Ë" | "a" -> print_s "ä" | "A" -> print_s "Ä" | "\\i" -> print_s "ï" | "i" -> print_s "ï" | "I" -> print_s "Ï" | "o" -> print_s "ö" | "O" -> print_s "Ö" | "u" -> print_s "ü" | "U" -> print_s "Ü" | s -> print_s s)]; def "\\u" [Raw_arg print_s ]; def "\\v" [Raw_arg(function | "C" -> print_s "Č" | "c" -> print_s "č" | "D" -> print_s "Ď" | "d" -> print_s "ď" | "E" -> print_s "Ě" | "e" -> print_s "ě" | "N" -> print_s "Ň" | "n" -> print_s "ň" | "r" -> print_s "ř" | "R" -> print_s "Ř" | "s" -> print_s "š" | "S" -> print_s "Š" | "T" -> print_s "Ť" | "t" -> print_s "ť" | "\\i" -> print_s "ĭ" | "i" -> print_s "ĭ" | "I" -> print_s "Ĭ" | "Z" -> print_s "Ž" | "z" -> print_s "ž" | s -> print_s s)]; def "\\H" [Raw_arg (function | "O" -> print_s "Ő" | "o" -> print_s "ő" | "U" -> print_s "Ű" | "u" -> print_s "ű" | s -> print_s s)]; def "\\r" [Raw_arg (function | "U" -> print_s "Ů" | "u" -> print_s "ů" | s -> print_s s)]; (* Math macros *) def "\\[" [Print "
"]; def "\\]" [Print "\n
"]; def "\\le" [Print "<="]; def "\\leq" [Print "<="]; def "\\log" [Print "log"]; def "\\ge" [Print ">="]; def "\\geq" [Print ">="]; def "\\neq" [Print "<>"]; def "\\circ" [Print "o"]; def "\\bigcirc" [Print "O"]; def "\\sim" [Print "~"]; def "\\(" [Print ""]; def "\\)" [Print ""]; def "\\mapsto" [Print "|->"]; def "\\times" [Print "×"]; def "\\neg" [Print "¬"]; def "\\frac" [Print "("; Print_arg; Print ")/("; Print_arg; Print ")"]; (* Math symbols printed as texts (could we do better?) *) def "\\ne" [Print "=/="]; def "\\in" [Print "in"]; def "\\forall" [Print "for all"]; def "\\exists" [Print "there exists"]; def "\\vdash" [Print "|-"]; def "\\ln" [Print "ln"]; def "\\gcd" [Print "gcd"]; def "\\min" [Print "min"]; def "\\max" [Print "max"]; def "\\exp" [Print "exp"]; def "\\rightarrow" [Print "->"]; def "\\to" [Print "->"]; def "\\longrightarrow" [Print "-->"]; def "\\Rightarrow" [Print "=>"]; def "\\leftarrow" [Print "<-"]; def "\\longleftarrow" [Print "<--"]; def "\\Leftarrow" [Print "<="]; def "\\leftrightarrow" [Print "<->"]; def "\\sqrt" [Print "sqrt("; Print_arg; Print ")"]; def "\\vee" [Print "V"]; def "\\lor" [Print "V"]; def "\\wedge" [Print "/\\"]; def "\\land" [Print "/\\"]; def "\\parallel" [Print "||"]; def "\\mid" [Print "|"]; def "\\cup" [Print "U"]; def "\\inf" [Print "inf"]; (* Misc. macros. *) def "\\TeX" [Print "TEX"]; def "\\LaTeX" [Print "LATEX"]; def "\\LaTeXe" [Print "LATEX 2e"]; def "\\tm" [Print "TM"]; def "\\par" [Print "

"]; def "\\@" []; def "\\#" [Print "#"]; def "\\/" []; def "\\-" []; def "\\left" []; def "\\right" []; def "\\smallskip" []; def "\\medskip" []; def "\\bigskip" []; def "\\relax" []; def "\\markboth" [Skip_arg; Skip_arg]; def "\\dots" [Print "..."]; def "\\dot" [Print "."]; def "\\simeq" [Print "˜="]; def "\\approx" [Print "˜"]; def "\\^circ" [Print "°"]; def "\\ldots" [Print "..."]; def "\\cdot" [Print "·"]; def "\\cdots" [Print "..."]; def "\\newpage" []; def "\\hbox" [Print_arg]; def "\\noindent" []; def "\\label" [Print ""]; def "\\ref" [Print "(ref)"]; def "\\index" [Skip_arg]; def "\\\\" [Print "
"]; def "\\," []; def "\\;" []; def "\\!" []; def "\\hspace" [Skip_arg; Print " "]; def "\\symbol" [Raw_arg (function s -> try let n = int_of_string s in print_c (Char.chr n) with _ -> ())]; def "\\html" [Raw_arg print_s]; (* hyperref *) def "\\href" [Print ""; Print_arg; Print ""]; (* Bibliography *) def "\\begin{thebibliography}" [Print "

References

\n
\n"; Skip_arg]; def "\\end{thebibliography}" [Print "
"]; def "\\bibitem" [Raw_arg (function r -> print_s "
["; print_s r; print_s "]\n"; print_s "
")]; (* Greek letters *) (*** List.iter (fun symbol -> def ("\\" ^ symbol) [Print ("" ^ symbol ^ "")]) ["alpha";"beta";"gamma";"delta";"epsilon";"varepsilon";"zeta";"eta"; "theta";"vartheta";"iota";"kappa";"lambda";"mu";"nu";"xi";"pi";"varpi"; "rho";"varrho";"sigma";"varsigma";"tau";"upsilon";"phi";"varphi"; "chi";"psi";"omega";"Gamma";"Delta";"Theta";"Lambda";"Xi";"Pi"; "Sigma";"Upsilon";"Phi";"Psi";"Omega"]; ***) def "\\alpha" [Print "α"]; def "\\beta" [Print "β"]; def "\\gamma" [Print "γ"]; def "\\delta" [Print "δ"]; def "\\epsilon" [Print "ε"]; def "\\varepsilon" [Print "ε"]; def "\\zeta" [Print "ζ"]; def "\\eta" [Print "η"]; def "\\theta" [Print "θ"]; def "\\vartheta" [Print "θ"]; def "\\iota" [Print "ι"]; def "\\kappa" [Print "κ"]; def "\\lambda" [Print "λ"]; def "\\mu" [Print "μ"]; def "\\nu" [Print "ν"]; def "\\xi" [Print "ξ"]; def "\\pi" [Print "π"]; def "\\varpi" [Print "ϖ"]; def "\\rho" [Print "ρ"]; def "\\varrho" [Print "ρ"]; def "\\sigma" [Print "σ"]; def "\\varsigma" [Print "ς"]; def "\\tau" [Print "τ"]; def "\\upsilon" [Print "υ"]; def "\\phi" [Print "φ"]; def "\\varphi" [Print "φ"]; def "\\chi" [Print "χ"]; def "\\psi" [Print "ψ"]; def "\\omega" [Print "ω"]; def "\\Gamma" [Print "Γ"]; def "\\Delta" [Print "Δ"]; def "\\Theta" [Print "Θ"]; def "\\Lambda" [Print "Λ"]; def "\\Xi" [Print "Ξ"]; def "\\Pi" [Print "Π"]; def "\\Sigma" [Print "Σ"]; def "\\Upsilon" [Print "Υ"]; def "\\Phi" [Print "Φ"]; def "\\Psi" [Print "Ψ"]; def "\\Omega" [Print "Ω"]; (* macros for the AMS styles *) def "\\bysame" [Print "           "]; def "\\MR" [Raw_arg (fun s -> let mr = try let i = String.index s ' ' in if i=0 then raise Not_found; String.sub s 0 i with Not_found -> s in print_s "MR "; print_s s; print_s "")]; def "\\MRhref" [Print ""; Print_arg; Print ""]; (* macros for the aaai-named style *) def "\\em" []; def "\\protect" []; def "\\bgroup" []; (* should go into latexscan? *) def "\\egroup" []; (* should go into latexscan? *) def "\\citename" []; () (*s Macros for German BibTeX style. *) let is_german_style = function | "gerabbrv" | "geralpha" | "gerapali" | "gerplain" | "gerunsrt" -> true | _ -> false let init_style_macros st = if is_german_style st then begin List.iter (fun (m,s) -> def m [ Print s; Print_arg ]) [ "\\btxetalshort", "et al" ; "\\btxeditorshort", "Hrsg"; "\\Btxeditorshort", "Hrsg"; "\\btxeditorsshort", "Hrsg"; "\\Btxeditorsshort", "Hrsg"; "\\btxvolumeshort", "Bd"; "\\Btxvolumeshort", "Bd"; "\\btxnumbershort", "Nr"; "\\Btxnumbershort", "Nr"; "\\btxeditionshort", "Aufl"; "\\Btxeditionshort", "Aufl"; "\\btxchaptershort", "Kap"; "\\Btxchaptershort", "Kap"; "\\btxpageshort", "S"; "\\Btxpageshort", "S"; "\\btxpagesshort", "S"; "\\Btxpagesshort", "S"; "\\btxtechrepshort", "Techn. Ber"; "\\Btxtechrepshort", "Techn. Ber"; "\\btxmonjanshort", "Jan"; "\\btxmonfebshort", "Feb"; "\\btxmonaprshort", "Apr"; "\\btxmonaugshort", "Aug"; "\\btxmonsepshort", "Sep"; "\\btxmonoctshort", "Okt"; "\\btxmonnovshort", "Nov"; "\\btxmondecshort", "Dez"; ]; List.iter (fun (m,s) -> def m [ Skip_arg; Print s]) [ "\\btxetallong", "et alii"; "\\btxandshort", "und"; "\\btxandlong", "und"; "\\btxinlong", "in:"; "\\btxinshort", "in:"; "\\btxofseriesshort", "d. Reihe"; "\\btxinseriesshort", "in"; "\\btxofserieslong", "der Reihe"; "\\btxinserieslong", "in"; "\\btxeditorlong", "Herausgeber"; "\\Btxeditorlong", "Herausgeber"; "\\btxeditorslong", "Herausgeber"; "\\Btxeditorslong", "Herausgeber"; "\\btxvolumelong", "Band"; "\\Btxvolumelong", "Band"; "\\btxnumberlong", "Nummer"; "\\Btxnumberlong", "Nummer"; "\\btxeditionlong", "Auflage"; "\\Btxeditionlong", "Auflage"; "\\btxchapterlong", "Kapitel"; "\\Btxchapterlong", "Kapitel"; "\\btxpagelong", "Seite"; "\\Btxpagelong", "Seite"; "\\btxpageslong", "Seiten"; "\\Btxpageslong", "Seiten"; "\\btxmastthesis", "Diplomarbeit"; "\\btxphdthesis", "Doktorarbeit"; "\\btxtechreplong", "Technischer Bericht"; "\\Btxtechreplong", "Technischer Bericht"; "\\btxmonjanlong", "Januar"; "\\btxmonfeblong", "Februar"; "\\btxmonmarlong", "März"; "\\btxmonaprlong", "April"; "\\btxmonmaylong", "Mai"; "\\btxmonjunlong", "Juni"; "\\btxmonjullong", "Juli"; "\\btxmonauglong", "August"; "\\btxmonseplong", "September"; "\\btxmonoctlong", "Oktober"; "\\btxmonnovlong", "November"; "\\btxmondeclong", "Dezember"; "\\btxmonmarshort", "März"; "\\btxmonmayshort", "Mai"; "\\btxmonjunshort", "Juni"; "\\btxmonjulshort", "Juli"; "\\Btxinlong", "In:"; "\\Btxinshort", "In:"; ] end