--- doc/help/texxml2latex.pl 2004/09/14 21:18:44 1.10 +++ doc/help/texxml2latex.pl 2004/09/14 22:26:17 1.11 @@ -44,6 +44,25 @@ my $tmpdir = File::Temp::tempdir('loncap open (LATEX_FILE, $dirprefix . "Latex_Header.tex"); print ; +sub escape_latex { + my ($string)=@_; + $string=~s/\\/\\ensuremath{\\backslash}/g; + $string=~s/([^\\]|^)\%/$1\\\%/g; + $string=~s/([^\\]|^)\$/$1\\\$/g; + $string=~s/([^\\])\_/$1\\_/g; + $string=~s/\$\$/\$\\\$/g; + $string=~s/\_\_/\_\\\_/g; + $string=~s/\#\#/\#\\\#/g; + $string=~s/([^\\]|^)(\~|\^)/$1\\$2\\strut /g; + $string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less +# $string=&Apache::lonprintout::character_chart($string); + # any & or # leftover should be safe to just escape + $string=~s/([^\\]|^)\&/$1\\\&/g; + $string=~s/([^\\]|^)\#/$1\\\#/g; + $string=~s/\|/\$\\mid\$/g; + return $string; +} + while (my $token = $p->get_token()) { my $type = $token->[0]; @@ -52,27 +71,25 @@ while (my $token = $p->get_token()) my $attr = $token->[2]; if ($tag eq 'section') { my $title = $attr->{'name'}; - print "\\section{$title}\n\n"; + print "\\section{".&escape_latex($title)."}\n\n"; } if ($tag eq 'subsection') { my $title = $attr->{'name'}; - print "\\subsection{$title}\n\n"; + print "\\subsection{"&escape_latex($title)."}\n\n"; } if ($tag eq 'subsubsection') { my $title = $attr->{'name'}; - print "\\subsubsection{$title}\n\n"; + print "\\subsubsection{".&escape_latex($title)."}\n\n"; } if ($tag eq 'file') { my $file = $attr->{'name'}; open (LATEX_FILE, $dirprefix . $file) or ($! = 1, die "Can't find LaTeX file $dirprefix/$file; terminating build."); - my $esc_file=$file; - $esc_file=~s/_/\\_/g; if ($include_filenames) { - print "\\textrm{File: \\bf $esc_file}\\\\\n"; + print "\\textrm{File: \\bf ".&escape_latex($file)."}\\\\\n"; } print ; print "\n\n";