Use a Unicode default with project-level LaTeX compatibility

This commit is contained in:
gloamxun committed 2026-12-02 21:43:38 +08:00
1 parent 38a2a4a958
commit 81ac3ae321
11 files changed
+741 -126

No files matched your search

+38 -19
View File
@@ -1,13 +1,14 @@
//! Bootstrap the installed Windows editor from the packaged TeX resources.
use crate::{WebAssets, library::Library, serve};
use crate::{WebAssets, library::{EditorFormat, Library}, serve};
use serde::Deserialize;
use sha2::{Digest, Sha256};
use std::{
env,
ffi::{OsStr, OsString},
fs::{self, File, OpenOptions},
io::{self, Read, Write},
io::{self, Read},
path::{Path, PathBuf},
time::Instant,
};
use texrra_engine::native::{CompileRequest, Entry, dump_format, job_time};
use texrra_tex_core::{
@@ -76,24 +77,16 @@ pub(super) fn run(mut arguments: impl Iterator<Item = OsString>) -> LaunchResult
configure_environment(&backend, &state, &font_maps)?;
start_lease()?;
let format = runtime.join("latex.tfx");
if !format.is_file() {
let ini = roots[1].join("tex/latex/tex-ini-files/pdflatex.ini");
build_format(&ini, &runtime, &format, &roots)?;
}
let manifest = runtime.join("format-resources.json");
let manifest_bytes = serde_json::to_vec(&serde_json::json!({"texmf_roots": roots}))?;
if fs::read(&manifest).ok().as_deref() != Some(&manifest_bytes) {
fs::write(&manifest, manifest_bytes)?;
}
let manifest = manifest.canonicalize()?;
let primary = desktop_format(&runtime, &manifest, &roots, InputProfile::TeX8Bit, "pdflatex")?;
let unicode = desktop_format(&runtime, &manifest, &roots, InputProfile::XeTeX, "xelatex")?;
let web = WebAssets::load(&backend.join("web"))?;
let library = Library::new(
home.join("projects"),
format.canonicalize()?,
manifest.canonicalize()?,
runtime.join("web-runs"),
InputProfile::TeX8Bit,
)?;
let library = Library::new(home.join("projects"), runtime.join("web-runs"), primary, Some(unicode))?;
serve(Some(web), Some(library), 0, None)
}
@@ -167,15 +160,41 @@ fn start_lease() -> io::Result<()> {
Ok(())
}
fn build_format(ini: &Path, runtime: &Path, format: &Path, roots: &[PathBuf]) -> LaunchResult<()> {
let ini = ini.canonicalize()?;
let world = WorldConfig::from_environment(runtime, roots.to_vec())?;
fn desktop_format(
runtime: &Path,
manifest: &Path,
roots: &[PathBuf],
profile: InputProfile,
name: &'static str,
) -> LaunchResult<EditorFormat> {
let ini = roots[1].join("tex/latex/tex-ini-files").join(format!("{name}.ini")).canonicalize()?;
let directory = runtime.join(name);
fs::create_dir_all(&directory)?;
let output = directory.canonicalize()?.join("latex.tfx");
let roots = roots.to_vec();
Ok(EditorFormat::lazy(output.clone(), manifest.to_owned(), profile, move || {
let started = Instant::now();
let result = build_format(&ini, &output, &roots, profile).map_err(|error| error.to_string());
if env::var_os("TEXRRA_EDITOR_PREPARATION_TRACE").is_some_and(|value| value == "1") {
eprintln!("Texrra editor preparation {}", serde_json::json!({
"stage": "build-format",
"mode": name,
"ms": started.elapsed().as_secs_f64() * 1000.0,
"ok": result.is_ok(),
}));
}
result
}))
}
fn build_format(ini: &Path, format: &Path, roots: &[PathBuf], profile: InputProfile) -> LaunchResult<()> {
let directory = format.parent().expect("format has a directory");
let world = WorldConfig::from_environment(directory, roots.to_vec())?;
let mut request = CompileRequest::new(world, ini, format, job_time()?);
request.entry = Entry::Initex;
request.input_profile = profile;
request.etex = true;
request.limits.steps = 600_000_000;
println!("Texrra desktop preparing format");
io::stdout().flush()?;
dump_format(request, Cancellation::default())?;
Ok(())
}