Browse Source

proof of concept mtex/lasem tex-svg compilation

master
alistair 3 years ago
parent
commit
23570d69ee
  1. 8
      CMakeLists.txt
  2. 44
      main.cpp

8
CMakeLists.txt

@ -54,11 +54,12 @@ endif() @@ -54,11 +54,12 @@ endif()
link_directories(${GLIB_LIBRARY_DIRS})
ADD_EXECUTABLE(stgen3 util.cpp darkhttpd.c duktape/src/duktape.c markdown.cpp main.cpp)
ADD_EXECUTABLE(stgen3 util.cpp darkhttpd.c duktape/src/duktape.c markdown.cpp
main.cpp lib/cpp-base64/base64.cpp)
target_include_directories(stgen3 PRIVATE include duktape/src itexToMML/itex-src
lib/lasem/src )
target_include_directories(stgen3 PRIVATE include duktape/src lib/mtex2MML/src itexToMML/itex-src
lib/lasem/src lib/cpp-base64)
# Horrible Horrible headers for lasem
target_include_directories(stgen3 PRIVATE ${GLIB_INCLUDE_DIRS} /usr/include/cairo /usr/include/gdk-pixbuf-2.0 /usr/include/pango-1.0 /usr/include/harfbuzz/)
@ -74,6 +75,7 @@ add_definitions(${GLIB_CFLAGS_OTHER}) @@ -74,6 +75,7 @@ add_definitions(${GLIB_CFLAGS_OTHER})
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/MultiMarkdown/build/libMultiMarkdown.a)
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/itexToMML/itex-src/libitex2MML.a)
target_link_libraries(stgen3 PRIVATE ${CMAKE_SOURCE_DIR}/lib/mtex2MML/build/libmtex2MML.a)
target_link_libraries(stgen3 PRIVATE tinyxml2)
target_link_libraries(stgen3 PRIVATE lexbor )
target_link_libraries(stgen3 PRIVATE source-highlight)

44
main.cpp

@ -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_itex(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_mtex(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.topsot.net (c) 2020-2021 Alistair Michael.");
const std::string short_info("stgen3 prerelease from git.topost.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 mathtext = dukengine.eval_katex(tt);
std::string mtext = dukengine.eval_katex(tt);
#endif
// ok itex only understands display math?
std::string mathtext = imtx.get_svg_from_itex("$$" + tt.substr(2, tt.size() - 4) + "$$");
std::string mtext = imtx.get_svg_from_mtex("$$" + 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,

Loading…
Cancel
Save