--- doc/help/texxml2latex.pl 2003/09/02 18:29:58 1.9 +++ doc/help/texxml2latex.pl 2004/09/14 22:26:17 1.11 @@ -36,6 +36,7 @@ use File::Temp; my $p = HTML::TokeParser->new( $ARGV[0] ); my $dirprefix = "../../loncom/html/adm/help/tex/"; +my $include_filenames = ($ARGV[1] eq '--with-filenames'); # Make myself a temp dir for processing POD my $tmpdir = File::Temp::tempdir('loncapahelpgenXXXXXXX', TMPDIR => 1); @@ -43,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]; @@ -51,23 +71,26 @@ 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."); + if ($include_filenames) { + print "\\textrm{File: \\bf ".&escape_latex($file)."}\\\\\n"; + } print ; print "\n\n"; }