synctex

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Parse(path string, opts ...Option) (*File, error)

Parse reads a .synctex.gz file from disk. Returns a File with the indexed records ready for Forward queries.

func (*File) Backward

func (f *File) Backward(page int, x, y int) (sourceFile string, line int, ok bool)

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

func (f *File) Forward(sourceFile string, line int) (Record, bool)

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

func (f *File) ResolveSource(rel string) (string, bool)

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

func WithProjectRoot(root string) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL