Download and parse LaTeX source files from arXiv preprints
SKILL.md
arXiv LaTeX Source Access Guide
Overview
arXiv stores the original LaTeX source files for the vast majority of its 2.4 million+ preprints. Accessing LaTeX source provides major advantages over PDF parsing: exact mathematical notation as written by the author, structured sections and labels, machine-readable bibliography entries, and intact figure captions, table data, and cross-references.
For formula extraction, citation graph construction, section-level text analysis, or training data curation for scientific language models, LaTeX source is the gold standard. PDF parsing introduces OCR errors in equations, loses structural hierarchy, and mangles complex tables.
The e-print endpoint serves source bundles as gzip-compressed tarballs (.tar.gz) containing .tex files, figures, .bib/.bbl bibliography files, style files, and supplementary materials. No authentication is required.
Authentication
No authentication or API key is required. The e-print endpoint is publicly accessible. However, arXiv asks that automated tools set a descriptive User-Agent header and comply with rate limits.
Core Endpoints
Download LaTeX Source
URL: GET https://arxiv.org/e-print/{arxiv_id}
Response: application/gzip — a .tar.gz archive containing the source files
Parameters:
Param
Type
Required
Description
arxiv_id
string
Yes
arXiv identifier, e.g. 2301.00001 or 2301.00001v2 for a specific version
ETag: SHA-256 hash provided for caching: sha256:f1ffe8ec...
Format Detection
The endpoint almost always returns a gzip-compressed tar archive. Rare cases (very old or single-file submissions) may return a single gzip-compressed .tex file without tar wrapper. Always verify format before extracting:
A source archive typically contains multiple files. To find the main document:
Look for \documentclass in .tex files — this marks the root document
Check for a README.txt that may specify the main file
If multiple .tex files contain \documentclass, prefer the one with \begin{document}
import tarfile, re
def find_main_tex(tar_path):
with tarfile.open(tar_path, 'r:gz') as tar:
tex_files = [m for m in tar.getmembers() if m.name.endswith('.tex')]
for member in tex_files:
content = tar.extractfile(member).read().decode('utf-8', errors='ignore')
if r'\documentclass' in content and r'\begin{document}' in content:
return member.name, content
return None, None
Extracting Sections
LaTeX sections follow a predictable hierarchy:
import re
def extract_sections(tex_content):
pattern = r'\\(section|subsection|subsubsection)\{([^}]+)\}'
sections = re.findall(pattern, tex_content)
return [(level, title) for level, title in sections]
# [('section', 'Introduction'), ('section', 'Related Work'), ...]
Extracting Equations
def extract_equations(tex_content):
patterns = [
r'\\\[(.+?)\\\]',
r'\\begin\{equation\}(.+?)\\end\{equation\}',
r'\\begin\{align\*?\}(.+?)\\end\{align\*?\}',
]
equations = []
for pat in patterns:
equations.extend(re.findall(pat, tex_content, re.DOTALL))
return equations