[gnome-latex: 19/205] compile latex and view DVI
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 19/205] compile latex and view DVI
- Date: Fri, 14 Dec 2018 10:48:28 +0000 (UTC)
commit c3246ac949f76763e0348de3cc598b0787154073
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Fri Aug 7 14:49:38 2009 +0200
compile latex and view DVI
TODO | 6 +-
src/callbacks.c | 222 +++++++++++++++++++++++++++++++-------------------------
src/callbacks.h | 2 +
src/main.c | 4 +-
4 files changed, 131 insertions(+), 103 deletions(-)
---
diff --git a/TODO b/TODO
index 8a93168..c9392e9 100644
--- a/TODO
+++ b/TODO
@@ -20,8 +20,8 @@ Jul 31, 2009 to Aug 7, 2009
x undo/redo
x font monospace
-[-] compile and view
+[x] compile and view
x compile (pdflatex)
x view PDF
- - compile (latex)
- - view DVI
+ x compile (latex)
+ x view DVI
diff --git a/src/callbacks.c b/src/callbacks.c
index e20ea84..a9c916e 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -19,6 +19,8 @@ static void file_save (void);
static gboolean close_all (void);
static void set_title (void);
static void set_undo_redo_sensitivity (void);
+static void run_compilation (gchar *command);
+static void view_document (gchar *doc_type, gchar *doc_extension);
void
cb_new (void)
@@ -221,112 +223,27 @@ cb_line_numbers (GtkToggleAction *action, gpointer user_data)
}
void
-cb_pdflatex (void)
+cb_latex (void)
{
- if (docs.active != NULL)
- {
- GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
-
- // the current document is a *.tex file?
- gboolean tex_file = g_regex_match_simple ("\\.tex$", docs.active->path, 0, 0);
- if (! tex_file)
- {
- gchar *text = g_strdup_printf (_("compilation failed: %s is not a *.tex file"),
- g_path_get_basename (docs.active->path));
-
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
- return;
- }
-
- // run the command in the directory where the .tex is
- gchar *dir_backup = g_get_current_dir ();
- gchar *dir = g_path_get_dirname (docs.active->path);
- g_chdir (dir);
- gchar *command = g_strdup_printf ("pdflatex -interaction=nonstopmode %s",
- docs.active->path);
- gchar *output;
- GError *error = NULL;
-
- print_info ("execution of the command: %s", command);
-
- g_spawn_command_line_sync (command, &output, NULL, NULL, &error);
- g_chdir (dir_backup);
-
- // an error occured
- if (error != NULL)
- {
- print_warning ("execution failed: %s", error->message);
- g_error_free (error);
- return;
- }
+ run_compilation ("latex -interaction=nonstopmode");
+}
- // show the message of the command
- gtk_text_buffer_set_text (log_buffer, output, -1);
+void
+cb_pdflatex (void)
+{
+ run_compilation ("pdflatex -interaction=nonstopmode");
+}
- g_free (dir_backup);
- g_free (dir);
- g_free (command);
- g_free (output);
- }
+void
+cb_view_dvi (void)
+{
+ view_document ("DVI", ".dvi");
}
void
cb_view_pdf (void)
{
- if (docs.active != NULL)
- {
- GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
-
- GError *error = NULL;
- GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
-
- // the current document is a *.tex file?
- gboolean tex_file = g_regex_match (regex, docs.active->path, 0, NULL);
- if (! tex_file)
- {
- gchar *text = g_strdup_printf (_("view PDF failed: %s is not a *.tex file"),
- g_path_get_basename (docs.active->path));
-
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
- g_regex_unref (regex);
- return;
- }
-
- // replace .tex by .pdf
- gchar *pdf_path = g_regex_replace_literal (regex, docs.active->path,
- -1, 0, ".pdf", 0, NULL);
-
- // the PDF file exist?
- if (! g_file_test (pdf_path, G_FILE_TEST_IS_REGULAR))
- {
- gchar *text = g_strdup_printf (
- _("%s does not exist. If this is not already made, compile the
document with pdflatex."),
- g_path_get_basename (pdf_path));
-
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
- g_free (pdf_path);
- g_regex_unref (regex);
- return;
- }
-
- // run the command
- gchar *command = g_strdup_printf ("evince %s", pdf_path);
- print_info ("execution of the command: %s", command);
- g_spawn_command_line_async (command, &error);
-
- if (error != NULL)
- {
- print_warning ("execution failed: %s", error->message);
- g_error_free (error);
- }
-
- g_regex_unref (regex);
- g_free (pdf_path);
- g_free (command);
- }
+ view_document ("PDF", ".pdf");
}
void
@@ -562,3 +479,112 @@ set_undo_redo_sensitivity (void)
gtk_action_set_sensitive (docs.undo, can_undo);
gtk_action_set_sensitive (docs.redo, can_redo);
}
+
+static void
+run_compilation (gchar *command)
+{
+ if (docs.active != NULL)
+ {
+ GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
+
+ // the current document is a *.tex file?
+ gboolean tex_file = g_regex_match_simple ("\\.tex$", docs.active->path, 0, 0);
+ if (! tex_file)
+ {
+ gchar *text = g_strdup_printf (_("compilation failed: %s is not a *.tex file"),
+ g_path_get_basename (docs.active->path));
+
+ gtk_text_buffer_set_text (log_buffer, text, -1);
+ g_free (text);
+ return;
+ }
+
+ // run the command in the directory where the .tex is
+ gchar *dir_backup = g_get_current_dir ();
+ gchar *dir = g_path_get_dirname (docs.active->path);
+ g_chdir (dir);
+ gchar *full_command = g_strdup_printf ("%s %s", command, docs.active->path);
+ gchar *output;
+ GError *error = NULL;
+
+ print_info ("execution of the command: %s", full_command);
+
+ g_spawn_command_line_sync (full_command, &output, NULL, NULL, &error);
+ g_chdir (dir_backup);
+
+ // an error occured
+ if (error != NULL)
+ {
+ print_warning ("execution failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ // show the message of the command
+ else
+ gtk_text_buffer_set_text (log_buffer, output, -1);
+
+ g_free (dir_backup);
+ g_free (dir);
+ g_free (full_command);
+ g_free (output);
+ }
+}
+
+static void
+view_document (gchar *doc_type, gchar *doc_extension)
+{
+ if (docs.active != NULL)
+ {
+ GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
+
+ GError *error = NULL;
+ GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
+
+ // the current document is a *.tex file?
+ gboolean tex_file = g_regex_match (regex, docs.active->path, 0, NULL);
+ if (! tex_file)
+ {
+ gchar *text = g_strdup_printf (_("view %s failed: %s is not a *.tex file"),
+ doc_type, g_path_get_basename (docs.active->path));
+
+ gtk_text_buffer_set_text (log_buffer, text, -1);
+ g_free (text);
+ g_regex_unref (regex);
+ return;
+ }
+
+ // replace .tex by .pdf
+ gchar *doc_path = g_regex_replace_literal (regex, docs.active->path,
+ -1, 0, doc_extension, 0, NULL);
+
+ // the document (PDF, DVI, ...) file exist?
+ if (! g_file_test (doc_path, G_FILE_TEST_IS_REGULAR))
+ {
+ gchar *text = g_strdup_printf (
+ _("%s does not exist. If this is not already made, compile the
document with the right command."),
+ g_path_get_basename (doc_path));
+
+ gtk_text_buffer_set_text (log_buffer, text, -1);
+ g_free (text);
+ g_free (doc_path);
+ g_regex_unref (regex);
+ return;
+ }
+
+ // run the command
+ gchar *command = g_strdup_printf ("evince %s", doc_path);
+ print_info ("execution of the command: %s", command);
+ g_spawn_command_line_async (command, &error);
+
+ if (error != NULL)
+ {
+ print_warning ("execution failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_regex_unref (regex);
+ g_free (doc_path);
+ g_free (command);
+ }
+}
+
diff --git a/src/callbacks.h b/src/callbacks.h
index e56ad63..4bb5025 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -9,7 +9,9 @@ void cb_close (void);
void cb_quit (void);
void cb_undo (void);
void cb_redo (void);
+void cb_latex (void);
void cb_pdflatex (void);
+void cb_view_dvi (void);
void cb_view_pdf (void);
void cb_about_dialog (void);
void cb_text_changed (GtkWidget *widget, gpointer user_data);
diff --git a/src/main.c b/src/main.c
index bbd8e6a..01b9e4d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -71,9 +71,9 @@ main (int argc, char *argv[])
{"LaTeX", NULL, "LaTeX", NULL, NULL, NULL},
{"compile_latex", GTK_STOCK_EXECUTE, _("Compile (latex)"), "<Release>F5",
- _("Produce the document in DVI format"), NULL},
+ _("Produce the document in DVI format"), G_CALLBACK (cb_latex)},
{"viewDVI", GTK_STOCK_FILE, _("View DVI"), "<Release>F6",
- _("View the DVI file"), NULL},
+ _("View the DVI file"), G_CALLBACK (cb_view_dvi)},
{"compile_pdflatex", GTK_STOCK_EXECUTE, _("Compile (pdflatex)"), "<Release>F7",
_("Produce the document in PDF format"), G_CALLBACK (cb_pdflatex)},
{"viewPDF", GTK_STOCK_FILE, _("View PDF"), "<Release>F8",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]