Skip to content

Instantly share code, notes, and snippets.



Last active Oct 15, 2019
What would you like to do?
[F#] Fable + MathJax
open System
open Fable.Core
open Fable.Core.JsInterop
open Browser.Types
open Browser
// ref.
[<Emit("convert($0, $1)")>]
let render output (input:string): unit = jsNative
let matrix m = seq {
yield @"\left(\begin{matrix}"
for ms in m do
yield String.concat " & " ms + @" \\"
yield @"\end{matrix}\right)" }
seq {
let v = [["a"]; ["b"]; ["c"]]
let w = [["d" ; "e" ; "f"]]
yield! matrix v
yield! matrix w
yield "="
yield! v |> Seq.mapi (fun i r ->
w.[0] |> Seq.mapi (fun j c ->
if i = j then "inner" else "exterior"
|> sprintf @"\underbrace{%s%s}_{%s}" r.[0] c))
|> matrix }
|> String.concat System.Environment.NewLine
|> render (document.getElementById "math")
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<!-- ref. -->
<script src=""></script>
<script id="MathJax-script" src=""></script>
<div id="math"></div>
function convert(output, input) {
output.innerHTML = '';
var options = MathJax.getMetricsFor(output);
options.display = true;
MathJax.tex2chtmlPromise(input, options).then(function (node) {
// The promise returns the typeset node, which we add to the output
// Then update the document to include the adjusted CSS for the
// content of the new equation.
}).catch(function (err) {
// If there was an error, put the message into the output instead
var pre = output.appendChild(document.createElement('pre'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment