mathematical 1.6.20 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -16
- data/Rakefile +80 -17
- data/ext/mathematical/CMakeLists.txt +23 -43
- data/ext/mathematical/extconf.rb +70 -24
- data/ext/mathematical/mtex2MML/CMakeLists.txt +5 -5
- data/ext/mathematical/mtex2MML/README.md +19 -19
- data/ext/mathematical/mtex2MML/deps/uthash/package.json +2 -1
- data/ext/mathematical/mtex2MML/deps/uthash/utarray.h +35 -22
- data/ext/mathematical/mtex2MML/deps/uthash/uthash.h +524 -458
- data/ext/mathematical/mtex2MML/deps/uthash/utlist.h +255 -74
- data/ext/mathematical/mtex2MML/deps/uthash/utringbuffer.h +14 -14
- data/ext/mathematical/mtex2MML/deps/uthash/utstack.h +88 -0
- data/ext/mathematical/mtex2MML/deps/uthash/utstring.h +34 -25
- data/ext/mathematical/mtex2MML/script/cibuild +5 -48
- data/ext/mathematical/mtex2MML/script/test-quick +48 -0
- data/ext/mathematical/mtex2MML/src/environment.c +5 -1
- data/ext/mathematical/mtex2MML/tests/mathjax.c +591 -591
- data/ext/pulldown-latex/Cargo.lock +1833 -0
- data/fonts/cmex10.ttf +0 -0
- data/fonts/cmmi10.ttf +0 -0
- data/fonts/cmr10.ttf +0 -0
- data/fonts/cmsy10.ttf +0 -0
- data/fonts/eufm10.ttf +0 -0
- data/fonts/fonts.conf +11 -0
- data/fonts/msam10.ttf +0 -0
- data/fonts/msbm10.ttf +0 -0
- data/lib/mathematical/version.rb +1 -1
- data/lib/mathematical.rb +16 -1
- data/mathematical.gemspec +6 -2
- metadata +34 -11
- data/ext/mathematical/mtex2MML/appveyor.yml +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d09fb5b145019bd3222fb6e898aeb619eb9a410a3aa50e44a378b7648f6bc3d3
|
|
4
|
+
data.tar.gz: ba29dec9368b6765c4672ca4bcfc536cbc1179b7717ce40933f95ca67048d4a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0062f484bb16e2d012802c6f4f8bfc8467192f5037a8791890767ff986c411494ed50a766ad1ef1c5aaa68cf7c77d6f1d3375d20ddc3c51fa324aefeb015a6ca
|
|
7
|
+
data.tar.gz: 9a1e643541901146695cb94669103f314a688f50f5664e65b7ffa7614fd002cb6d7c48ed10e69ce0415ca10211a6675c6ef5e48293175becf03641808167e4d8
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Please reach out if you would like to mantain SVG and PNG portions of the librar
|
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
17
|
-
Add this line to your application's Gemfile:
|
|
17
|
+
Precompiled native gems are available for Linux, macOS, and Windows. Add this line to your application's Gemfile:
|
|
18
18
|
|
|
19
19
|
gem 'mathematical'
|
|
20
20
|
|
|
@@ -26,7 +26,21 @@ Or install it yourself as:
|
|
|
26
26
|
|
|
27
27
|
$ gem install mathematical
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### Platform-specific notes
|
|
30
|
+
|
|
31
|
+
**Linux** (x86_64 and ARM, glibc and musl): Fully self-contained — no additional dependencies needed.
|
|
32
|
+
|
|
33
|
+
**macOS**: Install runtime libraries via Homebrew:
|
|
34
|
+
|
|
35
|
+
$ brew install glib gdk-pixbuf cairo pango libxml2
|
|
36
|
+
|
|
37
|
+
**Windows**: Install runtime libraries via MSYS2 (UCRT64):
|
|
38
|
+
|
|
39
|
+
$ pacman -S mingw-w64-ucrt-x86_64-glib2 mingw-w64-ucrt-x86_64-cairo mingw-w64-ucrt-x86_64-pango mingw-w64-ucrt-x86_64-gdk-pixbuf2 mingw-w64-ucrt-x86_64-libxml2
|
|
40
|
+
|
|
41
|
+
### Building from source
|
|
42
|
+
|
|
43
|
+
If no precompiled gem is available for your platform, it will be compiled from source. You'll need cmake, pkg-config, bison, flex, and the development headers for glib, cairo, pango, gdk-pixbuf, and libxml2.
|
|
30
44
|
|
|
31
45
|
## Usage
|
|
32
46
|
|
|
@@ -112,28 +126,24 @@ Check out [SUPPORTED.md on the mtex2MML website](https://github.com/gjtorikian/m
|
|
|
112
126
|
|
|
113
127
|
**Note**: This library makes a few assumptions about the strings that you pass in. It assumes that `$..$` is inline math and `$$..$$` is display math.
|
|
114
128
|
|
|
115
|
-
## Building
|
|
129
|
+
## Building from source
|
|
130
|
+
|
|
131
|
+
To build from source, install the development dependencies for your platform:
|
|
132
|
+
|
|
133
|
+
**Linux (Debian/Ubuntu):**
|
|
116
134
|
|
|
117
|
-
|
|
135
|
+
$ sudo apt-get install cmake bison flex pkg-config libglib2.0-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev libxml2-dev
|
|
118
136
|
|
|
119
|
-
|
|
120
|
-
* GNU make
|
|
121
|
-
* glib-2.0
|
|
122
|
-
* gdk-pixbuf-2.0
|
|
123
|
-
* xml2
|
|
124
|
-
* cairo
|
|
125
|
-
* pango
|
|
126
|
-
* [Dependencies for mtex2MML](https://github.com/gjtorikian/mtex2MML#building)
|
|
137
|
+
**macOS:**
|
|
127
138
|
|
|
128
|
-
|
|
139
|
+
$ brew install glib gdk-pixbuf cairo pango cmake pkg-config
|
|
140
|
+
|
|
141
|
+
Then:
|
|
129
142
|
|
|
130
143
|
```
|
|
131
|
-
script/bootstrap
|
|
132
144
|
bundle exec rake compile
|
|
133
145
|
```
|
|
134
146
|
|
|
135
|
-
If there were no errors, you're done! Otherwise, make sure to follow the dependency instructions.
|
|
136
|
-
|
|
137
147
|
### Fonts and special notices for Mac OS X
|
|
138
148
|
|
|
139
149
|
Install the fonts with:
|
data/Rakefile
CHANGED
|
@@ -6,42 +6,105 @@ require "rake/testtask"
|
|
|
6
6
|
require "fileutils"
|
|
7
7
|
require "tmpdir"
|
|
8
8
|
|
|
9
|
-
LASEM_DIR = File.expand_path(File.join(File.dirname(__FILE__), "ext", "mathematical", "lasem"))
|
|
10
|
-
|
|
11
9
|
Rake::TestTask.new do |t|
|
|
12
10
|
t.libs << "test"
|
|
13
11
|
t.test_files = FileList["test/**/*_test.rb"]
|
|
14
12
|
t.verbose = true
|
|
15
13
|
end
|
|
16
14
|
|
|
15
|
+
# ─── Extension compilation ─────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
17
|
require "rake/extensiontask"
|
|
18
|
+
|
|
19
|
+
CROSS_PLATFORMS = [
|
|
20
|
+
"x86_64-linux-gnu",
|
|
21
|
+
"x86_64-linux-musl",
|
|
22
|
+
"aarch64-linux-gnu",
|
|
23
|
+
"aarch64-linux-musl",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
NATIVE_PLATFORMS = [
|
|
27
|
+
"arm64-darwin",
|
|
28
|
+
"x86_64-darwin",
|
|
29
|
+
"x64-mingw-ucrt",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
ALL_PLATFORMS = CROSS_PLATFORMS + NATIVE_PLATFORMS
|
|
33
|
+
|
|
34
|
+
# Ruby versions to target for precompiled gems
|
|
35
|
+
CROSS_RUBIES = ["3.1.0", "3.2.0", "3.3.0", "3.4.0", "4.0.0"]
|
|
36
|
+
|
|
18
37
|
spec = Gem::Specification.load("mathematical.gemspec")
|
|
38
|
+
|
|
19
39
|
Rake::ExtensionTask.new("mathematical", spec) do |ext|
|
|
20
40
|
ext.lib_dir = File.join("lib", "mathematical")
|
|
41
|
+
ext.cross_compile = true
|
|
42
|
+
ext.cross_platform = CROSS_PLATFORMS
|
|
43
|
+
ext.cross_config_options << "--enable-cross-build"
|
|
44
|
+
|
|
45
|
+
ext.cross_compiling do |cross_spec|
|
|
46
|
+
# Native gems don't need source files — the compiled .so is included
|
|
47
|
+
cross_spec.files.reject! { |path| File.fnmatch?("ext/**/*", path) }
|
|
48
|
+
# Include font files in native gems
|
|
49
|
+
cross_spec.files += Dir.glob("fonts/**/*")
|
|
50
|
+
end
|
|
21
51
|
end
|
|
22
52
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
# Set RUBY_CC_VERSION for cross-compilation
|
|
54
|
+
begin
|
|
55
|
+
require "rake_compiler_dock"
|
|
56
|
+
ENV["RUBY_CC_VERSION"] = RakeCompilerDock.ruby_cc_version("3.1", "3.2", "3.3", "3.4", "4.0")
|
|
57
|
+
rescue LoadError
|
|
58
|
+
ENV["RUBY_CC_VERSION"] = CROSS_RUBIES.join(":")
|
|
59
|
+
end
|
|
26
60
|
|
|
27
|
-
|
|
61
|
+
# ─── Cross-compiled gem tasks (Linux via rake-compiler-dock) ───────────────────
|
|
62
|
+
|
|
63
|
+
namespace "gem" do
|
|
64
|
+
CROSS_PLATFORMS.each do |platform|
|
|
65
|
+
desc "Build native gem for #{platform}"
|
|
66
|
+
task platform do
|
|
67
|
+
require "rake_compiler_dock"
|
|
68
|
+
|
|
69
|
+
# Both GNU and musl RCD containers are Debian-based (musl uses a cross-compiler,
|
|
70
|
+
# NOT Alpine). Install deps with apt-get, running as root inside the container.
|
|
71
|
+
RakeCompilerDock.sh(<<~SCRIPT, platform: platform, verbose: true)
|
|
72
|
+
set -e
|
|
73
|
+
sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends \
|
|
74
|
+
cmake bison flex pkg-config ninja-build python3 python3-pip
|
|
75
|
+
# RCD containers (Ubuntu 20.04) ship old CMake 3.16 and Meson 0.53;
|
|
76
|
+
# libxml2 2.12+ needs CMake 3.18+ and glib 2.80+ needs Meson 1.2+
|
|
77
|
+
pip3 install --upgrade cmake meson packaging
|
|
78
|
+
export PATH="$(python3 -m site --user-base)/bin:$PATH"
|
|
79
|
+
# Build static deps from source (Debian lacks .a files for meson-built libs)
|
|
80
|
+
script/build_static_deps
|
|
81
|
+
# RCD containers use rbenv; override .ruby-version which may not match
|
|
82
|
+
export RBENV_VERSION="$(rbenv versions --bare | tail -1)"
|
|
83
|
+
gem install bundler --no-document
|
|
84
|
+
bundle install
|
|
85
|
+
bundle exec rake native:#{platform} gem MAKE="nice make -j$(nproc)"
|
|
86
|
+
SCRIPT
|
|
87
|
+
end
|
|
88
|
+
end
|
|
28
89
|
|
|
29
|
-
|
|
90
|
+
desc "Build native gems for all Linux platforms"
|
|
91
|
+
multitask linux: CROSS_PLATFORMS
|
|
30
92
|
|
|
31
|
-
|
|
32
|
-
|
|
93
|
+
desc "Build the source (platform=ruby) gem"
|
|
94
|
+
task :source do
|
|
95
|
+
sh "gem build mathematical.gemspec"
|
|
96
|
+
end
|
|
33
97
|
end
|
|
34
98
|
|
|
35
|
-
|
|
36
|
-
task :copy_samples do
|
|
37
|
-
Dir.mktmpdir do |tmp|
|
|
38
|
-
system "cp -r samples #{tmp}"
|
|
99
|
+
# ─── Default tasks ─────────────────────────────────────────────────────────────
|
|
39
100
|
|
|
40
|
-
|
|
101
|
+
task default: [:test]
|
|
41
102
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
103
|
+
Gem::PackageTask.new(spec)
|
|
104
|
+
|
|
105
|
+
Rake::Task[:test].prerequisites
|
|
106
|
+
|
|
107
|
+
task build: [:clean]
|
|
45
108
|
|
|
46
109
|
require "rubocop/rake_task"
|
|
47
110
|
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
# General project setup
|
|
4
4
|
#
|
|
5
5
|
#
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR)
|
|
9
|
-
cmake_policy(SET CMP0015 NEW)
|
|
6
|
+
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
|
7
|
+
project(lasem C)
|
|
10
8
|
set(CMAKE_MACOSX_RPATH 1)
|
|
9
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
11
10
|
|
|
12
11
|
set(LIBRARY "lasem")
|
|
13
12
|
set(VERSION 0.6)
|
|
@@ -17,7 +16,6 @@ find_package(PkgConfig REQUIRED)
|
|
|
17
16
|
set(LASEM_SRC_DIR ${CMAKE_SOURCE_DIR}/lasem/src/)
|
|
18
17
|
set(MTEX2MML_SRC_DIR ${CMAKE_SOURCE_DIR}/mtex2MML/src/)
|
|
19
18
|
set(MTEX2MML_BUILD_DIR ${CMAKE_SOURCE_DIR}/mtex2MML/build/)
|
|
20
|
-
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${RUBY_INCLUDE_PATH} ${MTEX2MML_SRC_DIR} ${LASEM_SRC_DIR})
|
|
21
19
|
|
|
22
20
|
file(GLOB_RECURSE LASEM_SRC ${LASEM_SRC_DIR}/*.c)
|
|
23
21
|
file(GLOB_RECURSE LASEM_HEADERS ${LASEM_SRC_DIR}/*.h)
|
|
@@ -25,11 +23,16 @@ list(REMOVE_ITEM LASEM_SRC "${LASEM_SRC_DIR}/lasemrender.c")
|
|
|
25
23
|
list(REMOVE_ITEM LASEM_SRC "${LASEM_SRC_DIR}/lsmitex.c")
|
|
26
24
|
list(APPEND LASEM_SRC "${CMAKE_SOURCE_DIR}/lasem_overrides.c")
|
|
27
25
|
|
|
28
|
-
# If you're reading this and it's giving you errors, fix it and send
|
|
29
|
-
# me the patch. Much appreciated.
|
|
30
26
|
add_definitions(-DPACKAGE_LOCALE_DIR="/usr/share/locale")
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
# On Windows with MSYS2, glib/pango/gdk-pixbuf/cairo are shared libraries (DLLs).
|
|
29
|
+
# Do NOT define *_STATIC_COMPILATION — headers must use __declspec(dllimport)
|
|
30
|
+
# so the linker correctly resolves symbols via the import libraries (.dll.a).
|
|
31
|
+
|
|
32
|
+
# Build lasem as a STATIC library so it links directly into the Ruby extension.
|
|
33
|
+
# Lasem is LGPL-2.1+, but since mathematical is MIT and fully open source,
|
|
34
|
+
# LGPL obligations are trivially satisfied (users can rebuild from source).
|
|
35
|
+
add_library(${LIBRARY} STATIC
|
|
33
36
|
${LASEM_SRC}
|
|
34
37
|
)
|
|
35
38
|
|
|
@@ -41,7 +44,7 @@ add_library(${LIBRARY} SHARED
|
|
|
41
44
|
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
|
|
42
45
|
pkg_check_modules(CAIRO REQUIRED cairo)
|
|
43
46
|
pkg_check_modules(PANGO REQUIRED pango)
|
|
44
|
-
pkg_check_modules(
|
|
47
|
+
pkg_check_modules(GDK_PIXBUF2 REQUIRED gdk-pixbuf-2.0)
|
|
45
48
|
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
|
|
46
49
|
pkg_check_modules(GIO2 REQUIRED gio-2.0)
|
|
47
50
|
pkg_check_modules(PANGO_CAIRO REQUIRED pangocairo)
|
|
@@ -66,40 +69,16 @@ if(CMAKE_HOST_APPLE AND APPLE)
|
|
|
66
69
|
endif()
|
|
67
70
|
endif()
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
# find dependencies
|
|
74
|
-
# glib
|
|
75
|
-
find_path(GLIB_INCLUDE_DIR glib.h)
|
|
76
|
-
find_library(GLIB_GLIB_LIBRARY glib-${GLIB_LIB_SUFFIX})
|
|
77
|
-
find_library(GLIB_GIO_LIBRARY gio-${GLIB_LIB_SUFFIX})
|
|
78
|
-
find_library(GLIB_GMODULE_LIBRARY gmodule-${GLIB_LIB_SUFFIX})
|
|
79
|
-
find_library(GLIB_GOBJECT_LIBRARY gobject-${GLIB_LIB_SUFFIX})
|
|
80
|
-
set(GLIB_LIBRARIES ${GLIB_GLIB_LIBRARY} ${GLIB_GIO_LIBRARY} ${GLIB_GMODULE_LIBRARY} ${GLIB_GOBJECT_LIBRARY})
|
|
81
|
-
|
|
82
|
-
# pango
|
|
83
|
-
find_path(PANGO_INCLUDE_DIR pango/pango.h)
|
|
84
|
-
find_library(PANGO_LIBRARY pango-${PANGO_LIB_SUFFIX})
|
|
85
|
-
find_library(PANGO_CAIRO_LIBRARY pangocairo-${PANGO_LIB_SUFFIX})
|
|
86
|
-
set(PANGO_LIBRARIES ${PANGO_LIBRARY} ${PANGO_CAIRO_LIBRARY})
|
|
87
|
-
|
|
88
|
-
# cairo
|
|
89
|
-
find_library(CAIRO_LIBRARY cairo${CAIRO_LIB_SUFFIX})
|
|
90
|
-
find_library(CAIRO_GOBJECT_LIBRARY cairo-gobject${CAIRO_LIB_SUFFIX})
|
|
91
|
-
set(CAIRO_LIBRARIES ${CAIRO_LIBRARY} ${CAIRO_GOBJECT_LIBRARY})
|
|
92
|
-
find_path(CAIRO_INCLUDE_DIR cairo.h)
|
|
93
|
-
|
|
94
|
-
# gdk-pixbuf
|
|
95
|
-
find_path(GDK_PIXBUF_INCLUDE_DIR gdk-pixbuf/gdk-pixbuf.h)
|
|
96
|
-
find_library(GDK_PIXBUF_LIBRARY gdk_pixbuf-${GDK_PIXBUF_LIB_SUFFIX})
|
|
72
|
+
target_include_directories(${LIBRARY} PRIVATE
|
|
73
|
+
${MTEX2MML_SRC_DIR}
|
|
74
|
+
${LASEM_SRC_DIR}
|
|
75
|
+
)
|
|
97
76
|
|
|
98
|
-
|
|
99
|
-
${
|
|
77
|
+
target_include_directories(${LIBRARY} PUBLIC
|
|
78
|
+
${RUBY_INCLUDE_PATH}
|
|
100
79
|
${GLIB2_INCLUDE_DIRS}
|
|
101
80
|
${CAIRO_INCLUDE_DIRS}
|
|
102
|
-
${
|
|
81
|
+
${GDK_PIXBUF2_INCLUDE_DIRS}
|
|
103
82
|
${LIBXML2_INCLUDE_DIRS}
|
|
104
83
|
${LIBXML2_MACOS_INCLUDE_DIRS}
|
|
105
84
|
${GIO2_INCLUDE_DIRS}
|
|
@@ -107,11 +86,12 @@ include_directories(${LIBRARY}
|
|
|
107
86
|
)
|
|
108
87
|
|
|
109
88
|
target_link_libraries(${LIBRARY}
|
|
110
|
-
${
|
|
89
|
+
${GLIB2_LIBRARIES}
|
|
111
90
|
${CAIRO_LIBRARIES}
|
|
112
91
|
${PANGO_LIBRARIES}
|
|
113
|
-
${
|
|
92
|
+
${GDK_PIXBUF2_LIBRARIES}
|
|
114
93
|
${LIBXML2_LIBRARIES}
|
|
115
|
-
${
|
|
94
|
+
${GIO2_LIBRARIES}
|
|
95
|
+
${PANGO_CAIRO_LIBRARIES}
|
|
116
96
|
${MTEX2MML_BUILD_DIR}/libmtex2MML.a
|
|
117
97
|
)
|
data/ext/mathematical/extconf.rb
CHANGED
|
@@ -6,6 +6,7 @@ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM.match?(/darwin|mac os/)
|
|
|
6
6
|
|
|
7
7
|
require "mkmf"
|
|
8
8
|
require "rbconfig"
|
|
9
|
+
require "fileutils"
|
|
9
10
|
|
|
10
11
|
OS = case RbConfig::CONFIG["host_os"]
|
|
11
12
|
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
|
@@ -17,15 +18,32 @@ when /linux/
|
|
|
17
18
|
when /solaris|bsd/
|
|
18
19
|
:unix
|
|
19
20
|
else
|
|
20
|
-
raise
|
|
21
|
+
raise "unknown os: #{RbConfig::CONFIG["host_os"].inspect}"
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
LIBDIR = RbConfig::CONFIG["libdir"]
|
|
24
25
|
INCLUDEDIR = RbConfig::CONFIG["includedir"]
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
SHARED_EXT = case OS
|
|
28
|
+
when :macos then "dylib"
|
|
29
|
+
when :windows then "dll"
|
|
30
|
+
else "so"
|
|
31
|
+
end
|
|
32
|
+
|
|
26
33
|
# Starting in Catalina, libxml2 was moved elsewhere
|
|
27
34
|
SDKROOT = OS == :macos ? %x(/usr/bin/xcrun --show-sdk-path).chomp : ""
|
|
28
|
-
RPATH = OS == :macos ? "-rpath @loader_path/../../ext/mathematical/lib"
|
|
35
|
+
RPATH = OS == :macos ? "-rpath @loader_path/../../ext/mathematical/lib" : ""
|
|
36
|
+
|
|
37
|
+
# Windows needs the MSYS Makefiles generator for cmake
|
|
38
|
+
CMAKE_GENERATOR = OS == :windows ? '-G "MSYS Makefiles"' : ""
|
|
39
|
+
|
|
40
|
+
# Cross-compilation support
|
|
41
|
+
CROSS_BUILD = enable_config("cross-build", false)
|
|
42
|
+
if CROSS_BUILD
|
|
43
|
+
# In cross-compilation mode, use the cross-compiler
|
|
44
|
+
RbConfig::CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
|
45
|
+
RbConfig::CONFIG["CXX"] = ENV["CXX"] if ENV["CXX"]
|
|
46
|
+
end
|
|
29
47
|
|
|
30
48
|
unless find_executable("cmake")
|
|
31
49
|
$stderr.puts "\n\n\n[ERROR]: cmake is required and not installed. Get it here: http://www.cmake.org/\n\n"
|
|
@@ -40,6 +58,14 @@ def using_system_mtex2mml?
|
|
|
40
58
|
arg_config("--use-system-mtex2MML", !!ENV["MATHEMATICAL_USE_SYSTEM_MTEX2MML"])
|
|
41
59
|
end
|
|
42
60
|
|
|
61
|
+
# Check for vendored static dependencies (built by script/build_static_deps)
|
|
62
|
+
VENDOR_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "vendor"))
|
|
63
|
+
if File.directory?(File.join(VENDOR_DIR, "lib"))
|
|
64
|
+
ENV["PKG_CONFIG_PATH"] = "#{File.join(VENDOR_DIR, "lib", "pkgconfig")}:#{File.join(VENDOR_DIR, "lib64", "pkgconfig")}:#{ENV["PKG_CONFIG_PATH"]}"
|
|
65
|
+
ENV["PKG_CONFIG_LIBDIR"] = "" if CROSS_BUILD # Don't search system pkg-config in cross mode
|
|
66
|
+
puts "*** Using vendored static deps from #{VENDOR_DIR} ***"
|
|
67
|
+
end
|
|
68
|
+
|
|
43
69
|
LASEM_DIR = File.expand_path(File.join(File.dirname(__FILE__), "lasem"))
|
|
44
70
|
LASEM_BUILD_DIR = File.join(LASEM_DIR, "build")
|
|
45
71
|
LASEM_SRC_DIR = File.expand_path(File.join(LASEM_DIR, "src"))
|
|
@@ -51,7 +77,10 @@ MTEX2MML_SRC_DIR = File.expand_path(File.join(MTEX2MML_DIR, "src"))
|
|
|
51
77
|
MTEX2MML_LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), "lib"))
|
|
52
78
|
|
|
53
79
|
if OS == :macos
|
|
54
|
-
|
|
80
|
+
# Homebrew paths must come before X11 so we get newer versions of libs like cairo
|
|
81
|
+
homebrew_prefix = %x(brew --prefix 2>/dev/null).chomp
|
|
82
|
+
homebrew_pkgconfig = "#{homebrew_prefix}/lib/pkgconfig" unless homebrew_prefix.empty?
|
|
83
|
+
ENV["PKG_CONFIG_PATH"] = [homebrew_pkgconfig, "/opt/X11/lib/pkgconfig", ENV["PKG_CONFIG_PATH"]].compact.join(":")
|
|
55
84
|
end
|
|
56
85
|
|
|
57
86
|
# pre-compile checks
|
|
@@ -62,8 +91,6 @@ find_header("libxml/parser.h", "/include/libxml2", "/usr/include/libxml2", "/usr
|
|
|
62
91
|
find_header("libxml/xpath.h", "/include/libxml2", "/usr/include/libxml2", "/usr/local/include/libxml2", "#{SDKROOT}/usr/include/libxml2")
|
|
63
92
|
find_header("libxml/xpathInternals.h", "/include/libxml2", "/usr/include/libxml2", "/usr/local/include/libxml2", "#{SDKROOT}/usr/include/libxml2")
|
|
64
93
|
|
|
65
|
-
# TODO: we need to clear out the build dir that's erroneously getting packaged
|
|
66
|
-
# this causes problems, as Linux installation is expecting OS X output
|
|
67
94
|
def clean_dir(dir)
|
|
68
95
|
if File.directory?(dir)
|
|
69
96
|
FileUtils.rm_rf(dir)
|
|
@@ -74,40 +101,42 @@ end
|
|
|
74
101
|
clean_dir(MTEX2MML_BUILD_DIR)
|
|
75
102
|
clean_dir(LASEM_BUILD_DIR)
|
|
76
103
|
|
|
104
|
+
# Pass cross-compiler settings to cmake if available
|
|
105
|
+
cmake_env = ""
|
|
106
|
+
if ENV["CC"]
|
|
107
|
+
cmake_env += " -DCMAKE_C_COMPILER=#{ENV["CC"]}"
|
|
108
|
+
end
|
|
109
|
+
if ENV["CXX"]
|
|
110
|
+
cmake_env += " -DCMAKE_CXX_COMPILER=#{ENV["CXX"]}"
|
|
111
|
+
end
|
|
112
|
+
|
|
77
113
|
if !using_system_mtex2mml?
|
|
78
114
|
# build mtex2MML library
|
|
79
|
-
Dir.chdir(MTEX2MML_BUILD_DIR) do
|
|
80
|
-
system "cmake .."
|
|
115
|
+
Dir.chdir(MTEX2MML_BUILD_DIR) do # rubocop:disable ThreadSafety/DirChdir
|
|
116
|
+
system "cmake #{CMAKE_GENERATOR}#{cmake_env} .."
|
|
81
117
|
system "make libmtex2MML_static"
|
|
82
118
|
end
|
|
83
119
|
FileUtils.mkdir_p(MTEX2MML_LIB_DIR)
|
|
84
120
|
FileUtils.cp_r(File.join(MTEX2MML_BUILD_DIR, "libmtex2MML.a"), MTEX2MML_LIB_DIR)
|
|
85
121
|
$LIBS << " -lmtex2MML"
|
|
86
|
-
elsif dir_config("mtex2MML").any? || system("dpkg -s libmtex2MML >/dev/null")
|
|
122
|
+
elsif dir_config("mtex2MML").any? || system("dpkg -s libmtex2MML >/dev/null 2>&1")
|
|
87
123
|
$LIBS << " -lmtex2MML"
|
|
88
124
|
else
|
|
89
|
-
# NOTE: pkg_config implicitly adds right -l argument for the linker.
|
|
90
125
|
pkg_config("libmtex2MML") || pkg_config("mtex2MML")
|
|
91
126
|
end
|
|
92
127
|
|
|
93
128
|
if !using_system_lasem?
|
|
94
|
-
# build Lasem library
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
system "cmake ../.."
|
|
129
|
+
# build Lasem library as STATIC (linked directly into the Ruby extension)
|
|
130
|
+
Dir.chdir(LASEM_BUILD_DIR) do # rubocop:disable ThreadSafety/DirChdir
|
|
131
|
+
system "cmake #{CMAKE_GENERATOR}#{cmake_env} ../.."
|
|
98
132
|
system "make"
|
|
99
133
|
end
|
|
100
134
|
FileUtils.mkdir_p(LASEM_LIB_DIR)
|
|
101
|
-
FileUtils.cp_r(File.join(LASEM_BUILD_DIR, "liblasem
|
|
102
|
-
$LIBS <<
|
|
103
|
-
|
|
104
|
-
else
|
|
105
|
-
" -llasem"
|
|
106
|
-
end
|
|
107
|
-
elsif dir_config("lasem").any? || system("dpkg -s liblasem >/dev/null")
|
|
135
|
+
FileUtils.cp_r(File.join(LASEM_BUILD_DIR, "liblasem.a"), LASEM_LIB_DIR)
|
|
136
|
+
$LIBS << " -llasem"
|
|
137
|
+
elsif dir_config("lasem").any? || system("dpkg -s liblasem >/dev/null 2>&1")
|
|
108
138
|
$LIBS << " -llasem"
|
|
109
139
|
else
|
|
110
|
-
# NOTE: pkg_config implicitly adds right -l argument for the linker.
|
|
111
140
|
pkg_config("liblasem") || pkg_config("lasem")
|
|
112
141
|
end
|
|
113
142
|
|
|
@@ -120,10 +149,27 @@ dir_config("mathematical", HEADER_DIRS, LIB_DIRS)
|
|
|
120
149
|
|
|
121
150
|
find_header("mtex2MML.h", MTEX2MML_SRC_DIR)
|
|
122
151
|
|
|
123
|
-
flag = ENV["
|
|
124
|
-
|
|
152
|
+
flag = ENV["CI"] ? "-O0" : "-O2"
|
|
153
|
+
|
|
154
|
+
# Get link flags — prefer static linking when available
|
|
155
|
+
pkg_config_static_flag = File.directory?(VENDOR_DIR) ? "--static" : ""
|
|
156
|
+
|
|
157
|
+
# Link flags for system libraries must appear AFTER -llasem and -lmtex2MML
|
|
158
|
+
# because the linker resolves symbols left-to-right: liblasem.a references
|
|
159
|
+
# glib/libxml2 symbols, so those libs must come after -llasem.
|
|
160
|
+
# We append directly to $LIBS (which becomes LOCAL_LIBS in the Makefile)
|
|
161
|
+
# to guarantee correct ordering on all platforms including Windows.
|
|
162
|
+
pkg_packages = "glib-2.0 gdk-pixbuf-2.0 cairo pango pangocairo gio-2.0 libxml-2.0"
|
|
163
|
+
pkg_libs = %x(pkg-config #{pkg_config_static_flag} --libs #{pkg_packages}).chomp
|
|
164
|
+
puts "*** pkg-config --libs: #{pkg_libs} ***"
|
|
165
|
+
$LIBS << " #{pkg_libs}"
|
|
166
|
+
|
|
167
|
+
$LDFLAGS << " #{RPATH}" unless RPATH.empty?
|
|
125
168
|
$CFLAGS << " #{flag} #{%x(pkg-config --cflags glib-2.0 gdk-pixbuf-2.0 cairo pango).chomp}"
|
|
126
169
|
|
|
170
|
+
# fPIC is needed for linking static libs into the shared extension
|
|
171
|
+
$CFLAGS << " -fPIC" unless OS == :windows
|
|
172
|
+
|
|
127
173
|
create_makefile("mathematical/mathematical")
|
|
128
174
|
|
|
129
175
|
# rubocop:enable Style/GlobalVars
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
# General project setup
|
|
15
15
|
#
|
|
16
16
|
#
|
|
17
|
+
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
|
17
18
|
project(mtex2MML)
|
|
18
19
|
enable_language(C)
|
|
19
|
-
cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR)
|
|
20
20
|
cmake_policy(SET CMP0015 NEW)
|
|
21
21
|
|
|
22
22
|
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/astyle.cmake")
|
|
@@ -194,7 +194,7 @@ endif(MSVC)
|
|
|
194
194
|
if (BUILD_CLAR)
|
|
195
195
|
include (CTest)
|
|
196
196
|
enable_testing()
|
|
197
|
-
find_package(
|
|
197
|
+
find_package(Python REQUIRED)
|
|
198
198
|
|
|
199
199
|
set(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/")
|
|
200
200
|
set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests")
|
|
@@ -202,7 +202,7 @@ if (BUILD_CLAR)
|
|
|
202
202
|
add_definitions(-DCLAR_TMPDIR=\"libmtex2MML_tests\")
|
|
203
203
|
|
|
204
204
|
include_directories(${CLAR_PATH})
|
|
205
|
-
file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
|
|
205
|
+
file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h, ${CLAR_PATH}/*/*.py)
|
|
206
206
|
set(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar.c"
|
|
207
207
|
"${CLAR_PATH}/array.c"
|
|
208
208
|
"${CLAR_PATH}/basic.c"
|
|
@@ -220,7 +220,7 @@ if (BUILD_CLAR)
|
|
|
220
220
|
|
|
221
221
|
add_custom_command(
|
|
222
222
|
OUTPUT ${CLAR_PATH}/clar.suite
|
|
223
|
-
COMMAND ${
|
|
223
|
+
COMMAND ${Python_EXECUTABLE} generate.py
|
|
224
224
|
DEPENDS ${SRC_TEST}
|
|
225
225
|
WORKING_DIRECTORY ${CLAR_PATH}
|
|
226
226
|
)
|
|
@@ -240,7 +240,7 @@ if (BUILD_CLAR)
|
|
|
240
240
|
|
|
241
241
|
add_custom_command(TARGET mtex2MML_clar
|
|
242
242
|
POST_BUILD
|
|
243
|
-
COMMAND ${
|
|
243
|
+
COMMAND ${Python_EXECUTABLE} mathjax_generate.py
|
|
244
244
|
WORKING_DIRECTORY ${CLAR_PATH}
|
|
245
245
|
)
|
|
246
246
|
|
|
@@ -42,26 +42,26 @@ Both a static and dynamic library are created as part of the `cmake` build proce
|
|
|
42
42
|
|
|
43
43
|
The library exposes the following methods:
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
- `char * mtex2MML_parse(const char * str, unsigned long strlen, const int options)`: Converts a single TeX equation in `str` to MathML. Returns just the MathML equation, as a string.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
- `char * mtex2MML_global_parse(const char * str, unsigned long strlen, const int options, int global_start)`: The same as `mtex2MML_parse`, but allows you to provide a starting integer for equation numbering. Returns just the MathML equation, as a string.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
- `int mtex2MML_filter(const char * str, unsigned long strlen, const int options)`: Given a string with a mix of TeX math and non-math elements, this returns a single string containing just the converted math elements. Equations are automatically numbered. Returns a `status` indicating success (`0`) or failure. You must access the resulting string with `mtex2MML_output`.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
- `int mtex2MML_text_filter(const char * str, unsigned long strlen, const int options)`: Given a string with a mix of TeX math and non-math elements, this converts all the math and leaves the rest of the string unmodified. Equations are automatically numbered. Returns a `status` indicating success (`0`) or failure. You must access the resulting string with `mtex2MML_output`. HTML within a math equation are normalized (eg. `<` becomes `<`).
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
- `int mtex2MML_strict_filter(const char * str, unsigned long strlen, const int options)`: Given a string with a mix of TeX math and non-math elements, this converts all the math and leaves the rest of the string unmodified. Equations are automatically numbered. Returns a `status` indicating success (`0`) or failure. You must access the resulting string with `mtex2MML_output`. HTML tags are removed completely.
|
|
54
54
|
|
|
55
55
|
The `options` argument determines which types of delimiters are to be used:
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
- `MTEX2MML_DELIMITER_DEFAULT` is the default, using `$..$` for inline and `$$..$$` for display.
|
|
58
|
+
- `MTEX2MML_DELIMITER_DOLLAR` uses single dollar signs: `$..$` for inline.
|
|
59
|
+
- `MTEX2MML_DELIMITER_DOUBLE` uses double dollar signs: `$$..$$` for display.
|
|
60
|
+
- `MTEX2MML_DELIMITER_PARENS` uses parenthesis: `\(..\)` for inline.
|
|
61
|
+
- `MTEX2MML_DELIMITER_BRACKETS` uses brackets: `\[..\]` for display.
|
|
62
|
+
- `MTEX2MML_DELIMITER_ENVIRONMENTS` supports bare `\\begin..\\end` environments.
|
|
63
63
|
|
|
64
|
-
[The
|
|
64
|
+
[The _tests/basic.c_](tests/basic.c) and [the _tests/delimiters.c_](tests/delimiters.c) suites provides a demonstrate of how these methods can be used.
|
|
65
65
|
|
|
66
66
|
### As a command
|
|
67
67
|
|
|
@@ -77,16 +77,16 @@ Use `mtex2MML -h` to get documentation on the options.
|
|
|
77
77
|
|
|
78
78
|
A `0` status indicates a success, while anything else indicates a failure, [as per the Bison documentation](http://www.gnu.org/software/bison/manual/html_node/Parser-Function.html). If a token cannot be parsed, or if the tokenization is nested too deep, the library will bail with a non-zero status code. An error message is also printed to STDERR.
|
|
79
79
|
|
|
80
|
-
[The
|
|
80
|
+
[The _tests/maliciousness.c_ suite](tests/maliciousness.c) has a demonstration on how to perform error handling.
|
|
81
81
|
|
|
82
82
|
## Building
|
|
83
83
|
|
|
84
84
|
To build mtex2MML, you need:
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
- [CMake](http://www.cmake.org/download/) (at least version 2.8.7)
|
|
87
|
+
- [Bison](https://www.gnu.org/software/bison/)
|
|
88
|
+
- [Flex](http://flex.sourceforge.net/)
|
|
89
|
+
- [Python3](https://www.python.org/) (just for the tests)
|
|
90
90
|
|
|
91
91
|
### OS X (brew or macports), Ubuntu and Arch Linux
|
|
92
92
|
|
|
@@ -120,8 +120,8 @@ ctest -V
|
|
|
120
120
|
|
|
121
121
|
mtex2MML has a test suite that mimics the one found in [MathJax](https://github.com/mathjax/MathJax-test), with a few exceptions:
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
- Files marked as `.xtex` have features that are not implemented, but probably should be in the future.
|
|
124
|
+
- Files marked as `.no_tex` have features that probably won't be implemented.
|
|
125
125
|
|
|
126
126
|
During the test run, the suite will list the percentage of features that still need coverage.
|
|
127
127
|
|