{"record":{"id":"1cd4bd546d2a1dd0","repo":"tonhowtf/omniget","slug":"o-source-deste-arxiv-e-um-pdf-nao-tem-latex","errorCode":null,"errorMessage":"o source deste arXiv e um PDF, nao tem LaTeX","messagePattern":"o source deste arXiv e um PDF, nao tem LaTeX","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/arxiv.rs","lineNumber":364,"sourceCode":"fn is_gzip(b: &[u8]) -> bool {\n    b.len() > 2 && b[0] == 0x1f && b[1] == 0x8b\n}\n\nfn is_tar(b: &[u8]) -> bool {\n    b.len() > 262 && &b[257..262] == b\"ustar\"\n}\n\nfn gunzip(b: &[u8]) -> anyhow::Result<Vec<u8>> {\n    use std::io::Read;\n    let mut out = Vec::new();\n    flate2::read::GzDecoder::new(b).read_to_end(&mut out)?;\n    Ok(out)\n}\n\n/// Aceita o tar.gz do `e-print`, um tar cru, um `.tex` gzipado ou o `.tex` solto.\npub fn extract_source(bytes: &[u8]) -> anyhow::Result<SourceBundle> {\n    if bytes.starts_with(b\"%PDF\") {\n        return Err(anyhow!(\"o source deste arXiv e um PDF, nao tem LaTeX\"));\n    }\n    let raw = if is_gzip(bytes) {\n        gunzip(bytes)?\n    } else {\n        bytes.to_vec()\n    };\n    if !is_tar(&raw) {\n        let text = String::from_utf8_lossy(&raw).to_string();\n        if !text.contains('\\\\') {\n            return Err(anyhow!(\"source do arXiv nao parece LaTeX\"));\n        }\n        return Ok(SourceBundle {\n            main: text,\n            files: vec![\"main.tex\".to_string()],\n        });\n    }\n\n    let mut texts: HashMap<String, String> = HashMap::new();","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/arxiv.rs#L346-L382","documentation":"extract_source inspects the first bytes of the e-print payload; if it starts with \"%PDF\" the \"source\" arXiv served is actually a rendered PDF, not LaTeX. Since the tool's purpose is to obtain LaTeX, it refuses with this error. This happens for papers whose authors submitted only PDFs (arXiv keeps the PDF as the e-print in that case).","triggerScenarios":"Calling fetch_source / extract_source on an arXiv paper that has no TeX submission — authors uploaded a PDF-only submission, so /e-print returns the PDF bytes.","commonSituations":"Older papers or submissions from fields (e.g. some math/physics scans) where the author never provided TeX; papers replaced with PDF-only versions; trying to extract LaTeX from scanned documents.","solutions":["No LaTeX exists for this paper — don't retry; detect the PDF magic bytes client-side and skip it.","Check the paper's arXiv page for an 'Other formats' / source availability indicator.","Fall back to PDF text extraction if the goal is just content.","Inform the user that only a PDF source is available for this id."],"exampleFix":"// before\nlet bytes = fetch_source(...)?;\nlet bundle = extract_source(&bytes)?;\n// after\nlet bytes = fetch_source(...)?;\nif bytes.starts_with(b\"%PDF\") {\n    anyhow::bail!(\"paper {} so tem PDF, sem LaTeX disponivel\", id);\n}\nlet bundle = extract_source(&bytes)?;","handlingStrategy":"fallback","validationCode":"// antes de extrair LaTeX:\nif bytes.starts_with(b\"%PDF\") {\n    bail!(\"paper sem fonte LaTeX (so PDF)\");\n}","typeGuard":null,"tryCatchPattern":"match extract_source(&bytes) {\n    Err(e) if e.to_string().contains(\"e um PDF\") => {\n        // caminho alternativo: extrair texto do PDF\n        extract_pdf_text(&bytes)\n    }\n    other => other,\n}","preventionTips":["Check the %PDF magic bytes right after download and skip PDF-only papers early.","Maintain a skip-list of ids known to lack TeX sources.","Check the paper's arXiv listing page for source availability before fetching."],"tags":["arxiv","latex","pdf","unsupported-content"],"backgroundTag":"incompatible-source-type","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"}