I managed to include latexrender (http://www.mayer.dial.pipex.com/tex.htm) into my new Zend Framework based project and everything seems to be working fine except the ajax-based preview strips “+” sign from my formulas for some reason.
Here’s my html fragment with example textarea:
<dt id="formula-label"><label for="formula" class="required">Formula:</label></dt>
<dd id="formula-element">
<textarea name="formula" id="formula" rows="5" cols="40"></textarea>
<p class="description"><span class="preview-formula"></span></p></dd>
<button name="previewtformula" id="previewformula" type="button" onclick="generatePreview('formula')">Preview</button>
Here’s the corresponding Zend form code:
$formula = $this->createElement('textarea', 'formula');
$formula->setLabel('Formula:');
$formula->setRequired(true);
$formula->setAttrib('rows', 5);
$formula->setAttrib('cols', 40);
$formula->setDescription('<span class="preview-formula"></span>');
$formula->getDecorator('Description')->setEscape(false);
$this->addElement($formula);
$prevFormula = $this->createElement('button', 'preview-formula');
$prevFormula->setAttrib('onclick', "generatePreview('formula')");
$prevFormula->setLabel('Preview');
$prevFormula->removeDecorator('DtDdWrapper');
$this->addElement($prevFormula);
javascript file:
function generatePreview(elem){
var details = $('textarea#'+elem).val();
$.ajax({
type: 'POST',
url: '/formula/preview',
async: false,
data: 'details=' + details,
success: function(responseText) {
$("span.preview-"+elem).html(responseText);
}
});
};
and my controller action:
public function previewAction() {
if($this->_request->isXmlHttpRequest()) {
$this->_helper->viewRenderer->setNoRender();
$this->_helper->Layout->disableLayout();
$data = $this->_request->getPost();
$latex = new My_LatexRender();
echo nl2br($latex->latex_content($data['details']));
} else {
return $this->_redirect('/index');
}
}
like I said everything is working fine, the images are saving to the disk nicely and formulas added to the database are intact (there are “+” signs) but when i preview the formulas it somehow got strip from all “+” signs so for example
“2+2” saves in database as “2+2” but in preview it’s just “22”
not sure if there are other characters stripped, haven’t noticed any so far
i found solution. i had to change
to