function _escape_tex($tex)
    {
        $tex = str_replace("\\", "\\\\", $tex);
        $tex = str_replace('#', '\#', $tex);
        $tex = str_replace('$', '\$', $tex);
        $tex = str_replace('%', '\%', $tex);
        $tex = str_replace('^', '\^', $tex);
        $tex = str_replace('&', '\&', $tex);
        $tex = str_replace('_', '\_', $tex);
        $tex = str_replace('{', '\{', $tex);
        $tex = str_replace('}', '\}', $tex);
        return ($tex);
    }