Documentation
¶
Overview ¶
Package synctex parses TeX's synctex.gz output and answers the two queries the editor needs :
Forward : (file, line) → (page, x, y, height) Backward : (page, x, y) → (file, line) [V0.2]
The file format is well-documented in the synctex source (Jérôme Laurens, "SyncTeX: introduction to the engine"), but the gist is :
SyncTeX Version:1
Input:N:/path/to/file.tex ← fileTag → path map
...
Magnification:1000
Unit:1
X Offset:0
Y Offset:0
Content:
{P ← page block (P is page number)
[N,L:X,Y:W,H,D ← node : tag N, line L, x/y/...
h N,L:X,Y:W,H,D
...
}
...
Postamble:
We only care about the records that map line → page+pos, so the parser is line-oriented + ignores boxes we don't understand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
Inputs map[int]string // tag → absolute source path
Records []Record
// contains filtered or unexported fields
}
func Parse ¶
Parse reads a .synctex.gz file from disk. Returns a File with the indexed records ready for Forward queries.
func (*File) Backward ¶
Backward : given a (page, x, y) in synctex sp, pick the source (file, line) closest to that point. V0.2 — used once the PDF.js viewer is wired so the user can click on a glyph + jump back.
func (*File) Forward ¶
Forward : given a (source file, line), pick the best record to jump the PDF viewer to. We pick the record on the nearest line ≥ the query, falling back to the largest line < query when nothing at or after exists.
func (*File) ResolveSource ¶
ResolveSource maps an editor-side source path to the absolute path SyncTeX would have recorded. The editor passes a project- relative file ("main.tex") ; the synctex Input: entries are absolute paths under the compile workdir. We match by suffix.
type Option ¶
type Option func(*parseOptions)
Option tunes Parse behaviour. The zero value is the legacy default (no project-root sanitisation) ; handlers that know the project boundary pass WithProjectRoot so untrusted Input: paths can't be echoed back to the SPA verbatim.
func WithProjectRoot ¶
WithProjectRoot scopes Input: paths to the given project root. Paths that fall outside the root are dropped with no record kept, and paths inside the root are rewritten to relative-to-root form so Backward() never leaks absolute host paths.
type Record ¶
type Record struct {
FileTag int
Line int
Page int
// X / Y are in synctex "scaled points" (sp). The unit conversion
// to PDF points is X/65536, but we expose the raw sp so callers
// can decide what to do (PDF.js wants PDF points + DPI scaling).
X int
Y int
}
Record is one node from the synctex stream — a hit point that pins a source line to a PDF coordinate.