asciidoctor-latexmath 1.0.0.pre.dev.1 → 2.0.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 +119 -36
- data/lib/asciidoctor/latexmath/attribute_resolver.rb +485 -0
- data/lib/asciidoctor/latexmath/cache/cache_entry.rb +31 -0
- data/lib/asciidoctor/latexmath/cache/cache_key.rb +33 -0
- data/lib/asciidoctor/latexmath/cache/disk_cache.rb +151 -0
- data/lib/asciidoctor/latexmath/command_runner.rb +116 -0
- data/lib/asciidoctor/latexmath/converters/html5.rb +72 -0
- data/lib/asciidoctor/latexmath/errors.rb +134 -0
- data/lib/asciidoctor/latexmath/html_builder.rb +103 -0
- data/lib/asciidoctor/latexmath/math_expression.rb +22 -0
- data/lib/asciidoctor/latexmath/path_utils.rb +46 -0
- data/lib/asciidoctor/latexmath/processors/block_processor.rb +74 -0
- data/lib/asciidoctor/latexmath/processors/inline_macro_processor.rb +70 -0
- data/lib/asciidoctor/latexmath/processors/statistics_postprocessor.rb +18 -0
- data/lib/asciidoctor/latexmath/render_request.rb +32 -0
- data/lib/asciidoctor/latexmath/renderer_service.rb +748 -0
- data/lib/asciidoctor/latexmath/rendering/pdf_to_png_renderer.rb +97 -0
- data/lib/asciidoctor/latexmath/rendering/pdf_to_svg_renderer.rb +84 -0
- data/lib/asciidoctor/latexmath/rendering/pdflatex_renderer.rb +166 -0
- data/lib/asciidoctor/latexmath/rendering/pipeline.rb +58 -0
- data/lib/asciidoctor/latexmath/rendering/renderer.rb +33 -0
- data/lib/asciidoctor/latexmath/rendering/tool_detector.rb +320 -0
- data/lib/asciidoctor/latexmath/rendering/toolchain_record.rb +21 -0
- data/lib/asciidoctor/latexmath/statistics/collector.rb +47 -0
- data/lib/asciidoctor/latexmath/support/conflict_registry.rb +75 -0
- data/lib/{asciidoctor-latexmath → asciidoctor/latexmath}/version.rb +1 -1
- data/lib/asciidoctor-latexmath.rb +93 -3
- metadata +34 -12
- data/lib/asciidoctor-latexmath/renderer.rb +0 -515
- data/lib/asciidoctor-latexmath/treeprocessor.rb +0 -369
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29ce5a1a06289846344cb4d2ee9517e2b111953db7622641cf6e5f3381bb2e22
|
4
|
+
data.tar.gz: 4fec6a20f4a0cb2031c1eeefb7db0223cdfcf1d2912bc4aa09dfe0e97ddd939f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5f299a442fa6690968c0d6af098e4d5343b4f03ca32d1d8d4c7596d912015bae804bd2480c147e14599d8a8908b0251f08c25b45469610e9d0967db82f3a45
|
7
|
+
data.tar.gz: 440d246a9f510ba1e7fa2ed5341d48c7508428df0f02118b6101b32a704d0d0e6007e8ea1c56378e3fdad55a9cf4cf16bfe86249dcb4d9308547f3b7fd3c9c1f
|
data/README.md
CHANGED
@@ -4,19 +4,31 @@ Offline `latexmath` rendering for Asciidoctor documents powered by your local La
|
|
4
4
|
|
5
5
|
## Table of Contents
|
6
6
|
|
7
|
-
- [
|
8
|
-
- [
|
9
|
-
- [
|
10
|
-
- [
|
11
|
-
- [
|
12
|
-
- [
|
13
|
-
- [
|
14
|
-
- [
|
15
|
-
- [
|
16
|
-
- [
|
17
|
-
- [
|
18
|
-
- [
|
19
|
-
- [
|
7
|
+
- [asciidoctor-latexmath](#asciidoctor-latexmath)
|
8
|
+
- [Table of Contents](#table-of-contents)
|
9
|
+
- [Overview](#overview)
|
10
|
+
- [Features](#features)
|
11
|
+
- [Security Note](#security-note)
|
12
|
+
- [How It Works](#how-it-works)
|
13
|
+
- [Output Formats](#output-formats)
|
14
|
+
- [Prerequisites](#prerequisites)
|
15
|
+
- [Installation](#installation)
|
16
|
+
- [Using RubyGems](#using-rubygems)
|
17
|
+
- [Using Bundler](#using-bundler)
|
18
|
+
- [From Source](#from-source)
|
19
|
+
- [Quick Start](#quick-start)
|
20
|
+
- [Document Attributes](#document-attributes)
|
21
|
+
- [Document-level configuration](#document-level-configuration)
|
22
|
+
- [Font size control](#font-size-control)
|
23
|
+
- [Element attributes \& options](#element-attributes--options)
|
24
|
+
- [Caching](#caching)
|
25
|
+
- [Why asciidoctor-latexmath?](#why-asciidoctor-latexmath)
|
26
|
+
- [Accessibility \& Semantics](#accessibility--semantics)
|
27
|
+
- [Statistics Line](#statistics-line)
|
28
|
+
- [Troubleshooting](#troubleshooting)
|
29
|
+
- [Contributing](#contributing)
|
30
|
+
- [Author](#author)
|
31
|
+
- [License](#license)
|
20
32
|
|
21
33
|
## Overview
|
22
34
|
|
@@ -28,7 +40,17 @@ Offline `latexmath` rendering for Asciidoctor documents powered by your local La
|
|
28
40
|
- **LaTeX fidelity** – relies on the same `pdflatex`, `xelatex`, or `lualatex` tooling used for high-quality print workflows.
|
29
41
|
- **Multiple output formats** – generate PDF, SVG, or PNG assets to match your target backend.
|
30
42
|
- **Drop-in integration** – register the extension once and keep authoring with the familiar `latexmath` syntax.
|
31
|
-
- **Intelligent caching** – reuse previously rendered
|
43
|
+
- **Intelligent caching** – reuse previously rendered block and inline formulas; cache hits skip the LaTeX toolchain entirely.
|
44
|
+
|
45
|
+
## Security Note
|
46
|
+
|
47
|
+
This extension assumes a trusted documentation source (version-controlled repository you control). Explicit output basenames (first positional block attribute) may include relative path segments including `..` and can therefore write outside the images directory intentionally (spec FR-008/FR-009 under trust model FR-036). If you process untrusted / user‑supplied AsciiDoc:
|
48
|
+
|
49
|
+
1. Disable asciidoctor-latexmath for that pipeline; OR
|
50
|
+
2. Run in a container / chroot / sandbox restricting filesystem writes; OR
|
51
|
+
3. (Future) Enable the planned strict mode (will reject path traversal).
|
52
|
+
|
53
|
+
Shell escape is never enabled (FR-017). Cache key excludes engine & converter tool names/versions (P5 / FR-011); pin a single toolchain if you need identical byte output across environments.
|
32
54
|
|
33
55
|
## How It Works
|
34
56
|
|
@@ -129,40 +151,101 @@ The extension replaces both expressions with rendered images that match the form
|
|
129
151
|
|
130
152
|
## Document Attributes
|
131
153
|
|
132
|
-
|
133
|
-
|
134
|
-
|
|
135
|
-
|
|
136
|
-
| `
|
137
|
-
| `latexmath-
|
138
|
-
| `latexmath-preamble` |
|
139
|
-
| `
|
140
|
-
| `latexmath-
|
141
|
-
| `latexmath-
|
142
|
-
| `latexmath-
|
143
|
-
| `latexmath-
|
144
|
-
| `latexmath-
|
145
|
-
| `latexmath-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
154
|
+
### Document-level configuration
|
155
|
+
|
156
|
+
| Attribute | Aliases / CLI | Description | Values | Default |
|
157
|
+
| --------- | ------------- | ----------- | ------ | ------- |
|
158
|
+
| `stem` | `-a stem=latexmath` | Enables global stem support so bare `stem:[...]` calls delegate to this extension. | `latexmath`, `tex` | *(not set)* |
|
159
|
+
| `latexmath-format` | `-a latexmath-format=svg` | Desired output format for every rendered asset. | `svg`, `pdf`, `png` | `svg` |
|
160
|
+
| `latexmath-preamble` | `-a latexmath-preamble=...` | Additional LaTeX preamble injected before `\begin{document}`. Per-expression `preamble=` overrides the document value. | Raw LaTeX | *(empty)* |
|
161
|
+
| `latexmath-fontsize` | `-a latexmath-fontsize=12pt` | Appends a font-size option to the standalone `\documentclass`. Expressions can override with `fontsize=`. | Values ending with `pt` (e.g., `10pt`, `12pt`) | `12pt` |
|
162
|
+
| `latexmath-ppi` | `-a latexmath-ppi=300` | Pixels-per-inch for PNG renders. Ignored for SVG/PDF. | Integer 72–600 | `300` |
|
163
|
+
| `latexmath-timeout` | `-a latexmath-timeout=120` | Maximum wall-clock time (seconds) each expression may consume before the renderer aborts and raises/places a placeholder. | Positive integer | `120` |
|
164
|
+
| `latexmath-cache` | `-a latexmath-cache=false` | Toggle the on-disk cache. `false` forces regeneration without persisting results. | `true`, `false` | `true` |
|
165
|
+
| `latexmath-cachedir` | `-a latexmath-cachedir=build/.cache/latexmath` | Cache location precedence: element `cachedir=` → `:latexmath-cachedir:` → `<outdir>/<imagesdir>` (when present) → `<outdir>/.asciidoctor/latexmath`. | Path | `<outdir>/.asciidoctor/latexmath` |
|
166
|
+
| `latexmath-keep-artifacts` | `-a latexmath-keep-artifacts=true` | Retain intermediate `.tex`, `.log`, and PDF files for debugging. | `true`, `false` | `false` |
|
167
|
+
| `latexmath-artifacts-dir` | `-a latexmath-artifacts-dir=build/latexmath-artifacts` | Destination for kept artifacts when `latexmath-keep-artifacts` is enabled. | Path | `<cachedir>/artifacts` |
|
168
|
+
| `pdflatex` / `latexmath-pdflatex` | `-a pdflatex=tectonic` | Document-wide LaTeX engine command. Elements can override with `pdflatex=`. | `pdflatex`, `xelatex`, `lualatex`, `tectonic`, or absolute path | `pdflatex` |
|
169
|
+
| `latexmath-svg-tool` | `-a latexmath-svg-tool=pdf2svg` | Preferred SVG converter (`dvisvgm` or `pdf2svg`). Paths are allowed. | Tool id or absolute path | auto-detect (`dvisvgm` then `pdf2svg`) |
|
170
|
+
| `latexmath-pdf2svg` | `-a latexmath-pdf2svg=/opt/bin/dvisvgm` | Legacy alias for the SVG converter attribute. Logs a one-time info message then normalizes to `latexmath-svg-tool`. | Path | *(same as above)* |
|
171
|
+
| `latexmath-png-tool` | `-a latexmath-png-tool=magick` | Preferred PNG conversion tool. | `pdftoppm`, `magick`, `gs`, or path | auto-detect (`pdftoppm`, `magick`, `gs`) |
|
172
|
+
| `latexmath-pdftoppm` | `-a latexmath-pdftoppm=/opt/bin/pdftoppm` | Legacy alias for PNG converter selection. Logs a one-time info message. | Path | *(same as above)* |
|
173
|
+
| `latexmath-on-error` | `-a latexmath-on-error=abort` | Rendering failure policy. `log` inserts an HTML placeholder, `abort` stops the build. | `log`, `abort` | `log` |
|
174
|
+
|
175
|
+
> Deprecated alias: `latexmath-cache-dir` / `cache-dir` is still accepted (emits a one-time INFO log) but you should prefer `latexmath-cachedir` / `cachedir`.
|
176
|
+
|
177
|
+
#### Font size control
|
178
|
+
|
179
|
+
The renderer always emits `\documentclass[preview,border=2pt,<size>]{standalone}`. The document attribute `:latexmath-fontsize:` sets the default size (12pt); blocks and inline macros can override it with `fontsize=` while still participating in caching. Values must end with `pt`—otherwise the extension raises `Asciidoctor::Latexmath::UnsupportedValueError` with an actionable hint.
|
180
|
+
|
181
|
+
```adoc
|
182
|
+
:latexmath-fontsize: 10pt
|
183
|
+
|
184
|
+
[latexmath, fontsize=18pt]
|
185
|
+
+++
|
186
|
+
\int_a^b f(x)\,dx
|
187
|
+
+++
|
188
|
+
```
|
189
|
+
|
190
|
+
### Element attributes & options
|
191
|
+
|
192
|
+
| Attribute / Option | Applies To | Description | Values / Notes |
|
193
|
+
| ------------------ | ---------- | ----------- | -------------- |
|
194
|
+
| `target=` (first positional attribute) | Block | Explicit output basename (may include subdirectories). | Filename |
|
195
|
+
| `format` (second positional attribute) | Block | Overrides output format for this expression only. | `svg`, `pdf`, `png` |
|
196
|
+
| `format=` | Block / Inline | Keyword attribute equivalent to the positional format override. | `svg`, `pdf`, `png` |
|
197
|
+
| `preamble=` | Block / Inline | Replaces the document-level preamble for this expression. | Raw LaTeX |
|
198
|
+
| `fontsize=` | Block / Inline | Overrides the `\documentclass` font-size option for this expression. | Values ending with `pt` (e.g., `10pt`, `12pt`) |
|
199
|
+
| `ppi=` | Block / Inline | Per-expression PNG density (only used when `format=png`). | Integer 72–600 |
|
200
|
+
| `timeout=` | Block / Inline | Overrides the timeout for the current expression. | Positive integer |
|
201
|
+
| `cache=` | Block / Inline | Enables/disables cache usage for the expression. | `true`, `false` |
|
202
|
+
| `%nocache` option | Block | Shortcut that skips both cache read and write. | Use as `[latexmath%nocache]` |
|
203
|
+
| `keep-artifacts` option | Block | Preserve intermediate files for this expression. | `[latexmath, options="keep-artifacts"]` |
|
204
|
+
| `artifacts-dir=` / `artifactsdir=` | Block / Inline | Custom artifact directory when `keep-artifacts` is active. | Path |
|
205
|
+
| `cachedir=` / `cache-dir=` | Block / Inline | Store/read cache entries for this expression in a custom directory. Logs a deprecation warning when `cache-dir=` is used. | Path |
|
206
|
+
| `pdflatex=` | Block / Inline | Per-expression engine command (allows flags or absolute paths). | Command string |
|
207
|
+
| `latexmath-svg-tool=` / `latexmath-pdf2svg=` | Block / Inline | Choose a specific SVG converter or executable path. | Tool id / path |
|
208
|
+
| `latexmath-png-tool=` / `latexmath-pdftoppm=` | Block / Inline | Choose a specific PNG converter or executable path. | Tool id / path |
|
209
|
+
| `on-error=` | Block / Inline | Override the error handling policy locally. | `log`, `abort` |
|
210
|
+
| `role=` | Block / Inline | Adds additional roles/CSS classes; the extension always reapplies the `math` role and accessible markup. | Space-separated roles |
|
211
|
+
| `align=` | Block | Aligns the enclosing block (`left`, `center`, `right`). | CSS alignment keyword |
|
212
|
+
|
213
|
+
Inline macros support the same keyword attributes except for positional `target=`/`format`. Attributes follow asciidoctor-diagram precedence: element attribute → element options → document attribute → default.
|
214
|
+
|
215
|
+
Set attributes via the CLI (`-a latexmath-format=png`) or inside the document header. Positional attributes follow the asciidoctor-diagram convention: `[latexmath, basename, format]`.
|
216
|
+
|
217
|
+
All generated images respect Asciidoctor's standard image directory rules. Use `imagesoutdir` to control the physical output location and `imagesdir` to influence how assets are referenced in HTML. Inline math inside literal table cells is also supported—the processor injects the rendered `<span class="image math">…</span>` markup automatically.
|
150
218
|
|
151
219
|
## Caching
|
152
220
|
|
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
|
221
|
+
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 hash the following ordered fields with SHA256: extension version, normalized content hash, output format, preamble hash, font-size hash, PPI (PNG only, otherwise `-`), and entry type (`block` | `inline`). Delimiter changes, engine switches, or tool swaps do **not** affect the cache key (FR-011 / P5), so switching `pdflatex` → `xelatex` with other factors constant reuses the same cache entry. Inline rendering via `-a latexmath-inline` reuses the cached inline markup; enabling `-a data-uri` does not invalidate cached images.
|
154
222
|
|
155
|
-
By default, cache files live under `<outdir>/.asciidoctor/latexmath`. Override this location with `-a latexmath-
|
223
|
+
By default, cache files live under `<outdir>/.asciidoctor/latexmath`. Override this location with `-a latexmath-cachedir=path/to/cache` (legacy `-a latexmath-cache-dir=...` still works but logs a deprecation message) 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
224
|
|
157
225
|
## Why asciidoctor-latexmath?
|
158
226
|
|
159
227
|
| Feature | asciidoctor-latexmath | asciidoctor-mathematical |
|
160
228
|
| ------- | --------------------- | ------------------------- |
|
161
|
-
| Input types | `latexmath`
|
162
|
-
| Rendering backend | Local LaTeX engine (`pdflatex
|
229
|
+
| Input types | `latexmath` (block + inline) | `latexmath` and `stem` |
|
230
|
+
| Rendering backend | Local LaTeX engine (`pdflatex` / `xelatex` / `lualatex` / `tectonic`) | Native Mathematical library |
|
163
231
|
| Output formats | PDF, SVG, PNG | PNG (default) / SVG |
|
232
|
+
| Accessibility defaults | `role="math"` + `alt` attributes derived from source | Requires manual markup |
|
164
233
|
| External dependencies | Leverages standard LaTeX installation | Requires the Mathematical gem and Cairo stack |
|
165
234
|
|
235
|
+
## Accessibility & Semantics
|
236
|
+
|
237
|
+
Rendered output keeps formulas accessible by emitting `<img>` elements with `role="math"`, `alt` text set to the raw LaTeX snippet, and a `data-latex-original` attribute for tooling. Blocks inherit the usual Asciidoctor figure roles, while inline expressions blend into text content without breaking line height.
|
238
|
+
|
239
|
+
## Statistics Line
|
240
|
+
|
241
|
+
When logging at INFO (the default), the extension prints a single summary line per run:
|
242
|
+
|
243
|
+
```
|
244
|
+
latexmath stats: renders=<int> cache_hits=<int> avg_render_ms=<int> avg_hit_ms=<int>
|
245
|
+
```
|
246
|
+
|
247
|
+
Fields are fixed in name and order (FR-022 / FR-035). Use this line to monitor warm-cache behaviour in CI or to flag unexpected cache misses.
|
248
|
+
|
166
249
|
Choose `asciidoctor-latexmath` when you already depend on a LaTeX distribution and want fully offline builds with minimal additional dependencies.
|
167
250
|
|
168
251
|
## Troubleshooting
|