summaryrefslogtreecommitdiff
path: root/math/texutil.ml
diff options
context:
space:
mode:
Diffstat (limited to 'math/texutil.ml')
-rw-r--r--math/texutil.ml30
1 files changed, 26 insertions, 4 deletions
diff --git a/math/texutil.ml b/math/texutil.ml
index ad4fce10..cc7f48fa 100644
--- a/math/texutil.ml
+++ b/math/texutil.ml
@@ -1,3 +1,4 @@
+(* vim: set sw=8 ts=8 et: *)
open Parser
open Render_info
open Tex
@@ -10,6 +11,7 @@ let tex_part = function
| MHTMLABLEC (_,t,_,_,_) -> t
| HTMLABLE_BIG (t,_) -> t
| TEX_ONLY t -> t
+
let rec render_tex = function
TEX_FQ (a,b,c) -> (render_tex a) ^ "_{" ^ (render_tex b) ^ "}^{" ^ (render_tex c) ^ "}"
| TEX_DQ (a,b) -> (render_tex a) ^ "_{" ^ (render_tex b) ^ "}"
@@ -38,28 +40,40 @@ let rec render_tex = function
(* Dynamic loading*)
type encoding_t = LATIN1 | LATIN2 | UTF8
+(* module properties *)
let modules_ams = ref false
let modules_nonascii = ref false
let modules_encoding = ref UTF8
let modules_color = ref false
+(* wrappers to easily set / reset module properties *)
let tex_use_ams () = modules_ams := true
let tex_use_nonascii () = modules_nonascii := true
let tex_use_color () = modules_color := true
-let tex_mod_reset () = (modules_ams := false; modules_nonascii := false; modules_encoding := UTF8; modules_color := false)
+let tex_mod_reset () = (
+ modules_ams := false;
+ modules_nonascii := false;
+ modules_encoding := UTF8;
+ modules_color := false
+ )
+(* Return TeX fragment for one of the encodings in (UTF8,LATIN1,LATIN2) *)
let get_encoding = function
UTF8 -> "\\usepackage{ucs}\n\\usepackage[utf8]{inputenc}\n"
| LATIN1 -> "\\usepackage[latin1]{inputenc}\n"
| LATIN2 -> "\\usepackage[latin2]{inputenc}\n"
+(* TeX fragment inserted before the output *)
let get_preface () = "\\nonstopmode\n\\documentclass[12pt]{article}\n" ^
(if !modules_nonascii then get_encoding !modules_encoding else "") ^
(if !modules_ams then "\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n" else "") ^
(if !modules_color then "\\usepackage[dvips,usenames]{color}\n" else "") ^
"\\usepackage{cancel}\n\\pagestyle{empty}\n\\begin{document}\n$$\n"
+
+(* TeX fragment appended after the content *)
let get_footer () = "\n$$\n\\end{document}\n"
+(* Default to UTF8 *)
let set_encoding = function
"ISO-8859-1" -> modules_encoding := LATIN1
| "iso-8859-1" -> modules_encoding := LATIN1
@@ -80,7 +94,7 @@ let find = function
| "\\Gamma" -> LITERAL (HTMLABLEC (FONT_UF, "\\Gamma ", "Γ"))
| "\\delta" -> LITERAL (HTMLABLEC (FONT_UF, "\\delta ", "δ"))
| "\\Delta" -> LITERAL (HTMLABLEC (FONT_UF, "\\Delta ", "Δ"))
- | "\\epsilon" -> LITERAL (HTMLABLEC (FONT_UF, "\\epsilon ", "ε"))
+ | "\\epsilon" -> LITERAL (TEX_ONLY "\\epsilon ")
| "\\Epsilon" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
"\\mathrm{E}", "Ε")))
| "\\varepsilon" -> LITERAL (TEX_ONLY "\\varepsilon ")
@@ -119,7 +133,7 @@ let find = function
| "\\Rho" -> (tex_use_ams (); LITERAL (HTMLABLEC (FONT_UF,
"\\mathrm{P}", "Ρ")))
| "\\varrho" -> LITERAL (TEX_ONLY "\\varrho ")
- | "\\sim" -> LITERAL (HTMLABLEC (FONT_UF, "\\sim ", "˜"))
+ | "\\sim" -> LITERAL (HTMLABLEC (FONT_UF, "\\sim ", "∼"))
| "\\sigma" -> LITERAL (HTMLABLEC (FONT_UF, "\\sigma ", "σ"))
| "\\Sigma" -> LITERAL (HTMLABLEC (FONT_UF, "\\Sigma ", "Σ"))
| "\\varsigma" -> LITERAL (TEX_ONLY "\\varsigma ")
@@ -128,7 +142,7 @@ let find = function
"\\mathrm{T}", "Τ")))
| "\\upsilon" -> LITERAL (HTMLABLEC (FONT_UF, "\\upsilon ", "υ"))
| "\\Upsilon" -> LITERAL (HTMLABLEC (FONT_UF, "\\Upsilon ", "Υ"))
- | "\\phi" -> LITERAL (HTMLABLEC (FONT_UF, "\\phi ", "φ"))
+ | "\\phi" -> LITERAL (TEX_ONLY "\\phi ")
| "\\Phi" -> LITERAL (HTMLABLEC (FONT_UF, "\\Phi ", "Φ"))
| "\\varphi" -> LITERAL (TEX_ONLY "\\varphi ")
| "\\chi" -> LITERAL (HTMLABLEC (FONT_UF, "\\chi ", "χ"))
@@ -409,6 +423,10 @@ let find = function
| "\\mod" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UFH,"\\mod ", "mod")))
| "\\Diamond" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\Diamond ", "◊")))
| "\\dotsb" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\dotsb ", "⋅⋅⋅")))
+ | "\\dotsc" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\dotsc ", "...")))
+ | "\\dotsi" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\dotsi ", "⋅⋅⋅")))
+ | "\\dotsm" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\dotsm ", "⋅⋅⋅")))
+ | "\\dotso" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UF, "\\dotso ", "...")))
| "\\reals" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UFH,"\\mathbb{R}", "<b>R</b>")))
| "\\Reals" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UFH,"\\mathbb{R}", "<b>R</b>")))
| "\\R" -> (tex_use_ams (); LITERAL (HTMLABLE (FONT_UFH,"\\mathbb{R}", "<b>R</b>")))
@@ -508,12 +526,15 @@ let find = function
| "\\over" -> FUN_INFIXh ("\\over ", fun num den -> Html.html_render num, "<hr style=\"{background: black}\"/>", Html.html_render den)
| "\\sqrt" -> FUN_AR1 "\\sqrt "
| "\\cancel" -> FUN_AR1 "\\cancel "
+ | "\\bcancel" -> FUN_AR1 "\\bcancel "
+ | "\\xcancel" -> FUN_AR1 "\\xcancel "
| "\\cancelto" -> FUN_AR2 "\\cancelto "
| "\\pmod" -> FUN_AR1hl ("\\pmod ", ("(mod ", ")"))
| "\\bmod" -> FUN_AR1hl ("\\bmod ", ("mod ", ""))
| "\\emph" -> FUN_AR1 "\\emph "
| "\\texttt" -> FUN_AR1 "\\texttt "
| "\\textbf" -> FUN_AR1 "\\textbf "
+ | "\\textsf" -> FUN_AR1 "\\textsf "
| "\\textit" -> FUN_AR1hf ("\\textit ", FONTFORCE_IT)
| "\\textrm" -> FUN_AR1hf ("\\textrm ", FONTFORCE_RM)
| "\\rm" -> DECLh ("\\rm ", FONTFORCE_RM)
@@ -726,6 +747,7 @@ let find = function
| "\\mathsf" -> (tex_use_ams (); FUN_AR1 "\\mathsf ")
| "\\mathcal" -> (tex_use_ams (); FUN_AR1 "\\mathcal ")
| "\\mathbb" -> (tex_use_ams (); FUN_AR1 "\\mathbb ")
+ | "\\mathtt" -> (tex_use_ams (); FUN_AR1 "\\mathtt ")
| "\\mathfrak" -> (tex_use_ams (); FUN_AR1 "\\mathfrak ")
| "\\operatorname" -> (tex_use_ams (); FUN_AR1 "\\operatorname ")
| "\\text" -> raise (Failure "malformatted \\text")