SyncTeX API Reference¶
Auto-generated API documentation for the synctex module.
synctex
¶
SyncTeX parser for bidirectional search between PDF and source.
Pure Python implementation using only the standard library.
Parses .synctex or .synctex.gz files produced by TeX engines with
-synctex=1 and provides spatial queries for both directions:
- Inverse search: PDF position → source file and line number
- Forward search: Source file and line number → PDF position
Typical usage::
data = parse_synctex("main.synctex.gz", strip_prefix="/workspace/")
# Inverse: click on PDF → find source
result = inverse_search(data, page=1, x=150.0, y=300.0)
# result: {"file": "main.tex", "line": 42}
# Forward: jump from source → find PDF position
result = forward_search(data, file="main.tex", line=42)
# result: {"page": 1, "x": 150.0, "y": 300.0}
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
HBox
dataclass
¶
A horizontal box record from a SyncTeX file.
Represents a line-level element with its source location and bounding box in scaled points.
Source code in synctex/synctex.py
SyncTeXData
dataclass
¶
Parsed SyncTeX data ready for spatial queries.
Attributes:
| Name | Type | Description |
|---|---|---|
inputs |
dict[int, str]
|
Mapping from file tag (int) to file path (str). |
pages |
dict[int, list[HBox]]
|
Mapping from 1-based page number to list of HBox records. |
magnification |
int
|
TeX magnification factor (typically 1000). |
unit |
int
|
Coordinate unit in scaled points (typically 1). |
x_offset |
int
|
Horizontal offset in scaled points. |
y_offset |
int
|
Vertical offset in scaled points. |
Source code in synctex/synctex.py
parse_synctex(synctex_path, *, strip_prefix='')
¶
Parse a SyncTeX file (.synctex or .synctex.gz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
synctex_path
|
str
|
Path to the SyncTeX file. |
required |
strip_prefix
|
str
|
Prefix to strip from input file paths.
For Docker builds this is typically |
''
|
Returns:
| Type | Description |
|---|---|
SyncTeXData
|
Parsed SyncTeX data for use with :func: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the file cannot be parsed. |
Source code in synctex/synctex.py
inverse_search(data, page, x, y)
¶
Find the source location for a point on a PDF page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
SyncTeXData
|
Parsed SyncTeX data from :func: |
required |
page
|
int
|
1-based page number. |
required |
x
|
float
|
Horizontal position in PDF points (72 DPI), from the left edge. |
required |
y
|
float
|
Vertical position in PDF points (72 DPI), from the top edge. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | int] | None
|
A dict |
dict[str, str | int] | None
|
if no matching source location is found. |
Source code in synctex/synctex.py
forward_search(data, file, line)
¶
Find the PDF position for a source file and line number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
SyncTeXData
|
Parsed SyncTeX data from :func: |
required |
file
|
str
|
Source file path (relative, as stored in |
required |
line
|
int
|
1-based line number in the source file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int | float] | None
|
A dict |
dict[str, int | float] | None
|
in PDF points (72 DPI) on success, or |
dict[str, int | float] | None
|
position is found. |