Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
16 KiB

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