A few LaTeX bugfixes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@169 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2014-09-04 17:47:49 +00:00
parent 74d7599b11
commit a336023983
11 changed files with 99 additions and 42 deletions

View file

@ -14,5 +14,5 @@ Bugs and feature requests should be reported to
henrikjust (at) openoffice.org henrikjust (at) openoffice.org
August 2014 September 2014
Henrik Just Henrik Just

View file

@ -2,9 +2,15 @@ Changelog for Writer2LaTeX version 1.2 -> 1.4
---------- version 1.3.2 alpha ---------- ---------- version 1.3.2 alpha ----------
[w2l] Bugfix (StarMath conversion): Protect the character [ after \\ in gather and matrix environments
[w2l] Bugfix: Protect the character [ after \\ in tables
[w2l] Bugfix (StarMath conversion): Usage of \multiscripts and \mathoverstrike now loads the required calc.sty
[w2l] Bugfix (StarMath conversion): Do not create display equations in table cells [w2l] Bugfix (StarMath conversion): Do not create display equations in table cells
[w2l] Bugfix (StarMath conversion): Use array instead of matrix if there is more than 10 columns [w2l] Bugfix (StarMath conversion): Set the counter MaxMatrixCols if there are matrices with more than 10 columns
[w2l] Bugfix (StarMath conversion): Add braces if the argument to a command is a space, e.g. \text{ } [w2l] Bugfix (StarMath conversion): Add braces if the argument to a command is a space, e.g. \text{ }

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2012-08-28) * Version 1.4 (2014-09-03)
* *
*/ */
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information // Version information
private static final String VERSION = "1.3.2"; private static final String VERSION = "1.3.2";
private static final String DATE = "2014-08-28"; private static final String DATE = "2014-09-03";
/** Return the Writer2LaTeX version in the form /** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/> * (major version).(minor version).(patch level)<br/>

View file

@ -62,10 +62,10 @@ public class BinaryGraphicsDocument implements OutputFile {
* @param sFileExtension the file extension * @param sFileExtension the file extension
* @param sMimeType the MIME type of the document * @param sMimeType the MIME type of the document
*/ */
public BinaryGraphicsDocument(String name, String sFileExtension, String sMimeType) { public BinaryGraphicsDocument(String sName, String sFileExtension, String sMimeType) {
this.sFileExtension = sFileExtension; this.sFileExtension = sFileExtension;
this.sMimeType = sMimeType; this.sMimeType = sMimeType;
sFileName = Misc.trimDocumentName(name, sFileExtension); sFileName = Misc.trimDocumentName(sName, sFileExtension);
} }
/** Set image contents to a byte array /** Set image contents to a byte array

View file

@ -72,7 +72,7 @@ public final class ImageConverter {
/** Construct a new <code>ImageConverter</code> referring to a specific document /** Construct a new <code>ImageConverter</code> referring to a specific document
* *
* @param doc the office document used * @param ofr the office reader to use
* @param bExtractEPS set true if EPS content should be extracted from SVM files * @param bExtractEPS set true if EPS content should be extracted from SVM files
*/ */
public ImageConverter(OfficeReader ofr, boolean bDestructive, boolean bExtractEPS) { public ImageConverter(OfficeReader ofr, boolean bDestructive, boolean bExtractEPS) {

View file

@ -166,7 +166,7 @@ public class DrawConverter extends ConverterHelper {
} }
} }
else { // unsupported object else { // unsupported object
System.out.println("Unsupported "+sHref); //System.out.println("Unsupported "+sHref);
boolean bIgnore = true; boolean bIgnore = true;
if (ofr.isOpenDocument()) { // look for replacement image if (ofr.isOpenDocument()) { // look for replacement image
Element replacementImage = Misc.getChildByTagName(getFrame(node),XMLString.DRAW_IMAGE); Element replacementImage = Misc.getChildByTagName(getFrame(node),XMLString.DRAW_IMAGE);

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-2006 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.0 (2007-10-02) * Version 1.4 (2014-09-03)
* *
*/ */
@ -43,6 +43,10 @@ public class LaTeXDocumentPortion {
private boolean bWrap; // Do we allow line wrap in this portion? private boolean bWrap; // Do we allow line wrap in this portion?
/** Construct a new empty <code>LaTeXDocumentPortion</code>
*
* @param bWrap set to true if lines may be wrapped on writing
*/
public LaTeXDocumentPortion(boolean bWrap){ public LaTeXDocumentPortion(boolean bWrap){
this.bWrap = bWrap; this.bWrap = bWrap;
nodes = new Vector<Object>(); nodes = new Vector<Object>();
@ -50,7 +54,11 @@ public class LaTeXDocumentPortion {
bEmpty = true; bEmpty = true;
} }
/** Add another portion to the end of this portion */ /** Add another portion to the end of this portion
*
* @param ldp The <code>LaTeXDocuemtPortion</code> to add
* @return a reference to this <code>LaTeXDocumentPortion</code> (not the appended one)
*/
public LaTeXDocumentPortion append(LaTeXDocumentPortion ldp) { public LaTeXDocumentPortion append(LaTeXDocumentPortion ldp) {
if (!bEmpty) { if (!bEmpty) {
// add the current node to the node list and create new current node // add the current node to the node list and create new current node
@ -62,14 +70,21 @@ public class LaTeXDocumentPortion {
return this; return this;
} }
/** Add a string to the end of this portion */ /** Add a string to the end of this portion
*
* @param s the string to add
* @return a reference to this <code>LaTeXDocumentPortion</code>
*/
public LaTeXDocumentPortion append(String s){ public LaTeXDocumentPortion append(String s){
curText.append(s); curText.append(s);
bEmpty = false; // even if this is the empty string! bEmpty = false; // even if this is the empty string!
return this; return this;
} }
/** Add a newline to the end of this portion */ /** Add a newline to the end of this portion
*
* @return a reference to this <code>LaTeXDocumentPortion</code>
*/
public LaTeXDocumentPortion nl(){ public LaTeXDocumentPortion nl(){
curText.append("\n"); curText.append("\n");
bEmpty = false; bEmpty = false;
@ -164,7 +179,13 @@ public class LaTeXDocumentPortion {
} }
} }
/** Write this portion to the output (note: nLineLen=0 means no wrap) */ /** Write this portion to the output
*
* @param osw an <code>OutputStreamWriter</code> to write to
* @param nLineLen the line length after which automatic line breaks should occur if allowed (nLineLen=0 means no wrap)
* @param sNewline the newline character(s) to use
* @throws IOException if an exception occurs writing to to osw
*/
public void write(OutputStreamWriter osw, int nLineLen, String sNewline) throws IOException { public void write(OutputStreamWriter osw, int nLineLen, String sNewline) throws IOException {
int n = nodes.size(); int n = nodes.size();
for (int i=0; i<n; i++) { for (int i=0; i<n; i++) {
@ -188,7 +209,10 @@ public class LaTeXDocumentPortion {
} }
} }
/** Return the content of this LaTeXDocumentStream as a string */ /** Return the content of this LaTeXDocumentPortion as a string
*
* @return a string representation of the <code>LaTeXDocumentPortion</code>
*/
public String toString() { public String toString() {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
int n = nodes.size(); int n = nodes.size();
@ -197,7 +221,7 @@ public class LaTeXDocumentPortion {
buf.append(((LaTeXDocumentPortion) nodes.get(i)).toString()); buf.append(((LaTeXDocumentPortion) nodes.get(i)).toString());
} }
else { else {
buf.append(((StringBuffer) nodes.get(i)).toString()); buf.append((StringBuffer) nodes.get(i));
} }
} }
if (!bEmpty) { // write current node as well if (!bEmpty) { // write current node as well
@ -205,10 +229,4 @@ public class LaTeXDocumentPortion {
} }
return buf.toString(); return buf.toString();
} }
}
} // end class LaTeXDocumentPortion
// TO DO: consider StringBuffer->ByteArrayOutputStream (performance??)

View file

@ -772,6 +772,9 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
} }
public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) {
if (bMultiscripts || bMathoverstrike) {
pack.append("\\usepackage{calc}").nl();
}
if (config.useOoomath()) { if (config.useOoomath()) {
pack.append("\\usepackage{ooomath}").nl(); pack.append("\\usepackage{ooomath}").nl();
} }
@ -1054,7 +1057,12 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
bufTable.append("\\begin{gathered}").append(sLine); bufTable.append("\\begin{gathered}").append(sLine);
while (curToken.eType==Token.NEWLINE){ while (curToken.eType==Token.NEWLINE){
nextToken(); nextToken();
bufTable.append("\\\\").append(line(fSize,eAlign,false)); bufTable.append("\\\\");
sLine = line(fSize,eAlign,false);
if (sLine.length()>0 && sLine.charAt(0)=='[') { // Protect [ after \\
bufTable.append("{}");
}
bufTable.append(sLine);
} }
return bufTable.append("\\end{gathered}").toString(); return bufTable.append("\\end{gathered}").toString();
} }
@ -1599,11 +1607,17 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
nextToken(); nextToken();
if (curToken.eType==Token.LGROUP){ if (curToken.eType==Token.LGROUP){
StringBuffer bufStack=new StringBuffer().append("\\begin{matrix}"); StringBuffer bufStack=new StringBuffer().append("\\begin{matrix}");
do { nextToken();
bufStack.append(align(fSize,eAlign,true,true));
while (curToken.eType==Token.POUND) {
bufStack.append("\\\\");
nextToken(); nextToken();
bufStack.append(align(fSize,eAlign,true,true)); String sAlign = align(fSize,eAlign,true,true);
if (curToken.eType==Token.POUND) bufStack.append("\\\\"); if (sAlign.length()>0 && sAlign.charAt(0)=='[') { // Protect [ after \\
} while (curToken.eType==Token.POUND); bufStack.append("{}");
}
bufStack.append(sAlign);
}
if (curToken.eType==Token.RGROUP) nextToken(); // otherwise error in formula - ignore if (curToken.eType==Token.RGROUP) nextToken(); // otherwise error in formula - ignore
return bufStack.append("\\end{matrix}").toString(); return bufStack.append("\\end{matrix}").toString();
} }
@ -1617,17 +1631,24 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
if (curToken.eType==Token.LGROUP){ if (curToken.eType==Token.LGROUP){
StringBuffer bufMatrix = new StringBuffer().append("\\begin{matrix}"); StringBuffer bufMatrix = new StringBuffer().append("\\begin{matrix}");
int nCols = 1; int nCols = 1;
boolean bProtect = false;
do { do {
nextToken(); nextToken();
bufMatrix.append(align(fSize,eAlign,true,true)); String sAlign = align(fSize,eAlign,true,true);
if (bProtect && sAlign.length()>0 && sAlign.charAt(0)=='[') { // Protect [ after \\
bufMatrix.append("{}");
}
bufMatrix.append(sAlign);
if (curToken.eType==Token.POUND) { if (curToken.eType==Token.POUND) {
bufMatrix.append("&"); bufMatrix.append("&");
nCols++; nCols++;
bProtect = false;
} }
else if (curToken.eType==Token.DPOUND) { else if (curToken.eType==Token.DPOUND) {
bufMatrix.append("\\\\"); bufMatrix.append("\\\\");
nMaxMatrixCols = Math.max(nCols, nMaxMatrixCols); nMaxMatrixCols = Math.max(nCols, nMaxMatrixCols);
nCols = 1; nCols = 1;
bProtect = true;
} }
} while (curToken.eType==Token.POUND || curToken.eType==Token.DPOUND); } while (curToken.eType==Token.POUND || curToken.eType==Token.DPOUND);
if (curToken.eType==Token.RGROUP) nextToken(); // otherwise error in formula- ignore if (curToken.eType==Token.RGROUP) nextToken(); // otherwise error in formula- ignore

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-2011 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2011-04-20) * Version 1.4 (2014-09-03)
* *
*/ */
@ -414,12 +414,15 @@ public class TableConverter extends ConverterHelper {
int nRowCount = table.getRowCount(); int nRowCount = table.getRowCount();
int nColCount = table.getColCount(); int nColCount = table.getColCount();
boolean bFirst = true; boolean bFirst = true;
boolean bProtect = false; // Do we need to protect '['?
int nPreviousRow = -1; int nPreviousRow = -1;
for (int nRow=0; nRow<nRowCount; nRow++) { for (int nRow=0; nRow<nRowCount; nRow++) {
if (rowTypes[nRow]==rowType) { if (rowTypes[nRow]==rowType) {
// Add interrow material from previous row, if any // Add interrow material from previous row, if any
if (nPreviousRow>-1) { if (nPreviousRow>-1) {
ldp.append(formatter.getInterrowMaterial(nPreviousRow+1)).nl(); String sInterRowMaterial = formatter.getInterrowMaterial(nPreviousRow+1);
ldp.append(sInterRowMaterial).nl();
if (sInterRowMaterial.length()>0) { bProtect=false; }
} }
nPreviousRow = nRow; nPreviousRow = nRow;
@ -430,12 +433,13 @@ public class TableConverter extends ConverterHelper {
bFirst=false; bFirst=false;
} }
// Export columns in this row // Export columns in this row
LaTeXDocumentPortion rowLdp = new LaTeXDocumentPortion(true);
Context icRow = (Context) oc.clone(); Context icRow = (Context) oc.clone();
BeforeAfter baRow = new BeforeAfter(); BeforeAfter baRow = new BeforeAfter();
formatter.applyRowStyle(nRow,baRow,icRow); formatter.applyRowStyle(nRow,baRow,icRow);
if (!baRow.isEmpty()) { if (!baRow.isEmpty()) {
ldp.append(baRow.getBefore()); rowLdp.append(baRow.getBefore());
if (!formatter.isSimple()) { ldp.nl(); } if (!formatter.isSimple()) { rowLdp.nl(); }
} }
int nCol = 0; int nCol = 0;
while (nCol<nColCount) { while (nCol<nColCount) {
@ -445,18 +449,18 @@ public class TableConverter extends ConverterHelper {
Context icCell = (Context) icRow.clone(); Context icCell = (Context) icRow.clone();
BeforeAfter baCell = new BeforeAfter(); BeforeAfter baCell = new BeforeAfter();
formatter.applyCellStyle(nRow,nCol,baCell,icCell); formatter.applyCellStyle(nRow,nCol,baCell,icCell);
ldp.append(baCell.getBefore()); rowLdp.append(baCell.getBefore());
if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); } if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); }
palette.getBlockCv().traverseBlockText(cell,ldp,icCell); palette.getBlockCv().traverseBlockText(cell,rowLdp,icCell);
ldp.append(baCell.getAfter()); rowLdp.append(baCell.getAfter());
} }
// Otherwise ignore; the cell is covered by a \multicolumn entry. // Otherwise ignore; the cell is covered by a \multicolumn entry.
// (table:covered-table-cell) // (table:covered-table-cell)
int nColSpan = Misc.getPosInteger(cell.getAttribute( int nColSpan = Misc.getPosInteger(cell.getAttribute(
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1); XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
if (nCol+nColSpan<nColCount) { if (nCol+nColSpan<nColCount) {
if (formatter.isSimple()) { ldp.append(" & "); } if (formatter.isSimple()) { rowLdp.append(" & "); }
else { ldp.append(" &").nl(); } else { rowLdp.append(" &").nl(); }
} }
nCol+=nColSpan; nCol+=nColSpan;
} }
@ -464,7 +468,15 @@ public class TableConverter extends ConverterHelper {
nCol++; nCol++;
} }
} }
ldp.append("\\\\"); rowLdp.append("\\\\");
// We have to translate the row to a string to avoid extra newlines and to see the first characters
String sRowLdp = rowLdp.toString();
// Protect leading [
if (bProtect && ((sRowLdp.length()>0 && sRowLdp.charAt(0)=='[') || sRowLdp.startsWith("\n["))) {
ldp.append("{}");
}
ldp.append(sRowLdp);
bProtect = true;
} }
} }
// Add interrow material from last row, if required // Add interrow material from last row, if required

View file

@ -78,7 +78,7 @@ public class SimpleXMLParser extends DefaultHandler {
// We don't need - and in fact should avoid - any external entities // We don't need - and in fact should avoid - any external entities
@Override public InputSource resolveEntity(String publicID, String systemID) throws SAXException { @Override public InputSource resolveEntity(String publicID, String systemID) throws SAXException {
System.out.println("resolveEntity "+publicID+" "+systemID); //System.out.println("resolveEntity "+publicID+" "+systemID);
return new InputSource(new StringReader("")); return new InputSource(new StringReader(""));
} }

View file

@ -95,7 +95,7 @@ In addition to oxt, the build file supports the following targets:
clean clean
Henrik Just, August 2014 Henrik Just, September 2014
Thanks to Michael Niedermair for writing the original ant build file Thanks to Michael Niedermair for writing the original ant build file