From: Michael Wiebusch Date: Fri, 11 Jul 2014 14:40:05 +0000 (+0200) Subject: better latex escape character substitution in xml-db2tex.pl X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=00a0ab8e1e0604f334a6d0223e5b602c6c0ab80b;p=daqtools.git better latex escape character substitution in xml-db2tex.pl --- diff --git a/xml-db/xml-db2tex.pl b/xml-db/xml-db2tex.pl index 3be89fc..990f684 100755 --- a/xml-db/xml-db2tex.pl +++ b/xml-db/xml-db2tex.pl @@ -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/{$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 +} + +