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



commit aaec4dfadfe235779c53e403fb4095af795355c4
Author: Josef Kufner <josef kufner cz>
Date:   Sun Feb 10 11:49:30 2019 +0000

    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]