JabRef support
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@84 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
8b7154ca6b
commit
905918aaf2
26 changed files with 315 additions and 188 deletions
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2011-01-12)
|
||||
* Version 1.2 (2011-01-25)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -32,8 +32,8 @@ package writer2latex.api;
|
|||
public class ConverterFactory {
|
||||
|
||||
// Version information
|
||||
private static final String VERSION = "1.1.9";
|
||||
private static final String DATE = "2011-01-12";
|
||||
private static final String VERSION = "1.1.6";
|
||||
private static final String DATE = "2011-01-25";
|
||||
|
||||
/** Return the Writer2LaTeX version in the form
|
||||
* (major version).(minor version).(patch level)<br/>
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-10-13)
|
||||
* Version 1.2 (2011-01-24)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -58,6 +58,9 @@ public class FieldConverter extends ConverterHelper {
|
|||
|
||||
// Identify Zotero items
|
||||
private static final String ZOTERO_ITEM = "ZOTERO_ITEM";
|
||||
// Identify JabRef items
|
||||
private static final String JABREF_ITEM_1 = "JR_cite_1";
|
||||
private static final String JABREF_ITEM_2 = "JR_cite_2";
|
||||
|
||||
// Links & references
|
||||
private ExportNameCollection targets = new ExportNameCollection(true);
|
||||
|
@ -79,6 +82,7 @@ public class FieldConverter extends ConverterHelper {
|
|||
private boolean bUsesTitleref = false;
|
||||
private boolean bUsesOooref = false;
|
||||
private boolean bConvertZotero = false;
|
||||
private boolean bConvertJabRef = false;
|
||||
private boolean bNeedNatbib = false;
|
||||
|
||||
public FieldConverter(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) {
|
||||
|
@ -86,6 +90,7 @@ public class FieldConverter extends ConverterHelper {
|
|||
// hyperref.sty is not compatible with titleref.sty and oooref.sty:
|
||||
bUseHyperref = config.useHyperref() && !config.useTitleref() && !config.useOooref();
|
||||
bConvertZotero = config.useBibtex() && config.zoteroBibtexFiles().length()>0;
|
||||
bConvertJabRef = config.useBibtex() && config.jabrefBibtexFiles().length()>0;
|
||||
}
|
||||
|
||||
/** <p>Append declarations needed by the <code>FieldConverter</code> to
|
||||
|
@ -598,7 +603,7 @@ public class FieldConverter extends ConverterHelper {
|
|||
ldp.append("}");
|
||||
}
|
||||
|
||||
oc.setInZoteroText(true);
|
||||
oc.setInZoteroJabRefText(true);
|
||||
|
||||
bNeedNatbib = true;
|
||||
|
||||
|
@ -609,6 +614,27 @@ public class FieldConverter extends ConverterHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Try to handle this reference name as a JabRef reference, return true on success
|
||||
private boolean handleJabRefReferenceName(String sName, LaTeXDocumentPortion ldp, Context oc) {
|
||||
// First parse the reference name:
|
||||
// A JabRef reference name has the form JR_cite_n_identifiers where
|
||||
// n=1 for (Author date) and n=2 for Author (date) citations
|
||||
// identifiers is a comma separated list of BibTeX keys
|
||||
if (sName.startsWith(JABREF_ITEM_1)) {
|
||||
ldp.append("\\citep{").append(sName.substring(JABREF_ITEM_1.length()+1)).append("}");
|
||||
oc.setInZoteroJabRefText(true);
|
||||
bNeedNatbib = true;
|
||||
return true;
|
||||
}
|
||||
else if (sName.startsWith(JABREF_ITEM_2)) {
|
||||
ldp.append("\\citet{").append(sName.substring(JABREF_ITEM_2.length()+1)).append("}");
|
||||
oc.setInZoteroJabRefText(true);
|
||||
bNeedNatbib = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String shortenRefname(String s) {
|
||||
// For Zotero items, use the trailing unique identifier
|
||||
if (s.startsWith(ZOTERO_ITEM)) {
|
||||
|
@ -627,8 +653,8 @@ public class FieldConverter extends ConverterHelper {
|
|||
* @param oc the current context
|
||||
*/
|
||||
public void handleReferenceMarkEnd(Element node, LaTeXDocumentPortion ldp, Context oc) {
|
||||
// Nothing to do, except to mark that this ends any Zotero citation
|
||||
oc.setInZoteroText(false);
|
||||
// Nothing to do, except to mark that this ends any Zotero/JabRef citation
|
||||
oc.setInZoteroJabRefText(false);
|
||||
}
|
||||
|
||||
/** <p>Process a reference mark (text:reference-mark or text:reference-mark-start tag)</p>
|
||||
|
@ -640,8 +666,9 @@ public class FieldConverter extends ConverterHelper {
|
|||
public void handleReferenceMark(Element node, LaTeXDocumentPortion ldp, Context oc) {
|
||||
if (!oc.isInSection() && !oc.isInCaption() && !oc.isVerbatim()) {
|
||||
String sName = node.getAttribute(XMLString.TEXT_NAME);
|
||||
// Zotero (mis)uses reference marks to store citations, so check this first
|
||||
if (sName!=null && (!bConvertZotero || !handleZoteroReferenceName(sName, ldp, oc))) {
|
||||
// Zotero and JabRef (mis)uses reference marks to store citations, so check this first
|
||||
if (sName!=null && (!bConvertZotero || !handleZoteroReferenceName(sName, ldp, oc))
|
||||
&& (!bConvertJabRef || !handleJabRefReferenceName(sName, ldp, oc))) {
|
||||
// Plain reference mark
|
||||
// Note: Always include \label here, even when it's not used
|
||||
ldp.append("\\label{ref:"+refnames.getExportName(shortenRefname(sName))+"}");
|
||||
|
|
|
@ -195,11 +195,11 @@ public class InlineConverter extends ConverterHelper {
|
|||
case Node.TEXT_NODE:
|
||||
String s = childNode.getNodeValue();
|
||||
if (s.length() > 0) {
|
||||
if (oc.isInZoteroText()) { // Comment out Zotero citations
|
||||
if (oc.isInZoteroJabRefText()) { // Comment out Zotero citations
|
||||
ldp.append("%");
|
||||
}
|
||||
ldp.append(palette.getI18n().convert(s, false, oc.getLang()));
|
||||
if (oc.isInZoteroText()) { // End comment out
|
||||
if (oc.isInZoteroJabRefText()) { // End comment out
|
||||
ldp.nl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-12-15)
|
||||
* Version 1.2 (2011-01-23)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// I. Define items needed by ConfigBase
|
||||
|
||||
protected int getOptionCount() { return 67; }
|
||||
protected int getOptionCount() { return 68; }
|
||||
protected String getDefaultConfigPath() { return "/writer2latex/latex/config/"; }
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
@ -145,38 +145,39 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
|
|||
private static final int BIBTEX_STYLE = 32;
|
||||
private static final int EXTERNAL_BIBTEX_FILES = 33;
|
||||
private static final int ZOTERO_BIBTEX_FILES = 34;
|
||||
private static final int NATBIB_OPTIONS = 35;
|
||||
private static final int FORMATTING = 36;
|
||||
private static final int PAGE_FORMATTING = 37;
|
||||
private static final int OTHER_STYLES = 38;
|
||||
private static final int IMAGE_CONTENT = 39;
|
||||
private static final int TABLE_CONTENT = 40;
|
||||
private static final int TABLE_FIRST_HEAD_STYLE = 41;
|
||||
private static final int TABLE_HEAD_STYLE = 42;
|
||||
private static final int TABLE_FOOT_STYLE = 43;
|
||||
private static final int TABLE_LAST_FOOT_STYLE = 44;
|
||||
private static final int IGNORE_HARD_PAGE_BREAKS = 45;
|
||||
private static final int IGNORE_HARD_LINE_BREAKS = 46;
|
||||
private static final int IGNORE_EMPTY_PARAGRAPHS = 47;
|
||||
private static final int IGNORE_DOUBLE_SPACES = 48;
|
||||
private static final int ALIGN_FRAMES = 49;
|
||||
private static final int FLOAT_FIGURES = 50;
|
||||
private static final int FLOAT_TABLES = 51;
|
||||
private static final int FLOAT_OPTIONS = 52;
|
||||
private static final int FIGURE_SEQUENCE_NAME = 53;
|
||||
private static final int TABLE_SEQUENCE_NAME = 54;
|
||||
private static final int IMAGE_OPTIONS = 55;
|
||||
private static final int REMOVE_GRAPHICS_EXTENSION = 56;
|
||||
private static final int ORIGINAL_IMAGE_SIZE = 57;
|
||||
private static final int SIMPLE_TABLE_LIMIT = 58;
|
||||
private static final int NOTES = 59;
|
||||
private static final int METADATA = 60;
|
||||
private static final int TABSTOP = 61;
|
||||
private static final int WRAP_LINES_AFTER = 62;
|
||||
private static final int SPLIT_LINKED_SECTIONS = 63;
|
||||
private static final int SPLIT_TOPLEVEL_SECTIONS = 64;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 65;
|
||||
private static final int DEBUG = 66;
|
||||
private static final int JABREF_BIBTEX_FILES = 35;
|
||||
private static final int NATBIB_OPTIONS = 36;
|
||||
private static final int FORMATTING = 37;
|
||||
private static final int PAGE_FORMATTING = 38;
|
||||
private static final int OTHER_STYLES = 39;
|
||||
private static final int IMAGE_CONTENT = 40;
|
||||
private static final int TABLE_CONTENT = 41;
|
||||
private static final int TABLE_FIRST_HEAD_STYLE = 42;
|
||||
private static final int TABLE_HEAD_STYLE = 43;
|
||||
private static final int TABLE_FOOT_STYLE = 44;
|
||||
private static final int TABLE_LAST_FOOT_STYLE = 45;
|
||||
private static final int IGNORE_HARD_PAGE_BREAKS = 46;
|
||||
private static final int IGNORE_HARD_LINE_BREAKS = 47;
|
||||
private static final int IGNORE_EMPTY_PARAGRAPHS = 48;
|
||||
private static final int IGNORE_DOUBLE_SPACES = 49;
|
||||
private static final int ALIGN_FRAMES = 50;
|
||||
private static final int FLOAT_FIGURES = 51;
|
||||
private static final int FLOAT_TABLES = 52;
|
||||
private static final int FLOAT_OPTIONS = 53;
|
||||
private static final int FIGURE_SEQUENCE_NAME = 54;
|
||||
private static final int TABLE_SEQUENCE_NAME = 55;
|
||||
private static final int IMAGE_OPTIONS = 56;
|
||||
private static final int REMOVE_GRAPHICS_EXTENSION = 57;
|
||||
private static final int ORIGINAL_IMAGE_SIZE = 58;
|
||||
private static final int SIMPLE_TABLE_LIMIT = 59;
|
||||
private static final int NOTES = 60;
|
||||
private static final int METADATA = 61;
|
||||
private static final int TABSTOP = 62;
|
||||
private static final int WRAP_LINES_AFTER = 63;
|
||||
private static final int SPLIT_LINKED_SECTIONS = 64;
|
||||
private static final int SPLIT_TOPLEVEL_SECTIONS = 65;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 66;
|
||||
private static final int DEBUG = 67;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// IV. Our options data
|
||||
|
@ -250,6 +251,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
|
|||
options[BIBTEX_STYLE] = new Option("bibtex_style","plain");
|
||||
options[EXTERNAL_BIBTEX_FILES] = new Option("external_bibtex_files","");
|
||||
options[ZOTERO_BIBTEX_FILES] = new Option("zotero_bibtex_files","");
|
||||
options[JABREF_BIBTEX_FILES] = new Option("jabref_bibtex_files","");
|
||||
options[NATBIB_OPTIONS] = new Option("natbib_options","");
|
||||
options[FORMATTING] = new IntegerOption("formatting","convert_basic") {
|
||||
public void setString(String sValue) {
|
||||
|
@ -661,6 +663,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
|
|||
public String bibtexStyle() { return options[BIBTEX_STYLE].getString(); }
|
||||
public String externalBibtexFiles() { return options[EXTERNAL_BIBTEX_FILES].getString(); }
|
||||
public String zoteroBibtexFiles() { return options[ZOTERO_BIBTEX_FILES].getString(); }
|
||||
public String jabrefBibtexFiles() { return options[JABREF_BIBTEX_FILES].getString(); }
|
||||
public String getNatbibOptions() { return options[NATBIB_OPTIONS].getString(); }
|
||||
|
||||
// Formatting options
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-10-06)
|
||||
* Version 1.2 (2011-01-24)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -121,6 +121,20 @@ public class SectionConverter extends ConverterHelper {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle a section as a JabRef bibliography
|
||||
private boolean handleJabRefBibliography(Element node, LaTeXDocumentPortion ldp, Context oc) {
|
||||
String sName = node.getAttribute(XMLString.TEXT_NAME);
|
||||
if (config.useBibtex() && config.jabrefBibtexFiles().length()>0 && sName.equals("JR_bib")) {
|
||||
// This section is a JabRef bibliography, and the user wishes to handle it as such
|
||||
// A JabRef bibliography is identified by the name JR_bib
|
||||
// Use the BibTeX style and files given in the configuration
|
||||
ldp.append("\\bibliographystyle{").append(config.bibtexStyle()).append("}").nl()
|
||||
.append("\\bibliography{").append(config.jabrefBibtexFiles()).append("}").nl();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** <p> Process a section (text:section tag)</p>
|
||||
* @param node The element containing the section
|
||||
|
@ -167,8 +181,8 @@ public class SectionConverter extends ConverterHelper {
|
|||
if (sFileName!=null) {
|
||||
ldp.append("\\input{").append(sFileName).append("}").nl();
|
||||
}
|
||||
// Zotero might have generated this section as a bibliograhy:
|
||||
if (!handleZoteroBibliography(node,sectionLdp,ic)) {
|
||||
// Zotero or JabRef might have generated this section as a bibliograhy:
|
||||
if (!handleZoteroBibliography(node,sectionLdp,ic) && !handleJabRefBibliography(node,sectionLdp,ic)) {
|
||||
palette.getBlockCv().traverseBlockText(node,sectionLdp,ic);
|
||||
}
|
||||
if (sectionLdp!=ldp) { sectionLdp.append("\\endinput").nl(); }
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-10-04)
|
||||
* Version 1.2 (2011-01-24)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -78,8 +78,8 @@ public class Context {
|
|||
// within a caption
|
||||
private boolean bInCaption = false;
|
||||
|
||||
// within a Zotero citation
|
||||
private boolean bInZoteroText = false;
|
||||
// within a Zotero/JabRef citation
|
||||
private boolean bInZoteroJabRefText = false;
|
||||
|
||||
// within a floating figure (figure environment)
|
||||
private boolean bInFigureFloat = false;
|
||||
|
@ -194,9 +194,9 @@ public class Context {
|
|||
|
||||
public boolean isInCaption() { return bInCaption; }
|
||||
|
||||
public void setInZoteroText(boolean bInZoteroText) { this.bInZoteroText = bInZoteroText; }
|
||||
public void setInZoteroJabRefText(boolean bInZoteroJabRefText) { this.bInZoteroJabRefText = bInZoteroJabRefText; }
|
||||
|
||||
public boolean isInZoteroText() { return bInZoteroText; }
|
||||
public boolean isInZoteroJabRefText() { return bInZoteroJabRefText; }
|
||||
|
||||
public void setInFigureFloat(boolean bInFigureFloat) { this.bInFigureFloat = bInFigureFloat; }
|
||||
|
||||
|
@ -309,6 +309,7 @@ public class Context {
|
|||
newContext.setInContinuedList(bInContinuedList);
|
||||
newContext.setInSection(bInSection);
|
||||
newContext.setInCaption(bInCaption);
|
||||
newContext.setInZoteroJabRefText(bInZoteroJabRefText);
|
||||
newContext.setInFigureFloat(bInFigureFloat);
|
||||
newContext.setInTableFloat(bInTableFloat);
|
||||
newContext.setInFrame(bInFrame);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue