Direct and Reverse Synchronization with Synctex

Direct and Reverse Synchronization with Synctex

Direct and reverse synchronization with SyncTEX Jérôme Laurens Département de mathématiques Université de Bourgogne 21078 Dijon Cedex FRANCE jerome (dot) laurens (at) u-bourgogne (dot) fr http://itexmac.sourceforge.net/SyncTeX.html Abstract We present a new technology named SyncTEX used to synchronize between the TEX input and the output. 1 What is synchronization? Creating documents with the TEX typesetting system often requires two windows, one for entering the text, the other one for viewing the resulting output. In general, documents are too long to fit in the visible frame of a window on screen, and what is really visible is only some part of either the input or the output. We say that the input view and the output view are synchronized if they are displaying the “same” portion of the document. Forwards or direct synchronization is the ability, for an output viewer, to scroll the window to a part corresponding to a given location in the input file. Backwards or reverse synchronization is the ability, for a text Figure 1: Synchronization in iT XMac2 based on editor, to scroll the text view to a part corresponding E SyncTEX technology with text analysis. to a given location in the output file. Figure1 is a screenshot illustrating SyncT EX supported in iTEXMac2, the TEX front end devel- oped by the author on Mac OS X. The top window is a text editor where an extract of the “Not so (or --synctex=1) and the same for xetex. With this short introduction to LATEX 2ε” is displayed. The option, a new informational line is printed at the end word “lscommand” has been selected and the viewer of the command output and reads SyncTeX written window at the bottom automatically scrolled to the on foo.synctex.gz. The new (compressed) auxil- position of this word in the output, highlighting it iary file named foo.synctex.gz is used by appli- with a small red arrow. The grey background was cations for the synchronization process; this is the added afterwards in the bottom window for the sake SyncTEX output file. of visibility on printed media. Setting the synctex option to -1 creates an uncompressed foo.synctex auxiliary file, more suit- 2 What is SyncTEX? able for certain operations. Setting it to 0 definitively This is a new technology embedded in both pdfTEX prevents SyncTEX activation. and X TE EX, available in the 2008 TEX Live and cor- There is also an eponymous new TEX primitive responding MiKTEX distributions. When activated, that you can set to 1 for SyncTEX activation from the it gives both text editors and output viewers the nec- source file: \synctex=1. It can be used, for example, essary information to complete the synchronization to temporarily disable SyncTEX operations for some process. It will be available in LuaTEX soon. input file by properly using \synctex=0. This prim- In order to activate SyncTEX, there is a new itive has no effect if the -synctex=0 command line command line option: option was given, or if the first page has already been pdftex -synctex=1 foo.tex shipped out (it is then too late to activate SyncTEX). TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting 365 Jérôme Laurens 3 Other synchronization technologies expansion only (in its head), and it does not know the corresponding output record until ship out time The commercial software Visual TEX available on Windows has had the PDF synchronization capabil- which occurs later (in its stomach). The problem is to force T X to remember the input record information ity embedded in its TEX engine since 1999. The E until ship out time. commercial software TEXtures available on Mac OS X has had embedded synchronization since 2000, but 4.2 Partial solutions using macros between the text source and the DVI output. Neither implementation is freely available to the public and The first idea, developed in the srcltx package, will not be considered in the remainder of this article. is to use the \special macro to keep track of the input record information until ship out time. By this Turning to the TEX macro level, Aleksander Si- method, it inserts in the text flow invisible material monic, the author of the WinEdt TEX shell on Win- dows, wrote before 1998 the srcltx macro package that dedicated DVI viewers can understand. The to enable synchronization between the text source main problem is that this invisible material is not and the DVI output. It is based on the powerful expected to be there and can alter significantly the \special command and was later integrated into line breaking mechanism or cause other packages to malfunction, which is extremely troublesome. the TEX engine as “source specials”. Heiko Oberdiek wrote vpe in 1999 where PDF technologies are used The second idea, developed in the pdfsync pack- for reverse synchronization from the PDF output age, is also to use macros, but in a different way to the text input. In 2003, the author wrote the because it is more difficult to manage PDF contents pdfsync package discussed in [5], [6] and [7], to al- than DVI contents. This package automatically adds low synchronization between the PDF output and in the input source some macros that act in two the text input, following ideas from Piero d’Ancona. steps. At macro expansion time, they write to an auxiliary file the input record information with a This was based on the use of pdfTEX commands sim- ilar to \special, with the same limitations, namely unique identifying tag. They also insert in the text an incompatibility with very useful packages and flow invisible material to prepare TEX to write the unwanted changes in the layout. output record information at ship out time, with None of these solutions is satisfying, being either exactly the same identifying tag. In this design, incomplete or unsafe, as we shall see. the problems concerning line breaking and package incompatibility remain. Moreover, the mapping be- 4 Solving the synchronization problem tween input and output records is not one to one, 4.1 Stating the problem which renders synchronization support very hard to implement for developers. The problem is to define a mapping between an input In these two different solutions, we see the in- record given by an input file name and a line number herent limits of synchronization using macros. More in that file, and an output record given by a page generally, we can say that those macros are active number and a location in that page of the output observers of the input records. In fact, by inserting file. The input record describes a certain part of the invisible material in the text flow they interact with input text whereas the output record describes the the typesetting process. On the contrary, SyncTEX corresponding location where this text appears in the is a neutral observer that never interacts with the output. The original TEX engine does not provide typesetting process. any facility for such a correspondence, except the debugging information used to report syntax errors 4.3 How SyncTEX works (we call it the current input record). More precisely, In fact, the only object that ever knows both the T X does not know at the same time both the input E input and output records is the TEX engine itself, records and their corresponding output records. In so it seems natural to embed some synchronization short, TEX parses each different line of the input technology into it. text file and expands the macros with its “eyes” and We first have to determine what kind of infor- “mouth” (according to [2], page 38), then it sends a mation is needed to achieve synchronization. For list of tokens into its “stomach”. In turn, the stomach that purpose, we follow [2] at page 63: “TEX makes creates lines of text, stacks them into paragraphs, complicated pages by starting with simple individ- and stacks the paragraphs into pages. Once a page ual characters and putting them together in larger is complete with the objects properly positioned, it units, and putting these together in still larger units, is shipped out to the output file. During this process, and so on. Conceptually, it’s a big paste-up job. TEX keeps the input record information until macro 366 TUGboat, Volume 29 (2008), No. 3 — Proceedings of the 2008 Annual Meeting Direct and reverse synchronization with SyncTEX The TEXnical terms used to describe such page con- process reaches in general a precision of ±1 line. struction are boxes and glue.” The key words are With additional technologies such as implemented in “characters”, “boxes” and “glue”. But since an in- iTEXMac2, we can even synchronize by words (see dividual character requires a considerable amount figure1), essentially always finding an exact word of extra memory, only horizontal boxes and vertical correspondence between input and output. boxes are taken into account at first. For these boxes, The next improvements are a consequence of we ask TEX to store in memory, at creation time and the overall design of SyncTEX. Since synchronization during their entire lifetime, the current input record. is deeply embedded into the TEX engines, there is At ship out time, we ask TEX to report for each box no TEX macro involved in the process. As a straight- the stored file name, the stored line number, the forward consequence, there cannot be any incom- horizontal and vertical positions, and the dimensions patibility with macro packages. Moreover, no extra as computed during typesetting. This information invisible material is added to the text flow, thus en- will be available for synchronization: for example suring that the layout of the documents is exactly the when the user clicks on some location of the PDF same whether SyncTEX is activated or not.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us