function stringToLatex($html) { if (empty($html)) { return $html; } $latex_output = ''; $convertor = new oqc_HtmlToLatexConverter(); $latex_output = $convertor->html2latex_formattext($html); // just replaces symbols with LaTex commands return $latex_output; }
function textBlocksToLatex($contract, $pdfData, $template) { //processing path html->smarty->latex->assemble into single file using skeleton/smarty $textBlocks = $contract->get_all_linked_textblocks(); $textBlocksHtml = array_map('getTextBlockHtml', $textBlocks); //$GLOBALS['log']->error('textBlocksToLatex: data transferred to pdf: '. var_export($textBlocksHtml,true)); if (!$textBlocksHtml) { return null; } $filenames = array(); foreach ($textBlocksHtml as $textBlockHtml) { //convert html files to latex $latex_output = ''; $smarty_output = ''; $smarty_output = oqc_replaceVariables($textBlockHtml, $pdfData); $convertor = new oqc_HtmlToLatexConverter(); $latex_output = $convertor->html2latex('<html><head></head><body>' . $smarty_output . '</body></html>'); // need to add head section for correct utf-8 handling $filename = tempnam(TMP_DIR, TEXTBLOCK_TMP_PREFIX); $filenames[] = $filename; file_put_contents($filename, $latex_output); } $variables = array('filenames' => $filenames); $filename = templateToLatex($template['TEXTBLOCKS_TEMPLATE'], $variables); if (!file_exists($filename)) { $GLOBALS['log']->error('OQC textBloksToLatex: Failed to convert HTML to Latex!'); return null; } else { $filenameWithExtension = $filename . '.tex'; rename($filename, $filenameWithExtension); $GLOBALS['log']->error('OQC textBloksToLatex: Converted texbloks filename is ' . $filenameWithExtension); // replace sequences of double newlines "\n\n" with "\newline \n" in latex file //$latexFileContents = file_get_contents($latexFilename); //$latexFileContents = preg_replace("/(.+)\\\\newline\n\n/", "$1 \\\\newline\n", $latexFileContents); //$latexFileContents = preg_replace("/(.+)\n\n/", "$1 \\\\newline\n", $latexFileContents); foreach ($filenames as $filename) { unlink($filename); } return $filenameWithExtension; // TODO unlink all temporal files } }