From: Joey Schulze Date: Thu, 4 Oct 2012 20:39:47 +0000 (+0200) Subject: Improve LaTeX conversion X-Git-Url: https://git.infodrom.org/?p=misc%2Fhallinta-metro;a=commitdiff_plain;h=61287833c26f7cec4d447c35438ace6e42ea5b18 Improve LaTeX conversion --- diff --git a/utils.php b/utils.php index 694c1ee..f998ced 100644 --- a/utils.php +++ b/utils.php @@ -22,11 +22,26 @@ function rm_tempdir($dir) system(sprintf("rm -rf %s", $dir)); } +function latexspecialchars($string) +{ + $map = array( + "#"=>"\\#", + "$"=>"\\$", + "%"=>"\\%", + "&"=>"\\&", + "~"=>"\\~{}", + "_"=>"\\_", + "^"=>"\\^{}", + "\\"=>"\\textbackslash", + "{"=>"\\{", + "}"=>"\\}", + ); + return preg_replace("/([\^\%~\\\\#\$%&_\{\}])/e", "\$map['$1']", $string); +} + function latex_encode($text) { - return str_replace(array("\\",'%','&'), - array('\\','\%','\&'), - utf8_decode($text)); + return latexspecialchars(utf8_decode($text)); } function ordersatz_archive($id, $title, $filename)