Provide a runnable local Beta and fix multi-page SVG previews
This commit is contained in:
1 parent
fb557c09c6
commit
9841e88900
7 files changed
+324
-9
No files matched your search
@@ -10,8 +10,8 @@ where their state, file effects, and cancellation can be verified.
|
|||||||
The [product goal](docs/NATIVE_PRODUCT_GOAL.md) defines compatibility and live
|
The [product goal](docs/NATIVE_PRODUCT_GOAL.md) defines compatibility and live
|
||||||
preview acceptance. The [publisher matrix](docs/PUBLISHER_TEMPLATE_MATRIX.md)
|
preview acceptance. The [publisher matrix](docs/PUBLISHER_TEMPLATE_MATRIX.md)
|
||||||
covers original journals, two-column journals, conferences, and arXiv.
|
covers original journals, two-column journals, conferences, and arXiv.
|
||||||
The [local beta milestone](docs/NATIVE_PRODUCT_GOAL.md#beta-优先交付) describes
|
The [local beta guide](docs/NATIVE_BETA.md) explains how to prepare a bundle,
|
||||||
the first supported projects and the edit, preview, and export workflow.
|
open a project in the native editor, and export a PDF.
|
||||||
|
|
||||||
## Native execution bootstrap
|
## Native execution bootstrap
|
||||||
|
|
||||||
|
|||||||
@@ -625,7 +625,7 @@ impl DisplayList {
|
|||||||
write!(
|
write!(
|
||||||
out,
|
out,
|
||||||
"<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"",
|
"<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"",
|
||||||
escape(font), escape(glyph), escape(&label), path,
|
escape_attribute(font), escape_attribute(glyph), escape_attribute(&label), path,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
if let Some([vx2, vy]) = vertical_origin {
|
if let Some([vx2, vy]) = vertical_origin {
|
||||||
let vx = f64::from(vx2) / 2.0;
|
let vx = f64::from(vx2) / 2.0;
|
||||||
@@ -680,7 +680,7 @@ impl DisplayList {
|
|||||||
write!(
|
write!(
|
||||||
out,
|
out,
|
||||||
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5})",
|
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5})",
|
||||||
escape(&font.name), escape(text),
|
escape_attribute(&font.name), escape_attribute(text),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
if transform.is_none() {
|
if transform.is_none() {
|
||||||
if let Some([a, b, c, d, e, f]) = vertical {
|
if let Some([a, b, c, d, e, f]) = vertical {
|
||||||
@@ -733,7 +733,7 @@ impl DisplayList {
|
|||||||
let scale = *size as f64 / 65_536_000.0;
|
let scale = *size as f64 / 65_536_000.0;
|
||||||
out.push_str(&format!(
|
out.push_str(&format!(
|
||||||
"<g data-font=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><use href=\"#math-{}-{slot}\" transform=\"translate({x:.5} {y:.5}) scale({scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/><text x=\"{x:.5}\" y=\"{y:.5}\" opacity=\"0\" aria-hidden=\"true\">{}</text></g>\n",
|
"<g data-font=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><use href=\"#math-{}-{slot}\" transform=\"translate({x:.5} {y:.5}) scale({scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/><text x=\"{x:.5}\" y=\"{y:.5}\" opacity=\"0\" aria-hidden=\"true\">{}</text></g>\n",
|
||||||
face.name(), escape(&character.to_string()), face.0,
|
escape_attribute(face.name()), escape_attribute(&character.to_string()), face.0,
|
||||||
fill[0], fill[1], fill[2], escape(&character.to_string())
|
fill[0], fill[1], fill[2], escape(&character.to_string())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -1083,6 +1083,15 @@ fn base64(data: &[u8]) -> String {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn escape_attribute(text: &str) -> String {
|
||||||
|
let escaped = escape(text);
|
||||||
|
if text.contains('"') {
|
||||||
|
escaped.replace('"', """)
|
||||||
|
} else {
|
||||||
|
escaped
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn escape(text: &str) -> String {
|
fn escape(text: &str) -> String {
|
||||||
text.replace('&', "&")
|
text.replace('&', "&")
|
||||||
.replace('<', "<")
|
.replace('<', "<")
|
||||||
|
|||||||
@@ -6,11 +6,31 @@ use texrra_tex_core::math::{MathAtom, parse_math};
|
|||||||
use texrra_tex_core::math_font::MathFontId;
|
use texrra_tex_core::math_font::MathFontId;
|
||||||
use texrra_tex_core::paragraph::{HorizontalItem, InlineSegment, ParagraphFont, ParagraphStyle};
|
use texrra_tex_core::paragraph::{HorizontalItem, InlineSegment, ParagraphFont, ParagraphStyle};
|
||||||
use texrra_tex_core::pdf::{PageOrigin, display_lists_to_pdf_with_cm_type1};
|
use texrra_tex_core::pdf::{PageOrigin, display_lists_to_pdf_with_cm_type1};
|
||||||
use texrra_tex_core::render::DisplayItem;
|
use texrra_tex_core::render::{DisplayItem, DisplayList};
|
||||||
use texrra_tex_core::{Document, Engine, Unit, VerticalItem};
|
use texrra_tex_core::{Document, Engine, Unit, VerticalItem};
|
||||||
|
|
||||||
const PT: i64 = 65_536;
|
const PT: i64 = 65_536;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn svg_glyph_labels_escape_attribute_quotes() {
|
||||||
|
let display = DisplayList {
|
||||||
|
width: 12 * PT,
|
||||||
|
height: 12 * PT,
|
||||||
|
items: vec![DisplayItem::MathGlyph {
|
||||||
|
x: 0,
|
||||||
|
y: 6 * PT,
|
||||||
|
size: 10 * PT,
|
||||||
|
character: '"',
|
||||||
|
face: MathFontId(0),
|
||||||
|
slot: b'"',
|
||||||
|
}],
|
||||||
|
..DisplayList::default()
|
||||||
|
};
|
||||||
|
let svg = display.try_to_svg().unwrap();
|
||||||
|
assert!(svg.contains(r#"aria-label="""><use"#));
|
||||||
|
assert!(svg.contains(r#"aria-hidden="true">"</text>"#));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn structural_display_edits_replay_the_preceding_paragraph_dependency() {
|
fn structural_display_edits_replay_the_preceding_paragraph_dependency() {
|
||||||
let style = ParagraphStyle {
|
let style = ParagraphStyle {
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# Route-D 本地 Beta
|
||||||
|
|
||||||
|
本地编辑器和命令行使用同一原生编译内核。准备时使用机器上已有的
|
||||||
|
TeX Live、字体和宏包。生成的目录包含两个程序、原生格式、资源记录
|
||||||
|
和 A4 多文件样例。格式沿用本机实际资源路径。
|
||||||
|
|
||||||
|
## 准备与启动
|
||||||
|
|
||||||
|
在安装了 Rust、Python 3.11 或更高版本与 TeX Live 的环境中,从仓库根目录运行。
|
||||||
|
目前这套流程已在 Fedora WSL 验证。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo build --locked --release --bin texrra --example native_editor
|
||||||
|
python3 scripts/native-beta.py prepare target/local-beta
|
||||||
|
python3 target/local-beta/native-beta.py open
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本调用 Route-D 执行 TeX Live 的原样 pdflatex.ini。首次准备会执行格式初始化。
|
||||||
|
编辑器启动后会在终端显示本地网址。打开该网址即可切换样例的主文件和子文件,
|
||||||
|
查看页面并下载 PDF。
|
||||||
|
|
||||||
|
准备 XeLaTeX 格式时加 `--input-profile xetex`。用 `--texmf-root` 指定额外
|
||||||
|
宏包或字体所在的 TeX 树时,按查找顺序列出本机使用的全部树。也可以成对给出
|
||||||
|
`--format-image` 和 `--format-resources`,使用在相同环境生成的格式与资源清单。
|
||||||
|
准备过程把实际资源搜索配置写进 `bundle.json`,供编辑器与命令行共用。
|
||||||
|
|
||||||
|
## 打开自己的项目
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 target/local-beta/native-beta.py open /path/to/main.tex \
|
||||||
|
--file chapter.tex --file figures/plot.pdf
|
||||||
|
python3 target/local-beta/native-beta.py compile /path/to/main.tex /path/to/output.pdf
|
||||||
|
```
|
||||||
|
|
||||||
|
`--file` 接收相对于主文件目录的路径,可列出子文件及实际使用的图像等资源。
|
||||||
|
编辑器在试用目录中创建工作副本。当前编辑内容保存在会话内,可以下载 PDF。
|
||||||
|
命令行按项目实际读写作业文件。需要 BibTeX 的项目可在辅助文件生成后
|
||||||
|
运行 BibTeX,再继续 LaTeX 编译到引用收敛。
|
||||||
|
|
||||||
|
## 已对照的项目
|
||||||
|
|
||||||
|
| 原样项目 | 编译模式 | 收敛页数 |
|
||||||
|
| --- | --- | ---: |
|
||||||
|
| 仓库 arXiv 样例 | pdfLaTeX | 3 |
|
||||||
|
| PLOS ONE | pdfLaTeX | 5 |
|
||||||
|
| Elsevier CAS 双栏 | pdfLaTeX | 6 |
|
||||||
|
| IEEE 会议 | pdfLaTeX | 1 |
|
||||||
|
| NeurIPS 2025 | XeLaTeX | 12 |
|
||||||
|
|
||||||
|
同一内核构建的实际参考对照见 [阶段记录](P2_M1_PROGRESS.md)。
|
||||||
|
样例的上游来源和资源版本见 [出版模板矩阵](PUBLISHER_TEMPLATE_MATRIX.md)。
|
||||||
|
更广的兼容性与正式实时性能按 [产品总目标](NATIVE_PRODUCT_GOAL.md) 继续验收。
|
||||||
@@ -18,6 +18,38 @@
|
|||||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;原样 12 页 NeurIPS 的中部编辑与恢复已验证前后缀复用、仅更新一页,且与独立全量一致。全部副作用/交叉编辑、旧来源与正式性能门禁仍待闭合 |
|
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;原样 12 页 NeurIPS 的中部编辑与恢复已验证前后缀复用、仅更新一页,且与独立全量一致。全部副作用/交叉编辑、旧来源与正式性能门禁仍待闭合 |
|
||||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||||
|
|
||||||
|
## 2026-11-29 本地 Beta 启动与五份原样模板
|
||||||
|
|
||||||
|
本地启动脚本准备同一构建的原生 CLI、编辑器、实际格式与资源配置。
|
||||||
|
Fedora WSL 上实际执行原样 pdflatex.ini 生成格式,并用该格式打开
|
||||||
|
A4 多文件。编辑器 PDF 与独立命令行从空 aux 收敛的 PDF 逐字节相同。
|
||||||
|
两个 profile 的本地包都走通启动。[使用指南](NATIVE_BETA.md)
|
||||||
|
|
||||||
|
原样 arXiv、PLOS ONE、Elsevier CAS 双栏、IEEE 会议和 XeLaTeX
|
||||||
|
NeurIPS 2025 合计 27 页、10,843 个词框。词序、词框和 144 DPI
|
||||||
|
灰度光栅逐页与冻结参考一致。各轮 aux 及实际流程生成的 bbl 或 out
|
||||||
|
逐字节一致。arXiv 首轮对照的首页含不同的编译日期。保持源文件与
|
||||||
|
格式,明确使用冻结参考的 2026-11-20 日期复验后首页一致。
|
||||||
|
保留初次差异。发布构建再次运行各项目的收敛作业,源输入和已核对的
|
||||||
|
PDF、aux、bbl、out 指纹全部保持。
|
||||||
|
|
||||||
|
12 页 NeurIPS 在编辑器首次预览遇到两个问题,均保留失败材料。种子
|
||||||
|
作业从一个显式字体路径找不到字形字体后,继续在 TeX 树解析成功。
|
||||||
|
快照现在保留实际存在的显式资源搜索目录及读到的字节。四页原生 SVG
|
||||||
|
随后暴露了字形属性中的未转义双引号。共享 SVG 输出修复了属性转义,
|
||||||
|
并增加定向回归。最终在 Edge 实际绘制全部 12 页。编辑和故障恢复
|
||||||
|
各只替换第 12 页,前 11 页保留 DOM 页面。错误请求保留可下载 PDF。
|
||||||
|
编辑版 PDF、aux 和 out 与同一构建的独立命令行收敛作业逐字节一致,
|
||||||
|
恢复 PDF 与原样导出逐字节一致。单次记录为首屏 20.54 秒、编辑后
|
||||||
|
可见 2.60 秒、恢复 0.83 秒。该次执行期间同机在复验出版样例。
|
||||||
|
|
||||||
|
本地 Beta 现在提供试用入口。当前编辑内容保存在会话,下一批优先
|
||||||
|
推进工作副本的源文件保存,并用原样多页项目定位首次预览与编辑耗时。
|
||||||
|
正式完整迁移和实时门槛按产品总目标验收。
|
||||||
|
|
||||||
|
证据在 target/native-beta-validation/。SHA256SUMS 指纹为
|
||||||
|
dd3d8a4d2dff519ad634eca6e75b04b6bff4ee2a87ca46ab2df9dfccd4cce439。
|
||||||
|
|
||||||
## 2026-11-29 行盒尺寸、分页返回与本地 Beta 验证
|
## 2026-11-29 行盒尺寸、分页返回与本地 Beta 验证
|
||||||
|
|
||||||
pdfTeX 的每行、首行和末行高度深度参数进入实际段落行盒。首行高度
|
pdfTeX 的每行、首行和末行高度深度参数进入实际段落行盒。首行高度
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use texrra_engine::native::{
|
|||||||
};
|
};
|
||||||
use texrra_tex_core::{
|
use texrra_tex_core::{
|
||||||
execution::InputProfile,
|
execution::InputProfile,
|
||||||
resources::{InputPolicy, WorldConfig},
|
resources::{InputPolicy, SearchPath, WorldConfig},
|
||||||
};
|
};
|
||||||
use tiny_http::{Header, Method, Request, Response, Server};
|
use tiny_http::{Header, Method, Request, Response, Server};
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ fn prepare(
|
|||||||
) -> Result<EditorProject, Box<dyn std::error::Error>> {
|
) -> Result<EditorProject, Box<dyn std::error::Error>> {
|
||||||
let format_resources: Value = serde_json::from_slice(&fs::read(manifest)?)?;
|
let format_resources: Value = serde_json::from_slice(&fs::read(manifest)?)?;
|
||||||
let roots: Vec<PathBuf> = serde_json::from_value(format_resources["texmf_roots"].clone())?;
|
let roots: Vec<PathBuf> = serde_json::from_value(format_resources["texmf_roots"].clone())?;
|
||||||
let mut world = WorldConfig::from_environment(run, roots.clone())?;
|
let mut world = WorldConfig::from_environment(run, roots)?;
|
||||||
world.input_policy = InputPolicy::Tex;
|
world.input_policy = InputPolicy::Tex;
|
||||||
let name = source
|
let name = source
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -507,8 +507,18 @@ fn prepare(
|
|||||||
files.insert(path.clone(), Arc::from(fs::read(path)?));
|
files.insert(path.clone(), Arc::from(fs::read(path)?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut coverage = BTreeSet::from_iter(roots);
|
let mut coverage = BTreeSet::from_iter(world.texmf_roots.iter().cloned());
|
||||||
coverage.insert(run.to_owned());
|
coverage.insert(run.to_owned());
|
||||||
|
// A successful lookup can follow a miss in an explicit search directory.
|
||||||
|
// Keep those directories in the snapshot along with the resolved bytes.
|
||||||
|
for search in world.paths.values().flatten() {
|
||||||
|
if let SearchPath::Directory { path, .. } = search {
|
||||||
|
let path = run.join(path);
|
||||||
|
if path.is_dir() {
|
||||||
|
coverage.insert(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for path in files.keys() {
|
for path in files.keys() {
|
||||||
if !coverage.iter().any(|root| path.starts_with(root)) {
|
if !coverage.iter().any(|root| path.starts_with(root)) {
|
||||||
coverage.insert(path.parent().ok_or("A resource needs a parent")?.to_owned());
|
coverage.insert(path.parent().ok_or("A resource needs a parent")?.to_owned());
|
||||||
|
|||||||
@@ -0,0 +1,192 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Prepare and run a local Route-D editor and CLI with one TeX configuration."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import shlex
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
RESOURCE_ENV = (
|
||||||
|
"TEXINPUTS", "TFMFONTS", "VFFONTS", "T1FONTS", "OPENTYPEFONTS", "TTFONTS",
|
||||||
|
"PKFONTS", "ENCFONTS", "TEXFONTMAPS", "TEXFORMATS", "TEXMFCNF", "MISCFONTS",
|
||||||
|
"SFDFONTS", "CMAPFONTS", "texmf_casefold_search",
|
||||||
|
"FONTCONFIG_FILE", "FONTCONFIG_PATH", "TZ", "SOURCE_DATE_EPOCH", "FORCE_SOURCE_DATE",
|
||||||
|
)
|
||||||
|
FORMAT_ENTRIES = {"tex8bit": "pdflatex.ini", "xetex": "xelatex.ini"}
|
||||||
|
MANIFEST = "bundle.json"
|
||||||
|
FORMAT = "latex.tfx"
|
||||||
|
RESOURCES = "format-resources.json"
|
||||||
|
|
||||||
|
|
||||||
|
def digest(path):
|
||||||
|
with path.open("rb") as stream:
|
||||||
|
return hashlib.file_digest(stream, "sha256").hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def installed_path(argument):
|
||||||
|
output = subprocess.check_output(["kpsewhich", argument], text=True).strip()
|
||||||
|
if not output:
|
||||||
|
raise ValueError(f"TeX Live did not provide a path for {argument}")
|
||||||
|
return Path(output).resolve(strict=True)
|
||||||
|
|
||||||
|
|
||||||
|
def binary_name(name):
|
||||||
|
return name + (".exe" if os.name == "nt" else "")
|
||||||
|
|
||||||
|
|
||||||
|
def native_command(binary, profile, roots):
|
||||||
|
command = [binary, "native", "--job", "--etex", "--input-profile", profile,
|
||||||
|
"--input-policy", "tex", "--step-limit", "600000000"]
|
||||||
|
for root in roots:
|
||||||
|
command.extend(["--texmf-root", root])
|
||||||
|
return command
|
||||||
|
|
||||||
|
|
||||||
|
def roots_from_manifest(path):
|
||||||
|
roots = json.loads(path.read_text(encoding="utf-8"))["texmf_roots"]
|
||||||
|
for root in map(Path, roots):
|
||||||
|
if not root.is_absolute() or not root.is_dir():
|
||||||
|
raise ValueError(f"The TeX resource directory is unavailable: {root}")
|
||||||
|
return roots
|
||||||
|
|
||||||
|
|
||||||
|
def prepare(args):
|
||||||
|
repo = Path(__file__).resolve().parent.parent
|
||||||
|
target = repo / os.environ.get("CARGO_TARGET_DIR", "target") / "release"
|
||||||
|
texrra = (args.texrra or target / binary_name("texrra")).resolve(strict=True)
|
||||||
|
editor = (args.editor or target / "examples" / binary_name("native_editor")).resolve(strict=True)
|
||||||
|
saved_format = args.format_image.resolve(strict=True) if args.format_image else None
|
||||||
|
saved_resources = args.format_resources.resolve(strict=True) if args.format_resources else None
|
||||||
|
if saved_format:
|
||||||
|
roots_from_manifest(saved_resources)
|
||||||
|
else:
|
||||||
|
ini = (args.ini or installed_path(FORMAT_ENTRIES[args.input_profile])).resolve(strict=True)
|
||||||
|
roots = args.texmf_root or [
|
||||||
|
installed_path("-var-value=TEXMFDIST"),
|
||||||
|
installed_path("-var-value=TEXMFSYSVAR"),
|
||||||
|
]
|
||||||
|
roots = [root.resolve(strict=True) for root in roots]
|
||||||
|
|
||||||
|
bundle = args.bundle.resolve()
|
||||||
|
bundle.mkdir(parents=True)
|
||||||
|
format_path = bundle / FORMAT
|
||||||
|
resources = bundle / RESOURCES
|
||||||
|
if saved_format:
|
||||||
|
shutil.copyfile(saved_format, format_path)
|
||||||
|
shutil.copyfile(saved_resources, resources)
|
||||||
|
else:
|
||||||
|
env = {**os.environ, "TEXRRA_STATE_DIR": str(bundle / "state")}
|
||||||
|
command = native_command(texrra, args.input_profile, roots)
|
||||||
|
with (bundle / "format.log").open("wb") as log:
|
||||||
|
subprocess.run(
|
||||||
|
[*command, "--initex", "--dump-format", "--resource-manifest", resources,
|
||||||
|
ini, format_path],
|
||||||
|
env=env, cwd=bundle, stdout=log, stderr=subprocess.STDOUT, check=True,
|
||||||
|
)
|
||||||
|
roots = roots_from_manifest(resources)
|
||||||
|
|
||||||
|
binary_dir = bundle / "bin"
|
||||||
|
binary_dir.mkdir()
|
||||||
|
texrra_path = binary_dir / binary_name("texrra")
|
||||||
|
editor_path = binary_dir / binary_name("native_editor")
|
||||||
|
shutil.copy2(texrra, texrra_path)
|
||||||
|
shutil.copy2(editor, editor_path)
|
||||||
|
shutil.copy2(Path(__file__), bundle / "native-beta.py")
|
||||||
|
example = bundle / "a4-project"
|
||||||
|
shutil.copytree(repo / "examples/native-format-stage/a4-project", example)
|
||||||
|
files = [texrra_path, editor_path, format_path, resources, example / "main.tex",
|
||||||
|
example / "chapter.tex"]
|
||||||
|
receipt = {
|
||||||
|
"input_profile": args.input_profile,
|
||||||
|
"texmf_roots": roots,
|
||||||
|
"environment": {name: os.environ[name] for name in RESOURCE_ENV if name in os.environ},
|
||||||
|
"sha256": {path.relative_to(bundle).as_posix(): digest(path) for path in files},
|
||||||
|
}
|
||||||
|
(bundle / MANIFEST).write_text(json.dumps(receipt, indent=2) + "\n", encoding="utf-8")
|
||||||
|
print(f"Beta bundle ready at {bundle}")
|
||||||
|
print(f"Start the sample with python3 {shlex.quote(str(bundle / 'native-beta.py'))} open")
|
||||||
|
|
||||||
|
|
||||||
|
def launch(args):
|
||||||
|
bundle = Path(__file__).resolve().parent
|
||||||
|
manifest = json.loads((bundle / MANIFEST).read_text(encoding="utf-8"))
|
||||||
|
roots = roots_from_manifest(bundle / RESOURCES)
|
||||||
|
if roots != manifest["texmf_roots"]:
|
||||||
|
raise ValueError("The format resource roots differ from the prepared bundle")
|
||||||
|
env = os.environ.copy()
|
||||||
|
for name in (*RESOURCE_ENV, "TEXRRA_TEXMF"):
|
||||||
|
env.pop(name, None)
|
||||||
|
env.update(manifest["environment"])
|
||||||
|
env["TEXRRA_STATE_DIR"] = str(bundle / "state")
|
||||||
|
profile = manifest["input_profile"]
|
||||||
|
if args.action == "open":
|
||||||
|
source = args.entry.resolve(strict=True) if args.entry else bundle / "a4-project/main.tex"
|
||||||
|
assets = args.file if args.entry else ["chapter.tex", *args.file]
|
||||||
|
runs = bundle / "runs"
|
||||||
|
if args.run_dir:
|
||||||
|
run = args.run_dir.resolve()
|
||||||
|
else:
|
||||||
|
runs.mkdir(exist_ok=True)
|
||||||
|
run = Path(tempfile.mkdtemp(prefix="editor-", dir=runs)) / "project"
|
||||||
|
command = [
|
||||||
|
bundle / "bin" / binary_name("native_editor"), "--input-profile", profile,
|
||||||
|
source, bundle / FORMAT, bundle / RESOURCES, run, str(args.port), *assets,
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
command = native_command(bundle / "bin" / binary_name("texrra"), profile, roots)
|
||||||
|
command.extend(["--load-format", bundle / FORMAT, args.entry.resolve(strict=True),
|
||||||
|
args.output.resolve()])
|
||||||
|
os.execve(command[0], command, env)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
commands = parser.add_subparsers(dest="action", required=True)
|
||||||
|
|
||||||
|
setup = commands.add_parser("prepare", help="create a new local Beta directory")
|
||||||
|
setup.add_argument("bundle", type=Path)
|
||||||
|
setup.add_argument("--texrra", type=Path)
|
||||||
|
setup.add_argument("--editor", type=Path)
|
||||||
|
setup.add_argument("--input-profile", choices=FORMAT_ENTRIES, default="tex8bit")
|
||||||
|
setup.add_argument("--texmf-root", action="append", type=Path)
|
||||||
|
setup.add_argument("--ini", type=Path)
|
||||||
|
setup.add_argument("--format-image", type=Path)
|
||||||
|
setup.add_argument("--format-resources", type=Path)
|
||||||
|
|
||||||
|
editor = commands.add_parser("open", help="open a project or the bundled A4 sample")
|
||||||
|
editor.add_argument("entry", type=Path, nargs="?")
|
||||||
|
editor.add_argument("--file", action="append", default=[], help="path relative to the entry")
|
||||||
|
editor.add_argument("--run-dir", type=Path)
|
||||||
|
editor.add_argument("--port", type=int, default=0)
|
||||||
|
|
||||||
|
compiler = commands.add_parser("compile", help="produce a PDF with the bundle's native CLI")
|
||||||
|
compiler.add_argument("entry", type=Path)
|
||||||
|
compiler.add_argument("output", type=Path)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.action == "prepare":
|
||||||
|
if bool(args.format_image) != bool(args.format_resources):
|
||||||
|
setup.error("--format-image and --format-resources must be supplied together")
|
||||||
|
if args.format_image and (args.ini or args.texmf_root):
|
||||||
|
setup.error("--ini and --texmf-root apply when creating a format")
|
||||||
|
try:
|
||||||
|
if args.action == "prepare":
|
||||||
|
prepare(args)
|
||||||
|
else:
|
||||||
|
launch(args)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
log = args.bundle.resolve() / "format.log"
|
||||||
|
context = f". See {log}" if log.is_file() else ""
|
||||||
|
parser.exit(1, f"Beta preparation failed (exit {error.returncode}){context}\n")
|
||||||
|
except (OSError, ValueError, KeyError) as error:
|
||||||
|
parser.exit(1, f"{error}\n")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in new issue
Block a user