Reduce Windows desktop format, opening and edit latency

This commit is contained in:
gloamxun committed 2026-12-03 00:02:37 +08:00
1 parent 4655f8a3c9
commit 830292b9b6
15 files changed
+1006 -167

No files matched your search

+29 -1
View File
@@ -5,9 +5,12 @@ import argparse
import hashlib
import json
import lzma
import os
from pathlib import Path, PurePosixPath
import shutil
import stat
import struct
import subprocess
import tarfile
import tempfile
@@ -18,6 +21,7 @@ TOOLS = {
"bibtex.windows": ("bibtex.exe",),
"kpathsea.windows": ("kpsewhich.exe", "kpathsealibw64.dll", "msvcr100.dll"),
}
FORMAT_MODES = ("pdflatex", "xelatex")
UNICODE_PACKAGES = ("ctex", "xecjk", "zhnumber", "fandol", "xetex")
UNICODE_NOTICES = {
"ctex": {"doc/latex/ctex/README.md": "ctex-README.md"},
@@ -145,6 +149,28 @@ def copy_texmf(source, target, skip_generated):
shutil.copy2(path, staged)
def prepare_formats(output):
output = output.resolve(strict=True)
editor = output / "bin/native_editor.exe"
if os.name == "nt":
backend = str(output)
else:
backend = subprocess.check_output(["wslpath", "-w", str(output)], text=True).strip()
editor.chmod(editor.stat().st_mode | stat.S_IXUSR)
subprocess.run(
[str(editor), "--prepare-windows-formats", backend],
stdin=subprocess.DEVNULL,
check=True,
)
for name in FORMAT_MODES:
directory = output / "formats" / name
for filename in ("latex.tfx", "texsys.aux"):
path = directory / filename
if not path.is_file() or not path.stat().st_size:
raise ValueError(f"Missing generated {name} format input: {filename}")
(directory / "latex.log").unlink(missing_ok=True)
def stage(args, output):
reference = json.loads((args.reference / "bundle.json").read_text())
desktop = json.loads((args.reference / "desktop-bundle.json").read_text())
@@ -158,7 +184,8 @@ def stage(args, output):
font_maps = Path(reference["environment"]["TEXFONTMAPS"].rstrip(":"))
(texmf / "fonts").mkdir()
shutil.copy2(font_maps / "pdftex.map", texmf / "fonts")
for entry in ("pdflatex.ini", "xelatex.ini"):
for mode in FORMAT_MODES:
entry = f"{mode}.ini"
if not (texmf / "dist/tex/latex/tex-ini-files" / entry).is_file():
raise ValueError(f"Missing LaTeX initialization source: {entry}")
@@ -189,6 +216,7 @@ def stage(args, output):
texmf / "overlay", licenses / "texlive", args.downloads, database
)
prepare_formats(output)
files = {
path.relative_to(output).as_posix(): digest(path)
for path in sorted(output.rglob("*")) if path.is_file()