| 1 |
Copyright (c) 2008, 2009 jerome DOT laurens AT u-bourgogne DOT fr |
| 2 |
|
| 3 |
This file is part of the SyncTeX package. |
| 4 |
|
| 5 |
Latest Revision: Wed Jul 1 11:17:04 UTC 2009 |
| 6 |
|
| 7 |
License: |
| 8 |
-------- |
| 9 |
Permission is hereby granted, free of charge, to any person |
| 10 |
obtaining a copy of this software and associated documentation |
| 11 |
files (the "Software"), to deal in the Software without |
| 12 |
restriction, including without limitation the rights to use, |
| 13 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 |
copies of the Software, and to permit persons to whom the |
| 15 |
Software is furnished to do so, subject to the following |
| 16 |
conditions: |
| 17 |
|
| 18 |
The above copyright notice and this permission notice shall be |
| 19 |
included in all copies or substantial portions of the Software. |
| 20 |
|
| 21 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 23 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 24 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 25 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 26 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 27 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 28 |
OTHER DEALINGS IN THE SOFTWARE |
| 29 |
|
| 30 |
Except as contained in this notice, the name of the copyright holder |
| 31 |
shall not be used in advertising or otherwise to promote the sale, |
| 32 |
use or other dealings in this Software without prior written |
| 33 |
authorization from the copyright holder. |
| 34 |
|
| 35 |
Acknowledgments: |
| 36 |
---------------- |
| 37 |
The author received useful remarks from the pdfTeX developers, especially Hahn The Thanh, |
| 38 |
and significant help from XeTeX developer Jonathan Kew |
| 39 |
|
| 40 |
Nota Bene: |
| 41 |
---------- |
| 42 |
If you include or use a significant part of the synctex package into a software, |
| 43 |
I would appreciate to be listed as contributor and see "SyncTeX" highlighted. |
| 44 |
|
| 45 |
Version 1 |
| 46 |
Thu Jun 19 09:39:21 UTC 2008 |
| 47 |
|
| 48 |
Notice: |
| 49 |
------- |
| 50 |
|
| 51 |
@x |
| 52 |
@p function get_node(@!s:integer):pointer; {variable-size node allocation} |
| 53 |
@y |
| 54 |
@p function get_node(@!s:integer):pointer; {variable-size node allocation} |
| 55 |
@z |
| 56 |
|
| 57 |
@x tex.web l.2716 |
| 58 |
get_node:=r; |
| 59 |
@y |
| 60 |
@<Initialize bigger nodes with {\sl Sync\TeX} information@>; |
| 61 |
get_node:=r; |
| 62 |
@z |
| 63 |
|
| 64 |
@x tex.web l.4002: Copy |
| 65 |
@ @<Case statement to copy...@>= |
| 66 |
@y |
| 67 |
@ @<Case statement to copy...@>= |
| 68 |
@z |
| 69 |
|
| 70 |
@x |
| 71 |
hlist_node,vlist_node,unset_node: begin r:=get_node(box_node_size); |
| 72 |
@y |
| 73 |
hlist_node,vlist_node,unset_node: begin r:=get_node(box_node_size); |
| 74 |
@<Copy the box {\sl Sync\TeX} information@>; |
| 75 |
@z |
| 76 |
|
| 77 |
@x |
| 78 |
rule_node: begin r:=get_node(rule_node_size); words:=rule_node_size; |
| 79 |
@y |
| 80 |
rule_node: begin r:=get_node(rule_node_size); words:=rule_node_size-synctex_field_size;{{\sl Sync\TeX}: do not let \TeX\ copy the {\sl Sync\TeX} information} |
| 81 |
@<Copy the rule {\sl Sync\TeX} information@>; |
| 82 |
@z |
| 83 |
|
| 84 |
@x |
| 85 |
glue_node: begin r:=get_node(medium_node_size); add_glue_ref(glue_ptr(p)); |
| 86 |
@y |
| 87 |
glue_node: begin r:=get_node(medium_node_size); add_glue_ref(glue_ptr(p)); |
| 88 |
@<Copy the medium sized node {\sl Sync\TeX} information@>; |
| 89 |
@z |
| 90 |
|
| 91 |
@x |
| 92 |
@p procedure begin_file_reading; |
| 93 |
@y |
| 94 |
@p procedure begin_file_reading; |
| 95 |
@z |
| 96 |
|
| 97 |
@x |
| 98 |
name:=0; {|terminal_input| is now |true|} |
| 99 |
@y |
| 100 |
name:=0; {|terminal_input| is now |true|} |
| 101 |
@<Prepare terminal input {\sl Sync\TeX} information@>; |
| 102 |
@z |
| 103 |
|
| 104 |
@x |
| 105 |
@p procedure start_input; {\TeX\ will \.{\\input} something} |
| 106 |
@y |
| 107 |
@p procedure start_input; {\TeX\ will \.{\\input} something} |
| 108 |
@z |
| 109 |
|
| 110 |
@x tex.web l.10380 |
| 111 |
@<Read the first line of the new file@>; |
| 112 |
@y |
| 113 |
@<Prepare new file {\sl Sync\TeX} information@>; |
| 114 |
@<Read the first line of the new file@>; |
| 115 |
@z |
| 116 |
|
| 117 |
@x |
| 118 |
procedure hlist_out; {output an |hlist_node| box} |
| 119 |
@y |
| 120 |
procedure hlist_out; {output an |hlist_node| box} |
| 121 |
@z |
| 122 |
|
| 123 |
@x tex.web l.12338 |
| 124 |
while p<>null do @<Output node |p| for |hlist_out| and move to the next node, |
| 125 |
maintaining the condition |cur_v=base_line|@>; |
| 126 |
@y |
| 127 |
@<Start hlist {\sl Sync\TeX} information record@>; |
| 128 |
while p<>null do @<Output node |p| for |hlist_out| and move to the next node, |
| 129 |
maintaining the condition |cur_v=base_line|@>; |
| 130 |
@<Finish hlist {\sl Sync\TeX} information record@>; |
| 131 |
@z |
| 132 |
|
| 133 |
@x |
| 134 |
@<Output node |p| for |hlist_out|...@>= |
| 135 |
@y |
| 136 |
@<Output node |p| for |hlist_out|...@>= |
| 137 |
@z |
| 138 |
|
| 139 |
@x |
| 140 |
until not is_char_node(p); |
| 141 |
@y |
| 142 |
until not is_char_node(p); |
| 143 |
@<Record current point {\sl Sync\TeX} information@>; |
| 144 |
@z |
| 145 |
|
| 146 |
@x |
| 147 |
@ @<Output the non-|char_node| |p| for |hlist_out|...@>= |
| 148 |
@y |
| 149 |
@ @<Output the non-|char_node| |p| for |hlist_out|...@>= |
| 150 |
@z |
| 151 |
|
| 152 |
@x tex.web l.12390 |
| 153 |
move_past: cur_h:=cur_h+rule_wd; |
| 154 |
@y |
| 155 |
move_past: begin |
| 156 |
cur_h:=cur_h+rule_wd; |
| 157 |
@<Record horizontal |rule_node| or |glue_node| {\sl Sync\TeX} information@>; |
| 158 |
end; |
| 159 |
@z |
| 160 |
|
| 161 |
@x tex.web l.12394 |
| 162 |
@ @<Output a box in an hlist@>= |
| 163 |
if list_ptr(p)=null then cur_h:=cur_h+width(p) |
| 164 |
@y |
| 165 |
@ @<Output a box in an hlist@>= |
| 166 |
if list_ptr(p)=null then begin |
| 167 |
@<Record void list {\sl Sync\TeX} information@>; |
| 168 |
cur_h:=cur_h+width(p); |
| 169 |
end |
| 170 |
@z |
| 171 |
|
| 172 |
@x |
| 173 |
@p procedure vlist_out; {output a |vlist_node| box} |
| 174 |
@y |
| 175 |
@p procedure vlist_out; {output a |vlist_node| box} |
| 176 |
@z |
| 177 |
|
| 178 |
@x tex.web l.12534 |
| 179 |
top_edge:=cur_v; |
| 180 |
@y |
| 181 |
MISSING @<Start vlist {\sl Sync\TeX} information record@> before cur_v:=cur_v-height(this_box); |
| 182 |
top_edge:=cur_v; |
| 183 |
@z |
| 184 |
|
| 185 |
@x tex.web l.12535 |
| 186 |
while p<>null do @<Output node |p| for |vlist_out| and move to the next node, |
| 187 |
maintaining the condition |cur_h=left_edge|@>; |
| 188 |
@y |
| 189 |
while p<>null do @<Output node |p| for |vlist_out| and move to the next node, |
| 190 |
maintaining the condition |cur_h=left_edge|@>; |
| 191 |
@<Finish vlist {\sl Sync\TeX} information record@>; |
| 192 |
@z |
| 193 |
|
| 194 |
@x tex.web l.12569 |
| 195 |
@<Output a box in a vlist@>= |
| 196 |
if list_ptr(p)=null then cur_v:=cur_v+height(p)+depth(p) |
| 197 |
@y |
| 198 |
@<Output a box in a vlist@>= |
| 199 |
if list_ptr(p)=null then cur_v:=cur_v+height(p)+depth(p) |
| 200 |
MISSING @<Record void list {\sl Sync\TeX} information@>; |
| 201 |
@z |
| 202 |
|
| 203 |
@x tex.web l.12669 |
| 204 |
@!old_setting:0..max_selector; {saved |selector| setting} |
| 205 |
@y |
| 206 |
@!old_setting:0..max_selector; {saved |selector| setting} |
| 207 |
begin @<Start sheet {\sl Sync\TeX} information record@>; |
| 208 |
@z |
| 209 |
|
| 210 |
@x tex.web l.12692 |
| 211 |
@<Flush the box from memory, showing statistics if requested@>; |
| 212 |
end; |
| 213 |
@y |
| 214 |
@<Flush the box from memory, showing statistics if requested@>; |
| 215 |
end; |
| 216 |
@<Finish sheet {\sl Sync\TeX} information record@>; |
| 217 |
end; |
| 218 |
@z |
| 219 |
|
| 220 |
@x |
| 221 |
@<Append a ligature and/or kern to the translation...@>= |
| 222 |
@y |
| 223 |
@<Append a ligature and/or kern to the translation...@>= |
| 224 |
@z |
| 225 |
|
| 226 |
@x tex.web l.17887 |
| 227 |
if w<>0 then |
| 228 |
begin link(t):=new_kern(w); t:=link(t); w:=0; |
| 229 |
@y |
| 230 |
if w<>0 then |
| 231 |
begin link(t):=new_kern(w); t:=link(t); w:=0; |
| 232 |
sync_tag(t+medium_node_size):=0; {{\sl Sync\TeX}: do nothing, it is too late} |
| 233 |
@z |
| 234 |
|
| 235 |
@x tex.web l.19335 |
| 236 |
@<Initialize the special list...@>= |
| 237 |
type(page_head):=glue_node; subtype(page_head):=normal; |
| 238 |
@y |
| 239 |
@<Initialize the special list...@>= |
| 240 |
type(page_head):=glue_node; subtype(page_head):=normal; |
| 241 |
{{\sl Sync\TeX} watch point: box(|page_head|) size >= |glue_node| size} |
| 242 |
@z |
| 243 |
|
| 244 |
@x |
| 245 |
@<Move the cursor past a pseudo-ligature...@>= |
| 246 |
@y |
| 247 |
@<Move the cursor past a pseudo-ligature...@>= |
| 248 |
@z |
| 249 |
|
| 250 |
@x tex.web l.20188 |
| 251 |
free_node(temp_ptr,small_node_size); |
| 252 |
@y |
| 253 |
free_node(temp_ptr,small_node_size); {{\sl Sync\TeX} watch point: proper size!} |
| 254 |
@z |
| 255 |
|
| 256 |
@x |
| 257 |
procedure close_files_and_terminate; |
| 258 |
@y |
| 259 |
procedure close_files_and_terminate; |
| 260 |
@z |
| 261 |
|
| 262 |
@x tex.web l.24301 |
| 263 |
if log_opened then |
| 264 |
@y |
| 265 |
@<Close {\sl Sync\TeX} file and write status@>; |
| 266 |
if log_opened then |
| 267 |
@z |
| 268 |
|
| 269 |
@x tex.web + synctex-mem.ch0 |
| 270 |
@ Synchronization is achieved with the help of an auxiliary file... |
| 271 |
@y |
| 272 |
@ Synchronization is achieved with the help of an auxiliary file named |
| 273 |
`\.{{\sl jobname}.synctex}' ({\sl jobname} is the contents of the |
| 274 |
\.{\\jobname} macro), where a {\sl Sync\TeX} controller implemented |
| 275 |
in the external |synctex.c| file will store geometrical information. |
| 276 |
This {\sl Sync\TeX} controller will take care of every technical details |
| 277 |
concerning the {\sl Sync\TeX} file, we will only focus on the messages |
| 278 |
the controller will receive from the \TeX\ program. |
| 279 |
|
| 280 |
The most accurate synchronization information should allow to map |
| 281 |
any character of the input source file to the corresponding location |
| 282 |
in the output, if relevant. |
| 283 |
Ideally, the synchronization information of the input material consists of |
| 284 |
the file name, the line and column numbers of every character. |
| 285 |
The synchronization information in the output is simply the page number and |
| 286 |
either point coordinates, or box dimensions and position. |
| 287 |
The problem is that the mapping between these informations is only known at |
| 288 |
ship out time, which means that we must keep track of the input |
| 289 |
synchronization information until the pages ship out. |
| 290 |
|
| 291 |
As \TeX\ only knows about file names and line numbers, |
| 292 |
but forgets the column numbers, we only consider a |
| 293 |
restricted input synchronization information called {\sl Sync\TeX\ information}. |
| 294 |
It consists of a unique file name identifier, the {\sl Sync\TeX\ file tag}, |
| 295 |
and the line number. |
| 296 |
|
| 297 |
Keeping track of such information, |
| 298 |
should be different whether characters or nodes are involved. |
| 299 |
Actually, only certain nodes are involved in {\sl Sync\TeX}, |
| 300 |
we call them {\sl synchronized nodes}. |
| 301 |
Synchronized nodes store the {\sl Sync\TeX} information in their last two words: |
| 302 |
the first one contains a {\sl Sync\TeX\ file tag} uniquely identifying |
| 303 |
the input file, and the second one contains the current line number, |
| 304 |
as returned by the \.{\\inputlineno} primitive. |
| 305 |
The |synctex_field_size| macro contains the necessary size to store |
| 306 |
the {\sl Sync\TeX} information in a node. |
| 307 |
|
| 308 |
When declaring the size of a new node, it is recommanded to use the following |
| 309 |
convention: if the node is synchronized, use a definition similar to |
| 310 |
|my_synchronized_node_size|={\sl xxx}+|synctex_field_size|. |
| 311 |
Moreover, one should expect that the {\sl Sync\TeX} information is always stored |
| 312 |
in the last two words of a synchronized node. |
| 313 |
|
| 314 |
@ By default, every node with a sufficiently big size is initialized |
| 315 |
at creation time in the |get_node| routine with the current |
| 316 |
{\sl Sync\TeX} information, whether or not the node is synchronized. |
| 317 |
One purpose is to set this information very early in order to minimize code |
| 318 |
dependencies, including forthcoming extensions. |
| 319 |
Another purpose is to avoid the assumption that every node type has a dedicated getter, |
| 320 |
where initialization should take place. Actually, it appears that some nodes are created |
| 321 |
using directly the |get_node| routine and not the dedicated constructor. |
| 322 |
And finally, initializing the node at only one place is less error prone. |
| 323 |
|
| 324 |
@ @<Initialize bigger nodes with {\sl Sync\TeX} information@>= |
| 325 |
if s>=medium_node_size then |
| 326 |
begin |
| 327 |
sync_tag(r+s):=synctex_tag; |
| 328 |
sync_line(r+s):=line; |
| 329 |
end; |
| 330 |
|
| 331 |
@ Instead of storing the input file name, it is better to store just an identifier. |
| 332 |
Each time \TeX\ opens a new file, it notifies the {\sl Sync\TeX} controller with |
| 333 |
a |synctex_start_input| message. |
| 334 |
This controller will create a new {\sl Sync\TeX} file tag and |
| 335 |
will update the current input state record accordingly. |
| 336 |
If the input comes from the terminal or a pseudo file, the |synctex_tag| is set to 0. |
| 337 |
It results in automatically disabling synchronization for material |
| 338 |
input from the terminal or pseudo files. |
| 339 |
|
| 340 |
@ @<Prepare new file {\sl Sync\TeX} information@>= |
| 341 |
synctex_start_input; {Give control to the {\sl Sync\TeX} controller} |
| 342 |
|
| 343 |
@ @<Prepare terminal input {\sl Sync\TeX} information@>= |
| 344 |
synctex_tag:=0; |
| 345 |
|
| 346 |
@ @<Close {\sl Sync\TeX} file and write status@>= |
| 347 |
synctex_terminate(log_opened); {Let the {\sl Sync\TeX} controller close its files.} |
| 348 |
|
| 349 |
@ Synchronized nodes are boxes, math, kern and glue nodes. |
| 350 |
Other nodes should be synchronized too, in particular math noads. |
| 351 |
\TeX\ assumes that math, kern and glue nodes have the same size, |
| 352 |
this is why both are synchronized. |
| 353 |
{\sl In fine}, only horizontal lists are really used in {\sl Sync\TeX}, |
| 354 |
but all box nodes are considered the same with respect to synchronization, |
| 355 |
because a box node type is allowed to change at execution time. |
| 356 |
|
| 357 |
The next sections are the various messages sent to the {\sl Sync\TeX} controller. |
| 358 |
The argument is either the box or the node currently shipped out. |
| 359 |
The vertical boxes are not recorded, but the code is available for clients. |
| 360 |
|
| 361 |
@ @<Start sheet {\sl Sync\TeX} information record@>= |
| 362 |
synctex_sheet(mag); |
| 363 |
|
| 364 |
@ @<Finish sheet {\sl Sync\TeX} information record@>= |
| 365 |
synctex_teehs; |
| 366 |
|
| 367 |
@ @<Start vlist {\sl Sync\TeX} information record@>= |
| 368 |
synctex_vlist(this_box); |
| 369 |
|
| 370 |
@ @<Finish vlist {\sl Sync\TeX} information record@>= |
| 371 |
synctex_tsilv(this_box); |
| 372 |
|
| 373 |
@ @<Start hlist {\sl Sync\TeX} information record@>= |
| 374 |
synctex_hlist(this_box); |
| 375 |
|
| 376 |
@ @<Finish hlist {\sl Sync\TeX} information record@>= |
| 377 |
synctex_tsilh(this_box); |
| 378 |
|
| 379 |
@ @<Record void list {\sl Sync\TeX} information@>= |
| 380 |
if type(p)=vlist_node then begin |
| 381 |
synctex_void_vlist(p,this_box); |
| 382 |
end |
| 383 |
else begin |
| 384 |
synctex_void_hlist(p,this_box); |
| 385 |
end; |
| 386 |
|
| 387 |
@ @<Record current point {\sl Sync\TeX} information@>= |
| 388 |
synctex_current; |
| 389 |
|
| 390 |
@ @<Record horizontal |rule_node| or |glue_node| {\sl Sync\TeX} information@>= |
| 391 |
synctex_horizontal_rule_or_glue(p,this_box); |
| 392 |
|
| 393 |
@ @<Record |kern_node| {\sl Sync\TeX} information@>= |
| 394 |
synctex_kern(p,this_box); |
| 395 |
|
| 396 |
@ @<Record |math_node| {\sl Sync\TeX} information@>= |
| 397 |
synctex_math(p,this_box); |
| 398 |
|
| 399 |
@ When making a copy of a synchronized node, we might also have to duplicate |
| 400 |
the {\sl Sync\TeX} information by copying the two last words. |
| 401 |
This is the case for a |box_node| and for a |glue_node|, |
| 402 |
but not for a |math_node| nor a |kern_node|. These last two nodes always keep |
| 403 |
the {\sl Sync\TeX} information they received at creation time. |
| 404 |
|
| 405 |
@ @<Copy the box {\sl Sync\TeX} information@>= |
| 406 |
sync_tag(r+box_node_size):=sync_tag(p+box_node_size); |
| 407 |
sync_line(r+box_node_size):=sync_line(p+box_node_size); |
| 408 |
|
| 409 |
@ @<Copy the rule {\sl Sync\TeX} information@>= |
| 410 |
{|sync_tag(r+rule_node_size):=sync_tag(p+rule_node_size);| |
| 411 |
|sync_line(r+rule_node_size):=sync_line(p+rule_node_size);|} |
| 412 |
|
| 413 |
@ @<Copy the medium sized node {\sl Sync\TeX} information@>= |
| 414 |
sync_tag(r+medium_node_size):=sync_tag(p+medium_node_size); |
| 415 |
sync_line(r+medium_node_size):=sync_line(p+medium_node_size); |
| 416 |
|
| 417 |
@ {\sl Nota Bene:} |
| 418 |
The {\sl Sync\TeX} code is very close to the memory model. |
| 419 |
It is not connected to any other part of the code, |
| 420 |
except for memory management. It is possible to neutralize the {\sl Sync\TeX} code |
| 421 |
rather simply. The first step is to define a null |synctex_field_size|. |
| 422 |
The second step is to comment out the code in ``Initialize bigger nodes...'' and every |
| 423 |
``Copy ... {\sl Sync\TeX} information''. |
| 424 |
The last step will be to comment out the |synctex_tag_field| related code in the |
| 425 |
definition of |synctex_tag| and the various ``Prepare ... {\sl Sync\TeX} information''. |
| 426 |
Then all the remaining code should be just harmless. |
| 427 |
The resulting program would behave exactly the same as if absolutely no {\sl Sync\TeX} |
| 428 |
related code was there, including memory management. |
| 429 |
Of course, all this assumes that {\sl Sync\TeX} is turned off from the command line. |
| 430 |
@z |