NanoMichael / MicroTeX

A dynamic, cross-platform, and embeddable LaTeX rendering library
MIT License
418 stars 69 forks source link

Merge openmath refactor #73

Closed NanoMichael closed 3 years ago

NanoMichael commented 3 years ago
NanoMichael commented 3 years ago

This pull request merged the major improvements and refactors from the openmath branch. The major improvements are:

and something I forgot... I have adapted the cmake and the meson builds files, and @Alexxey593 might want to take a look at the file src/QTLatex.pri.

@sp1ritCS @PikachuHy @LyesSaadi @Alexxey593, I sincerely invite you to review my pull request, any comment is very appreciated.

sp1ritCS commented 3 years ago

Great, I don't see any issues with it and it seems to even be a drop-in replacement to the old one :).

However, it might be worth implementing the stuff from #72, as #72 will have no chance of working once this here is merged. If you could change ln 65 of src/meson.build from clatexmath to clatexmath_dep (this seems to be meson convention).

If you want to you can then just throw the clatexmath.wrap into your root (as there isn't any directory for this kind of stuff).

PikachuHy commented 3 years ago

Wow, cool

PikachuHy commented 3 years ago

When building with MSVC, I meet

LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\LaTeXQtSample.dir\LaTeXQtSample_autogen\mocs_compilation.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_texwidget.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_mainwindow.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_main.cpp.obj /out:LaTeX.exe /implib:LaTeX.lib /pdb:LaTeX.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\Qt\6.0.0\msvc2019_64\lib\Qt6Widgetsd.lib LaTeX.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Guid.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Cored.lib mpr.lib userenv.lib d3d11.lib dxgi.lib dxguid.lib C:\app\vcpkg\installed\x64-windows\debug\lib\tinyxml2d.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\LaTeXQtSample.dir/intermediate.manifest CMakeFiles\LaTeXQtSample.dir/manifest.res" failed (exit code 1120) with the following output:
LaTeX.lib(render.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z) referenced in function "public: virtual bool __cdecl tex::DefaultTeXFont::hasNextLarger(class tex::Char const &)" (?hasNextLarger@DefaultTeXFont@tex@@UEAA_NAEBVChar@2@@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2001: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getLigture(wchar_t,wchar_t)const " (?getLigture@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W0@Z) referenced in function "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::DefaultTeXFont::getLigature(struct tex::CharFont const &,struct tex::CharFont const &)" (?getLigature@DefaultTeXFont@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEBUCharFont@2@0@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::SymbolAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@SymbolAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(parser.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2019: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z) referenced in function "public: virtual class std::shared_ptr<class tex::Box> __cdecl tex::CedillaAtom::createBox(class tex::Environment &)" (?createBox@CedillaAtom@tex@@UEAA?AV?$shared_ptr@VBox@tex@@@std@@AEAVEnvironment@2@@Z)
LaTeX.lib(atom_char.cpp.obj) : error LNK2001: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z)
LaTeX.lib(atom_row.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::FixedCharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@FixedCharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.exe : fatal error LNK1120: 6 unresolved externals
ninja: build stopped: subcommand failed.

This may cause by inline function.

PikachuHy commented 3 years ago

However, there is no such problem when building with gcc.

PikachuHy commented 3 years ago

When building with gdi

graphic_win32.cpp(145): error C2065: 'Font_win': undeclared identifier
graphic_win32.cpp(145): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(145): error C2563: mismatch in formal parameter list
graphic_win32.cpp(145): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(145): error C2064: term does not evaluate to a function taking 3 arguments
graphic_win32.cpp(145): error C2059: syntax error: ')'
graphic_win32.cpp(185): error C2065: 'TextLayout_win': undeclared identifier
graphic_win32.cpp(185): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(185): error C2563: mismatch in formal parameter list
graphic_win32.cpp(185): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(185): error C2064: term does not evaluate to a function taking 2 arguments
graphic_win32.cpp(185): error C2059: syntax error: ')'
PikachuHy commented 3 years ago

patch.zip I will merge these patch later.

PikachuHy commented 3 years ago

for commit fix cmake build file https://github.com/NanoMichael/cLaTeXMath/pull/73/commits/a8d564ffc8e01ec5651b603e08f67a7545ec72dc Why delete other code folders? e.g. src/otf, src/unimath

PikachuHy commented 3 years ago

patch.zip I will merge these patch later.

see: https://github.com/NanoMichael/cLaTeXMath/pull/74

PikachuHy commented 3 years ago

When building with gdi

graphic_win32.cpp(145): error C2065: 'Font_win': undeclared identifier
graphic_win32.cpp(145): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(145): error C2563: mismatch in formal parameter list
graphic_win32.cpp(145): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(145): error C2064: term does not evaluate to a function taking 3 arguments
graphic_win32.cpp(145): error C2059: syntax error: ')'
graphic_win32.cpp(185): error C2065: 'TextLayout_win': undeclared identifier
graphic_win32.cpp(185): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(185): error C2563: mismatch in formal parameter list
graphic_win32.cpp(185): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(185): error C2064: term does not evaluate to a function taking 2 arguments
graphic_win32.cpp(185): error C2059: syntax error: ')'

fixed by: patch_win32.zip

PikachuHy commented 3 years ago

When building with gdi

graphic_win32.cpp(145): error C2065: 'Font_win': undeclared identifier
graphic_win32.cpp(145): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(145): error C2563: mismatch in formal parameter list
graphic_win32.cpp(145): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(145): error C2064: term does not evaluate to a function taking 3 arguments
graphic_win32.cpp(145): error C2059: syntax error: ')'
graphic_win32.cpp(185): error C2065: 'TextLayout_win': undeclared identifier
graphic_win32.cpp(185): error C2143: syntax error: missing ';' before 'constant'
graphic_win32.cpp(185): error C2563: mismatch in formal parameter list
graphic_win32.cpp(185): error C2298: missing call to bound pointer to member function
graphic_win32.cpp(185): error C2064: term does not evaluate to a function taking 2 arguments
graphic_win32.cpp(185): error C2059: syntax error: ')'

fixed by: patch_win32.zip

see https://github.com/NanoMichael/cLaTeXMath/pull/75

PikachuHy commented 3 years ago

When building with MSVC, I meet

LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\LaTeXQtSample.dir\LaTeXQtSample_autogen\mocs_compilation.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_texwidget.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_mainwindow.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_main.cpp.obj /out:LaTeX.exe /implib:LaTeX.lib /pdb:LaTeX.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\Qt\6.0.0\msvc2019_64\lib\Qt6Widgetsd.lib LaTeX.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Guid.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Cored.lib mpr.lib userenv.lib d3d11.lib dxgi.lib dxguid.lib C:\app\vcpkg\installed\x64-windows\debug\lib\tinyxml2d.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\LaTeXQtSample.dir/intermediate.manifest CMakeFiles\LaTeXQtSample.dir/manifest.res" failed (exit code 1120) with the following output:
LaTeX.lib(render.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z) referenced in function "public: virtual bool __cdecl tex::DefaultTeXFont::hasNextLarger(class tex::Char const &)" (?hasNextLarger@DefaultTeXFont@tex@@UEAA_NAEBVChar@2@@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2001: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getLigture(wchar_t,wchar_t)const " (?getLigture@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W0@Z) referenced in function "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::DefaultTeXFont::getLigature(struct tex::CharFont const &,struct tex::CharFont const &)" (?getLigature@DefaultTeXFont@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEBUCharFont@2@0@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::SymbolAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@SymbolAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(parser.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2019: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z) referenced in function "public: virtual class std::shared_ptr<class tex::Box> __cdecl tex::CedillaAtom::createBox(class tex::Environment &)" (?createBox@CedillaAtom@tex@@UEAA?AV?$shared_ptr@VBox@tex@@@std@@AEAVEnvironment@2@@Z)
LaTeX.lib(atom_char.cpp.obj) : error LNK2001: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z)
LaTeX.lib(atom_row.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::FixedCharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@FixedCharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.exe : fatal error LNK1120: 6 unresolved externals
ninja: build stopped: subcommand failed.

This may cause by inline function.

see https://github.com/NanoMichael/cLaTeXMath/pull/76

NanoMichael commented 3 years ago

for commit fix cmake build file a8d564f Why delete other code folders? e.g. src/otf, src/unimath

The src/otf and src/unimath are supports for the Unicode-math feature, and this feature support has not released yet, so these files were deleted.

PikachuHy commented 3 years ago

I propose to use rebase instead of merge for each PR.

image

PikachuHy commented 3 years ago

After merging my https://github.com/NanoMichael/cLaTeXMath/pull/76, I can't give any more suggestions for this PR Merge openmath refactor.

Next, I will add more CI configs (e.g. ubuntu Qt, windows Qt, windows GDI+) and polish the cmake config files.

😁

NanoMichael commented 3 years ago

I propose to use rebase instead of merge for each PR.

Nice advice, I'll use rebase as far as possible after.

Alexxey593 commented 3 years ago

Hi. How can I add tinyxml2 to the build on Windows?

sp1ritCS commented 3 years ago

Hi. How can I add tinyxml2 to the build on Windows?

I don't know Windows/MSVC but I assume you should be able to clone tinyxml2 into a subdirectory, compile a libtinyxml2.dll from there using meson/cmake. You'll probably need to move that dll into whatever dir the linker looks into for dlls. Then just add -I./subdir_path_of_tinyxml2 to your compiler flags and -ltinyxml2 to your linker flags. If pkg-config exists for windows, you can automate that entire setup with that.

PikachuHy commented 3 years ago

Hi. How can I add tinyxml2 to the build on Windows?

use vcpkg https://github.com/microsoft/vcpkg

sp1ritCS commented 3 years ago

LGTM from my side :D

(mind tagging a release [0.0.4] after merging for this? maybe even publishing an tar xz archive and pgp signing that)

NanoMichael commented 3 years ago

LGTM from my side :D

(mind tagging a release [0.0.4] after merging for this? maybe even publishing an tar xz archive and pgp signing that)

Good advice. I'm trying to solve the MSVC compilation issue (check #76), maybe it will take a while...

LyesSaadi commented 3 years ago

mind tagging a release [0.0.4]

A 0.1.0 would be more appropriate (maybe even a 1.0.0 ?), and it would be great if we could synchronize meson and cmake from now on please :P !

sp1ritCS commented 3 years ago

I'm trying to solve the MSVC compilation issue (check #76), maybe it will take a while...

Oh, wow thats a very "dirty PR" to say the least. gl (I sadly can't help with anything msvc related)

Good advice

yeah, I was just a bit unsure if your even allowed to use pgp in china, but seeing you signing your commits I think it's a non-issue 😄 .


if we could synchronize meson and cmake from now on please :P !

you mean release-wise? AFAIK the cmake one doesn't have any kind of version specified

LyesSaadi commented 3 years ago

you mean release-wise? AFAIK the cmake one doesn't have any kind of version specified

Hmm... Weird... I was certain that it was... I may be confusing two projects. Anyway, it would also be a good idea to synchronize them tag/release wise.

PikachuHy commented 3 years ago

Oh, wow thats a very "dirty PR" to say the least.

The errors are really weird. 😣

blackhole89 commented 3 years ago

I'm getting a bunch of new failures in the cmake-based build with this patch: see here.

It appears to start with

In file included from /home/runner/work/notekit/notekit/cLaTeXMath/src/utils/string_utils.cpp:1:0:
/home/runner/work/notekit/notekit/cLaTeXMath/src/utils/string_utils.h:104:58: error: ‘std::vector’ has not been declared
 inline void split(const std::string& str, char del, std::vector<std::string>& res) {

and go downhill from there.

(edit: I suspect that it's a versioning issue, as that particular CI rule is run on Ubuntu 18.04 rather than ubuntu-latest and has GCC 7.5.0 rather than 9.3.0. Is there anything we now need from the newer version, or should this be considered a bug?)

sp1ritCS commented 3 years ago

It seems like cLaTeXMath does not build with c++11 anymore, mind bumping this to 14 in the meson build file?

../subprojects/clatexmath/src/render.cpp:26:27: error: use of ‘auto’ in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
     BoxFilter filter = [](auto b) {
                           ^~~~
../subprojects/clatexmath/src/render.cpp: In lambda function:
../subprojects/clatexmath/src/render.cpp:27:39: error: request for member ‘get’ in ‘b’, which is of non-class type ‘int’
       return dynamic_cast<CharBox*>(b.get()) != nullptr;
                                       ^~~
../subprojects/clatexmath/src/render.cpp: In constructor ‘tex::TeXRender::TeXRender(tex::sptr<tex::Box>&, float, bool)’:
../subprojects/clatexmath/src/render.cpp:28:5: error: conversion from ‘tex::TeXRender::TeXRender(tex::sptr<tex::Box>&, float, bool)::<lambda(int)>’ to non-scalar type ‘tex::BoxFilter {aka std::function<bool(const std::shared_ptr<tex::Box>&)>}’ requested
     };
sp1ritCS commented 3 years ago

Here is the diff to a working version (fixes the vector issue @blackhole89 mentioned too)

diff --git a/src/meson.build b/src/meson.build
index 8a39af2..21822be 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -45,11 +45,11 @@ if cc.get_id() == 'gcc' and cc.version().version_compare('<9')
     deps += [ cc.find_library('stdc++fs') ]
 endif
 if cc.get_id() == 'gcc' and cc.version().version_compare('<8')
-       add_project_arguments('-std=c++11', language : 'cpp')
+       add_project_arguments('-std=c++14', language : 'cpp')
 elif cc.has_argument('--std=c++17')
        add_project_arguments('-std=c++17', language : 'cpp')
 else
-       add_project_arguments('-std=c++11', language : 'cpp')
+       add_project_arguments('-std=c++14', language : 'cpp')
 endif

 deps += [dependency('tinyxml2')]
diff --git a/src/utils/string_utils.h b/src/utils/string_utils.h
index 4627fa6..2244356 100644
--- a/src/utils/string_utils.h
+++ b/src/utils/string_utils.h
@@ -9,6 +9,7 @@
 #include <string>
 #include <functional>
 #include <map>
+#include <vector>

 namespace tex {
NanoMichael commented 3 years ago

I'm pretty like the destructing and auto lambda feature, I strongly suggest upgrading the compiler to C++14. See #81