package quickterface

  1. Overview
  2. Docs
Quick-to-program app interfaces in OCaml for terminal and web

Install

dune-project
 Dependency

Authors

Maintainers

Sources

quickterface-0.1.0.tbz
sha256=8261e3819564fb5d05f1f313e62b73382152591d7a4349ae5b1b08a4fc2469f3
sha512=e739a971bb0e696ab716c168419c59a3d195922d2d1e4963106a845e3442ffa085b05106f36cceeec9b806bf7d6ef2c31e98db04911fbf73c5ac0ce626449d0f

doc/src/quickterface/math.ml.html

Source file math.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
open! Core

type t =
  | Char of char
  | Literal of string
  | Infinity
  | Pi
  | E
  | Equals
  | Plus
  | Minus
  | Star
  | C_dot
  | Times
  | Divide
  | Plus_minus
  | Superscript of { base : t; superscript : t }
  | Subscript of { base : t; subscript : t }
  | Exp
  | Ln
  | Sin
  | Cos
  | List of t list
  | Frac of t * t
  | Bracketed of t
  | Partial
  | Integral of { lower : t option; upper : t option; body : t }
  | Less_than
  | Less_than_or_equal_to
  | Greater_than
  | Greater_than_or_equal_to
  | Not_equal
  | Approximately_equals
  | Equivalent_to

let rec latex_string_of_t = function
  | Char c -> Char.to_string c
  | Literal s -> s
  | Infinity -> "\\infty"
  | Pi -> "\\pi"
  | E -> "e"
  | Equals -> "="
  | Plus -> "+"
  | Minus -> "-"
  | Star -> "*"
  | C_dot -> "\\cdot"
  | Times -> "\\times"
  | Divide -> "\\div"
  | Plus_minus -> "\\pm"
  | Superscript { base; superscript } ->
      sprintf "{%s}^{%s}" (latex_string_of_t base)
        (latex_string_of_t superscript)
  | Subscript { base; subscript } ->
      sprintf "{%s}_{%s}" (latex_string_of_t base) (latex_string_of_t subscript)
  | Exp -> "\\exp"
  | Ln -> "\\ln"
  | Sin -> "\\sin"
  | Cos -> "\\cos"
  | List elements ->
      elements |> List.map ~f:latex_string_of_t |> String.concat ~sep:" "
  | Frac (num, denom) ->
      sprintf "\\frac{%s}{%s}" (latex_string_of_t num) (latex_string_of_t denom)
  | Bracketed inner -> sprintf "\\left(%s\\right)" (latex_string_of_t inner)
  | Partial -> "\\partial"
  | Integral { lower; upper; body } ->
      let lower_str =
        match lower with
        | None -> ""
        | Some l -> sprintf "_{%s}" (latex_string_of_t l)
      in
      let upper_str =
        match upper with
        | None -> ""
        | Some u -> sprintf "^{%s}" (latex_string_of_t u)
      in
      sprintf "\\int%s%s %s" lower_str upper_str (latex_string_of_t body)
  | Less_than -> "<"
  | Less_than_or_equal_to -> "\\leq"
  | Greater_than -> ">"
  | Greater_than_or_equal_to -> "\\geq"
  | Not_equal -> "\\neq"
  | Approximately_equals -> "\\approx"
  | Equivalent_to -> "\\equiv"