]> www.fi.muni.cz Git - evince.git/blob - cut-n-paste/synctex/synctex_parser.h
Revert "cut-n-paste: update synctex_parser to version 1.13"
[evince.git] / cut-n-paste / synctex / synctex_parser.h
1 /* 
2 Copyright (c) 2008, 2009, 2010 jerome DOT laurens AT u-bourgogne DOT fr
3
4 This file is part of the SyncTeX package.
5
6 Latest Revision: Wed Jul  1 11:16:51 UTC 2009
7
8 Version: 1.12
9 See synctex_parser_readme.txt for more details
10
11 License:
12 --------
13 Permission is hereby granted, free of charge, to any person
14 obtaining a copy of this software and associated documentation
15 files (the "Software"), to deal in the Software without
16 restriction, including without limitation the rights to use,
17 copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the
19 Software is furnished to do so, subject to the following
20 conditions:
21
22 The above copyright notice and this permission notice shall be
23 included in all copies or substantial portions of the Software.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
27 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 OTHER DEALINGS IN THE SOFTWARE
33
34 Except as contained in this notice, the name of the copyright holder  
35 shall not be used in advertising or otherwise to promote the sale,  
36 use or other dealings in this Software without prior written  
37 authorization from the copyright holder.
38
39 Acknowledgments:
40 ----------------
41 The author received useful remarks from the pdfTeX developers, especially Hahn The Thanh,
42 and significant help from XeTeX developer Jonathan Kew
43
44 Nota Bene:
45 ----------
46 If you include or use a significant part of the synctex package into a software,
47 I would appreciate to be listed as contributor and see "SyncTeX" highlighted.
48
49 Version 1
50 Thu Jun 19 09:39:21 UTC 2008
51
52 */
53
54 #ifndef __SYNCTEX_PARSER__
55 #   define __SYNCTEX_PARSER__
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /*  synctex_node_t is the type for all synctex nodes.
62  *  The synctex file is parsed into a tree of nodes, either sheet, boxes, math nodes... */
63 typedef struct _synctex_node *  synctex_node_t;
64
65 /*  The main synctex object is a scanner
66  *  Its implementation is considered private.
67  *  The basic workflow is
68  * - create a "synctex scanner" with the contents of a file
69  * - perform actions on that scanner like display or edit queries
70  * - free the scanner when the work is done
71  */
72 typedef struct __synctex_scanner_t _synctex_scanner_t;
73 typedef _synctex_scanner_t *  synctex_scanner_t;
74
75 /*  This is the designated method to create a new synctex scanner object.
76  *  output is the pdf/dvi/xdv file associated to the synctex file.
77  *  If necessary, it can be the tex file that originated the synctex file
78  *  but this might cause problems if the \jobname has a custom value.
79  *  Despite this method can accept a relative path in practice,
80  *  you should only pass a full path name.
81  *  The path should be encoded by the underlying file system,
82  *  assuming that it is based on 8 bits characters, including UTF8,
83  *  not 16 bits nor 32 bits.
84  *  The last file extension is removed and replaced by the proper extension.
85  *  Then the private method _synctex_scanner_new_with_contents_of_file is called.
86  *  NULL is returned in case of an error or non existent file.
87  *  Once you have a scanner, use the synctex_display_query and synctex_edit_query below.
88  *      The new "build_directory" argument is available since version 1.5.
89  *      It is the directory where all the auxiliary stuff is created.
90  *      Sometimes, the synctex output file and the pdf, dvi or xdv files are not created in the same directory.
91  *      This is the case in MikTeX (I will include this into TeX Live).
92  *      This directory path can be nil, it will be ignored.
93  *      It can be either absolute or relative to the directory of the output pdf (dvi or xdv) file.
94  *      If no synctex file is found in the same directory as the output file, then we try to find one in the build directory.
95  *  Please note that this new "build_directory" is provided as a convenient argument but should not be used.
96  *  In fact, this is implempented as a work around of a bug in MikTeX where the synctex file does not follow the pdf file.
97  *  The new "parse" argument is available since version 1.5. In general, use 1.
98  *  Use 0 only if you do not want to parse the content but just check the existence.
99  */
100 synctex_scanner_t synctex_scanner_new_with_output_file(const char * output, const char * build_directory, int parse);
101
102 /*  This is the designated method to delete a synctex scanner object.
103  *  Frees all the memory, you must call it when you are finished with the scanner.
104  */
105 void synctex_scanner_free(synctex_scanner_t scanner);
106
107 /*  Send this message to force the scanner to parse the contents of the synctex output file.
108  *  Nothing is performed if the file was already parsed.
109  *  In each query below, this message is sent, but if you need to access information more directly,
110  *  you must be sure that the parsing did occur.
111  *  Usage:
112  *              if((my_scanner = synctex_scanner_parse(my_scanner))) {
113  *                      continue with my_scanner...
114  *              } else {
115  *                      there was a problem
116  *              }
117  */
118 synctex_scanner_t synctex_scanner_parse(synctex_scanner_t scanner);
119
120 /*  The main entry points.
121  *  Given the file name, a line and a column number, synctex_display_query returns the number of nodes
122  *  satisfying the contrain. Use code like
123  *
124  *     if(synctex_display_query(scanner,name,line,column)>0) {
125  *         synctex_node_t node;
126  *         while((node = synctex_next_result(scanner))) {
127  *             // do something with node
128  *             ...
129  *         }
130  *     }
131  *
132  *  For example, one can
133  * - highlight each resulting node in the output, using synctex_node_h and synctex_node_v
134  * - highlight all the rectangles enclosing those nodes, using synctex_box_... functions
135  * - highlight just the character using that information
136  *
137  *  Given the page and the position in the page, synctex_edit_query returns the number of nodes
138  *  satisfying the contrain. Use code like
139  *
140  *     if(synctex_edit_query(scanner,page,h,v)>0) {
141  *         synctex_node_t node;
142  *         while(node = synctex_next_result(scanner)) {
143  *             // do something with node
144  *             ...
145  *         }
146  *     }
147  *
148  *  For example, one can
149  * - highlight each resulting line in the input,
150  * - highlight just the character using that information
151  *
152  *  page is 1 based
153  *  h and v are coordinates in 72 dpi unit, relative to the top left corner of the page.
154  *  If you make a new query, the result of the previous one is discarded.
155  *  If one of this function returns a non positive integer,
156  *  it means that an error occurred.
157  *
158  *  Both methods are conservative, in the sense that matching is weak.
159  *  If the exact column number is not found, there will be an answer with the whole line.
160  *
161  *  Sumatra-PDF, Skim, iTeXMac2 and Texworks are examples of open source software that use this library.
162  *  You can browse their code for a concrete implementation.
163  */
164 int synctex_display_query(synctex_scanner_t scanner,const char *  name,int line,int column);
165 int synctex_edit_query(synctex_scanner_t scanner,int page,float h,float v);
166 synctex_node_t synctex_next_result(synctex_scanner_t scanner);
167
168 /*  Display all the information contained in the scanner object.
169  *  If the records are too numerous, only the first ones are displayed.
170  *  This is mainly for informatinal purpose to help developers.
171  */
172 void synctex_scanner_display(synctex_scanner_t scanner);
173
174 /*  The x and y offset of the origin in TeX coordinates. The magnification
175    These are used by pdf viewers that want to display the real box size.
176    For example, getting the horizontal coordinates of a node would require
177    synctex_node_box_h(node)*synctex_scanner_magnification(scanner)+synctex_scanner_x_offset(scanner)
178    Getting its TeX width would simply require
179    synctex_node_box_width(node)*synctex_scanner_magnification(scanner)
180    but direct methods are available for that below.
181  */
182 int synctex_scanner_x_offset(synctex_scanner_t scanner);
183 int synctex_scanner_y_offset(synctex_scanner_t scanner);
184 float synctex_scanner_magnification(synctex_scanner_t scanner);
185
186 /*  Managing the input file names.
187  *  Given a tag, synctex_scanner_get_name will return the corresponding file name.
188  *  Conversely, given a file name, synctex_scanner_get_tag will retur, the corresponding tag.
189  *  The file name must be the very same as understood by TeX.
190  *  For example, if you \input myDir/foo.tex, the file name is myDir/foo.tex.
191  *  No automatic path expansion is performed.
192  *  Finally, synctex_scanner_input is the first input node of the scanner.
193  *  To browse all the input node, use a loop like
194  *
195  *     if((input_node = synctex_scanner_input(scanner))){
196  *         do {
197  *             blah
198  *         } while((input_node=synctex_node_sibling(input_node)));
199  *     }
200  *
201  *  The output is the name that was used to create the scanner.
202  *  The synctex is the real name of the synctex file,
203  *  it was obtained from output by setting the proper file extension.
204  */
205 const char * synctex_scanner_get_name(synctex_scanner_t scanner,int tag);
206 int synctex_scanner_get_tag(synctex_scanner_t scanner,const char * name);
207 synctex_node_t synctex_scanner_input(synctex_scanner_t scanner);
208 const char * synctex_scanner_get_output(synctex_scanner_t scanner);
209 const char * synctex_scanner_get_synctex(synctex_scanner_t scanner);
210
211 /*  Browsing the nodes
212  *  parent, child and sibling are standard names for tree nodes.
213  *  The parent is one level higher, the child is one level deeper,
214  *  and the sibling is at the same level.
215  *  The sheet of a node is the first ancestor, it is of type sheet.
216  *  A node and its sibling have the same parent.
217  *  A node is the parent of its child.
218  *  A node is either the child of its parent,
219  *  or belongs to the sibling chain of its parent's child.
220  *  The next node is either the child, the sibling or the parent's sibling,
221  *  unless the parent is a sheet.
222  *  This allows to navigate through all the nodes of a given sheet node:
223  *
224  *     synctex_node_t node = sheet;
225  *     while((node = synctex_node_next(node))) {
226  *         // do something with node
227  *     }
228  *
229  *  With synctex_sheet_content, you can retrieve the sheet node given the page.
230  *  The page is 1 based, according to TeX standards.
231  *  Conversely synctex_node_sheet allows to retrieve the sheet containing a given node.
232  */
233 synctex_node_t synctex_node_parent(synctex_node_t node);
234 synctex_node_t synctex_node_sheet(synctex_node_t node);
235 synctex_node_t synctex_node_child(synctex_node_t node);
236 synctex_node_t synctex_node_sibling(synctex_node_t node);
237 synctex_node_t synctex_node_next(synctex_node_t node);
238 synctex_node_t synctex_sheet_content(synctex_scanner_t scanner,int page);
239
240 /*  These are the types of the synctex nodes */
241 typedef enum {
242         synctex_node_type_error = 0,
243         synctex_node_type_input,
244         synctex_node_type_sheet,
245         synctex_node_type_vbox,
246         synctex_node_type_void_vbox,
247         synctex_node_type_hbox,
248         synctex_node_type_void_hbox,
249         synctex_node_type_kern,
250         synctex_node_type_glue,
251         synctex_node_type_math,
252         synctex_node_type_boundary,
253         synctex_node_number_of_types
254 } synctex_node_type_t;
255
256 /*  synctex_node_type gives the type of a given node,
257  *  synctex_node_isa gives the same information as a human readable text. */
258 synctex_node_type_t synctex_node_type(synctex_node_t node);
259 const char * synctex_node_isa(synctex_node_t node);
260
261 /*  This is primarily used for debugging purpose.
262  *  The second one logs information for the node and recursively displays information for its next node */
263 void synctex_node_log(synctex_node_t node);
264 void synctex_node_display(synctex_node_t node);
265
266 /*  Given a node, access to its tag, line and column.
267  *  The line and column numbers are 1 based.
268  *  The latter is not yet fully supported in TeX, the default implementation returns 0 which means the whole line.
269  *  When the tag is known, the scanner of the node will give the corresponding file name.
270  *  When the tag is known, the scanner of the node will give the name.
271  */
272 int synctex_node_tag(synctex_node_t node);
273 int synctex_node_line(synctex_node_t node);
274 int synctex_node_column(synctex_node_t node);
275
276 /*  This is the page where the node appears.
277  *  This is a 1 based index as given by TeX.
278  */
279 int synctex_node_page(synctex_node_t node);
280
281 /*  For quite all nodes, horizontal, vertical coordinates, and width.
282  *  These are expressed in TeX small points coordinates, with origin at the top left corner.
283  */
284 int synctex_node_h(synctex_node_t node);
285 int synctex_node_v(synctex_node_t node);
286 int synctex_node_width(synctex_node_t node);
287
288 /*  For all nodes, dimensions of the enclosing box.
289  *  These are expressed in TeX small points coordinates, with origin at the top left corner.
290  *  A box is enclosing itself.
291  */
292 int synctex_node_box_h(synctex_node_t node);
293 int synctex_node_box_v(synctex_node_t node);
294 int synctex_node_box_width(synctex_node_t node);
295 int synctex_node_box_height(synctex_node_t node);
296 int synctex_node_box_depth(synctex_node_t node);
297
298 /*  For quite all nodes, horizontal, vertical coordinates, and width.
299  *  The visible dimensions are bigger than real ones to compensate 0 width boxes
300  *  that do contain nodes.
301  *  These are expressed in page coordinates, with origin at the top left corner.
302  *  A box is enclosing itself.
303  */
304 float synctex_node_visible_h(synctex_node_t node);
305 float synctex_node_visible_v(synctex_node_t node);
306 float synctex_node_visible_width(synctex_node_t node);
307 /*  For all nodes, visible dimensions of the enclosing box.
308  *  A box is enclosing itself.
309  *  The visible dimensions are bigger than real ones to compensate 0 width boxes
310  *  that do contain nodes.
311  */
312 float synctex_node_box_visible_h(synctex_node_t node);
313 float synctex_node_box_visible_v(synctex_node_t node);
314 float synctex_node_box_visible_width(synctex_node_t node);
315 float synctex_node_box_visible_height(synctex_node_t node);
316 float synctex_node_box_visible_depth(synctex_node_t node);
317
318 /*  The main synctex updater object.
319  *  This object is used to append information to the synctex file.
320  *  Its implementation is considered private.
321  *  It is used by the synctex command line tool to take into account modifications
322  *  that could occur while postprocessing files by dvipdf like filters.
323  */
324 typedef struct __synctex_updater_t _synctex_updater_t;
325 typedef _synctex_updater_t * synctex_updater_t;
326
327 /*  Designated initializer.
328  *  Once you are done with your whole job,
329  *  free the updater */
330 synctex_updater_t synctex_updater_new_with_output_file(const char * output, const char * directory);
331
332 /*  Use the next functions to append records to the synctex file,
333  *  no consistency tests made on the arguments */
334 void synctex_updater_append_magnification(synctex_updater_t updater, char *  magnification);
335 void synctex_updater_append_x_offset(synctex_updater_t updater, char *  x_offset);
336 void synctex_updater_append_y_offset(synctex_updater_t updater, char *  y_offset);
337
338 /*  You MUST free the updater, once everything is properly appended */
339 void synctex_updater_free(synctex_updater_t updater);
340
341 #ifdef __cplusplus
342 }
343 #endif
344
345 #endif