w2l: Detect and ignore empty formulas

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@131 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2012-02-23 10:18:38 +00:00
parent 9e536ee10c
commit dbf2d63269
3 changed files with 40 additions and 26 deletions

View file

@ -2,7 +2,9 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2
---------- version 1.1.9 ---------- ---------- version 1.1.9 ----------
[w2l] The StarMath now avoids more redundant braces [w2l] Properly detect and ignore empty formulas (avoiding any occurrences of $ $ in the document)
[w2l] The StarMath converter now avoids redundant braces
[w2l] The StarMath converter is now a little more tolerant on errors like missing operands for a binary operator [w2l] The StarMath converter is now a little more tolerant on errors like missing operands for a binary operator
(import from MS Word may create such errors) (import from MS Word may create such errors)

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2010 by Henrik Just * Copyright: 2002-2012 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2010-10-09) * Version 1.2 (2012-02-23)
* *
*/ */
@ -157,10 +157,13 @@ public class DrawConverter extends ConverterHelper {
if (formula==null) { if (formula==null) {
formula = Misc.getChildByTagName(formuladoc,XMLString.MATH_MATH); formula = Misc.getChildByTagName(formuladoc,XMLString.MATH_MATH);
} }
ldp.append(" $") String sLaTeX = palette.getMathmlCv().convert(settings,formula);
.append(palette.getMathmlCv().convert(settings,formula)) if (!" ".equals(sLaTeX)) { // ignore empty formulas
.append("$"); ldp.append(" $")
if (Character.isLetterOrDigit(OfficeReader.getNextChar(node))) { ldp.append(" "); } .append(sLaTeX)
.append("$");
if (Character.isLetterOrDigit(OfficeReader.getNextChar(node))) { ldp.append(" "); }
}
} }
catch (org.xml.sax.SAXException e) { catch (org.xml.sax.SAXException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2010 by Henrik Just * Copyright: 2002-2012 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2010-04-29) * Version 1.2 (2012-02-23)
* *
*/ */
@ -103,7 +103,13 @@ public final class MathmlConverter extends ConverterHelper {
// TODO: Investigate if Vasil I. Yaroshevich's MathML->LaTeX // TODO: Investigate if Vasil I. Yaroshevich's MathML->LaTeX
// XSL transformation could be used here. (Potential problem: // XSL transformation could be used here. (Potential problem:
// OOo uses MathML 1.01, not MathML 2) // OOo uses MathML 1.01, not MathML 2)
return "\\text{Warning: No StarMath annotation}"; if (formula.hasChildNodes()) {
return "\\text{Warning: No StarMath annotation}";
}
else { // empty formula
return " ";
}
} }
// Data for display equations // Data for display equations
@ -163,22 +169,25 @@ public final class MathmlConverter extends ConverterHelper {
} }
private void handleDisplayEquation(Element equation, Element sequence, LaTeXDocumentPortion ldp) { private void handleDisplayEquation(Element equation, Element sequence, LaTeXDocumentPortion ldp) {
if (sequence!=null) { String sLaTeX = convert(null,equation);
// Numbered equation if (!" ".equals(sLaTeX)) { // ignore empty formulas
ldp.append("\\begin{equation}"); if (sequence!=null) {
palette.getFieldCv().handleSequenceLabel(sequence,ldp); // Numbered equation
ldp.nl() ldp.append("\\begin{equation}");
.append(convert(null,equation)).nl() palette.getFieldCv().handleSequenceLabel(sequence,ldp);
.append("\\end{equation}").nl(); ldp.nl()
if (bAddParAfterDisplay) { ldp.nl(); } .append(sLaTeX).nl()
} .append("\\end{equation}").nl();
else { if (bAddParAfterDisplay) { ldp.nl(); }
// Unnumbered equation }
ldp.append("\\begin{equation*}").nl() else {
.append(convert(null,equation)).nl() // Unnumbered equation
.append("\\end{equation*}").nl(); ldp.append("\\begin{equation*}").nl()
if (bAddParAfterDisplay) { ldp.nl(); } .append(sLaTeX).nl()
} .append("\\end{equation*}").nl();
if (bAddParAfterDisplay) { ldp.nl(); }
}
}
} }
private boolean parseDisplayEquation(Node node) { private boolean parseDisplayEquation(Node node) {