aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2017-01-14 19:41:27 -0800
committerbnewbold <bnewbold@robocracy.org>2017-01-14 19:52:56 -0800
commit0306854192ba35861d2365a00f080e1f7710e03b (patch)
tree00c047e814d75baf6008ef120fe57cdfb5102e44
parenta71465e935a178478d269e828550b7e3fc475fab (diff)
downloadmodelthing-0306854192ba35861d2365a00f080e1f7710e03b.tar.gz
modelthing-0306854192ba35861d2365a00f080e1f7710e03b.zip
add latex (via katex) to model pages
-rw-r--r--src/bin/mt-webface.rs3
-rw-r--r--webface/templates/base.html1
-rw-r--r--webface/templates/model_view.html28
3 files changed, 29 insertions, 3 deletions
diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs
index 5361a73..ed0cacb 100644
--- a/src/bin/mt-webface.rs
+++ b/src/bin/mt-webface.rs
@@ -21,6 +21,7 @@ use pencil::method::{Get, Post};
use regex::Regex;
use modelthing::transpile_scheme::TranspileScheme;
use modelthing::transpile_js::TranspileJS;
+use modelthing::transpile_latex::TranspileLaTeX;
/*
This command doesn't use error_chain (or raise errors in general) because the
@@ -84,6 +85,7 @@ fn model_view(r: &mut Request) -> PencilResult {
context.insert("markdown_html".to_string(), markdown_html);
context.insert("markdown".to_string(), me.markdown.clone());
context.insert("modelica".to_string(), format!("{:?}", me.ast));
+ context.insert("latex".to_string(), me.ast.repr_latex().unwrap());
context.insert("editable".to_string(),
if namespace == "sandbox" { "true".to_string() } else { "".to_string() });
r.app.render_template("model_view.html", &context)
@@ -108,6 +110,7 @@ fn model_repr(r: &mut Request) -> PencilResult {
match format {
"scheme" => Ok(Response::from(me.ast.repr_scheme().unwrap())),
"javascript" => Ok(Response::from(me.ast.repr_js().unwrap())),
+ "latex" => Ok(Response::from(me.ast.repr_latex().unwrap())),
_ => abort(403),
}
},
diff --git a/webface/templates/base.html b/webface/templates/base.html
index 65dafa3..231dfd9 100644
--- a/webface/templates/base.html
+++ b/webface/templates/base.html
@@ -8,6 +8,7 @@ html, body, div{ margin: 0; padding: 0; }
body { font-family: monospace; font-size: larger; line-height: 1.3; }
#content { max-width: 700px; margin: 0 auto; margin-top: 4em; }
</style>
+{{~#block head}}{{/block~}}
</head>
<body>
diff --git a/webface/templates/model_view.html b/webface/templates/model_view.html
index 4218f11..7b8a64d 100644
--- a/webface/templates/model_view.html
+++ b/webface/templates/model_view.html
@@ -1,3 +1,16 @@
+{{# partial head}}
+<link href="/static/katex-0.7.0/katex.min.css" rel="stylesheet">
+<script src="/static/katex-0.7.0/katex.min.js"></script>
+<script src="/static/katex-0.7.0/contrib/auto-render.min.js"></script>
+
+<script>
+ document.addEventListener("DOMContentLoaded", function() {
+ renderMathInElement(document.body);
+ });
+</script>
+{{/partial}}
+
+
{{# partial content}}
<h1 style="margin-bottom: 0.1em;">
<a href="/m/{{namespace}}/" style="color: black; text-decoration: none;">
@@ -10,16 +23,25 @@
<a href="markdown/">markdown</a> -
<a href="raw/">modelica</a> -
<a href="repr/?format=scheme">scheme</a> -
-<a href="repr/?format=javascript">javascript</a>
+<a href="repr/?format=javascript">javascript</a> -
+<a href="repr/?format=latex">latex</a>
</span>
<p><i style="color: #222222;">{{ model_description }}</i>
<br><br>
+
+{{# if latex }}
+<div style="margin-left: 0.25em; border-left: 4px solid #BBBBBB; padding: 0.5em;" id="model_latex">
+$${{ latex }}$$
+</div>
+{{/if}}
+
+{{{ markdown_html }}}
+
+<h2>Modelica Code</h2>
<pre style="margin-left: 0.25em; border-left: 4px solid #BBBBBB; padding: 0.5em;">
{{ modelica }}</pre>
<br>
-{{{ markdown_html }}}
-
{{/partial}}
{{~> base.html~}}