mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
Framework for math export exceptions. We can throw these if we find
something we don't know how to handle and fall back to images. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35024 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1c0d73425e
commit
7a8a1eca21
@ -1854,37 +1854,49 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
|
|||||||
|
|
||||||
docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
||||||
{
|
{
|
||||||
BufferParams::MathOutput mathtype = buffer().params().html_math_output;
|
BufferParams::MathOutput const mathtype =
|
||||||
|
buffer().params().html_math_output;
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
// FIXME Eventually we would like to do this inset by inset.
|
// FIXME Eventually we would like to do this inset by inset.
|
||||||
switch (mathtype) {
|
if (mathtype == BufferParams::MathML) {
|
||||||
case BufferParams::MathML: {
|
|
||||||
odocstringstream os;
|
odocstringstream os;
|
||||||
MathStream ms(os);
|
MathStream ms(os);
|
||||||
InsetMathGrid::mathmlize(ms);
|
try {
|
||||||
if (getType() == hullSimple)
|
InsetMathGrid::mathmlize(ms);
|
||||||
xs << html::StartTag("math",
|
success = true;
|
||||||
"xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
} catch (MathExportException const &) {}
|
||||||
else
|
if (success) {
|
||||||
xs << html::StartTag("math",
|
if (getType() == hullSimple)
|
||||||
"display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
xs << html::StartTag("math",
|
||||||
xs << XHTMLStream::NextRaw()
|
"xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
||||||
<< os.str()
|
else
|
||||||
<< html::EndTag("math");
|
xs << html::StartTag("math",
|
||||||
break;
|
"display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
||||||
}
|
xs << XHTMLStream::NextRaw()
|
||||||
case BufferParams::HTML: {
|
<< os.str()
|
||||||
|
<< html::EndTag("math");
|
||||||
|
}
|
||||||
|
} else if (mathtype == BufferParams::HTML) {
|
||||||
odocstringstream os;
|
odocstringstream os;
|
||||||
HtmlStream ms(os);
|
HtmlStream ms(os);
|
||||||
InsetMathGrid::htmlize(ms);
|
try {
|
||||||
string const tag = (getType() == hullSimple) ? "span" : "div";
|
InsetMathGrid::htmlize(ms);
|
||||||
xs << html::StartTag(tag, "class='formula'", true)
|
success = true;
|
||||||
<< XHTMLStream::NextRaw()
|
} catch (MathExportException const &) {}
|
||||||
<< os.str()
|
if (success) {
|
||||||
<< html::EndTag(tag);
|
string const tag = (getType() == hullSimple) ? "span" : "div";
|
||||||
break;
|
xs << html::StartTag(tag, "class='formula'", true)
|
||||||
}
|
<< XHTMLStream::NextRaw()
|
||||||
case BufferParams::Images: {
|
<< os.str()
|
||||||
|
<< html::EndTag(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the logic here is ugly, but it's meant to mean: if we've failed with
|
||||||
|
// one of the earlier attempts OR the mathtype IS Image, then try to
|
||||||
|
// export an image.
|
||||||
|
if (!success && mathtype != BufferParams::LaTeX) {
|
||||||
loadPreview(docit_);
|
loadPreview(docit_);
|
||||||
graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer());
|
graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer());
|
||||||
if (pimage) {
|
if (pimage) {
|
||||||
@ -1897,11 +1909,14 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
|||||||
xs.cr();
|
xs.cr();
|
||||||
// add the file to the list of files to be exported
|
// add the file to the list of files to be exported
|
||||||
op.exportdata->addExternalFile("xhtml", mathimg);
|
op.exportdata->addExternalFile("xhtml", mathimg);
|
||||||
break;
|
success = true;
|
||||||
}
|
}
|
||||||
LYXERR0("Unable to generate image. Falling through to LaTeX output.");
|
}
|
||||||
}
|
|
||||||
case BufferParams::LaTeX: {
|
// so we'll pass this test if we've failed everything else, or
|
||||||
|
// if mathtype was LaTeX, since we won't have entered any of the
|
||||||
|
// earlier branches
|
||||||
|
if (!success) {
|
||||||
string const tag = (getType() == hullSimple) ? "span" : "div";
|
string const tag = (getType() == hullSimple) ? "span" : "div";
|
||||||
// Unfortunately, we cannot use latexString() because we do not want
|
// Unfortunately, we cannot use latexString() because we do not want
|
||||||
// $...$ or whatever.
|
// $...$ or whatever.
|
||||||
@ -1920,7 +1935,6 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
|
|||||||
<< html::EndTag(tag);
|
<< html::EndTag(tag);
|
||||||
xs.cr();
|
xs.cr();
|
||||||
}
|
}
|
||||||
} // end switch
|
|
||||||
return docstring();
|
return docstring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +262,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Throw MathExportException to signal that the attempt to export
|
||||||
|
/// some math in the current format did not succeed. E.g., we can't
|
||||||
|
/// export xymatrix as MathML, so that will throw, and we'll fall back
|
||||||
|
/// to images.
|
||||||
|
class MathExportException : public std::exception {};
|
||||||
|
|
||||||
|
|
||||||
class MathStream {
|
class MathStream {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user