Created
August 26, 2010 20:07
-
-
Save unhammer/552143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: source/java/writer2latex/latex/InlineConverter.java | |
=================================================================== | |
--- source/java/writer2latex/latex/InlineConverter.java (revision 71) | |
+++ source/java/writer2latex/latex/InlineConverter.java (working copy) | |
@@ -195,7 +195,17 @@ | |
case Node.TEXT_NODE: | |
String s = childNode.getNodeValue(); | |
if (s.length() > 0) { | |
- ldp.append(palette.getI18n().convert(s, false, oc.getLang())); | |
+ if (oc.isZoteroText()) { | |
+ // Within Zotero ref-marks, the citation is given in plain text | |
+ // TODO: should we handle this in the if ref-marks section below? | |
+ ldp.append("%\n\\begin{comment}\n"); | |
+ ldp.append(palette.getI18n().convert(s, false, oc.getLang())); | |
+ ldp.append("\n\\end{comment}%\n"); | |
+ oc.setZoteroText(false); | |
+ } | |
+ else { | |
+ ldp.append(palette.getI18n().convert(s, false, oc.getLang())); | |
+ } | |
} | |
break; | |
@@ -348,7 +358,6 @@ | |
default: | |
// Do nothing | |
} | |
- | |
childNode = childNode.getNextSibling(); | |
} | |
Index: source/java/writer2latex/latex/FieldConverter.java | |
=================================================================== | |
--- source/java/writer2latex/latex/FieldConverter.java (revision 71) | |
+++ source/java/writer2latex/latex/FieldConverter.java (working copy) | |
@@ -422,9 +422,67 @@ | |
palette.getInlineCv().traversePCDATA(node,ldp,oc); | |
} | |
} | |
- } | |
+ } | |
- | |
+ /** <p>Process the text:name of a Zotero reference</p> | |
+ * @param str the value of the text:name attribute | |
+ * @return a complete LaTeX \cite{} command string | |
+ */ | |
+ private String zoteroHandleName(String str) { | |
+ System.err.println("handling:\n"+str); | |
+ // citekeys will become the keys in \cite{key1;key2;...} | |
+ StringBuffer citekeys = new StringBuffer(); | |
+ // pt is appended to \cite to create \citep | |
+ String pt = ""; | |
+ // pos marks how far we've read in str. Move now to the start of the first dict: | |
+ int pos = str.indexOf('{') + 1; | |
+ String key; // used below | |
+ // We match dict keys on the substring starting at pos | |
+ java.util.regex.Pattern keyPat = java.util.regex.Pattern.compile("^\\s*\"([^\"]+)\"\\s*:\\s*"); | |
+ // Not sure what the range of possible uri's could be, this might be too strict: | |
+ java.util.regex.Pattern uriPat = java.util.regex.Pattern.compile("^\\s*\\{\"uri\":\\[\"http://zotero\\.org/(users|groups)/[0-9]+/items/([^\\]]+)\"]\\}"); | |
+ java.util.regex.Matcher match; | |
+ while(pos < str.length() && pos > -1) { | |
+ System.err.println("whiling: " + Character.toString(str.charAt(pos))); | |
+ match = keyPat.matcher(str.substring(pos)); | |
+ if (match.find()) { | |
+ pos += match.end(); | |
+ key = match.group(1); | |
+ System.err.println("key: "+ key + ", pos: " + Integer.toString(pos)); | |
+ if(key.equals("sort")) { | |
+ // what does the sort key mean? | |
+ pos = str.indexOf(',', pos); // skip to next | |
+ } | |
+ else if(key.equals("suppressAuthor")) { | |
+ pt = "p"; | |
+ pos = str.indexOf(',', pos); | |
+ } | |
+ else if(key.equals("citationItems")) { | |
+ pos = str.indexOf('[', pos); | |
+ | |
+ while(pos < str.length() && pos > -1) { | |
+ match = uriPat.matcher(str.substring(pos)); | |
+ if (match.find()) { | |
+ pos += match.end(); | |
+ String uri = match.group(2); | |
+ System.err.println("uri: "+ uri + ", pos: " + Integer.toString(pos)); | |
+ citekeys.append(uri + ";"); | |
+ } | |
+ pos++; | |
+ } | |
+ } | |
+ } | |
+ pos++; | |
+ } | |
+ if (citekeys.length() > 0) { | |
+ citekeys.deleteCharAt(citekeys.length() - 1); // Delete the last ';' | |
+ return "\\cite" + pt + "{" + citekeys.toString() + "}"; | |
+ } | |
+ else { | |
+ return ""; // TODO: found no citekeys, output a warning? | |
+ } | |
+ } | |
+ | |
/** <p>Process a reference mark (text:reference-mark tag)</p> | |
* @param node The element containing the reference mark | |
* @param ldp the <code>LaTeXDocumentPortion</code> to which | |
@@ -436,7 +494,16 @@ | |
// Note: Always include \label here, even when it's not used | |
String sName = node.getAttribute(XMLString.TEXT_NAME); | |
if (sName!=null) { | |
- ldp.append("\\label{ref:"+refnames.getExportName(sName)+"}"); | |
+ if (sName.substring(0,11).equals("ZOTERO_ITEM")) { | |
+ // TODO: a constant for the "ZOTERO_ITEM" string, | |
+ // TODO: check a user-variable for "handle Zotero references" | |
+ ldp.append(zoteroHandleName(sName)); | |
+ // Make sure we comment out the plain-text citation that follows: | |
+ oc.setZoteroText(true); | |
+ } | |
+ else { | |
+ ldp.append("\\label{ref:"+refnames.getExportName(sName)+"}"); | |
+ } | |
} | |
} | |
else { | |
Index: source/java/writer2latex/latex/util/Context.java | |
=================================================================== | |
--- source/java/writer2latex/latex/util/Context.java (revision 71) | |
+++ source/java/writer2latex/latex/util/Context.java (working copy) | |
@@ -107,6 +107,9 @@ | |
// Inside an area, where lists are ignored | |
private boolean bIgnoreLists = false; | |
+ // Inside a Zotero reference-mark, where text should be commented out | |
+ private boolean bZoteroText = false; | |
+ | |
// *** Accessor Methods *** | |
public void setBgColor(String sBgColor) { this.sBgColor = sBgColor; } | |
@@ -221,6 +224,12 @@ | |
public boolean isIgnoreLists() { return bIgnoreLists; } | |
+ public void setZoteroText(boolean bZoteroText) { | |
+ this.bZoteroText = bZoteroText; | |
+ } | |
+ | |
+ public boolean isZoteroText() { return bZoteroText; } | |
+ | |
public void setNoLineBreaks(boolean bNoLineBreaks) { | |
this.bNoLineBreaks = bNoLineBreaks; | |
} | |
@@ -310,6 +319,7 @@ | |
newContext.setMathMode(bMathMode); | |
newContext.setNoFootnotes(bNoFootnotes); | |
newContext.setIgnoreLists(bIgnoreLists); | |
+ newContext.setZoteroText(bZoteroText); | |
newContext.setNoLineBreaks(bNoLineBreaks); | |
return newContext; | |
Index: build.xml | |
=================================================================== | |
--- build.xml (revision 71) | |
+++ build.xml (working copy) | |
@@ -8,8 +8,8 @@ | |
<project name="w2l" default="help" basedir="."> | |
<!-- set this property to the location of your SO/OOo installation --> | |
- <property name="OFFICE_CLASSES" location="/usr/share/java/openoffice" /> | |
- <property name="URE_CLASSES" location="/usr/share/java/openoffice" /> | |
+ <property name="OFFICE_CLASSES" location="/usr/lib/openoffice/basis-link/program/classes" /> | |
+ <property name="URE_CLASSES" location="/usr/lib/openoffice/basis-link/ure-link/share/java" /> | |
<description>writer2latex - build file</description> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment