TeX driver: Conditionally emit "\input graphics" control sequence.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 26 Oct 2020 18:11:28 +0000 (19:11 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 26 Oct 2020 18:11:28 +0000 (19:11 +0100)
Only emit the \input graphicx control sequence if it is actually needed.
This way, systems which do not have the graphicx package installed will
not fail on examples which need no graphics component.

src/output/tex.c

index 4191e6938179b30fa420540830f4b59b9fca8a82..ee23505cce6041d625a312c481bfdcdca692ae12 100644 (file)
@@ -66,6 +66,7 @@ struct tex_driver
     struct output_driver driver;
     /* A hash table containing any Tex macros which need to be emitted.  */
     struct hmap macros;
+    bool require_graphics;
 #ifdef HAVE_CAIRO
     struct cell_color fg;
     struct cell_color bg;
@@ -215,8 +216,6 @@ tex_destroy (struct output_driver *driver)
   shipout (&tex->preamble_list, "%%%% Define the horizontal space between table columns\n");
   shipout (&tex->preamble_list, "\\def\\psppcolumnspace{1mm}\n\n");
 
-  shipout (&tex->preamble_list, "\\input graphicx\n\n");
-
   char *ln = get_language ();
   if (ln)
     shipout (&tex->preamble_list, "%%%% Language is \"%s\"\n", ln);
@@ -260,6 +259,9 @@ tex_destroy (struct output_driver *driver)
     }
   hmap_destroy (&tex->macros);
 
+  if (tex->require_graphics)
+    shipout (&tex->preamble_list, "\\input graphicx\n\n");
+
   post_process_tokens (tex->file, &tex->preamble_list);
 
   shipout (&tex->token_list, "\n\\bye\n");
@@ -327,6 +329,7 @@ tex_submit (struct output_driver *driver,
           //          printf ("The chart title is %s\n", title);
 
           shipout (&tex->token_list, "\\includegraphics{%s}\n", file_name);
+          tex->require_graphics = true;
           free (file_name);
         }
     }