Okular

synctex_parser.h
1 /*
2  SPDX-FileCopyrightText: 2008-2017 jerome DOT laurens AT u-bourgogne DOT fr
3  SPDX-License-Identifier: X11
4 
5  This file is part of the __SyncTeX__ package.
6 
7  [//]: # (Latest Revision: Fri Jul 14 16:20:41 UTC 2017)
8  [//]: # (Version: 1.19)
9 
10  See `synctex_parser_readme.md` for more details
11 
12  ## Acknowledgments:
13 
14  The author received useful remarks from the __pdfTeX__ developers, especially Hahn The Thanh,
15  and significant help from __XeTeX__ developer Jonathan Kew.
16 
17  ## Nota Bene:
18 
19  If you include or use a significant part of the __SyncTeX__ package into a software,
20  I would appreciate to be listed as contributor and see "__SyncTeX__" highlighted.
21 */
22 
23 #ifndef __SYNCTEX_PARSER__
24 #define __SYNCTEX_PARSER__
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define SYNCTEX_VERSION_STRING "1.19"
31 
32 /* The main synctex object is a scanner.
33  * Its implementation is considered private.
34  * The basic workflow is
35  * - create a "synctex scanner" with the contents of a file
36  * - perform actions on that scanner like
37  synctex_display_query or synctex_edit_query below.
38  * - perform actions on nodes returned by the scanner
39  * - free the scanner when the work is done
40  */
41 typedef struct synctex_scanner_t synctex_scanner_s;
42 typedef synctex_scanner_s *synctex_scanner_p;
43 
44 /**
45  * This is the designated method to create
46  * a new synctex scanner object.
47  * - argument output: the pdf/dvi/xdv file associated
48  * to the synctex file.
49  * If necessary, it can be the tex file that
50  * originated the synctex file but this might cause
51  * problems if the \\jobname has a custom value.
52  * Despite this method can accept a relative path
53  * in practice, you should only pass full paths.
54  * The path should be encoded by the underlying
55  * file system, assuming that it is based on
56  * 8 bits characters, including UTF8,
57  * not 16 bits nor 32 bits.
58  * The last file extension is removed and
59  * replaced by the proper extension,
60  * either synctex or synctex.gz.
61  * - argument build_directory: It is the directory where
62  * all the auxiliary stuff is created.
63  * If no synctex file is found in the same directory
64  * as the output file, then we try to find one in
65  * this build directory.
66  * It is the directory where all the auxiliary
67  * stuff is created. Sometimes, the synctex output
68  * file and the pdf, dvi or xdv files are not
69  * created in the same location. See MikTeX.
70  * This directory path can be NULL,
71  * it will be ignored then.
72  * It can be either absolute or relative to the
73  * directory of the output pdf (dvi or xdv) file.
74  * Please note that this new argument is provided
75  * as a convenience but should not be used.
76  * Available since version 1.5.
77  * - argument parse: In general, use 1.
78  * Use 0 only if you do not want to parse the
79  * content but just check for existence.
80  * Available since version 1.5
81  * - resturn: a scanner. NULL is returned in case
82  * of an error or non existent file.
83  */
84 synctex_scanner_p synctex_scanner_new_with_output_file(const char *output, const char *build_directory, int parse);
85 
86 /**
87  * Designated method to delete a synctex scanner object,
88  * including all its internal resources.
89  * Frees all the memory, you must call it when you are finished with the scanner.
90  * - argument scanner: a scanner.
91  * - returns: an integer used for testing purposes.
92  */
93 int synctex_scanner_free(synctex_scanner_p scanner);
94 
95 /**
96  * Send this message to force the scanner to
97  * parse the contents of the synctex output file.
98  * Nothing is performed if the file was already parsed.
99  * In each query below, this message is sent,
100  * but if you need to access information more directly,
101  * you must ensure that the parsing did occur.
102  * Usage:
103  * if((my_scanner = synctex_scanner_parse(my_scanner))) {
104  * continue with my_scanner...
105  * } else {
106  * there was a problem
107  * }
108  * - returns: the argument on success.
109  * On failure, frees scanner and returns NULL.
110  */
111 synctex_scanner_p synctex_scanner_parse(synctex_scanner_p scanner);
112 
113 /* synctex_node_p is the type for all synctex nodes.
114  * Its implementation is considered private.
115  * The synctex file is parsed into a tree of nodes, either sheet, form, boxes, math nodes... */
116 
117 typedef struct synctex_node_t synctex_node_s;
118 typedef synctex_node_s *synctex_node_p;
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,page_hint)>0) {
125  * synctex_node_p node;
126  * while((node = synctex_scanner_next_result(scanner))) {
127  * // do something with node
128  * ...
129  * }
130  * }
131  *
132  * Please notice that since version 1.19,
133  * there is a new argument page_hint.
134  * The results in pages closer to page_hint are given first.
135  * For example, one can
136  * - highlight each resulting node in the output, using synctex_node_visible_h and synctex_node_visible_v
137  * - highlight all the rectangles enclosing those nodes, using synctex_node_box_visible_... functions
138  * - highlight just the character using that information
139  *
140  * Given the page and the position in the page, synctex_edit_query returns the number of nodes
141  * satisfying the contrain. Use code like
142  *
143  * if(synctex_edit_query(scanner,page,h,v)>0) {
144  * synctex_node_p node;
145  * while(node = synctex_scanner_next_result(scanner)) {
146  * // do something with node
147  * ...
148  * }
149  * }
150  *
151  * For example, one can
152  * - highlight each resulting line in the input,
153  * - highlight just the character using that information
154  *
155  * page is 1 based
156  * h and v are coordinates in 72 dpi unit, relative to the top left corner of the page.
157  * If you make a new query, the result of the previous one is discarded. If you need to make more than one query
158  * in parallel, use the iterator API exposed in
159  * the synctex_parser_private.h header.
160  * If one of this function returns a negative integer,
161  * it means that an error occurred.
162  *
163  * Both methods are conservative, in the sense that matching is weak.
164  * If the exact column number is not found, there will be an answer with the whole line.
165  *
166  * Sumatra-PDF, Skim, iTeXMac2, TeXShop and Texworks are examples of open source software that use this library.
167  * You can browse their code for a concrete implementation.
168  */
169 typedef long synctex_status_t;
170 /* The page_hint argument is used to resolve ambiguities.
171  * Whenever, different matches occur, the ones closest
172  * to the page will be given first. Pass a negative number
173  * when in doubt. Using pdf forms may lead to ambiguities.
174  */
175 synctex_status_t synctex_display_query(synctex_scanner_p scanner, const char *name, int line, int column, int page_hint);
176 synctex_status_t synctex_edit_query(synctex_scanner_p scanner, int page, float h, float v);
177 synctex_node_p synctex_scanner_next_result(synctex_scanner_p scanner);
178 synctex_status_t synctex_scanner_reset_result(synctex_scanner_p scanner);
179 
180 /**
181  * The horizontal and vertical location,
182  * the width, height and depth of a box enclosing node.
183  * All dimensions are given in page coordinates
184  * as opposite to TeX coordinates.
185  * The origin is at the top left corner of the page.
186  * Code example for Qt5:
187  * (from TeXworks source TWSynchronize.cpp)
188  * QRectF nodeRect(synctex_node_box_visible_h(node),
189  * synctex_node_box_visible_v(node) -
190  * synctex_node_box_visible_height(node),
191  * synctex_node_box_visible_width(node),
192  * synctex_node_box_visible_height(node) +
193  * synctex_node_box_visible_depth(node));
194  * Code example for Cocoa:
195  * NSRect bounds = [pdfPage
196  * boundsForBox:kPDFDisplayBoxMediaBox];
197  * NSRect nodeRect = NSMakeRect(
198  * synctex_node_box_visible_h(node),
199  * NSMaxY(bounds)-synctex_node_box_visible_v(node) +
200  * synctex_node_box_visible_height(node),
201  * synctex_node_box_visible_width(node),
202  * synctex_node_box_visible_height(node) +
203  * synctex_node_box_visible_depth(node)
204  * );
205  * The visible dimensions are bigger than real ones
206  * to compensate 0 width boxes or nodes intentionally
207  * put outside the box (using \\kern for example).
208  * - parameter node: a node.
209  * - returns: a float.
210  * - author: JL
211  */
212 float synctex_node_box_visible_h(synctex_node_p node);
213 float synctex_node_box_visible_v(synctex_node_p node);
214 float synctex_node_box_visible_width(synctex_node_p node);
215 float synctex_node_box_visible_height(synctex_node_p node);
216 float synctex_node_box_visible_depth(synctex_node_p node);
217 
218 /**
219  * For quite all nodes, horizontal and vertical coordinates, and width.
220  * All dimensions are given in page coordinates
221  * as opposite to TeX coordinates.
222  * The origin is at the top left corner of the page.
223  * The visible dimensions are bigger than real ones
224  * to compensate 0 width boxes or nodes intentionally
225  * put outside the box (using \\kern for example).
226  * All nodes have coordinates, but all nodes don't
227  * have non null size. For example, math nodes
228  * have no width according to TeX, and in that case
229  * synctex_node_visible_width simply returns 0.
230  * The same holds for kern nodes that do not have
231  * height nor depth, etc...
232  */
233 float synctex_node_visible_h(synctex_node_p node);
234 float synctex_node_visible_v(synctex_node_p node);
235 float synctex_node_visible_width(synctex_node_p node);
236 float synctex_node_visible_height(synctex_node_p node);
237 float synctex_node_visible_depth(synctex_node_p node);
238 
239 /**
240  * Given a node, access to its tag, line and column.
241  * The line and column numbers are 1 based.
242  * The latter is not yet fully supported in TeX,
243  * the default implementation returns 0
244  * which means the whole line.
245  * synctex_node_get_name returns the path of the
246  * TeX source file that was used to create the node.
247  * When the tag is known, the scanner of the node
248  * will also give that same file name, see
249  * synctex_scanner_get_name below.
250  */
251 int synctex_node_tag(synctex_node_p node);
252 int synctex_node_line(synctex_node_p node);
253 int synctex_node_column(synctex_node_p node);
254 const char *synctex_node_get_name(synctex_node_p node);
255 
256 /**
257  This is the page where the node appears.
258  * This is a 1 based index as given by TeX.
259  */
260 int synctex_node_page(synctex_node_p node);
261 
262 /**
263  * Display all the information contained in the scanner.
264  * If the records are too numerous, only the first ones are displayed.
265  * This is mainly for informational purpose to help developers.
266  */
267 void synctex_scanner_display(synctex_scanner_p scanner);
268 
269 /* Managing the input file names.
270  * Given a tag, synctex_scanner_get_name will return the corresponding file name.
271  * Conversely, given a file name, synctex_scanner_get_tag will return, the corresponding tag.
272  * The file name must be the very same as understood by TeX.
273  * For example, if you \input myDir/foo.tex, the file name is myDir/foo.tex.
274  * No automatic path expansion is performed.
275  * Finally, synctex_scanner_input is the first input node of the scanner.
276  * To browse all the input node, use a loop like
277  * ...
278  * synctex_node_p = input_node;
279  * ...
280  * if((input_node = synctex_scanner_input(scanner))) {
281  * do {
282  * blah
283  * } while((input_node=synctex_node_sibling(input_node)));
284  * }
285  *
286  * The output is the name that was used to create the scanner.
287  * The synctex is the real name of the synctex file,
288  * it was obtained from output by setting the proper file extension.
289  */
290 const char *synctex_scanner_get_name(synctex_scanner_p scanner, int tag);
291 
292 int synctex_scanner_get_tag(synctex_scanner_p scanner, const char *name);
293 
294 synctex_node_p synctex_scanner_input(synctex_scanner_p scanner);
295 synctex_node_p synctex_scanner_input_with_tag(synctex_scanner_p scanner, int tag);
296 const char *synctex_scanner_get_output(synctex_scanner_p scanner);
297 const char *synctex_scanner_get_synctex(synctex_scanner_p scanner);
298 
299 /* The x and y offset of the origin in TeX coordinates. The magnification
300  These are used by pdf viewers that want to display the real box size.
301  For example, getting the horizontal coordinates of a node would require
302  synctex_node_box_h(node)*synctex_scanner_magnification(scanner)+synctex_scanner_x_offset(scanner)
303  Getting its TeX width would simply require
304  synctex_node_box_width(node)*synctex_scanner_magnification(scanner)
305  but direct methods are available for that below.
306  */
307 int synctex_scanner_x_offset(synctex_scanner_p scanner);
308 int synctex_scanner_y_offset(synctex_scanner_p scanner);
309 float synctex_scanner_magnification(synctex_scanner_p scanner);
310 
311 /**
312  * ## Browsing the nodes
313  * parent, child and sibling are standard names for tree nodes.
314  * The parent is one level higher,
315  * the child is one level deeper,
316  * and the sibling is at the same level.
317  * A node and its sibling have the same parent.
318  * A node is the parent of its children.
319  * A node is either the child of its parent,
320  * or belongs to the sibling chain of its parent's child.
321  * The sheet or form of a node is the topmost ancestor,
322  * it is of type sheet or form.
323  * The next node is either the child, the sibling or the parent's sibling,
324  * unless the parent is a sheet, a form or NULL.
325  * This allows to navigate through all the nodes of a given sheet node:
326  *
327  * synctex_node_p node = sheet;
328  * while((node = synctex_node_next(node))) {
329  * // do something with node
330  * }
331  *
332  * With synctex_sheet_content and synctex_form_content,
333  * you can retrieve the sheet node given the page
334  * or form tag.
335  * The page is 1 based, according to TeX standards.
336  * Conversely synctex_node_parent_sheet or
337  * synctex_node_parent_form allows to retrieve
338  * the sheet or the form containing a given node.
339  * Notice that a node is not contained in a sheet
340  * and a form at the same time.
341  * Some nodes are not contained in either (handles).
342  */
343 
344 synctex_node_p synctex_node_parent(synctex_node_p node);
345 synctex_node_p synctex_node_parent_sheet(synctex_node_p node);
346 synctex_node_p synctex_node_parent_form(synctex_node_p node);
347 synctex_node_p synctex_node_child(synctex_node_p node);
348 synctex_node_p synctex_node_last_child(synctex_node_p node);
349 synctex_node_p synctex_node_sibling(synctex_node_p node);
350 synctex_node_p synctex_node_last_sibling(synctex_node_p node);
351 synctex_node_p synctex_node_arg_sibling(synctex_node_p node);
352 synctex_node_p synctex_node_next(synctex_node_p node);
353 
354 /**
355  * Top level entry points.
356  * The scanner owns a list of sheet siblings and
357  * a list of form siblings.
358  * Sheets or forms have one child which is a box:
359  * theie contents.
360  * - argument page: 1 based sheet page number.
361  * - argument tag: 1 based form tag number.
362  */
363 synctex_node_p synctex_sheet(synctex_scanner_p scanner, int page);
364 synctex_node_p synctex_sheet_content(synctex_scanner_p scanner, int page);
365 synctex_node_p synctex_form(synctex_scanner_p scanner, int tag);
366 synctex_node_p synctex_form_content(synctex_scanner_p scanner, int tag);
367 
368 /* This is primarily used for debugging purpose.
369  * The second one logs information for the node and recursively displays information for its next node */
370 void synctex_node_log(synctex_node_p node);
371 void synctex_node_display(synctex_node_p node);
372 
373 /* For quite all nodes, horizontal, vertical coordinates, and width.
374  * These are expressed in TeX small points coordinates, with origin at the top left corner.
375  */
376 int synctex_node_h(synctex_node_p node);
377 int synctex_node_v(synctex_node_p node);
378 int synctex_node_width(synctex_node_p node);
379 int synctex_node_height(synctex_node_p node);
380 int synctex_node_depth(synctex_node_p node);
381 
382 /* For all nodes, dimensions of the enclosing box.
383  * These are expressed in TeX small points coordinates, with origin at the top left corner.
384  * A box is enclosing itself.
385  */
386 int synctex_node_box_h(synctex_node_p node);
387 int synctex_node_box_v(synctex_node_p node);
388 int synctex_node_box_width(synctex_node_p node);
389 int synctex_node_box_height(synctex_node_p node);
390 int synctex_node_box_depth(synctex_node_p node);
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.