[dia/fix-tex] Do not escape TeX macros if string is marked properly -- "$...$" or "{...}"



commit 8eeb3bbab904ae6f4cb14794a152425438f8419c
Author: Josef Kufner <josef kufner cz>
Date:   Fri Feb 17 14:53:34 2017 +0100

    Do not escape TeX macros if string is marked properly -- "$...$" or "{...}"

 plug-ins/pgf/render_pgf.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/pgf/render_pgf.c b/plug-ins/pgf/render_pgf.c
index 1617d716..3b95cb05 100644
--- a/plug-ins/pgf/render_pgf.c
+++ b/plug-ins/pgf/render_pgf.c
@@ -1089,7 +1089,8 @@ draw_bezier_with_arrows(DiaRenderer *self, BezPoint *points, int num_points,
 static gchar *
 tex_escape_string(const gchar *src, DiaContext *ctx)
 {
-    GString *dest = g_string_sized_new(g_utf8_strlen(src, -1));
+    int len = g_utf8_strlen(src, -1);
+    GString *dest = g_string_sized_new(len);
     gchar *p;
 
     if (!g_utf8_validate(src, -1, NULL)) {
@@ -1097,6 +1098,15 @@ tex_escape_string(const gchar *src, DiaContext *ctx)
        return g_strdup(src);
     }
 
+    /* Do not escape TeX macros if string is marked properly -- "$...$" or "{...}" */
+    if (len > 2) {
+        char b = src[0];
+        char e = src[len - 1];
+        if ((b == '$' && e == '$') || (b == '{' && e == '}')) {
+            return g_strdup(src);
+        }
+    }
+
     p = (char *) src;
     while (*p != '\0') {
        switch (*p) {


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