Bug 113191 - inverse and forward search in pdf documents
Summary: inverse and forward search in pdf documents
Status: RESOLVED INTENTIONAL
Alias: None
Product: kpdf
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR wishlist
Target Milestone: ---
Assignee: Albert Astals Cid
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-24 08:57 UTC by Mario Cupelli
Modified: 2008-09-29 21:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Sync info between pdf file and tex source (6.13 KB, text/plain)
2006-07-31 16:26 UTC, Mario Cupelli
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Cupelli 2005-09-24 08:57:53 UTC
Version:            (using KDE KDE 3.4.2)
Installed from:    SuSE RPMs
OS:                Linux

latex and pdflatex are able to generate so called source specials (-src-specials) in dvi/pdf files. With these source specials you can click in the dvi file for example kdvi/xdvik and you see the corresponding source line in the editor (inverse search). The same mechanism is also available for forward search -> Jump from editor source to corresponding line in the dvi. It would be nice to have the same mechanism for a pdf viewer(kpdf or okular). I think many people do not know that pdflatex supports this feature at all, so it has not been requested yet. 

Under MacOS already exists a pdf-viewer that supports that feature.
(http://itexmac.sourceforge.net/pdfsync.html)
Comment 1 Mario Cupelli 2006-07-31 16:26:37 UTC
Created attachment 17184 [details]
Sync info between pdf file and tex source

Example for pdfsync and inverse search
Comment 2 Mario Cupelli 2006-07-31 16:29:36 UTC
pdfsync author (jlaurens@users.sourceforge.net)

What is the foo.pdfsync file?

This is a text file that contains information about the foo.pdf file and the source file used to generate it.
It is actually generated by pdflatex, provided you have the pdfsync.sty package and add in the preamble of your file
\usepackage{pdfsync}
This information is used by TeX front ends to allow synchronization from source to output, a la src-special. (option --src-specials)
This concept is generic and might be used with any kind of text (tex, xml, mp, raw) to pdf processor.

Download pdfsync.sty for LaTeX or Plain users?

Before pdfsync.sty or pdfsync.tex is submitted to CTAN, it is available at sourceforge at the bottom of the page there. Just download, expand and move the resulting pdfsync.sty to your ~/Library/texmf/tex/latex directory and the resulting pdfsync.tex to your ~/Library/texmf/tex/plain. All the necessary instructions to use the pdfsync feature should be given by your TeX front end if it supports it.

What does the foo.pdfsync contain?

Basically, it contains two converse many to many mappings between line numbers in TeX source files and locations in pages of an output pdf file.

What is the foo.pdfsync file format?

General format: text file
Encoding: subset of ASCII
General organization: by line
EOL format: undefined

First line: Name
 meaning: 	 the core name of the pdf output (\jobname in TeX)
This is the only encoding dependent part.
 type: 	 a single word, case sensitive
 Example: 	 foo
 status: 	required

Second line: Version
 meaning: 	 The version number, no yet used
 type: 	 printf("version %u", versionNumber), case insensitive
 Example: 	 Version 0
 status: 	 required

I use C's printf format syntax. For version 1, nothing else is required in the preamble

The rest of the file is an ordered sequence of lines with the following format. All these lines formats are references by the first character. The contents of the examples are the colored characters, sorry for monochrome users.

Version 0 variant

"(" line:
 status: 	 Optional
 type: 	 printf("(%s", inputFileName), case sensitive
 meaning: 	 The source file changes, all subsequent line and column numbers now refer to inputFileName. The path is relative to the directory containing the .pdfsync file. The "tex" extension is not required and can be added if necessary. Path separators are unix "/". The file extension is not required, "tex" is the default
 Example: 	 (Chapter1/MyOtherFoo

")" line:
 status: 	 Optional, but must match a corresponding "(" line
 type: 	 printf(")")
 meaning: 	 The end of the input file has been reached. Subsequent line and column numbers now refer to the calling file.
 Example: 	)

"l" (ell) line:
 status: 	 Optional
 type: 	 printf("l %u %u %u", recordNumber, lineNumber, columnNumber)
 meaning: 	 recordNumber allows to uniquelly identify the milestone.
 Example: 	 l 464 173

"s" line:
 status: 	 Optional
 type: 	 printf("s %u", sheetNumber)
 meaning: 	 Each time a new page is shipped out. All subsequent locations refer to the page of the pdf output numbered sheetNumber, until next page is shipped out. sheetNumber is a 1 based page number, increasing by one each time.
 Example: 	 s 0

"p" line:
 status: 	 Optional
 type: 	 printf("p %u %u %u", recordNumber, xPosition, yPosition)
 meaning: 	 A location in the current pdf page. It is automatically generated when using pdfsync.sty with pdflatex. TeX unit is used,
 Example: 	 p 464 7149061 19993810

"p*" line:
 status: 	 Optional
 type: 	 printf("p* %u %u %u", recordNumber, xPosition, yPosition),
star variant of the "p" line
 meaning: 	 A location in the current pdf page. This information is recorded when the user do wants it. Pdf viewers can display different kind of information for that kind of line (like iTeXMac does)
 Example: 	 p* 474 7149061 19043538

How dos it work?

Sample pdfsync file:

foo
version 0
l 0 13
l 1 19
l 2 24
l 3 33
l 4 35
l 5 13
l 6 17
[...]
l 431 134
l 432 134
[...]
s 1
p 430 2368143 54651247
p 398 21086469 3154577
[...]
p 431 2368143 402063
l 433 134
[...]
l 464 173
[...]
l 527 215
s 2
p 525 2368143 54651247
[...]
p 464 7149061 19993810
p* 474 7149061 19043538
p 475 14470540 19043538
[...]

what corresponds to line 173 of my foo.tex? I can see that the corresponding counter is 464, due to the line l 464 173. For 464, we find a p 464 7149061 19993810 line, after the s 2 one, it corresponds to a point of the second page of foo.pdf with tex coordinates 7149061 19993810, .

We can see that the "l" lines are written in the foo.pdfsync synchronously, which is not the case for "p" lines. We can also observe that sometimes no "p" line correspond to some "l" line, or multiple "p" lines do. Similarly, multiple "l" line can correspond to a unique location in a page. The most important problem is the support for multiple input files, which is not detailled here. However, people will appreciate the difficulties to design and implement the pdfsync feature.
Comment 3 Jonathan Thomas 2008-09-29 21:13:48 UTC
Could somebody move this to affect Okular? (It still does as of KDE 4.1.2)
Comment 4 Albert Astals Cid 2008-09-29 21:31:47 UTC
Okular already supports this, just the support is a bit flaky, but it's there, just needs someone that uses it to give ideas on how to do the user interaction part.

If you can give that feedback please contact the Okular developers at okular-devel@kde.org or #okular on freenode IRC

Changing to WONTFIX as KPDF is not getting new features.