MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtplot_latex_eps

Function gmtplot_latex_eps

src/gmt_plot.c:320–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320GMT_LOCAL unsigned char * gmtplot_latex_eps (struct GMT_CTRL *GMT, struct GMT_FONT *F, const char *string, struct imageinfo *h) {
321 /* Convert a string containing LaTeX syntax to an EPS image */
322 unsigned int i, o;
323 int error = 0;
324 char *text = NULL, *font, *code;
325 char tmpdir[PATH_MAX] = {""}, here[PATH_MAX] = {""}, file[PATH_MAX] = {""}, cmd[PATH_MAX] = {""};
326 unsigned char *picture = NULL;
327 FILE *fp = NULL;
328 struct GMTAPI_CTRL *API = GMT->parent;
329
330 if (gmtplot_has_title_breaks (GMT, string)) {
331 GMT_Report (API, GMT_MSG_ERROR, "LaTeX expressions are only allowed in single-line strings\n");
332 return NULL;
333 }
334
335 if (gmt_check_executable (GMT, "latex", "--version", NULL, NULL)) {
336 GMT_Report (API, GMT_MSG_DEBUG, "latex found.\n");
337 }
338 else {
339 GMT_Report (API, GMT_MSG_ERROR, "latex is not installed or not in your executable path - cannot process LaTeX to DVI.\n");
340 return NULL;
341 }
342 if (gmt_check_executable (GMT, "dvips", "--version", NULL, NULL)) {
343 GMT_Report (API, GMT_MSG_DEBUG, "dvips found.\n");
344 }
345 else {
346 GMT_Report (API, GMT_MSG_ERROR, "dvips is not installed or not in your executable path - cannot convert DVI to EPS.\n");
347 return NULL;
348 }
349
350 /* Create unique directory for outputs, stored in tmpdir */
351
352 if (gmt_create_tempdir (API, "gmt_latex", tmpdir))
353 return NULL;
354
355 /* Remember where we are */
356 if (getcwd (here, PATH_MAX) == NULL) {
357 GMT_Report (API, GMT_MSG_ERROR, "Unable to determine current working directory - exiting.\n");
358 return NULL;
359 }
360 gmt_replace_backslash_in_path (here);
361 /* Use tmpdir as the current directory */
362 if (chdir (tmpdir)) {
363 GMT_Report (API, GMT_MSG_ERROR, "Unable to change directory to %s - exiting.\n", tmpdir);
364 return NULL;
365 }
366 /* Create LaTeX file */
367 sprintf (file, "gmt_eq.tex");
368 if ((fp = fopen (file, "w")) == NULL) {
369 GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Could not create LaTeX file %s.\n", file);
370 return NULL;
371 }
372
373 /* Replace any @[ or <math> ... </math> with $ */
374 text = strdup (string);
375 for (i = o = 0; i < strlen (string); i++) {
376 if (string[i] == '@' && string[i+1] == '[')
377 text[o++] = '$', i++;

Callers 3

gmtplot_map_labelFunction · 0.85
gmt_map_textFunction · 0.85
gmtplot_place_latex_epsFunction · 0.85

Calls 8

gmtplot_has_title_breaksFunction · 0.85
GMT_ReportFunction · 0.85
gmt_check_executableFunction · 0.85
gmt_create_tempdirFunction · 0.85
strdupFunction · 0.85
PSL_loadepsFunction · 0.85
gmt_remove_dirFunction · 0.85

Tested by

no test coverage detected