@ -21,6 +21,8 @@
@@ -21,6 +21,8 @@
# include <thread>
# include <queue>
# include <base64.h>
extern " C " {
/*
* https : //gitlab.gnome.org/GNOME/lasem/-/tree/master/
@ -64,6 +66,7 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in
@@ -64,6 +66,7 @@ They are provided by the lyx-fonts package in fedora, and the ttf-lyx package in
# include "srchighlight.hpp"
# include "itex2MML.h"
# include "mtex2MML.h"
namespace lex {
extern " C " {
@ -190,34 +193,31 @@ class Imtex {
@@ -190,34 +193,31 @@ class Imtex {
}
std : : string get_svg_from_i tex ( const std : : string & itex ) {
auto doc =
LSM_DOM_DOCUMENT ( lsm_mathml_document_new_from_itex ( itex . c_str ( ) , itex . size ( ) , NULL ) ) ;
std : : string get_svg_from_m tex ( const std : : string & itex ) {
char * mml = mtex2MML_parse ( itex . c_str ( ) , itex . size ( ) , 0 ) ;
if ( doc = = NULL ) {
if ( ! mml ) {
spdlog : : error ( " Failed to parse itex {} " , itex ) ;
return itex ;
}
/* if (!_hide_before_object (doc, option_element_id)) {
g_object_unref ( doc ) ;
spdlog : : error ( " Invalid document? " ) ;
return itex ;
}
*/
//auto doc = LSM_DOM_DOCUMENT(mml);
char * tbuffer ;
gsize size ;
auto doc = lsm_dom_document_new_from_memory ( mml , - 1 , NULL ) ;
lsm_dom_document_save_to_memory ( doc , & tbuffer , & size , NULL ) ;
mtex2MML_free_string ( mml ) ;
std : : string mathml { tbuffer , tbuffer + size } ;
spdlog : : info ( " Mathml: {} " , mathml ) ;
char * tbuffer ;
gsize size ;
lsm_dom_document_save_to_memory ( doc , & tbuffer , & size , NULL ) ;
g_free ( tbuffer ) ;
std : : string mathml { tbuffer , tbuffer + size } ;
spdlog : : info ( " Mathml: {} " , mathml ) ;
g_free ( tbuffer ) ;
auto view = lsm_dom_document_create_view ( doc ) ;
lsm_dom_view_set_resolution ( view , option_ppi ) ;
@ -229,7 +229,6 @@ class Imtex {
@@ -229,7 +229,6 @@ class Imtex {
//auto surface = cairo_svg_surface_create (output_filename,
// width_pt, height_pt);
std : : string bufer { } ;
cairo_surface_t * surface = cairo_svg_surface_create_for_stream ( cairo_stream_to_buffer_func , ( void * ) & bufer , width_pt , height_pt ) ;
@ -292,7 +291,7 @@ const std::string TEST_PORT = "8000";
@@ -292,7 +291,7 @@ const std::string TEST_PORT = "8000";
static volatile bool continue_running = true ;
const std : : string short_info ( " stgen3 prerelease from git.tops ot.net (c) 2020-2021 Alistair Michael. " ) ;
const std : : string short_info ( " stgen3 prerelease from git.topos t.net (c) 2020-2021 Alistair Michael. " ) ;
using json = nlohmann : : json ;
namespace fs = std : : filesystem ;
@ -557,17 +556,20 @@ class builder {
@@ -557,17 +556,20 @@ class builder {
const std : : string tt { ( const char * ) text , ( const char * ) text + len } ;
# ifdef katex_support
std : : string math text = dukengine . eval_katex ( tt ) ;
std : : string mtext = dukengine . eval_katex ( tt ) ;
# endif
// ok itex only understands display math?
std : : string math text = imtx . get_svg_from_i tex ( " $$ " + tt . substr ( 2 , tt . size ( ) - 4 ) + " $$ " ) ;
std : : string mtext = imtx . get_svg_from_m tex ( " $$ " + tt . substr ( 2 , tt . size ( ) - 4 ) + " $$ " ) ;
const unsigned char local_name [ ] = " 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 ) ;
auto elem = lxb_dom_interface_element ( ele ) ;
lxb_dom_node_t * n = lxb_html_document_parse_fragment ( document ,