From 729e088fa259291c0ff66123747337ec706f940f Mon Sep 17 00:00:00 2001 From: henrikjust Date: Mon, 22 Jun 2015 10:59:48 +0000 Subject: [PATCH] w2l use thebibliography environment if not using BibTeX git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@257 f0f2a975-2e09-46c8-9428-3b39399b9f3c --- source/distro/changelog.txt | 4 + .../base/BibliographyGenerator.java | 70 +++-- .../writer2latex/bibtex/BibTeXDocument.java | 120 +++----- .../java/writer2latex/bibtex/Converter.java | 57 ++-- .../java/writer2latex/latex/BibConverter.java | 276 +++++++++++------- .../writer2latex/latex/ConverterHelper.java | 14 +- .../writer2latex/latex/ConverterPalette.java | 1 - .../writer2latex/latex/FieldConverter.java | 10 +- .../writer2latex/latex/{util => }/Info.java | 19 +- .../xhtml/XhtmlBibliographyGenerator.java | 4 +- 10 files changed, 318 insertions(+), 257 deletions(-) rename source/java/writer2latex/latex/{util => }/Info.java (78%) diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index 51cd0e9..94ad696 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,6 +2,10 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6 ---------- version 1.5.3 ---------- +[w2l] If use_bibtex is false, the bibliography is now exported using a thebibliography environment rather than as + plain text + TODO: Debugging and test + [w2x] The bibliography is now regenerated from the template. This implies that bibliographic citations now link directly to the cited work rather than to the bibliography as a whole. diff --git a/source/java/writer2latex/base/BibliographyGenerator.java b/source/java/writer2latex/base/BibliographyGenerator.java index 9712a36..233f4e3 100644 --- a/source/java/writer2latex/base/BibliographyGenerator.java +++ b/source/java/writer2latex/base/BibliographyGenerator.java @@ -20,13 +20,14 @@ * * All Rights Reserved. * - * Version 1.6 (2015-06-19) + * Version 1.6 (2015-06-20) * */ package writer2latex.base; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -57,13 +58,22 @@ public abstract class BibliographyGenerator { private List bibMarkList = new ArrayList(); // Map from key to label - private Map bibMarkCitation = new HashMap(); + private Map bibMarkLabel = new HashMap(); + + // Flag to identify numbering + private boolean bNumberedEntries = false; + + // Flag to identify truncation of templates + private boolean bSkipKey = false; /** Create a new bibliography generator based on a bibliography configuration and a list of bibliography marks * * @param ofr the office reader used to access the source document + * @param bSkipKey set to true if the key should be excluded when applying templates */ - protected BibliographyGenerator(OfficeReader ofr) { + protected BibliographyGenerator(OfficeReader ofr, boolean bSkipKey) { + this.bSkipKey = bSkipKey; + Element bibConfig = ofr.getBibliographyConfiguration(); if (bibConfig!=null) { if (bibConfig.hasAttribute(XMLString.TEXT_PREFIX)) { @@ -122,7 +132,7 @@ public abstract class BibliographyGenerator { private List sortKeys = null; private List sortAscending = null; - public Comparator setSortKeys(List sortKeys, List sortAscending) { + Comparator setSortKeys(List sortKeys, List sortAscending) { this.sortKeys = sortKeys; this.sortAscending = sortAscending; return this; @@ -145,34 +155,50 @@ public abstract class BibliographyGenerator { } private void createLabels(Element bibConfig) { - boolean bNumberedEntries = bibConfig!=null && "true".equals(bibConfig.getAttribute(XMLString.TEXT_NUMBERED_ENTRIES)); + bNumberedEntries = bibConfig!=null && "true".equals(bibConfig.getAttribute(XMLString.TEXT_NUMBERED_ENTRIES)); int nCount = bibMarkList.size(); for (int i=0; i getLabels() { + return bibMarkLabel.values(); + } + + /** Check whether entries are numbered rather than labeled with the key + * + * @return true if the entries are numbered + */ + protected boolean isNumberedEntries() { + return bNumberedEntries; + } + /** Get citation text for a reference to the bibliography * * @param sKey the key of the bibliography item * @return the citation text to be shown in the document */ public String generateCitation(String sKey) { - return sPrefix+bibMarkCitation.get(sKey)+sSuffix; + return sPrefix+bibMarkLabel.get(sKey)+sSuffix; } /** Generate a bibliography * * @param bibliography a text:bibliography-source element */ - public void generateBibliography(Element bibSource) { + protected void generateBibliography(Element bibSource) { Map bibEntryTemplate = collectTemplates(bibSource); for (Element bibMark : bibMarkList) { String sKey = bibMark.getAttribute(XMLString.TEXT_IDENTIFIER); @@ -188,8 +214,10 @@ public abstract class BibliographyGenerator { String sTitle = bibMark.getAttribute(XMLString.TEXT_TITLE); String sYear = bibMark.getAttribute(XMLString.TEXT_YEAR); insertBibliographyItem(null,sKey); - insertBibliographyItemElement(null,bibMarkCitation.get(sKey)); - insertBibliographyItemElement(null,": "); + if (!bSkipKey) { + insertBibliographyItemElement(null,bibMarkLabel.get(sKey)); + insertBibliographyItemElement(null,": "); + } insertBibliographyItemElement(null,sAuthor); insertBibliographyItemElement(null,", "); insertBibliographyItemElement(null,sTitle); @@ -216,24 +244,32 @@ public abstract class BibliographyGenerator { } private void applyTemplate(Element template, Element bibMark) { + boolean bSkip = bSkipKey; Node child = template.getFirstChild(); while (child!=null) { if (child.getNodeType()==Node.ELEMENT_NODE) { if (child.getNodeName().equals(XMLString.TEXT_INDEX_ENTRY_BIBLIOGRAPHY)) { String sField = Misc.getAttribute(child, XMLString.TEXT_BIBLIOGRAPHY_DATA_FIELD); if (sField!=null) { - String sElementStyleName = Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME); String sValue = bibMark.getAttribute("text:"+sField); if (sField.equals("identifier")) { - sValue = bibMarkCitation.get(sValue); + sValue = bibMarkLabel.get(sValue); + } + else { + bSkip = false; + } + if (!bSkip) { + String sElementStyleName = Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME); + insertBibliographyItemElement(sElementStyleName,sValue); } - insertBibliographyItemElement(sElementStyleName,sValue); } } else if (child.getNodeName().equals(XMLString.TEXT_INDEX_ENTRY_SPAN)) { - String sElementStyleName = Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME); - String sValue = Misc.getPCDATA(child); - insertBibliographyItemElement(sElementStyleName,sValue); + if (!bSkip) { + String sValue = Misc.getPCDATA(child); + String sElementStyleName = Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME); + insertBibliographyItemElement(sElementStyleName,sValue); + } } } child = child.getNextSibling(); diff --git a/source/java/writer2latex/bibtex/BibTeXDocument.java b/source/java/writer2latex/bibtex/BibTeXDocument.java index 463ef5f..1c4314b 100644 --- a/source/java/writer2latex/bibtex/BibTeXDocument.java +++ b/source/java/writer2latex/bibtex/BibTeXDocument.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-05-05) + * Version 1.6 (2015-06-22) * */ @@ -28,10 +28,13 @@ package writer2latex.bibtex; import java.util.Hashtable; import java.util.Enumeration; +import java.util.List; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; +import org.w3c.dom.Element; + import writer2latex.api.ConverterFactory; import writer2latex.api.MIMETypes; import writer2latex.api.OutputFile; @@ -40,11 +43,10 @@ import writer2latex.latex.i18n.ClassicI18n; import writer2latex.latex.i18n.I18n; import writer2latex.util.ExportNameCollection; import writer2latex.office.BibMark; -import writer2latex.office.BibMark.EntryType;; +import writer2latex.office.BibMark.EntryType; +import writer2latex.office.OfficeReader; -/** - *

Class representing a BibTeX document.

- * +/** Class representing a BibTeX document */ public class BibTeXDocument implements OutputFile { private static final String FILE_EXTENSION = ".bib"; @@ -56,36 +58,57 @@ public class BibTeXDocument implements OutputFile { private boolean bIsMaster; - /** - *

Constructs a new BibTeX Document.

+ /** Constructs a new BibTeX Document based on an office document * - *

This new document is empty. Bibliographic data must added - * using the put method.

- * - * @param sName The name of the BibTeXDocument. + * @param sName The name of the document + * @param bIsMaster is this a master document? + * @param ofr the office document */ - public BibTeXDocument(String sName, boolean bIsMaster) { - this.sName = trimDocumentName(sName); + public BibTeXDocument(String sName, boolean bIsMaster, OfficeReader ofr) { this.bIsMaster = bIsMaster; + loadEntries(ofr); // Use default config (only ascii, no extra font packages) i18n = new ClassicI18n(new LaTeXConfig()); } - /** - *

Returns the Document name with no file extension.

+ private void loadEntries(OfficeReader ofr) { + List bibMarks = ofr.getBibliographyMarks(); + for (Element bibMark : bibMarks) { + BibMark entry = new BibMark(bibMark); + entries.put(entry.getIdentifier(),entry); + exportNames.addName(entry.getIdentifier()); + } + } + + // Methods to query the content + + /** Test whether or not this BibTeX document contains any entries + * + * @return true if there is one or more entries in the document + */ + public boolean isEmpty() { + return entries.size()>0; + } + + /** Get export name for an identifier + * + * @param sIdentifier the identifier + * @return the export name + */ + public String getExportName(String sIdentifier) { + return exportNames.getExportName(sIdentifier); + } + + /** Returns the document name without file extension * - * @return The Document name with no file extension. + * @return the document name without file extension */ public String getName() { return sName; } + // Implement writer2latex.api.OutputFile - /** - *

Returns the Document name with file extension.

- * - * @return The Document name with file extension. - */ @Override public String getFileName() { return new String(sName + FILE_EXTENSION); } @@ -102,21 +125,7 @@ public class BibTeXDocument implements OutputFile { return false; } - /** - *

Writes out the Document content to the specified - * OutputStream.

- * - *

This method may not be thread-safe. - * Implementations may or may not synchronize this - * method. User code (i.e. caller) must make sure that - * calls to this method are thread-safe.

- * - * @param os OutputStream to write out the - * Document content. - * - * @throws IOException If any I/O error occurs. - */ - public void write(OutputStream os) throws IOException { + @Override public void write(OutputStream os) throws IOException { // BibTeX files are plain ascii OutputStreamWriter osw = new OutputStreamWriter(os,"ASCII"); osw.write("%% This file was converted to BibTeX by Writer2BibTeX ver. "+ConverterFactory.getVersion()+".\n"); @@ -155,43 +164,4 @@ public class BibTeXDocument implements OutputFile { osw.close(); } - /* - *

Check if this entry exists

- */ - public boolean containsKey(String sIdentifier) { - return entries.containsKey(sIdentifier); - } - - /* - *

Add an entry

- */ - public void put(BibMark entry) { - entries.put(entry.getIdentifier(),entry); - exportNames.addName(entry.getIdentifier()); - } - - /* - *

Get export name for an identifier

- */ - public String getExportName(String sIdentifier) { - return exportNames.getExportName(sIdentifier); - } - - /* - * Utility method to make sure the document name is stripped of any file - * extensions before use. - */ - private String trimDocumentName(String name) { - String temp = name.toLowerCase(); - - if (temp.endsWith(FILE_EXTENSION)) { - // strip the extension - int nlen = name.length(); - int endIndex = nlen - FILE_EXTENSION.length(); - name = name.substring(0,endIndex); - } - - return name; - } - } diff --git a/source/java/writer2latex/bibtex/Converter.java b/source/java/writer2latex/bibtex/Converter.java index c8a36c5..d36210e 100644 --- a/source/java/writer2latex/bibtex/Converter.java +++ b/source/java/writer2latex/bibtex/Converter.java @@ -16,75 +16,52 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2001-2010 by Henrik Just + * Copyright: 2001-2015 by Henrik Just * * All Rights Reserved. * - * version 1.2 (2010-03-28) + * Version 1.6 (2015-06-22) * */ package writer2latex.bibtex; import writer2latex.api.Config; -//import writer2latex.api.ConverterResult; import writer2latex.base.ConverterBase; import writer2latex.latex.LaTeXConfig; -import writer2latex.office.BibMark; -import writer2latex.office.XMLString; import writer2latex.util.Misc; -//import writer2latex.xmerge.ConvertData; -//import writer2latex.xmerge.OfficeDocument; - import java.io.IOException; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - *

BibTeX export

- * - *

This class extracts bibliographic information from an OpenDocument text file to a BibTeX data file.

- * +/** This class exports bibliographic information from an OpenDocument text file to a BibTeX data file */ public final class Converter extends ConverterBase { - // Configuration - TODO: Doesn't really use it - should use some fake config + // Implement converter API + + // TODO: Doesn't really use the configuration - should use some fake config private LaTeXConfig config; - - public Config getConfig() { return config; } - - // Constructor + public Converter() { super(); config = new LaTeXConfig(); } + + @Override public Config getConfig() { + return config; + } - /** - *

Convert the data passed into the InputStream - * into BibTeX format.

+ // Extend converter base + + /** Convert the document into BibTeX format.

* - * @throws IOException If any I/O error occurs. + * @throws IOException If any I/O error occurs. */ - public void convertInner() throws IOException { + @Override public void convertInner() throws IOException { sTargetFileName = Misc.trimDocumentName(sTargetFileName,".bib"); - BibTeXDocument bibDoc = new BibTeXDocument(sTargetFileName,true); - - // Collect all text:bibliography-mark elements from the content - Element doc = ofr.getContent(); - NodeList list; - list = doc.getElementsByTagName(XMLString.TEXT_BIBLIOGRAPHY_MARK); - int nLen = list.getLength(); - for (int i=0; i - *
  • use_bibtex: If true, citations will be exported as \cite - * commands. If false, citations will be exported as static text
  • - * - * The bibliography will be treated like this: - *
      +/** This class handles bibliographic citations and the bibliography. The result depends on these + * configuration options: *
    • use_index: If false, the bibliography will be omitted
    • *
    • use_bibtex true and external_bibtex_files * empty: The citations will be exported to a BibTeX file, which will be used @@ -55,111 +51,187 @@ import writer2latex.util.Misc; * non-empty: The citations will be not be exported to a BibTeX file, the * files referred to by the option will be used instead
    • *
    • use_bibtex false: The bibliography will be exported as - * static text. + * a thebibliography environment *
    • bibtex_style If BibTeX is used, this style will be applied *
    + * The citations will always be exported as \cite commands. */ -public class BibConverter extends ConverterHelper { - - private BibTeXDocument bibDoc; +class BibConverter extends ConverterHelper { + private BibTeXDocument bibDoc = null; + /** Construct a new BibConverter. + * * @param config the configuration to use * @param palette the ConverterPalette to use */ - public BibConverter(OfficeReader ofr,LaTeXConfig config, ConverterPalette palette) { + BibConverter(OfficeReader ofr,LaTeXConfig config, ConverterPalette palette) { super(ofr,config,palette); - } - - /** Append declarations needed by the BibConverter to - * the preamble. - * @param pack the LaTeXDocumentPortion to which - * declarations of packages should be added (\\usepackage). - * @param decl the LaTeXDocumentPortion to which - * other declarations should be added. - */ - public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { - // Use natbib - if (config.useBibtex() && config.useNatbib()) { - pack.append("\\usepackage"); - if (config.getNatbibOptions().length()>0) { - pack.append("[").append(config.getNatbibOptions()).append("]"); - } - pack.append("{natbib}").nl(); + + // We need to create a BibTeX document except if we are using external BibTeX files + if (!(config.useBibtex() && config.externalBibtexFiles().length()>0)) { + bibDoc = new BibTeXDocument(palette.getOutFileName(),false,ofr); } } - /** Process a bibliography (text:bibliography tag) - * @param node The element containing the Bibliography + /** Export the bibliography directly as a thebibliography environment (as an alternative to using BibTeX) + */ + private class ThebibliographyGenerator extends BibliographyGenerator { + // The bibliography is the be inserted in this LaTeX document portion with that context + private LaTeXDocumentPortion ldp; + private Context context; + + // The current bibliography item is to formatted with this before/after pair with that context + private BeforeAfter itemBa = null; + private Context itemContext = null; + + ThebibliographyGenerator(OfficeReader ofr) { + super(ofr,true); + } + + void handleBibliography(Element bibliography, LaTeXDocumentPortion ldp, Context context) { + this.ldp = ldp; + this.context = context; + + String sWidestLabel = ""; + Collection labels = getLabels(); + for (String sLabel : labels) { + if (sLabel.length()>=sWidestLabel.length()) { + sWidestLabel = sLabel; + } + } + + ldp.append("\\begin{thebibliography}{").append(sWidestLabel).append("}\n"); + generateBibliography(bibliography); + endBibliographyItem(); + ldp.append("\\end{thebibliography}\n"); + } + + @Override protected void insertBibliographyItem(String sStyleName, String sKey) { + endBibliographyItem(); + + itemBa = new BeforeAfter(); + itemContext = (Context) context.clone(); + + // Apply paragraph style (character formatting only) + StyleWithProperties style = ofr.getParStyle(sStyleName); + if (style!=null) { + palette.getI18n().applyLanguage(style,true,true,itemBa); + palette.getCharSc().applyFont(style,true,true,itemBa,itemContext); + if (itemBa.getBefore().length()>0) { + itemBa.add(" ",""); + itemBa.enclose("{", "}"); + } + } + + // Convert item + ldp.append(itemBa.getBefore()); + palette.getI18n().pushSpecialTable(palette.getCharSc().getFontName(style)); + + ldp.append("\\bibitem"); + if (!isNumberedEntries()) { + ldp.append("[").append(bibDoc.getExportName(sKey)).append("]"); + } + ldp.append("{").append(bibDoc.getExportName(sKey)).append("} "); + } + + private void endBibliographyItem() { + if (itemBa!=null) { + palette.getI18n().popSpecialTable(); + ldp.append(itemBa.getAfter()).append("\n"); + itemBa = null; + } + } + + @Override protected void insertBibliographyItemElement(String sStyleName, String sText) { + BeforeAfter ba = new BeforeAfter(); + Context elementContext = (Context) itemContext.clone(); + + // Apply character style + StyleWithProperties style = ofr.getTextStyle(sStyleName); + palette.getCharSc().applyTextStyle(sStyleName,ba,elementContext); + + // Convert text + ldp.append(ba.getBefore()); + palette.getI18n().pushSpecialTable(palette.getCharSc().getFontName(style)); + ldp.append(palette.getI18n().convert(sText, false, elementContext.getLang())); + palette.getI18n().popSpecialTable(); + ldp.append(ba.getAfter()); + } + } + + /** Append declarations needed by the BibConverter to the preamble. + * + * @param pack the LaTeXDocumentPortion to which declarations of packages (\\usepackage) should be added. + * @param decl the LaTeXDocumentPortion to which other declarations should be added. + */ + void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { + // Currently nothing + } + + /** Process a bibliography + * + * @param node A text:bibliography element * @param ldp the LaTeXDocumentPortion to which LaTeX code should be added * @param oc the current context */ - public void handleBibliography (Element node, LaTeXDocumentPortion ldp, Context oc) { - if (config.noIndex()) { return; } - if (config.useBibtex()) { - // Use the style given in the configuration - // TODO: Create a bst file from the settings of the text:bibliography - ldp.append("\\bibliographystyle{") - .append(config.bibtexStyle()) - .append("}").nl(); - - // Use BibTeX file from configuration, or exported BibTeX file - if (config.externalBibtexFiles().length()>0) { - ldp.append("\\bibliography{") - .append(config.externalBibtexFiles()) - .append("}").nl(); - } - else { - if (bibDoc==null) { bibDoc = new BibTeXDocument(palette.getOutFileName(),false); } - ldp.append("\\bibliography{") - .append(bibDoc.getName()) - .append("}").nl(); - } - } - else { // typeset current content - Element body = Misc.getChildByTagName(node,XMLString.TEXT_INDEX_BODY); - if (body!=null) { - Element title = Misc.getChildByTagName(body,XMLString.TEXT_INDEX_TITLE); - if (title!=null) { palette.getBlockCv().traverseBlockText(title,ldp,oc); } - palette.getBlockCv().traverseBlockText(body,ldp,oc); - } - } - } - - /** Process a Bibliography Mark (text:bibliography-mark tag) - * @param node The element containing the Mark - * @param ldp the LaTeXDocumentPortion to which LaTeX code should be added - * @param oc the current context - */ - public void handleBibliographyMark(Element node, LaTeXDocumentPortion ldp, Context oc) { - if (config.useBibtex()) { - String sIdentifier = node.getAttribute(XMLString.TEXT_IDENTIFIER); - if (sIdentifier!=null) { - if (config.externalBibtexFiles().length()==0) { - if (bibDoc==null) { bibDoc = new BibTeXDocument(palette.getOutFileName(),false); } - if (!bibDoc.containsKey(sIdentifier)) { - bibDoc.put(new BibMark(node)); - } - } - // Insert citation: Original if using external files; stripped if exporting BibTeX - ldp.append("\\cite{") - .append(config.externalBibtexFiles().length()==0 ? bibDoc.getExportName(sIdentifier) : sIdentifier) - .append("}"); - } - } - else { // use current value - palette.getInlineCv().traverseInlineText(node,ldp,oc); + void handleBibliography(Element node, LaTeXDocumentPortion ldp, Context oc) { + if (!config.noIndex()) { + if (config.useBibtex()) { // Export using BibTeX + handleBibliographyAsBibTeX(ldp); + } + else { // Export as thebibliography environment + ThebibliographyGenerator bibCv = new ThebibliographyGenerator(ofr); + Element source = Misc.getChildByTagName(node,XMLString.TEXT_BIBLIOGRAPHY_SOURCE); + bibCv.handleBibliography(source, ldp, oc); + } } } - - /** Get the BibTeX document, if any (the document is only created if it's - * specified in the configuration *and* the document contains bibliographic - * data *and* the configuration does not specify external BibTeX files - * @return the BiBTeXDocument, or null if it does not exist). - */ - public BibTeXDocument getBibTeXDocument () { - return bibDoc; - } - + private void handleBibliographyAsBibTeX(LaTeXDocumentPortion ldp) { + // Use the style given in the configuration + ldp.append("\\bibliographystyle{") + .append(config.bibtexStyle()) + .append("}").nl(); + + // Use BibTeX file from configuration, or exported BibTeX file + if (config.externalBibtexFiles().length()>0) { + ldp.append("\\bibliography{") + .append(config.externalBibtexFiles()) + .append("}").nl(); + } + else { + ldp.append("\\bibliography{") + .append(bibDoc.getName()) + .append("}").nl(); + } + } + + /** Process a Bibliography Mark + * @param node a text:bibliography-mark element + * @param ldp the LaTeXDocumentPortion to which LaTeX code should be added + * @param oc the current context + */ + void handleBibliographyMark(Element node, LaTeXDocumentPortion ldp, Context oc) { + String sIdentifier = node.getAttribute(XMLString.TEXT_IDENTIFIER); + if (sIdentifier!=null) { + // Use original citation if using external files; stripped if exporting BibTeX + ldp.append("\\cite{") + .append(config.externalBibtexFiles().length()==0 ? bibDoc.getExportName(sIdentifier) : sIdentifier) + .append("}"); + } + } + + /** Get the BibTeX document, if any (that is if the document contains bibliographic data and + * the configuration does not specify external BibTeX files) + * + * @return the BiBTeXDocument, or null if no BibTeX file is needed + */ + BibTeXDocument getBibTeXDocument() { + if (bibDoc!=null && !bibDoc.isEmpty()) { + return bibDoc; + } + return null; + } + } \ No newline at end of file diff --git a/source/java/writer2latex/latex/ConverterHelper.java b/source/java/writer2latex/latex/ConverterHelper.java index 822b275..ba16733 100644 --- a/source/java/writer2latex/latex/ConverterHelper.java +++ b/source/java/writer2latex/latex/ConverterHelper.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-15) + * Version 1.6 (2015-06-20) * */ @@ -31,18 +31,18 @@ import writer2latex.office.OfficeReader; /** *

    This is an abstract superclass for converter helpers.

    */ -public abstract class ConverterHelper { +abstract class ConverterHelper { - protected OfficeReader ofr; - protected LaTeXConfig config; - protected ConverterPalette palette; + OfficeReader ofr; + LaTeXConfig config; + ConverterPalette palette; - protected ConverterHelper(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) { + ConverterHelper(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) { this.ofr = ofr; this.config = config; this.palette = palette; } - public abstract void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl); + abstract void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl); } \ No newline at end of file diff --git a/source/java/writer2latex/latex/ConverterPalette.java b/source/java/writer2latex/latex/ConverterPalette.java index 0eec9b4..9200149 100644 --- a/source/java/writer2latex/latex/ConverterPalette.java +++ b/source/java/writer2latex/latex/ConverterPalette.java @@ -37,7 +37,6 @@ import writer2latex.latex.i18n.ClassicI18n; import writer2latex.latex.i18n.I18n; import writer2latex.latex.i18n.XeTeXI18n; import writer2latex.latex.util.Context; -import writer2latex.latex.util.Info; import writer2latex.util.CSVList; import writer2latex.util.ExportNameCollection; import writer2latex.util.Misc; diff --git a/source/java/writer2latex/latex/FieldConverter.java b/source/java/writer2latex/latex/FieldConverter.java index d075ad0..0e639f0 100644 --- a/source/java/writer2latex/latex/FieldConverter.java +++ b/source/java/writer2latex/latex/FieldConverter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-15) + * Version 1.6 (2015-06-22) * */ @@ -104,6 +104,14 @@ public class FieldConverter extends ConverterHelper { * other declarations should be added. */ public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { + // Use natbib + if (config.useBibtex() && config.useNatbib()) { + pack.append("\\usepackage"); + if (config.getNatbibOptions().length()>0) { + pack.append("[").append(config.getNatbibOptions()).append("]"); + } + pack.append("{natbib}").nl(); + } // use lastpage.sty if (bUsesPageCount) { pack.append("\\usepackage{lastpage}").nl(); diff --git a/source/java/writer2latex/latex/util/Info.java b/source/java/writer2latex/latex/Info.java similarity index 78% rename from source/java/writer2latex/latex/util/Info.java rename to source/java/writer2latex/latex/Info.java index 21bef95..656248e 100644 --- a/source/java/writer2latex/latex/util/Info.java +++ b/source/java/writer2latex/latex/Info.java @@ -20,38 +20,33 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-15) + * Version 1.6 (2015-06-21) * */ -package writer2latex.latex.util; +package writer2latex.latex; import org.w3c.dom.Element; -import writer2latex.latex.LaTeXConfig; import writer2latex.util.Misc; import writer2latex.office.OfficeReader; import writer2latex.office.StyleWithProperties; import writer2latex.office.XMLString; -import writer2latex.latex.LaTeXDocumentPortion; -import writer2latex.latex.ConverterHelper; -import writer2latex.latex.ConverterPalette; -/** - *

    This class creates various information to the user about the conversion.

    +/** This class creates various information to the user about the conversion. */ -public class Info extends ConverterHelper { +class Info extends ConverterHelper { @Override public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) { // Currently nothing } - public Info(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) { + Info(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) { super(ofr,config,palette); } - public void addDebugInfo(Element node, LaTeXDocumentPortion ldp) { + void addDebugInfo(Element node, LaTeXDocumentPortion ldp) { if (config.debug()) { ldp.append("% ").append(node.getNodeName()); addDebugInfo(node,ldp,XMLString.TEXT_ID); @@ -69,7 +64,7 @@ public class Info extends ConverterHelper { } } - private void addDebugInfo(Element node, LaTeXDocumentPortion ldp, String sAttribute) { + void addDebugInfo(Element node, LaTeXDocumentPortion ldp, String sAttribute) { String sValue = Misc.getAttribute(node,sAttribute); if (sValue!=null) { ldp.append(" ").append(sAttribute).append("=\"").append(sValue).append("\""); diff --git a/source/java/writer2latex/xhtml/XhtmlBibliographyGenerator.java b/source/java/writer2latex/xhtml/XhtmlBibliographyGenerator.java index ac36075..d68b4d1 100644 --- a/source/java/writer2latex/xhtml/XhtmlBibliographyGenerator.java +++ b/source/java/writer2latex/xhtml/XhtmlBibliographyGenerator.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-06-18) + * Version 1.6 (2015-06-20) * */ @@ -38,7 +38,7 @@ class XhtmlBibliographyGenerator extends BibliographyGenerator { private Element currentPar; // The paragraph of the current item XhtmlBibliographyGenerator(OfficeReader ofr, Converter converter) { - super(ofr); + super(ofr,false); this.converter = converter; }