]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
better latex escape character substitution in xml-db2tex.pl
authorMichael Wiebusch <antiquark@gmx.net>
Fri, 11 Jul 2014 14:40:05 +0000 (16:40 +0200)
committerMichael Wiebusch <antiquark@gmx.net>
Fri, 11 Jul 2014 14:40:11 +0000 (16:40 +0200)
xml-db/xml-db2tex.pl

index 3be89fc41e85e57ebbc29b7c9fca0d23fcb3d2ac..990f684fd541c49744d6358b7424bc64efb9dde2 100755 (executable)
@@ -11,6 +11,7 @@ use FileHandle;
 use Getopt::Long;
 use File::Basename;
 use File::Copy;
+
 # use Cwd;
 
 my $opt;
@@ -137,11 +138,12 @@ sub setEntity {
   
   $self->{entity}=$entity;
   
-  if(-e $entity) { # treat as /path/to/File
-    $self->{entityFile} = $entity;
-  } elsif (-e dirname($0)."/cache/".$entity.".entity"){
+  if (-e dirname($0)."/cache/".$entity.".entity"){
+    # look in ./cache/ for "EntityName.entity"
     $self->{entityFile} = dirname($0)."/cache/".$entity.".entity";
-  } else {
+  } elsif(-e $entity) { # treat as /path/to/File
+    $self->{entityFile} = $entity;
+  } else { 
     die "Entity $entity not found (not even in xml-db/cache)\n";
   }
 }
@@ -154,6 +156,7 @@ sub produceTable {
   for my $name (@$list) { # processing the list
     my $node = $xmldb->{entity}->{$name};
     my $type = $node->{type};
+    my $description = $node->{description};
     my $repeat = $node->{repeat} || 1;
     my $stepsize = $node->{stepsize}||1;
     my $bits = " ";
@@ -166,6 +169,10 @@ sub produceTable {
        $bits = "$start--$stop";
       }
     }
+    # escape special latex characters
+    $name = escapelatex($name);
+    $description = escapelatex($description);
+    
     #indent register fields
     if ($type eq 'field'){
       $name= '\quad  '.$name;
@@ -192,7 +199,8 @@ sub produceTable {
         name => $name_,
         addr => $hexaddr,
         bits => $bits,
-        addr_uint => $addr_
+        addr_uint => $addr_,
+        description => $description
       });
     }
   }
@@ -253,6 +261,31 @@ sub produceTable {
 
 }
 
+
+sub escapelatex{
+  
+  my $text = shift;
+  $text =~ s/\\/\\textbackslash /g;
+  $text =~ s/~/\\textasciitilde /g;
+  
+  $text =~ s/#/\\#/g;
+  $text =~ s/%/\\%/g;
+  $text =~ s/&/\\&/g;
+  $text =~ s/{/\\{/g;
+  $text =~ s/}/\\}/g;
+#   $text =~ s/>/\\>/g;
+#   $text =~ s/</\\</g;
+#   $text =~ s/"/\\"/g;
+  $text =~ s/\^/\\^/g;
+  $text =~ s/_/\\_/g;
+#   $text =~ s/\[/\\\[/g;
+#   $text =~ s/\]/\\\]/g;
+  
+  return $text;
+  
+}
+
+
 sub writeTexFile {
   my $self = shift;
   my $output = shift;
@@ -464,7 +497,8 @@ sub generateString {
         push(@line,$data->{$dataKey});
       }
       my $line = "  ".join(" & ", @line) . ' \\\\'."\n";
-      $line =~ s/_/\\_/g; # remove all stupid underscores
+#       $line =~ s/_/\\_/g; # remove all stupid underscores
+#       $line = escapelatex($line);
       $str.=$line;
       
     }
@@ -479,4 +513,6 @@ sub generateString {
   
 #   $str.='\end{table}'."\n";
   return $str;
-}
\ No newline at end of file
+}
+
+