Browse Source

katex

master
alistair 3 years ago
parent
commit
60e1ad859f
  1. 27
      main.cpp
  2. 11
      notes/math.md
  3. 35
      notes/math.sync-conflict-20210727-160813-SROMGUW.md
  4. 5
      notes/syntax.md

27
main.cpp

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
#include <queue>
#include <base64.h>
#define katex_support
extern "C" {
/*
@ -67,7 +68,6 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in @@ -67,7 +68,6 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in
#include "itex2MML.h"
#include "mtex2MML.h"
#include "SimpleSvg.hh"
namespace lex {
extern "C" {
@ -509,7 +509,6 @@ class builder { @@ -509,7 +509,6 @@ class builder {
std::unordered_map<fs::path, time_t, pathHash> last_build;
gnu_highlighter shl {};
imtex::Imtex imtx {};
SimpleSVG mathRenderer{} ;
const std::set<std::string> apply_templates_exts {"md","html", "txt", "markdown", "xml", "atom", "rss"};
@ -558,30 +557,24 @@ class builder { @@ -558,30 +557,24 @@ class builder {
const std::string tt {(const char *)text, (const char *)text + len};
#ifdef katex_support
std::string mtext = dukengine.eval_katex(tt);
std::string mathtext = dukengine.eval_katex(tt);
#endif
std::string mtext = imtx.get_svg_from_mtex(tt);
// std::string mtext = imtx.get_svg_from_mtex(tt);
const unsigned char local_name[] = "math";
std::string style = "inline-math";
if (text[1] == '[')
style = "display-math";
// auto mathtext = "<img src='data:image/svg+xml;base64, " + base64_encode_mime(mtext) + "'/>";
lxb_html_element_t * ele = lxb_html_document_create_element(document, local_name,
(size_t)4, nullptr);
lxb_html_element_t * elem = lxb_html_document_create_element(document, (const unsigned char *)"img", 3, NULL);
auto nelem = lxb_dom_interface_element(elem);
std::string alttext = tt.substr(2, tt.length() - 4);
auto imgsrc = "data:image/svg+xml;base64, " + base64_encode_mime(mtext);
lxb_dom_element_set_attribute(nelem, (const unsigned char*)"alt", 3, (const unsigned char*)alttext.c_str(), alttext.length());
lxb_dom_element_set_attribute(nelem, (const unsigned char*)"src", 3, (const unsigned char*)imgsrc.c_str(), imgsrc.length());
lxb_dom_element_set_attribute(nelem, (const unsigned char*)"class", 5, (const unsigned char*)style.c_str(), style.length());
auto elem = lxb_dom_interface_element(ele);
lxb_dom_node_t *n = lxb_html_document_parse_fragment(document,
elem, (const unsigned char *)mathtext.c_str(), mathtext.length());
lxb_dom_node_insert_after(&element->node, lxb_dom_interface_node(nelem));
lxb_dom_node_insert_after(&element->node, n);
lxb_dom_node_remove(&element->node);
}

11
notes/math.md

@ -35,3 +35,14 @@ curl -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmex10.ttf \ @@ -35,3 +35,14 @@ curl -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmex10.ttf \
source: https://github.com/gjtorikian/mathematical
azip of all t3 fonts: https://mirror.aarnet.edu.au/pub/CTAN/fonts/cm/ps-type3.zip
### Alternative to Lexbor
- libtidy to convert to XHTML
- https://api.html-tidy.org/tidy/tidylib_api_5.8.0/libtidy_04.html
- pugixml to edit XHTML
- https://pugixml.org/docs/quickstart.html
- use katex in quickjs to render math

35
notes/math.sync-conflict-20210727-160813-SROMGUW.md

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
Wikipedia uses mathml on top of svg with the following css:
```css
.mwe-math-mathml-a11y {
clip: rect(1px,1px,1px,1px);
overflow: hidden;
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
```
The mathml is before the image, with overflow hidden set and 0 opacity. The latex is set as the SVG's alt text.
Each equation is its own request.
## Fonts
Fonts can be downloaded this way
```sh
curl -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmex10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmmi10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmr10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmsy10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/esint10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/eufm10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/msam10.ttf \
-LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/msbm10.ttf
```
source: https://github.com/gjtorikian/mathematical

5
notes/syntax.md

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
- syntax can be generated using syntect
- https://crates.io/crates/syntect
- Write a c interface to the rust library and call the c interface from c++.
Loading…
Cancel
Save