From dbf2d632693be0d2625235d10ccd531694c03fcd Mon Sep 17 00:00:00 2001 From: henrikjust Date: Thu, 23 Feb 2012 10:18:38 +0000 Subject: [PATCH] w2l: Detect and ignore empty formulas git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@131 f0f2a975-2e09-46c8-9428-3b39399b9f3c --- source/distro/changelog.txt | 4 +- .../writer2latex/latex/DrawConverter.java | 15 +++--- .../writer2latex/latex/MathmlConverter.java | 47 +++++++++++-------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index cdd5387..2851863 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,7 +2,9 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2 ---------- 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 (import from MS Word may create such errors) diff --git a/source/java/writer2latex/latex/DrawConverter.java b/source/java/writer2latex/latex/DrawConverter.java index 3e494df..97adddd 100644 --- a/source/java/writer2latex/latex/DrawConverter.java +++ b/source/java/writer2latex/latex/DrawConverter.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2010 by Henrik Just + * Copyright: 2002-2012 by Henrik Just * * 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) { formula = Misc.getChildByTagName(formuladoc,XMLString.MATH_MATH); } - ldp.append(" $") - .append(palette.getMathmlCv().convert(settings,formula)) - .append("$"); - if (Character.isLetterOrDigit(OfficeReader.getNextChar(node))) { ldp.append(" "); } + String sLaTeX = palette.getMathmlCv().convert(settings,formula); + if (!" ".equals(sLaTeX)) { // ignore empty formulas + ldp.append(" $") + .append(sLaTeX) + .append("$"); + if (Character.isLetterOrDigit(OfficeReader.getNextChar(node))) { ldp.append(" "); } + } } catch (org.xml.sax.SAXException e) { e.printStackTrace(); diff --git a/source/java/writer2latex/latex/MathmlConverter.java b/source/java/writer2latex/latex/MathmlConverter.java index 123d599..674da80 100644 --- a/source/java/writer2latex/latex/MathmlConverter.java +++ b/source/java/writer2latex/latex/MathmlConverter.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2010 by Henrik Just + * Copyright: 2002-2012 by Henrik Just * * 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 // XSL transformation could be used here. (Potential problem: // 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 @@ -163,22 +169,25 @@ public final class MathmlConverter extends ConverterHelper { } private void handleDisplayEquation(Element equation, Element sequence, LaTeXDocumentPortion ldp) { - if (sequence!=null) { - // Numbered equation - ldp.append("\\begin{equation}"); - palette.getFieldCv().handleSequenceLabel(sequence,ldp); - ldp.nl() - .append(convert(null,equation)).nl() - .append("\\end{equation}").nl(); - if (bAddParAfterDisplay) { ldp.nl(); } - } - else { - // Unnumbered equation - ldp.append("\\begin{equation*}").nl() - .append(convert(null,equation)).nl() - .append("\\end{equation*}").nl(); - if (bAddParAfterDisplay) { ldp.nl(); } - } + String sLaTeX = convert(null,equation); + if (!" ".equals(sLaTeX)) { // ignore empty formulas + if (sequence!=null) { + // Numbered equation + ldp.append("\\begin{equation}"); + palette.getFieldCv().handleSequenceLabel(sequence,ldp); + ldp.nl() + .append(sLaTeX).nl() + .append("\\end{equation}").nl(); + if (bAddParAfterDisplay) { ldp.nl(); } + } + else { + // Unnumbered equation + ldp.append("\\begin{equation*}").nl() + .append(sLaTeX).nl() + .append("\\end{equation*}").nl(); + if (bAddParAfterDisplay) { ldp.nl(); } + } + } } private boolean parseDisplayEquation(Node node) {