asciidoctor-latexmath 1.0.0.pre.dev.1
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 +7 -0
- data/LICENSE +183 -0
- data/README.md +185 -0
- data/lib/asciidoctor-latexmath/renderer.rb +515 -0
- data/lib/asciidoctor-latexmath/treeprocessor.rb +369 -0
- data/lib/asciidoctor-latexmath/version.rb +11 -0
- data/lib/asciidoctor-latexmath.rb +12 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76676b29d9c14de950508c4620ede617e51f5cc874ad9c16aa8ac9fe98726304
|
4
|
+
data.tar.gz: c361670b70f0db1ea1f1756698af831b94bd257186080bae157cfce6607b6e7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70205787e5d7cf969ff5015afa71130f1e90b187da5103a0a6ca2c468edb6555e9fd539eb60b4fce7e5185880b79b0804fc152ae3b4e1b3a0998bb97957b52ea
|
7
|
+
data.tar.gz: 7f618f19aa454abf8c60790b0d0d666efbd902bf2757ca3e66617f745ee8b275ed7323630e1ba757ae726fd305cee2ff26496b267111e7d7e9b4da07691d3be8
|
data/LICENSE
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
Linking exception:
|
2
|
+
|
3
|
+
As a special exception to the GNU Lesser General Public License version 3
|
4
|
+
("LGPL3"), the copyright holders of this Library give you permission to convey
|
5
|
+
to a third party a Combined Work that links statically or dynamically to this
|
6
|
+
Library without providing any Minimal Corresponding Source or Minimal
|
7
|
+
Application Code as set out in 4d or providing the installation information set
|
8
|
+
out in section 4e, provided that you comply with the other provisions of LGPL3
|
9
|
+
and provided that you meet, for the Application the terms and conditions of the
|
10
|
+
license(s) which apply to the Application.
|
11
|
+
|
12
|
+
Except as stated in this special exception, the provisions of LGPL3 will
|
13
|
+
continue to comply in full to this Library. If you modify this Library, you may
|
14
|
+
apply this exception to your version of this Library, but you are not obliged
|
15
|
+
to do so. If you do not wish to do so, delete this exception statement from
|
16
|
+
your version. This exception does not (and cannot) modify any license terms
|
17
|
+
which apply to the Application, with which you must still comply.
|
18
|
+
|
19
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
20
|
+
Version 3, 29 June 2007
|
21
|
+
|
22
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
23
|
+
Everyone is permitted to copy and distribute verbatim copies
|
24
|
+
of this license document, but changing it is not allowed.
|
25
|
+
|
26
|
+
|
27
|
+
This version of the GNU Lesser General Public License incorporates
|
28
|
+
the terms and conditions of version 3 of the GNU General Public
|
29
|
+
License, supplemented by the additional permissions listed below.
|
30
|
+
|
31
|
+
0. Additional Definitions.
|
32
|
+
|
33
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
34
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
35
|
+
General Public License.
|
36
|
+
|
37
|
+
"The Library" refers to a covered work governed by this License,
|
38
|
+
other than an Application or a Combined Work as defined below.
|
39
|
+
|
40
|
+
An "Application" is any work that makes use of an interface provided
|
41
|
+
by the Library, but which is not otherwise based on the Library.
|
42
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
43
|
+
of using an interface provided by the Library.
|
44
|
+
|
45
|
+
A "Combined Work" is a work produced by combining or linking an
|
46
|
+
Application with the Library. The particular version of the Library
|
47
|
+
with which the Combined Work was made is also called the "Linked
|
48
|
+
Version".
|
49
|
+
|
50
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
51
|
+
Corresponding Source for the Combined Work, excluding any source code
|
52
|
+
for portions of the Combined Work that, considered in isolation, are
|
53
|
+
based on the Application, and not on the Linked Version.
|
54
|
+
|
55
|
+
The "Corresponding Application Code" for a Combined Work means the
|
56
|
+
object code and/or source code for the Application, including any data
|
57
|
+
and utility programs needed for reproducing the Combined Work from the
|
58
|
+
Application, but excluding the System Libraries of the Combined Work.
|
59
|
+
|
60
|
+
1. Exception to Section 3 of the GNU GPL.
|
61
|
+
|
62
|
+
You may convey a covered work under sections 3 and 4 of this License
|
63
|
+
without being bound by section 3 of the GNU GPL.
|
64
|
+
|
65
|
+
2. Conveying Modified Versions.
|
66
|
+
|
67
|
+
If you modify a copy of the Library, and, in your modifications, a
|
68
|
+
facility refers to a function or data to be supplied by an Application
|
69
|
+
that uses the facility (other than as an argument passed when the
|
70
|
+
facility is invoked), then you may convey a copy of the modified
|
71
|
+
version:
|
72
|
+
|
73
|
+
a) under this License, provided that you make a good faith effort to
|
74
|
+
ensure that, in the event an Application does not supply the
|
75
|
+
function or data, the facility still operates, and performs
|
76
|
+
whatever part of its purpose remains meaningful, or
|
77
|
+
|
78
|
+
b) under the GNU GPL, with none of the additional permissions of
|
79
|
+
this License applicable to that copy.
|
80
|
+
|
81
|
+
3. Object Code Incorporating Material from Library Header Files.
|
82
|
+
|
83
|
+
The object code form of an Application may incorporate material from
|
84
|
+
a header file that is part of the Library. You may convey such object
|
85
|
+
code under terms of your choice, provided that, if the incorporated
|
86
|
+
material is not limited to numerical parameters, data structure
|
87
|
+
layouts and accessors, or small macros, inline functions and templates
|
88
|
+
(ten or fewer lines in length), you do both of the following:
|
89
|
+
|
90
|
+
a) Give prominent notice with each copy of the object code that the
|
91
|
+
Library is used in it and that the Library and its use are
|
92
|
+
covered by this License.
|
93
|
+
|
94
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
95
|
+
document.
|
96
|
+
|
97
|
+
4. Combined Works.
|
98
|
+
|
99
|
+
You may convey a Combined Work under terms of your choice that,
|
100
|
+
taken together, effectively do not restrict modification of the
|
101
|
+
portions of the Library contained in the Combined Work and reverse
|
102
|
+
engineering for debugging such modifications, if you also do each of
|
103
|
+
the following:
|
104
|
+
|
105
|
+
a) Give prominent notice with each copy of the Combined Work that
|
106
|
+
the Library is used in it and that the Library and its use are
|
107
|
+
covered by this License.
|
108
|
+
|
109
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
110
|
+
document.
|
111
|
+
|
112
|
+
c) For a Combined Work that displays copyright notices during
|
113
|
+
execution, include the copyright notice for the Library among
|
114
|
+
these notices, as well as a reference directing the user to the
|
115
|
+
copies of the GNU GPL and this license document.
|
116
|
+
|
117
|
+
d) Do one of the following:
|
118
|
+
|
119
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
120
|
+
License, and the Corresponding Application Code in a form
|
121
|
+
suitable for, and under terms that permit, the user to
|
122
|
+
recombine or relink the Application with a modified version of
|
123
|
+
the Linked Version to produce a modified Combined Work, in the
|
124
|
+
manner specified by section 6 of the GNU GPL for conveying
|
125
|
+
Corresponding Source.
|
126
|
+
|
127
|
+
1) Use a suitable shared library mechanism for linking with the
|
128
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
129
|
+
a copy of the Library already present on the user's computer
|
130
|
+
system, and (b) will operate properly with a modified version
|
131
|
+
of the Library that is interface-compatible with the Linked
|
132
|
+
Version.
|
133
|
+
|
134
|
+
e) Provide Installation Information, but only if you would otherwise
|
135
|
+
be required to provide such information under section 6 of the
|
136
|
+
GNU GPL, and only to the extent that such information is
|
137
|
+
necessary to install and execute a modified version of the
|
138
|
+
Combined Work produced by recombining or relinking the
|
139
|
+
Application with a modified version of the Linked Version. (If
|
140
|
+
you use option 4d0, the Installation Information must accompany
|
141
|
+
the Minimal Corresponding Source and Corresponding Application
|
142
|
+
Code. If you use option 4d1, you must provide the Installation
|
143
|
+
Information in the manner specified by section 6 of the GNU GPL
|
144
|
+
for conveying Corresponding Source.)
|
145
|
+
|
146
|
+
5. Combined Libraries.
|
147
|
+
|
148
|
+
You may place library facilities that are a work based on the
|
149
|
+
Library side by side in a single library together with other library
|
150
|
+
facilities that are not Applications and are not covered by this
|
151
|
+
License, and convey such a combined library under terms of your
|
152
|
+
choice, if you do both of the following:
|
153
|
+
|
154
|
+
a) Accompany the combined library with a copy of the same work based
|
155
|
+
on the Library, uncombined with any other library facilities,
|
156
|
+
conveyed under the terms of this License.
|
157
|
+
|
158
|
+
b) Give prominent notice with the combined library that part of it
|
159
|
+
is a work based on the Library, and explaining where to find the
|
160
|
+
accompanying uncombined form of the same work.
|
161
|
+
|
162
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
163
|
+
|
164
|
+
The Free Software Foundation may publish revised and/or new versions
|
165
|
+
of the GNU Lesser General Public License from time to time. Such new
|
166
|
+
versions will be similar in spirit to the present version, but may
|
167
|
+
differ in detail to address new problems or concerns.
|
168
|
+
|
169
|
+
Each version is given a distinguishing version number. If the
|
170
|
+
Library as you received it specifies that a certain numbered version
|
171
|
+
of the GNU Lesser General Public License "or any later version"
|
172
|
+
applies to it, you have the option of following the terms and
|
173
|
+
conditions either of that published version or of any later version
|
174
|
+
published by the Free Software Foundation. If the Library as you
|
175
|
+
received it does not specify a version number of the GNU Lesser
|
176
|
+
General Public License, you may choose any version of the GNU Lesser
|
177
|
+
General Public License ever published by the Free Software Foundation.
|
178
|
+
|
179
|
+
If the Library as you received it specifies that a proxy can decide
|
180
|
+
whether future versions of the GNU Lesser General Public License shall
|
181
|
+
apply, that proxy's public statement of acceptance of any version is
|
182
|
+
permanent authorization for you to choose that version for the
|
183
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
# asciidoctor-latexmath
|
2
|
+
|
3
|
+
Offline `latexmath` rendering for Asciidoctor documents powered by your local LaTeX toolchain.
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
|
7
|
+
- [Overview](#overview)
|
8
|
+
- [Features](#features)
|
9
|
+
- [How It Works](#how-it-works)
|
10
|
+
- [Output Formats](#output-formats)
|
11
|
+
- [Prerequisites](#prerequisites)
|
12
|
+
- [Installation](#installation)
|
13
|
+
- [Quick Start](#quick-start)
|
14
|
+
- [Document Attributes](#document-attributes)
|
15
|
+
- [Why asciidoctor-latexmath?](#why-asciidoctor-latexmath)
|
16
|
+
- [Troubleshooting](#troubleshooting)
|
17
|
+
- [Contributing](#contributing)
|
18
|
+
- [Author](#author)
|
19
|
+
- [License](#license)
|
20
|
+
|
21
|
+
## Overview
|
22
|
+
|
23
|
+
`asciidoctor-latexmath` is an Asciidoctor extension that renders `latexmath` blocks and inline macros into static images. It leverages the LaTeX toolchain already installed on your system so you can produce consistent formulas in environments where MathJax or similar browser-side renderers are not an option.
|
24
|
+
|
25
|
+
## Features
|
26
|
+
|
27
|
+
- **Offline-first rendering** – no external services or JavaScript runtime required.
|
28
|
+
- **LaTeX fidelity** – relies on the same `pdflatex`, `xelatex`, or `lualatex` tooling used for high-quality print workflows.
|
29
|
+
- **Multiple output formats** – generate PDF, SVG, or PNG assets to match your target backend.
|
30
|
+
- **Drop-in integration** – register the extension once and keep authoring with the familiar `latexmath` syntax.
|
31
|
+
- **Intelligent caching** – reuse previously rendered formulas (including inline data URIs) to keep iterative builds fast.
|
32
|
+
|
33
|
+
## How It Works
|
34
|
+
|
35
|
+
1. The extension intercepts `latexmath` blocks and inline macros during the Asciidoctor conversion pipeline.
|
36
|
+
2. The captured TeX snippet is compiled with your preferred LaTeX engine (`pdflatex`, `xelatex`, `lualatex`, or `tectonic`) into a minimal standalone document.
|
37
|
+
3. The resulting PDF is post-processed into the requested target format (PDF/SVG/PNG).
|
38
|
+
4. The rendered asset is embedded back into the document output so it behaves like any other image.
|
39
|
+
|
40
|
+
All processing happens locally, which keeps your documentation builds reproducible and secure.
|
41
|
+
|
42
|
+
## Output Formats
|
43
|
+
|
44
|
+
| Format | Description | Typical Use Cases |
|
45
|
+
| ------ | ----------- | ----------------- |
|
46
|
+
| `pdf` | Keeps the raw LaTeX PDF output for backends that accept vector PDFs. | Asciidoctor PDF, print-ready workflows |
|
47
|
+
| `svg` | Converts the PDF to scalable vector graphics. | Responsive HTML output, retina displays |
|
48
|
+
| `png` | Rasterizes the PDF into a bitmap image. | Legacy HTML pipelines, slide decks |
|
49
|
+
|
50
|
+
## Prerequisites
|
51
|
+
|
52
|
+
Make sure the following tools are available on your system `PATH` before enabling the extension:
|
53
|
+
|
54
|
+
- **Ruby 3.3+** and **Asciidoctor 2.0+**
|
55
|
+
- A LaTeX engine such as **`pdflatex`**, **`xelatex`**, **`lualatex`**, or **`tectonic`** (provided by TeX Live, MiKTeX, MacTeX, etc.)
|
56
|
+
- Optional: **`dvisvgm`** for SVG conversion and **ImageMagick** or **ghostscript** for PNG conversion
|
57
|
+
- Computer Modern fonts (usually bundled with the TeX distribution)
|
58
|
+
|
59
|
+
You can verify `pdflatex` availability with:
|
60
|
+
|
61
|
+
```bash
|
62
|
+
pdflatex --version
|
63
|
+
```
|
64
|
+
|
65
|
+
Swap in another engine if that is your default workflow—for example, `xelatex --version` or `tectonic --help`.
|
66
|
+
|
67
|
+
## Installation
|
68
|
+
|
69
|
+
### Using RubyGems
|
70
|
+
|
71
|
+
```bash
|
72
|
+
gem install asciidoctor-latexmath
|
73
|
+
```
|
74
|
+
|
75
|
+
### Using Bundler
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
gem 'asciidoctor-latexmath'
|
79
|
+
```
|
80
|
+
|
81
|
+
Run `bundle install` to make the extension available to your project.
|
82
|
+
|
83
|
+
### From Source
|
84
|
+
|
85
|
+
Clone this repository and point Asciidoctor at the local checkout:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
git clone https://github.com/your-org/asciidoctor-latexmath.git
|
89
|
+
cd asciidoctor-latexmath
|
90
|
+
bundle install
|
91
|
+
```
|
92
|
+
|
93
|
+
Then require the extension via a relative path (see [Quick Start](#quick-start)).
|
94
|
+
|
95
|
+
## Quick Start
|
96
|
+
|
97
|
+
Render a document with offline `latexmath` support:
|
98
|
+
|
99
|
+
```bash
|
100
|
+
asciidoctor -r asciidoctor-latexmath -a latexmath-format=svg sample.adoc
|
101
|
+
```
|
102
|
+
|
103
|
+
Select a different engine by providing the `pdflatex` attribute at runtime. For example, to build with `tectonic`:
|
104
|
+
|
105
|
+
```bash
|
106
|
+
asciidoctor -r asciidoctor-latexmath -a pdflatex=tectonic -a latexmath-format=svg sample.adoc
|
107
|
+
```
|
108
|
+
|
109
|
+
During development, load the registration file directly from your working tree:
|
110
|
+
|
111
|
+
```bash
|
112
|
+
asciidoctor -r ./lib/asciidoctor-latexmath.rb -a latexmath-format=svg sample.adoc
|
113
|
+
```
|
114
|
+
|
115
|
+
Sample AsciiDoc snippet:
|
116
|
+
|
117
|
+
```adoc
|
118
|
+
The famous mass-energy equivalence equation is shown below.
|
119
|
+
|
120
|
+
[latexmath]
|
121
|
+
+++
|
122
|
+
E = mc^2
|
123
|
+
+++
|
124
|
+
|
125
|
+
Einstein also described spacetime curvature with the inline latexmath:[E_{\mu\nu} = 8 \pi T_{\mu\nu}] variant.
|
126
|
+
```
|
127
|
+
|
128
|
+
The extension replaces both expressions with rendered images that match the format specified in `latexmath-format`.
|
129
|
+
|
130
|
+
## Document Attributes
|
131
|
+
|
132
|
+
| Attribute | Description | Values | Default |
|
133
|
+
| --------- | ----------- | ------ | ------- |
|
134
|
+
| `stem` | Enables global stem support. Set to `latexmath` (or `tex`) to make bare `stem:[...]` invocations render through this extension. | `latexmath`, `tex`, etc. | *(not set)* |
|
135
|
+
| `latexmath-format` | Desired output format for generated assets. | `pdf`, `svg`, `png` | `svg` |
|
136
|
+
| `latexmath-inline` | Embed inline formulas directly into the HTML output instead of linking to image files. Works with `svg` (inline markup) and `png` (data URI). | `true`, `false` | `false` |
|
137
|
+
| `latexmath-ppi` | Pixels per inch for PNG rasterization. Ignored for `pdf`/`svg`. | Any positive number | `300` |
|
138
|
+
| `latexmath-preamble` | Extra LaTeX preamble inserted before `\begin{document}`. Useful for additional packages or macro definitions. | LaTeX snippet | *(empty)* |
|
139
|
+
| `pdflatex` | Command used to compile the temporary LaTeX document. | `pdflatex`, `xelatex`, `lualatex`, `tectonic`, absolute path | `pdflatex` |
|
140
|
+
| `latexmath-pdf2svg` | Converter used when `latexmath-format=svg`. Override if your toolchain provides an alternative. | `pdf2svg`, absolute path | `pdf2svg` |
|
141
|
+
| `latexmath-png-tool` | Converter used when `latexmath-format=png`. The extension auto-detects `magick`, `convert`, or `pdftoppm`; set this attribute to force a specific command. | Command name or path | *(auto)* |
|
142
|
+
| `latexmath-keep-artifacts` | Preserve the generated `.tex`, `.log`, and intermediate PDF files for inspection. | `true`, `false` | `false` |
|
143
|
+
| `latexmath-artifacts-dir` | Destination directory for kept artifacts when `latexmath-keep-artifacts=true`. Relative paths are resolved from the document directory. | Path | `imagesoutdir` (or document directory) |
|
144
|
+
| `latexmath-cache` | Enables the on-disk cache for rendered formulas. Set to `false` to force regeneration on every run. | `true`, `false` | `true` |
|
145
|
+
| `latexmath-cache-dir` | Directory that stores cached render metadata and assets. Resolved relative to the document directory when relative. | Path | `<outdir>/.asciidoctor/latexmath` |
|
146
|
+
|
147
|
+
All generated images follow Asciidoctor's standard image directory rules. Set `imagesoutdir` to control where files are written on disk and `imagesdir` to influence how they are referenced from the rendered document. Inline math inside literal table cells is also supported—the extension adds macro substitutions automatically so the rendered `<span class="image">…</span>` markup appears inside the literal block.
|
148
|
+
|
149
|
+
Set attributes via the CLI or document header, for example: `-a latexmath-format=png`.
|
150
|
+
|
151
|
+
## Caching
|
152
|
+
|
153
|
+
The renderer persists every successful compilation so repeated conversions can reuse the existing SVG/PNG/PDF payloads without invoking your LaTeX toolchain again. Cache entries are keyed by the equation text, display/inline mode, selected output format, preamble contents, and rendering tools, which keeps results correct even when you tweak your setup. Inline rendering via `-a latexmath-inline` reuses the cached inline markup as well, so enabling `-a data-uri` no longer slows down incremental builds.
|
154
|
+
|
155
|
+
By default, cache files live under `<outdir>/.asciidoctor/latexmath`. Override this location with `-a latexmath-cache-dir=path/to/cache` or disable caching altogether with `-a latexmath-cache=false` when you need a clean rebuild. Removing the cache directory forces the next run to regenerate every formula.
|
156
|
+
|
157
|
+
## Why asciidoctor-latexmath?
|
158
|
+
|
159
|
+
| Feature | asciidoctor-latexmath | asciidoctor-mathematical |
|
160
|
+
| ------- | --------------------- | ------------------------- |
|
161
|
+
| Input types | `latexmath` only | `latexmath` and `stem` |
|
162
|
+
| Rendering backend | Local LaTeX engine (`pdflatex`/`xelatex`/`lualatex`/`tectonic`) | Native Mathematical library |
|
163
|
+
| Output formats | PDF, SVG, PNG | PNG (default) / SVG |
|
164
|
+
| External dependencies | Leverages standard LaTeX installation | Requires the Mathematical gem and Cairo stack |
|
165
|
+
|
166
|
+
Choose `asciidoctor-latexmath` when you already depend on a LaTeX distribution and want fully offline builds with minimal additional dependencies.
|
167
|
+
|
168
|
+
## Troubleshooting
|
169
|
+
|
170
|
+
- **LaTeX engine not found** – install a LaTeX distribution (TeX Live, MiKTeX, MacTeX, or Tectonic) and ensure the binaries are on your `PATH`.
|
171
|
+
- **Blank or clipped formulas** – enable `-a latexmath-keep-artifacts=true` and inspect the generated `.log` file for LaTeX errors.
|
172
|
+
- **Missing glyphs** – install Computer Modern or other math-capable fonts that ship with TeX Live/MacTeX.
|
173
|
+
- **Slow builds** – caching is enabled by default; ensure `<outdir>/.asciidoctor/latexmath` is writable. Use `-a latexmath-cache=false` if you need to force a full regeneration.
|
174
|
+
|
175
|
+
## Contributing
|
176
|
+
|
177
|
+
Bug reports, feature requests, and patches are welcome. Please open an issue describing the use case before submitting large changes. If you plan to contribute code, follow the established Ruby style guidelines and add documentation or samples for new behaviors.
|
178
|
+
|
179
|
+
## Author
|
180
|
+
|
181
|
+
Created and maintained by Shuai Zhang.
|
182
|
+
|
183
|
+
## License
|
184
|
+
|
185
|
+
Licensed under the **LGPL-3.0-or-later WITH LGPL-3.0-linking-exception**. See `LICENSE` for the full text.
|