patch for inserting raw latex command to gnumeric for exporting latex files



Hi, all
Is there anybody can remember that I had asked how to insert raw latex command in gnumeric for exporting latex?
http://mail.gnome.org/archives/gnumeric-list/2004-June/msg00023.html
Some people on this list told me that no way. Now I implement it myself and the patch is attached(latex.patch).
Let me give some explanations:
1. I tested on gnumeirc-1.2.13, it worked fine. If you don't want to compile it from source, you may try the pre-compiled file. Extract the attachment to overrite your original html plugins, backup your files first! 2. To insert raw latex command, please put them between '\L{' and '}'. The '{'s and '}'s must be matched, that is to say you can't put a unmatched brackets in it, I think there is no need to to so in latex. What's in gnumeric What's in latex foo \L{E=m\cdot{}c^2} foo foo E=m\cdot{}c^2 foo
foo \L{{aa}{bb}{a{b}c}} foo               foo {aa}{bb}{a{b}c} foo
foo \L{a}\L{b} foo                              foo ab foo

I think this patch would be very convinient for those who take gnumeric as their latex table-maker, just as me. :-)

Any reply please cc to me, for I don't subscribe the mailing list.

--
Best regards
Shixin Zeng

--- gnumeric-1.2.13/plugins/html/latex.c        2004-05-13 02:41:22.000000000 +0800
+++ gnumeric-1.2.13.new/plugins/html/latex.c    2004-11-20 16:32:14.434540992 +0800
@@ -133,6 +133,89 @@
 };
 
 /**
+ * latex_raw_utf :
+ * @p :            a pointer to a char, start of the string to be processed
+ * @output : output stream where the processed characters are written.
+ * 
+ * This determinate the mode of the string.
+ * If @p is in form of \L{foo}, the exact "foo" will be put into @output, without any esacaping.
+ * return the char pointer next to '}' of \L{foo}
+ * else return @p untouched; 
+ */
+static const char*
+latex_raw_utf(const char *p, GsfOutput *output)
+{
+    const char *p_begin, *p_end, *p_orig;
+    p_orig = p;
+    if(g_utf8_get_char(p) == '\\'){
+       p = g_utf8_next_char(p);
+       if(g_utf8_get_char(p) == 'L'){
+           p = g_utf8_next_char(p);
+           if(g_utf8_get_char(p) == '{'){
+               p_begin = g_utf8_next_char(p);
+               /* to find the matching close bracket */
+               int depth = 1;
+               for(; *p; p = g_utf8_next_char(p)){
+                   if(g_utf8_get_char(p) == '{')
+                       depth++;
+                   else if(g_utf8_get_char(p) == '}'){
+                       depth--;
+                       if(depth == 0){
+                           p_end = p;
+                           /* put the string beginning from p_begin to p_end to output */
+                           gsf_output_write(output, p_end - p_begin, p_begin);
+                           return p;
+                       }
+                   }
+               }
+           }
+       }
+    }
+    return p_orig;
+}
+       
+/**
+ * latex_raw_latin :
+ * @p :            a pointer to a char, start of the string to be processed
+ * @output : output stream where the processed characters are written.
+ * 
+ * This determinate the mode of the string.
+ * If @p is in form of \L{foo}, the exact "foo" will be put into @output, without any esacaping.
+ * return the char pointer next to '}' of \L{foo}
+ * else return @p untouched; 
+ */
+static const char*
+latex_raw_latin(const char *p, GsfOutput *output)
+{
+   const char *p_begin, *p_end, *p_orig;
+    
+    p_orig = p;
+    if(*p++ == '\\'){
+       if(*p++ == 'L'){
+           if(*p++ == '{'){
+               p_begin = p;
+               /* to find the matching close bracket */
+               int depth = 1;
+               for(; *p; p++){
+                   if(*p == '{')
+                       depth++;
+                   else if(*p == '}'){
+                       depth--;
+                       if(depth == 0){
+                           p_end = p;
+                           /* put the string beginning from p_begin to p_end to output */
+                           gsf_output_write(output, p_end - p_begin, p_begin);
+                           return p;
+                       }
+                   }
+               }
+           }
+       }
+    }
+    return p_orig;
+}
+    
+/**
  * latex_fputs_utf :
  *
  * @p :      a pointer to a char, start of the string to be processed.
@@ -144,9 +227,10 @@
 static void
 latex_fputs_utf (char const *p, GsfOutput *output)
 {
+    const char *rlt;
        for (; *p; p = g_utf8_next_char (p)) {
                switch (g_utf8_get_char (p)) {
-                       
+
                        /* These are the classic TeX symbols $ & % # _ { } (see Lamport, p.15) */
                case '$': case '&': case '%': case '#':
                case '_': case '{': case '}':
@@ -157,7 +241,11 @@
                        gsf_output_printf (output, "\\%c{ }", *p);
                        break;
                case '\\':
-                       gsf_output_puts (output, "$\\backslash$");
+                       rlt = latex_raw_utf(p, output);
+                       if(rlt == p)
+                           gsf_output_puts (output, "$\\backslash$");
+                       else
+                           p = rlt;
                        break;
                        /* Are these available only in LaTeX through mathmode? */
                case '>': case '<':
@@ -185,6 +273,7 @@
 static void
 latex_math_fputs_utf (char const *p, GsfOutput *output)
 {
+    const char *rlt;
        for (; *p; p = g_utf8_next_char (p)) {
                switch (g_utf8_get_char (p)) {
 
@@ -197,9 +286,12 @@
                                gsf_output_printf (output, "\\%c{ }", *p);
                                break;
                        case '\\':
-                               gsf_output_puts (output, "\\backslash");
+                               rlt = latex_raw_utf(p, output);
+                               if(rlt == p)
+                                   gsf_output_puts (output, "$\\backslash$");
+                               else
+                                   p = rlt;
                                break;
-
                        default:
                                gsf_output_write (output, 
                                                  (g_utf8_next_char (p)) - p, p);
@@ -222,6 +314,7 @@
 {
        char * encoded_text = NULL;
        char * p;
+    const char * rlt;
        gsize bytes_read;
        gsize bytes_written;
        GError * error = NULL;
@@ -249,7 +342,11 @@
                        gsf_output_printf (output, "\\%c{ }", *p);
                        break;
                case '\\':
-                       gsf_output_puts (output, "$\\backslash$");
+                       rlt = latex_raw_latin(p, output);
+                       if(rlt == p)
+                           gsf_output_puts (output, "$\\backslash$");
+                       else
+                           p = rlt;
                        break;
                        /* Are these available only in LaTeX through mathmode? */
                case '>': case '<': case 'ยต':
@@ -279,6 +376,7 @@
 {
        char * encoded_text = NULL;
        char * p;
+    const char * rlt;
        gsize bytes_read;
        gsize bytes_written;
        GError * error = NULL;
@@ -305,7 +403,11 @@
                                gsf_output_printf (output, "\\%c{ }", *p);
                                break;
                        case '\\':
-                               gsf_output_puts (output, "\\backslash");
+                               rlt = latex_raw_latin(p, output);
+                               if(rlt == p)
+                                   gsf_output_puts (output, "$\\backslash$");
+                               else
+                                   p = rlt;
                                break;
 
                        default:

Attachment: html.tgz
Description: GNU Unix tar archive



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]