Handle BibTeX files with non-ascii encodings

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@263 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2015-07-27 07:52:38 +00:00
parent 5e9dfc8678
commit 658952d328
22 changed files with 207 additions and 113 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-07-01)
* Version 1.6 (2015-07-27)
*
*/
@ -32,8 +32,8 @@ package writer2latex.api;
public class ConverterFactory {
// Version information
private static final String VERSION = "1.5.3";
private static final String DATE = "2015-07-01";
private static final String VERSION = "1.6";
private static final String DATE = "2015-07-27";
/** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/>

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-07-01)
* Version 1.6 (2015-07-27)
*
*/
@ -33,6 +33,7 @@ import org.w3c.dom.Element;
import writer2latex.base.BibliographyGenerator;
import writer2latex.bibtex.BibTeXDocument;
import writer2latex.latex.i18n.ClassicI18n;
import writer2latex.latex.util.BeforeAfter;
import writer2latex.latex.util.Context;
@ -60,6 +61,8 @@ class BibConverter extends ConverterHelper {
private BibTeXDocument bibDoc = null;
private boolean bUseBibTeX;
private String sBibTeXEncoding = null;
private String sDocumentEncoding = null;
/** Construct a new BibConverter.
*
@ -74,6 +77,16 @@ class BibConverter extends ConverterHelper {
bibDoc = new BibTeXDocument(palette.getOutFileName(),false,ofr);
}
// We need to use a different encoding for the BibTeX files
if (config.externalBibtexFiles().length()>0) {
int nBibTeXEncoding = config.getBibtexEncoding();
int nDocumentEncoding = config.getInputencoding();
if (config.getBackend()!=LaTeXConfig.XETEX && nBibTeXEncoding>-1 && nBibTeXEncoding!=nDocumentEncoding) {
sBibTeXEncoding = ClassicI18n.writeInputenc(nBibTeXEncoding);
sDocumentEncoding = ClassicI18n.writeInputenc(nDocumentEncoding);
}
}
// We need to export it
bUseBibTeX = config.useBibtex();
}
@ -199,10 +212,17 @@ class BibConverter extends ConverterHelper {
.append("}").nl();
// Use BibTeX file from configuration, or exported BibTeX file
// TODO: For XeTeX, probably use \XeTeXdefaultencoding?
if (config.externalBibtexFiles().length()>0) {
ldp.append("\\bibliography{")
if (sBibTeXEncoding!=null) {
ldp.append("\\inputencoding{").append(sBibTeXEncoding).append("}").nl();
}
ldp.append("\\bibliography{")
.append(config.externalBibtexFiles())
.append("}").nl();
if (sBibTeXEncoding!=null) {
ldp.append("\\inputencoding{").append(sDocumentEncoding).append("}").nl();
}
}
else {
ldp.append("\\bibliography{")

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-06-23)
* Version 1.6 (2015-07-23)
*
*/
@ -49,7 +49,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
/////////////////////////////////////////////////////////////////////////
// I. Define items needed by ConfigBase
protected int getOptionCount() { return 72; }
protected int getOptionCount() { return 73; }
protected String getDefaultConfigPath() { return "/writer2latex/latex/config/"; }
/////////////////////////////////////////////////////////////////////////
@ -144,45 +144,46 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
private static final int USE_BIBTEX = 30;
private static final int BIBTEX_STYLE = 31;
private static final int EXTERNAL_BIBTEX_FILES = 32;
private static final int ZOTERO_BIBTEX_FILES = 33;
private static final int JABREF_BIBTEX_FILES = 34;
private static final int INCLUDE_ORIGINAL_CITATIONS = 35;
private static final int USE_NATBIB = 36;
private static final int NATBIB_OPTIONS = 37;
private static final int FONT = 38;
private static final int FORMATTING = 39;
private static final int PAGE_FORMATTING = 40;
private static final int OTHER_STYLES = 41;
private static final int IMAGE_CONTENT = 42;
private static final int TABLE_CONTENT = 43;
private static final int TABLE_FIRST_HEAD_STYLE = 44;
private static final int TABLE_HEAD_STYLE = 45;
private static final int TABLE_FOOT_STYLE = 46;
private static final int TABLE_LAST_FOOT_STYLE = 47;
private static final int IGNORE_HARD_PAGE_BREAKS = 48;
private static final int IGNORE_HARD_LINE_BREAKS = 49;
private static final int IGNORE_EMPTY_PARAGRAPHS =50;
private static final int IGNORE_DOUBLE_SPACES = 51;
private static final int DISPLAY_HIDDEN_TEXT = 52;
private static final int ALIGN_FRAMES = 53;
private static final int FLOAT_FIGURES = 54;
private static final int FLOAT_TABLES = 55;
private static final int FLOAT_OPTIONS = 56;
private static final int FIGURE_SEQUENCE_NAME = 57;
private static final int TABLE_SEQUENCE_NAME = 58;
private static final int IMAGE_OPTIONS = 59;
private static final int REMOVE_GRAPHICS_EXTENSION = 60;
private static final int ORIGINAL_IMAGE_SIZE = 61;
private static final int SIMPLE_TABLE_LIMIT = 62;
private static final int NOTES = 63;
private static final int METADATA = 64;
private static final int TABSTOP = 65;
private static final int WRAP_LINES_AFTER = 66;
private static final int SPLIT_LINKED_SECTIONS = 67;
private static final int SPLIT_TOPLEVEL_SECTIONS = 68;
private static final int SAVE_IMAGES_IN_SUBDIR = 69;
private static final int OLD_MATH_COLORS = 70;
private static final int DEBUG = 71;
private static final int BIBTEX_ENCODING = 33;
private static final int ZOTERO_BIBTEX_FILES = 34;
private static final int JABREF_BIBTEX_FILES = 35;
private static final int INCLUDE_ORIGINAL_CITATIONS = 36;
private static final int USE_NATBIB = 37;
private static final int NATBIB_OPTIONS = 38;
private static final int FONT = 39;
private static final int FORMATTING = 40;
private static final int PAGE_FORMATTING = 41;
private static final int OTHER_STYLES = 42;
private static final int IMAGE_CONTENT = 43;
private static final int TABLE_CONTENT = 44;
private static final int TABLE_FIRST_HEAD_STYLE = 45;
private static final int TABLE_HEAD_STYLE = 46;
private static final int TABLE_FOOT_STYLE = 47;
private static final int TABLE_LAST_FOOT_STYLE = 48;
private static final int IGNORE_HARD_PAGE_BREAKS = 49;
private static final int IGNORE_HARD_LINE_BREAKS = 50;
private static final int IGNORE_EMPTY_PARAGRAPHS =51;
private static final int IGNORE_DOUBLE_SPACES = 52;
private static final int DISPLAY_HIDDEN_TEXT = 53;
private static final int ALIGN_FRAMES = 54;
private static final int FLOAT_FIGURES = 55;
private static final int FLOAT_TABLES = 56;
private static final int FLOAT_OPTIONS = 57;
private static final int FIGURE_SEQUENCE_NAME = 58;
private static final int TABLE_SEQUENCE_NAME = 59;
private static final int IMAGE_OPTIONS = 60;
private static final int REMOVE_GRAPHICS_EXTENSION = 61;
private static final int ORIGINAL_IMAGE_SIZE = 62;
private static final int SIMPLE_TABLE_LIMIT = 63;
private static final int NOTES = 64;
private static final int METADATA = 65;
private static final int TABSTOP = 66;
private static final int WRAP_LINES_AFTER = 67;
private static final int SPLIT_LINKED_SECTIONS = 68;
private static final int SPLIT_TOPLEVEL_SECTIONS = 69;
private static final int SAVE_IMAGES_IN_SUBDIR = 70;
private static final int OLD_MATH_COLORS = 71;
private static final int DEBUG = 72;
/////////////////////////////////////////////////////////////////////////
// IV. Our options data
@ -254,6 +255,13 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
options[USE_BIBTEX] = new BooleanOption("use_bibtex","false");
options[BIBTEX_STYLE] = new Option("bibtex_style","plain");
options[EXTERNAL_BIBTEX_FILES] = new Option("external_bibtex_files","");
options[BIBTEX_ENCODING] = new IntegerOption("bibtex_encoding","document") {
public void setString(String sValue) {
super.setString(sValue);
if ("document".equals(sValue)) { nValue = -1; }
else { nValue = ClassicI18n.readInputenc(sValue); }
}
};
options[ZOTERO_BIBTEX_FILES] = new Option("zotero_bibtex_files","");
options[JABREF_BIBTEX_FILES] = new Option("jabref_bibtex_files","");
options[INCLUDE_ORIGINAL_CITATIONS] = new BooleanOption("include_original_citations","false");
@ -683,6 +691,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
public boolean useBibtex() { return ((BooleanOption) options[USE_BIBTEX]).getValue(); }
public String bibtexStyle() { return options[BIBTEX_STYLE].getString(); }
public String externalBibtexFiles() { return options[EXTERNAL_BIBTEX_FILES].getString(); }
public int getBibtexEncoding() { return ((IntegerOption) options[BIBTEX_ENCODING]).getValue(); }
public String zoteroBibtexFiles() { return options[ZOTERO_BIBTEX_FILES].getString(); }
public String jabrefBibtexFiles() { return options[JABREF_BIBTEX_FILES].getString(); }
public boolean includeOriginalCitations() { return ((BooleanOption) options[INCLUDE_ORIGINAL_CITATIONS]).getValue(); }

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-06-16)
* Version 1.6 (2015-07-23)
*
*/
package writer2latex.xhtml;
@ -61,6 +61,8 @@ final class IndexData {
*/
class TOCConverter extends IndexConverterHelper {
private static final String TOC_LINK_PREFIX = "toc";
private List<IndexData> indexes = new ArrayList<IndexData>(); // All tables of content
private List<TocEntry> tocEntries = new ArrayList<TocEntry>(); // All potential(!) toc items
private int nTocFileIndex = -1; // file index for main toc
@ -94,7 +96,7 @@ class TOCConverter extends IndexConverterHelper {
*/
void handleHeading(Element onode, Element heading, String sLabel) {
int nLevel = getTextCv().getOutlineLevel(onode);
String sTarget = "toc"+(++nTocIndex);
String sTarget = TOC_LINK_PREFIX+(++nTocIndex);
converter.addTarget(heading,sTarget);
this.currentChapter = onode;
@ -126,7 +128,7 @@ class TOCConverter extends IndexConverterHelper {
if (nLevel>config.getXhtmlSplitLevel()) {
Element div = converter.createElement("div");
hnode.appendChild(div);
sTarget = "toc"+(++nTocIndex);
sTarget = TOC_LINK_PREFIX+(++nTocIndex);
converter.addTarget(div,sTarget);
}
converter.addContentEntry(sLabel+converter.getPlainInlineText(onode), nLevel, sTarget);
@ -136,7 +138,7 @@ class TOCConverter extends IndexConverterHelper {
void handleParagraph(Element onode, Element par, String sCurrentListLabel) {
String sStyleName = Misc.getAttribute(onode,XMLString.TEXT_STYLE_NAME);
if (ofr.isIndexSourceStyle(getParSc().getRealParStyleName(sStyleName))) {
converter.addTarget(par,"toc"+(++nTocIndex));
converter.addTarget(par,TOC_LINK_PREFIX+(++nTocIndex));
TocEntry entry = new TocEntry();
entry.onode = (Element) onode;
entry.sLabel = sCurrentListLabel;
@ -151,7 +153,7 @@ class TOCConverter extends IndexConverterHelper {
* @param hnode the link target will be added to this inline HTML node
*/
void handleTocMark(Node onode, Node hnode) {
hnode.appendChild(converter.createTarget("toc"+(++nTocIndex)));
hnode.appendChild(converter.createTarget(TOC_LINK_PREFIX+(++nTocIndex)));
TocEntry entry = new TocEntry();
entry.onode = (Element) onode;
entry.nFileIndex = converter.getOutFileIndex();
@ -243,7 +245,7 @@ class TOCConverter extends IndexConverterHelper {
span.setAttribute("class","SectionNumber");
span.appendChild(converter.createTextNode(entry.sLabel));
}
Element a = converter.createLink("toc"+i);
Element a = converter.createLink(TOC_LINK_PREFIX+i);
p.appendChild(a);
getTextCv().traverseInlineText(entry.onode,a);
}
@ -255,7 +257,7 @@ class TOCConverter extends IndexConverterHelper {
if (entry.sLabel!=null) {
p.appendChild(converter.createTextNode(entry.sLabel));
}
Element a = converter.createLink("toc"+i);
Element a = converter.createLink(TOC_LINK_PREFIX+i);
p.appendChild(a);
getTextCv().traverseInlineText(entry.onode,a);
}
@ -269,7 +271,7 @@ class TOCConverter extends IndexConverterHelper {
if (entry.sLabel!=null) {
p.appendChild(converter.createTextNode(entry.sLabel));
}
Element a = converter.createLink("toc"+i);
Element a = converter.createLink(TOC_LINK_PREFIX+i);
p.appendChild(a);
getTextCv().traverseInlineText(entry.onode,a);
}
@ -278,7 +280,7 @@ class TOCConverter extends IndexConverterHelper {
int nLevel = Misc.getPosInteger(entry.onode.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1);
if (tocReader.useIndexMarks() && nLevel<=tocReader.getOutlineLevel()) {
Element p = getTextCv().createParagraph(li,sEntryStyleName[nLevel]);
Element a = converter.createLink("toc"+i);
Element a = converter.createLink(TOC_LINK_PREFIX+i);
p.appendChild(a);
a.appendChild(converter.createTextNode(IndexMark.getIndexValue(entry.onode)));
}
@ -287,7 +289,7 @@ class TOCConverter extends IndexConverterHelper {
int nLevel = Misc.getPosInteger(entry.onode.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1);
if (tocReader.useIndexMarks() && nLevel<=tocReader.getOutlineLevel()) {
Element p = getTextCv().createParagraph(li,sEntryStyleName[nLevel]);
Element a = converter.createLink("toc"+i);
Element a = converter.createLink(TOC_LINK_PREFIX+i);
p.appendChild(a);
a.appendChild(converter.createTextNode(IndexMark.getIndexValue(entry.onode)));
}
@ -353,7 +355,7 @@ class TOCConverter extends IndexConverterHelper {
String sNodeName = entry.onode.getTagName();
if (XMLString.TEXT_H.equals(sNodeName)) {
// Determine wether or not to include this heading
// Determine whether or not to include this heading
// Note that this condition misses the case where
// a heading of level n is followed by a heading of
// level n+2. This is considered a bug in the document!

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-06-16)
* Version 1.6 (2015-07-23)
*
*/
@ -50,7 +50,7 @@ public class TextConverter extends ConverterHelper {
// TODO: Accessor methods for sections
// Some (Sony?) EPUB readers have a limit on the file size of individual files
// In any case very large files could be a performance problem, hence we do automatic splitting
// after this number of characters. TODO: Make configurable.
// after this number of characters.
private int nSplitAfter = 150000;
private int nPageBreakSplit = XhtmlConfig.NONE; // Should we split at page breaks?
// TODO: Collect soft page breaks between table rows