More math and TexMaths work
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@160 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
79ae252419
commit
3dff4f20b4
15 changed files with 514 additions and 525 deletions
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-04-07)
|
||||
* Version 1.4 (2014-08-13)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -351,7 +351,7 @@ public class Converter extends ConverterBase {
|
|||
|
||||
// Load MathJax
|
||||
// TODO: Should we support different configurations of MathJax?
|
||||
if (nType==XhtmlDocument.HTML5 && config.useMathJax()) {
|
||||
if ((nType==XhtmlDocument.HTML5 || nType==XhtmlDocument.XHTML_MATHML) && config.useMathJax()) {
|
||||
for (int i=0; i<=nOutFileIndex; i++) {
|
||||
if (outFiles.get(i).hasMath()) {
|
||||
XhtmlDocument doc = outFiles.get(i);
|
||||
|
@ -360,7 +360,7 @@ public class Converter extends ConverterBase {
|
|||
Element script = doc.getContentDOM().createElement("script");
|
||||
head.appendChild(script);
|
||||
script.setAttribute("type", "text/javascript");
|
||||
script.setAttribute("src", "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML");
|
||||
script.setAttribute("src", "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-03-30)
|
||||
* Version 1.4 (2014-08-13)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class ConverterHelper {
|
|||
protected PresentationStyleConverter getPresentationSc() { return converter.getStyleCv().getPresentationSc(); }
|
||||
|
||||
protected PageStyleConverter getPageSc() { return converter.getStyleCv().getPageSc(); }
|
||||
|
||||
|
||||
protected TextConverter getTextCv() { return converter.getTextCv(); }
|
||||
|
||||
protected TableConverter getTableCv() { return converter.getTableCv(); }
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-04-07)
|
||||
* Version 1.4 (2014-08-12)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -331,16 +331,22 @@ public class DrawConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
else if (sName.equals(XMLString.DRAW_FRAME)) {
|
||||
// OpenDocument embeds the draw element in a frame element
|
||||
handleDrawElement(Misc.getFirstChildElement(onode),hnodeBlock,hnodeInline,nMode);
|
||||
// First check for TexMaths equation
|
||||
if (!getMathCv().convertTexMathsEquation(onode, hnodeBlock, hnodeInline, nMode)) {
|
||||
// OpenDocument embeds the draw element in a frame element
|
||||
handleDrawElement(Misc.getFirstChildElement(onode),hnodeBlock,hnodeInline,nMode);
|
||||
}
|
||||
}
|
||||
else if (sName.equals(XMLString.DRAW_G)) {
|
||||
handleDrawGroup(onode,hnodeBlock,hnodeInline,nMode);
|
||||
// First check for TexMaths equation
|
||||
if (!getMathCv().convertTexMathsEquation(onode, hnodeBlock, hnodeInline, nMode)) {
|
||||
handleDrawGroup(onode,hnodeBlock,hnodeInline,nMode);
|
||||
}
|
||||
}
|
||||
else if (sName.equals(XMLString.DRAW_CONTROL)) {
|
||||
handleDrawControl(onode,hnodeBlock,hnodeInline,nMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDrawObject(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {
|
||||
// TODO: Placement if not inline
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-04-07)
|
||||
* Version 1.4 (2014-08-13)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -72,9 +72,6 @@ public class MathConverter extends ConverterHelper {
|
|||
*/
|
||||
public void convert(Node image, Element onode, Node hnode) {
|
||||
if (bSupportMathML) {
|
||||
if (converter.getTextCv().isDisplayEquation()) {
|
||||
onode.setAttribute("display", "block");
|
||||
}
|
||||
convertAsMathML(onode,hnode);
|
||||
}
|
||||
else {
|
||||
|
@ -82,6 +79,57 @@ public class MathConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean convertTexMathsEquation(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {
|
||||
// If possible, add the object inline. In pure block context, add a div.
|
||||
Element hnode;
|
||||
if (hnodeInline!=null) {
|
||||
hnode = hnodeInline;
|
||||
}
|
||||
else {
|
||||
Element div = converter.createElement("div");
|
||||
hnodeBlock.appendChild(div);
|
||||
hnode = div;
|
||||
}
|
||||
|
||||
String sLaTeX = null;
|
||||
Element equation = converter.getTexMathsEquation(onode);
|
||||
if (equation!=null) {
|
||||
sLaTeX = Misc.getPCDATA(equation);
|
||||
}
|
||||
else { // Try OOoLaTeX
|
||||
// The LaTeX code is embedded in a custom style attribute:
|
||||
StyleWithProperties style = ofr.getFrameStyle(Misc.getAttribute(onode, XMLString.DRAW_STYLE_NAME));
|
||||
if (style!=null) {
|
||||
sLaTeX = style.getProperty("OOoLatexArgs");
|
||||
}
|
||||
}
|
||||
if (sLaTeX!=null) {
|
||||
// Format is <point size>X<mode>X<TeX code>X<format>X<resolution>X<transparency>
|
||||
// where X is a paragraph sign
|
||||
String sMathJax;
|
||||
if (config.useMathJax() && bSupportMathML) {
|
||||
switch (converter.getTexMathsStyle(sLaTeX)) {
|
||||
case inline:
|
||||
sMathJax = "\\("+converter.getTexMathsEquation(sLaTeX)+"\\)";
|
||||
break;
|
||||
case display:
|
||||
sMathJax = "\\["+converter.getTexMathsEquation(sLaTeX)+"\\]";
|
||||
break;
|
||||
case latex:
|
||||
default: // Arbitrary LaTeX; this is the tricky bit
|
||||
sMathJax = "\\("+converter.getTexMathsEquation(sLaTeX)+"\\)";
|
||||
}
|
||||
}
|
||||
else {
|
||||
sMathJax = " "+converter.getTexMathsEquation(sLaTeX)+" ";
|
||||
}
|
||||
hnode.appendChild(converter.createTextNode(sMathJax));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// For plain xhtml: Convert the formula as an image or as plain text
|
||||
private void convertAsImageOrText(Node image, Node onode, Node hnode) {
|
||||
NodeList annotationList = ((Element) onode).getElementsByTagName(XMLString.ANNOTATION); // Since OOo 3.2
|
||||
|
|
|
@ -16,18 +16,16 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2011-02-17)
|
||||
* Version 1.4 (2014-08-13)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.xhtml;
|
||||
|
||||
//import java.util.Enumeration;
|
||||
//import java.util.Hashtable;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -64,7 +62,7 @@ class StyleConverter extends ConverterHelper {
|
|||
|
||||
// Helper for page styles
|
||||
private PageStyleConverter pageSc;
|
||||
|
||||
|
||||
/** <p>Create a new <code>StyleConverter</code></p>
|
||||
*/
|
||||
public StyleConverter(OfficeReader ofr, XhtmlConfig config, Converter converter, int nType) {
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-04-07)
|
||||
* Version 1.4 (2014-08-13)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -141,9 +141,6 @@ public class TextConverter extends ConverterHelper {
|
|||
// We put it here and insert it in the first paragraph/heading to come:
|
||||
private Node asapNode = null;
|
||||
|
||||
// Are we within a display equation?
|
||||
private boolean bDisplayEquation = false;
|
||||
|
||||
// When generating toc, a few things should be done differently
|
||||
private boolean bInToc = false;
|
||||
|
||||
|
@ -361,10 +358,6 @@ public class TextConverter extends ConverterHelper {
|
|||
return inline;
|
||||
}
|
||||
|
||||
public boolean isDisplayEquation() {
|
||||
return bDisplayEquation;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// BLOCK TEXT (returns current html node at end of block)
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -820,9 +813,7 @@ public class TextConverter extends ConverterHelper {
|
|||
insertListLabel(currentListStyle, nCurrentListLevel, "ItemNumber", null, sCurrentListLabel, par);
|
||||
}
|
||||
sCurrentListLabel = null;
|
||||
bDisplayEquation=converter.parseDisplayEquation(onode);
|
||||
traverseInlineText(onode,par);
|
||||
bDisplayEquation=false;
|
||||
}
|
||||
else {
|
||||
// An empty paragraph (this includes paragraphs that only contains
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue