def xquote(nd): p = getap(nd) pr = p.find('.//'+NSW+'pPr') if pr==None: pr = etree.SubElement(p, NSW+'pPr') ind = etree.SubElement(pr, NSW+'ind') ind.set(NSW+'left','420') ind.set(NSW+'right','420') else: ind = pr.find('.//'+NSW+'ind') if ind == None: ind = etree.SubElement(pr, NSW+'ind') ind.set(NSW+'left','420') ind.set(NSW+'right','420') else: left = ind.get(NSW+'left') if left == None: left = '420' else: left = str(int(left)+420) ind.set(NSW+'left',left) right = ind.get(NSW+'right') if right == None: right = '420' else: right = str(int(right)+420) ind.set(NSW+'right',right) setap(nd, p) ct.cnl(nd)
def xquote(nd): p = getap(nd) pr = p.find('.//' + NSW + 'pPr') if pr == None: pr = etree.SubElement(p, NSW + 'pPr') ind = etree.SubElement(pr, NSW + 'ind') ind.set(NSW + 'left', '420') ind.set(NSW + 'right', '420') else: ind = pr.find('.//' + NSW + 'ind') if ind == None: ind = etree.SubElement(pr, NSW + 'ind') ind.set(NSW + 'left', '420') ind.set(NSW + 'right', '420') else: left = ind.get(NSW + 'left') if left == None: left = '420' else: left = str(int(left) + 420) ind.set(NSW + 'left', left) right = ind.get(NSW + 'right') if right == None: right = '420' else: right = str(int(right) + 420) ind.set(NSW + 'right', right) setap(nd, p) ct.cnl(nd)
def xcaption(nd): p = getap(nd) s = nd.captionName.textContent + ' ' + nd.ref.textContent + ': ' r = txt.tr(s) p.append(r) setap(nd, p) ct.cnl(nd)
def xpar(nd): if nd.childNodes: if nd.firstChild.nodeName in { 'enumerate', 'itemize', 'equation', 'abstract', 'thebibliography', 'table', 'centering', 'tabular', 'center' }: setap(nd, getap(nd)) ct.cnl(nd) return else: return if mmf.isset(): setap(nd, getap(nd)) ct.cnl(nd) return if nd.parentNode.nodeName == 'item': enum.itempar(nd) return p = etree.Element(NSW + 'p') setAlign(p) setx(nd, p, p) npf.clear() ct.cnl(nd) if npf.isset(): getap(nd).append(p)
def xpar(nd): if nd.childNodes: if nd.firstChild.nodeName in {'enumerate', 'itemize', 'equation', 'abstract', 'thebibliography', 'table', 'centering', 'tabular', 'center'}: setap(nd, getap(nd)) ct.cnl(nd) return else: return if mmf.isset(): setap(nd, getap(nd)) ct.cnl(nd) return if nd.parentNode.nodeName=='item': enum.itempar(nd) return p = etree.Element(NSW+'p') setAlign(p) setx(nd, p, p) npf.clear() ct.cnl(nd) if npf.isset(): getap(nd).append(p)
def xbgroup(nd): rif.push() rif.clear() rbf.push() rbf.clear() setap(nd, getap(nd)) ct.cnl(nd) rbf.pop() rif.pop()
def limlow(nd, s): ll = etree.Element(NSM + "limLow") e = etree.SubElement(ll, NSM + "e") e.append(txt.pmtr(s)) l = etree.SubElement(ll, NSM + "lim") getap(nd).append(ll) ns = nd.nextSibling if ns.nodeName == "active::_": setap(ns, l) ct.cnl(ns) nd.parentNode.removeChild(ns)
def limlow(nd, s): ll = etree.Element(NSM + 'limLow') e = etree.SubElement(ll, NSM + 'e') e.append(txt.pmtr(s)) l = etree.SubElement(ll, NSM + 'lim') getap(nd).append(ll) ns = nd.nextSibling if ns.nodeName == 'active::_': setap(ns, l) ct.cnl(ns) nd.parentNode.removeChild(ns)
def xmath(nd): mmf.push() mmf.set() if ntf.isset(): ntf.push() ntf.clear() setap(nd, getap(nd)) ct.cnl(nd) ntf.pop() else: e = etree.Element(NSM + "oMath") setx(nd, e, e) ct.cnl(nd) getap(nd).append(e) mmf.pop()
def xmath(nd): mmf.push() mmf.set() if ntf.isset(): ntf.push() ntf.clear() setap(nd, getap(nd)) ct.cnl(nd) ntf.pop() else: e = etree.Element(NSM + 'oMath') setx(nd, e, e) ct.cnl(nd) getap(nd).append(e) mmf.pop()
def xthanks(nd): def fr(sr): r = etree.Element(NSW+'r') rpr = etree.SubElement(r, NSW+'rPr') rs = etree.SubElement(rpr, NSW+'rStyle') rs.set(NSW+'val', 'sup') fr = etree.SubElement(r, NSW+sr) fr.set(NSW+'id', i) return r i = nd.id[1:] f = etree.Element(NSW+'footnote') f.set(NSW+'id', i) p = etree.SubElement(f, NSW+'p') setap(nd, p) p.append(fr('footnoteRef')) ct.cnl(nd) getap(nd).append(fr('footnoteReference')) docx.Footnotes.append(f)
def xthanks(nd): def fr(sr): r = etree.Element(NSW + 'r') rpr = etree.SubElement(r, NSW + 'rPr') rs = etree.SubElement(rpr, NSW + 'rStyle') rs.set(NSW + 'val', 'sup') fr = etree.SubElement(r, NSW + sr) fr.set(NSW + 'id', i) return r i = nd.id[1:] f = etree.Element(NSW + 'footnote') f.set(NSW + 'id', i) p = etree.SubElement(f, NSW + 'p') setap(nd, p) p.append(fr('footnoteRef')) ct.cnl(nd) getap(nd).append(fr('footnoteReference')) docx.Footnotes.append(f)
def xtheorem(nd): cap = nd.caption p = etree.Element(NSW+'p') setap(cap, p) rbf.push() rbf.set() ct.cnl(cap) p.append(txt.tr(' '+nd.ref.textContent)) rbf.pop() rif.push() rif.set() i = 1 if nd.childNodes[0].firstChild.nodeName == 'displaymath': i = 0 else: setap(nd.childNodes[0], p) ct.cnl(nd.childNodes[0]) np = getap(nd.parentNode) setap(nd, np) np.append(p) for par in nd.childNodes[i:]: ct.cnd(par) rif.pop() npf.clear()
def xtheorem(nd): cap = nd.caption p = etree.Element(NSW + 'p') setap(cap, p) rbf.push() rbf.set() ct.cnl(cap) p.append(txt.tr(' ' + nd.ref.textContent)) rbf.pop() rif.push() rif.set() i = 1 if nd.childNodes[0].firstChild.nodeName == 'displaymath': i = 0 else: setap(nd.childNodes[0], p) ct.cnl(nd.childNodes[0]) np = getap(nd.parentNode) setap(nd, np) np.append(p) for par in nd.childNodes[i:]: ct.cnd(par) rif.pop() npf.clear()
def narg(nd, char): n = etree.Element(NSM + "nary") getap(nd).append(n) np = etree.SubElement(n, NSM + "naryPr") ch = etree.SubElement(np, NSM + "chr") ch.set(NSM + "val", char) subHide = etree.SubElement(np, NSM + "subHide") subHide.set(NSM + "val", "1") supHide = etree.SubElement(np, NSM + "supHide") supHide.set(NSM + "val", "1") e = etree.SubElement(n, NSM + "e") d = nd.ownerDocument.createDocumentFragment() setap(d, e) ns = nd.nextSibling try: for x in range(0, 2): if ns.nodeName == "active::_": s = etree.SubElement(n, NSM + "sub") subHide.set(NSM + "val", "0") setap(ns, s) ct.cnl(ns) elif ns.nodeName == "active::^": s = etree.SubElement(n, NSM + "sup") supHide.set(NSM + "val", "0") setap(ns, s) ct.cnl(ns) else: while ns is not None: d.appendChild(ns) nd.parentNode.removeChild(ns) ns = nd.nextSibling ct.cnl(d) return nd.parentNode.removeChild(ns) ns = nd.nextSibling if nd.nodeType == 3 and ns.isspace(): nd.parentNode.removeChild(ns) ns = nd.nextSibling while ns is not None: d.appendChild(ns) nd.parentNode.removeChild(ns) ns = nd.nextSibling ct.cnl(d) return except AttributeError: return
def narg(nd, char): n = etree.Element(NSM + 'nary') getap(nd).append(n) np = etree.SubElement(n, NSM + 'naryPr') ch = etree.SubElement(np, NSM + 'chr') ch.set(NSM + 'val', char) subHide = etree.SubElement(np, NSM + 'subHide') subHide.set(NSM + 'val', '1') supHide = etree.SubElement(np, NSM + 'supHide') supHide.set(NSM + 'val', '1') e = etree.SubElement(n, NSM + 'e') d = nd.ownerDocument.createDocumentFragment() setap(d, e) ns = nd.nextSibling try: for x in range(0, 2): if ns.nodeName == 'active::_': s = etree.SubElement(n, NSM + 'sub') subHide.set(NSM + 'val', '0') setap(ns, s) ct.cnl(ns) elif ns.nodeName == 'active::^': s = etree.SubElement(n, NSM + 'sup') supHide.set(NSM + 'val', '0') setap(ns, s) ct.cnl(ns) else: while ns is not None: d.appendChild(ns) nd.parentNode.removeChild(ns) ns = nd.nextSibling ct.cnl(d) return nd.parentNode.removeChild(ns) ns = nd.nextSibling if nd.nodeType == 3 and ns.isspace(): nd.parentNode.removeChild(ns) ns = nd.nextSibling while ns is not None: d.appendChild(ns) nd.parentNode.removeChild(ns) ns = nd.nextSibling ct.cnl(d) return except AttributeError: return
def xitem(nd): setap(nd, getap(nd)) ct.cnl(nd)
def xtext(nd): ntf.push() ntf.set() setap(nd, getap(nd)) ct.cnl(nd) ntf.pop()
def xbibitem(nd): p = etree.Element(NSW + 'p') p.append(txt.tr('[' + nd.bibcite.childNodes[0] + '] ')) setap(nd.firstChild, p) ct.cnl(nd.firstChild) getap(nd).append(p)
def xem(nd): rif.set() setap(nd, getap(nd)) ct.cnl(nd) rif.clear()
def xcite(nd): f = nd.citation() setap(f, getap(nd)) ct.cnl(f)
def xtexttt(nd): ttf.set() setap(nd, getap(nd)) ct.cnl(nd) ttf.clear()
def xbibitem(nd): p = etree.Element(NSW+'p') p.append(txt.tr('['+nd.bibcite.childNodes[0]+'] ')) setap(nd.firstChild, p) ct.cnl(nd.firstChild) getap(nd).append(p)
def xbf(nd): rbf.set() setap(nd, getap(nd)) ct.cnl(nd) rbf.clear()