summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-20 11:33:00 +0000
committerschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-20 11:33:00 +0000
commit3ca1607c4a5cf21dacefcf2b091d343ecb5a9bcd (patch)
treed8b025463006c8f5d0316f47f078749f14dd937a /lib
parentb010add0a372c685f2e1e87044a343abdcf64cc7 (diff)
Clean up the cleaning up for latex:
Introduce a new function "CleanFromC" that takes a C string in the C source code notation and removes the backslashes. Use this when group properties (e.g. tags tables) are transformed to latex. Clean up the regexps so that they become more readable. git-svn-id: http://svn.cactuscode.org/flesh/trunk@3852 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rwxr-xr-xlib/sbin/InterLatex.pl2
-rw-r--r--lib/sbin/ThornUtils.pm53
2 files changed, 42 insertions, 13 deletions
diff --git a/lib/sbin/InterLatex.pl b/lib/sbin/InterLatex.pl
index 9017f992..b27f4f0b 100755
--- a/lib/sbin/InterLatex.pl
+++ b/lib/sbin/InterLatex.pl
@@ -326,7 +326,7 @@ sub LatexTableElement
my $var_counter = 0;
foreach my $group_detail (sort keys %{$thorn{"group details"}->{$group}})
{
- my $value = ThornUtils::CleanForLatex($thorn{"group details"}->{$group}->{$group_detail});
+ my $value = ThornUtils::CleanForLatex(ThornUtils::CleanFromC($thorn{"group details"}->{$group}->{$group_detail}));
# print nothign as we are dealing with the same group
if (! $firstpass) {
diff --git a/lib/sbin/ThornUtils.pm b/lib/sbin/ThornUtils.pm
index d08b6b69..845010dd 100644
--- a/lib/sbin/ThornUtils.pm
+++ b/lib/sbin/ThornUtils.pm
@@ -338,6 +338,35 @@ sub EndDocument
}
#/*@@
+# @routine CleanFromC
+# @date Aug 20 2004
+# @author Erik Schnetter
+# @desc
+# "Interprets" a C string, i.e., takes something that would be valid
+# in C (or CST) source code inside double quotes, and return the
+# string that it represents, i.e., it mainly removes backslashes.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub CleanFromC
+{
+ my $val = shift;
+
+ # unescape special characters
+ $val =~ s,\\\",\",g;
+
+ # do not unescape backslash-letter sequences;
+ # we assume that people want to see them instead of their effects
+
+ return $val;
+}
+
+#/*@@
# @routine CleanForLatex
# @date Sun Mar 3 19:05:41 CET 2002
# @author Ian Kelley
@@ -359,34 +388,34 @@ sub CleanForLatex
my $val = shift;
# escape special characters
- $val =~ s/\\/\{\\textbackslash\}/g;
- $val =~ s/~/\{\\textasciitilde\}/g;
- $val =~ s/</\{\\textless\}/g;
- $val =~ s/>/\{\\textgreater\}/g;
+ $val =~ s,\\,\{\\textbackslash\},g;
+ $val =~ s,~,\{\\textasciitilde\},g;
+ $val =~ s,<,\{\\textless\},g;
+ $val =~ s,>,\{\\textgreater\},g;
# at start of string, remove spaces before and after: "
- $val =~ s/^\s*?\"\s*?/\"/;
+ $val =~ s,^\s*?\"\s*?,\",;
# at end of string, remove spaces before and after: "
- $val =~ s/\s*?\"\s*?$/\"/;
+ $val =~ s,\s*?\"\s*?$,\",;
# escape _
- $val =~ s/\_/\\\_/g;
+ $val =~ s,\_,\\\_,g;
# escape $
- $val =~ s/\$/\\\$/g;
+ $val =~ s,\$,\\\$,g;
# escape ^
- $val =~ s/\^/\\\^/g;
+ $val =~ s,\^,\\\^,g;
# escape *
- $val =~ s/\*/\\\*/g;
+ $val =~ s,\*,\\\*,g;
# escape &
- $val =~ s/\&/\\\&/g;
+ $val =~ s,\&,\\\&,g;
# escape %
- $val =~ s/%/\\%/g;
+ $val =~ s,%,\\%,g;
return $val;
}