{"record":{"id":"27bd3f455a9e39d1","repo":"tonhowtf/omniget","slug":"nenhum-tex-com-begin-document","errorCode":null,"errorMessage":"nenhum .tex com \\begin{{document}}","messagePattern":"nenhum \\.tex com \\\\begin(.+?)\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/arxiv.rs","lineNumber":403,"sourceCode":"    for entry in archive.entries()? {\n        let mut entry = entry?;\n        let path = entry.path()?.to_string_lossy().to_string();\n        let lower = path.to_lowercase();\n        if !(lower.ends_with(\".tex\") || lower.ends_with(\".bbl\") || lower.ends_with(\".ltx\")) {\n            continue;\n        }\n        let mut buf = Vec::new();\n        use std::io::Read;\n        entry.read_to_end(&mut buf)?;\n        names.push(path.clone());\n        texts.insert(path, String::from_utf8_lossy(&buf).to_string());\n    }\n    if texts.is_empty() {\n        return Err(anyhow!(\"o tar do arXiv nao tem nenhum .tex\"));\n    }\n\n    let main_key =\n        pick_main(&texts).ok_or_else(|| anyhow!(\"nenhum .tex com \\\\begin{{document}}\"))?;\n    let main = texts.get(&main_key).cloned().unwrap_or_default();\n    let main = resolve_inputs(&main, &texts, 0);\n    names.sort();\n    Ok(SourceBundle { main, files: names })\n}\n\nfn pick_main(texts: &HashMap<String, String>) -> Option<String> {\n    let mut best: Option<(u32, usize, String)> = None;\n    for (k, v) in texts {\n        if !k.to_lowercase().ends_with(\".tex\") && !k.to_lowercase().ends_with(\".ltx\") {\n            continue;\n        }\n        let mut score = 0u32;\n        if v.contains(\"\\\\begin{document}\") {\n            score += 4;\n        }\n        if v.contains(\"\\\\documentclass\") {\n            score += 2;","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/arxiv.rs#L385-L421","documentation":"The tar had at least one .tex file, but pick_main could not determine a main document — none of the .tex texts contains \\begin{document}, which any compilable LaTeX root document must have. extract_source therefore fails with this message.","triggerScenarios":"extract_source on a source bundle whose .tex files are all include/fragment files (no root), or files in non-LaTeX TeX dialects (plain TeX, ConTeXt) lacking \\begin{document}.","commonSituations":"Plain TeX or ConTeXt submissions (different document markers); bundles where the root file uses a nonstandard class loaded via unusual preamble; fragmented multi-file papers whose root was excluded by the collector.","solutions":["Extend pick_main to also recognize ConTeXt (\\starttext) and plain TeX markers.","Check the tar contents — maybe the root .tex has an unexpected name or extension and wasn't collected.","Fall back to the largest .tex file as the main document when no \\begin{document} is found.","Skip such papers if compilable LaTeX is required."],"exampleFix":"// before\nlet main_key = pick_main(&texts).ok_or_else(|| anyhow!(\"nenhum .tex com \\\\begin{{document}}\"))?;\n// after\nlet main_key = pick_main(&texts)\n    .or_else(|| texts.iter().max_by_key(|(_, t)| t.len()).map(|(k, _)| k.clone()))\n    .ok_or_else(|| anyhow!(\"nenhum .tex com \\\\begin{{document}}\"))?;","handlingStrategy":"fallback","validationCode":"// heuristica propria antes da chamada:\nfn parece_main(t: &str) -> bool {\n    t.contains(\"\\\\begin{document}\") || t.contains(\"\\\\starttext\")\n}","typeGuard":null,"tryCatchPattern":"match extract_source(&bytes) {\n    Err(e) if e.to_string().contains(\"begin{document}\") => {\n        // fallback: maior .tex como raiz\n        eprintln!(\"sem raiz LaTeX clara; usando maior .tex como main\");\n    }\n    other => other,\n}","preventionTips":["Extend main-document detection to ConTeXt (\\starttext) and plain TeX bundles.","Fall back to the largest .tex when no \\begin{document} exists.","Log candidate .tex filenames to diagnose why pick_main failed."],"tags":["arxiv","latex","heuristic","missing-marker"],"backgroundTag":"unexpected-response-shape","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}