markitdown-gc 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. markitdown/GUIDE.md +93 -0
  2. markitdown/__about__.py +4 -0
  3. markitdown/__init__.py +34 -0
  4. markitdown/__main__.py +439 -0
  5. markitdown/_base_converter.py +109 -0
  6. markitdown/_exceptions.py +82 -0
  7. markitdown/_hwp_media.py +132 -0
  8. markitdown/_markitdown.py +861 -0
  9. markitdown/_media.py +67 -0
  10. markitdown/_stream_info.py +32 -0
  11. markitdown/_uri_utils.py +75 -0
  12. markitdown/converter_utils/__init__.py +0 -0
  13. markitdown/converter_utils/_image.py +19 -0
  14. markitdown/converter_utils/_xlsx_images.py +114 -0
  15. markitdown/converter_utils/docx/__init__.py +0 -0
  16. markitdown/converter_utils/docx/_images.py +118 -0
  17. markitdown/converter_utils/docx/math/__init__.py +0 -0
  18. markitdown/converter_utils/docx/math/latex_dict.py +291 -0
  19. markitdown/converter_utils/docx/math/omml.py +417 -0
  20. markitdown/converter_utils/docx/pre_process.py +290 -0
  21. markitdown/converters/__init__.py +56 -0
  22. markitdown/converters/_audio_converter.py +106 -0
  23. markitdown/converters/_bing_serp_converter.py +120 -0
  24. markitdown/converters/_csv_converter.py +133 -0
  25. markitdown/converters/_cu_converter.py +570 -0
  26. markitdown/converters/_doc_intel_converter.py +258 -0
  27. markitdown/converters/_docx_converter.py +163 -0
  28. markitdown/converters/_epub_converter.py +185 -0
  29. markitdown/converters/_exiftool.py +57 -0
  30. markitdown/converters/_html_converter.py +112 -0
  31. markitdown/converters/_hwp_converter.py +105 -0
  32. markitdown/converters/_image_converter.py +139 -0
  33. markitdown/converters/_ipynb_converter.py +103 -0
  34. markitdown/converters/_llm_caption.py +50 -0
  35. markitdown/converters/_markdownify.py +178 -0
  36. markitdown/converters/_outlook_msg_converter.py +349 -0
  37. markitdown/converters/_pdf_converter.py +593 -0
  38. markitdown/converters/_plain_text_converter.py +66 -0
  39. markitdown/converters/_pptx_converter.py +387 -0
  40. markitdown/converters/_rss_converter.py +488 -0
  41. markitdown/converters/_transcribe_audio.py +60 -0
  42. markitdown/converters/_wikipedia_converter.py +99 -0
  43. markitdown/converters/_xlsx_converter.py +279 -0
  44. markitdown/converters/_youtube_converter.py +256 -0
  45. markitdown/converters/_zip_converter.py +130 -0
  46. markitdown/ocr_triage.py +943 -0
  47. markitdown/py.typed +0 -0
  48. markitdown_gc-0.2.0.dist-info/METADATA +137 -0
  49. markitdown_gc-0.2.0.dist-info/RECORD +53 -0
  50. markitdown_gc-0.2.0.dist-info/WHEEL +4 -0
  51. markitdown_gc-0.2.0.dist-info/entry_points.txt +2 -0
  52. markitdown_gc-0.2.0.dist-info/licenses/LICENSE +21 -0
  53. markitdown_gc-0.2.0.dist-info/licenses/ThirdPartyNotices.md +232 -0
@@ -0,0 +1,291 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Adapted from https://github.com/xiilei/dwml/blob/master/dwml/latex_dict.py
5
+ On 25/03/2025
6
+ """
7
+
8
+ from __future__ import unicode_literals
9
+
10
+ CHARS = ("{", "}", "_", "^", "#", "&", "$", "%", "~")
11
+
12
+ BLANK = ""
13
+ BACKSLASH = "\\"
14
+ ALN = "&"
15
+
16
+ CHR = {
17
+ # Unicode : Latex Math Symbols
18
+ # Top accents
19
+ "\u0300": "\\grave{{{0}}}",
20
+ "\u0301": "\\acute{{{0}}}",
21
+ "\u0302": "\\hat{{{0}}}",
22
+ "\u0303": "\\tilde{{{0}}}",
23
+ "\u0304": "\\bar{{{0}}}",
24
+ "\u0305": "\\overbar{{{0}}}",
25
+ "\u0306": "\\breve{{{0}}}",
26
+ "\u0307": "\\dot{{{0}}}",
27
+ "\u0308": "\\ddot{{{0}}}",
28
+ "\u0309": "\\ovhook{{{0}}}",
29
+ "\u030a": "\\ocirc{{{0}}}",
30
+ "\u030c": "\\check{{{0}}}",
31
+ "\u0310": "\\candra{{{0}}}",
32
+ "\u0312": "\\oturnedcomma{{{0}}}",
33
+ "\u0315": "\\ocommatopright{{{0}}}",
34
+ "\u031a": "\\droang{{{0}}}",
35
+ "\u0338": "\\not{{{0}}}",
36
+ "\u20d0": "\\leftharpoonaccent{{{0}}}",
37
+ "\u20d1": "\\rightharpoonaccent{{{0}}}",
38
+ "\u20d2": "\\vertoverlay{{{0}}}",
39
+ "\u20d6": "\\overleftarrow{{{0}}}",
40
+ "\u20d7": "\\vec{{{0}}}",
41
+ "\u20db": "\\dddot{{{0}}}",
42
+ "\u20dc": "\\ddddot{{{0}}}",
43
+ "\u20e1": "\\overleftrightarrow{{{0}}}",
44
+ "\u20e7": "\\annuity{{{0}}}",
45
+ "\u20e9": "\\widebridgeabove{{{0}}}",
46
+ "\u20f0": "\\asteraccent{{{0}}}",
47
+ # Bottom accents
48
+ "\u0330": "\\wideutilde{{{0}}}",
49
+ "\u0331": "\\underbar{{{0}}}",
50
+ "\u20e8": "\\threeunderdot{{{0}}}",
51
+ "\u20ec": "\\underrightharpoondown{{{0}}}",
52
+ "\u20ed": "\\underleftharpoondown{{{0}}}",
53
+ "\u20ee": "\\underleftarrow{{{0}}}",
54
+ "\u20ef": "\\underrightarrow{{{0}}}",
55
+ # Over | group
56
+ "\u23b4": "\\overbracket{{{0}}}",
57
+ "\u23dc": "\\overparen{{{0}}}",
58
+ "\u23de": "\\overbrace{{{0}}}",
59
+ # Under| group
60
+ "\u23b5": "\\underbracket{{{0}}}",
61
+ "\u23dd": "\\underparen{{{0}}}",
62
+ "\u23df": "\\underbrace{{{0}}}",
63
+ }
64
+
65
+ CHR_BO = {
66
+ # Big operators,
67
+ "\u2140": "\\Bbbsum",
68
+ "\u220f": "\\prod",
69
+ "\u2210": "\\coprod",
70
+ "\u2211": "\\sum",
71
+ "\u222b": "\\int",
72
+ "\u22c0": "\\bigwedge",
73
+ "\u22c1": "\\bigvee",
74
+ "\u22c2": "\\bigcap",
75
+ "\u22c3": "\\bigcup",
76
+ "\u2a00": "\\bigodot",
77
+ "\u2a01": "\\bigoplus",
78
+ "\u2a02": "\\bigotimes",
79
+ }
80
+
81
+ T = {
82
+ # Greek letters
83
+ "\U0001d6fc": "\\alpha ",
84
+ "\U0001d6fd": "\\beta ",
85
+ "\U0001d6fe": "\\gamma ",
86
+ "\U0001d6ff": "\\delta ",
87
+ "\U0001d700": "\\epsilon ",
88
+ "\U0001d701": "\\zeta ",
89
+ "\U0001d702": "\\eta ",
90
+ "\U0001d703": "\\theta ",
91
+ "\U0001d704": "\\iota ",
92
+ "\U0001d705": "\\kappa ",
93
+ "\U0001d706": "\\lambda ",
94
+ "\U0001d707": "\\mu ",
95
+ "\U0001d708": "\\nu ",
96
+ "\U0001d709": "\\xi ",
97
+ "\U0001d70a": "\\omicron ",
98
+ "\U0001d70b": "\\pi ",
99
+ "\U0001d70c": "\\rho ",
100
+ "\U0001d70d": "\\varsigma ",
101
+ "\U0001d70e": "\\sigma ",
102
+ "\U0001d70f": "\\tau ",
103
+ "\U0001d710": "\\upsilon ",
104
+ "\U0001d711": "\\phi ",
105
+ "\U0001d712": "\\chi ",
106
+ "\U0001d713": "\\psi ",
107
+ "\U0001d714": "\\omega ",
108
+ "\U0001d715": "\\partial ",
109
+ "\U0001d716": "\\varepsilon ",
110
+ "\U0001d717": "\\vartheta ",
111
+ "\U0001d718": "\\varkappa ",
112
+ "\U0001d719": "\\varphi ",
113
+ "\U0001d71a": "\\varrho ",
114
+ "\U0001d71b": "\\varpi ",
115
+ # Relation symbols
116
+ "\u2190": "\\leftarrow ",
117
+ "\u2191": "\\uparrow ",
118
+ "\u2192": "\\rightarrow ",
119
+ "\u2193": "\\downarrow ",
120
+ "\u2194": "\\leftrightarrow ",
121
+ "\u2195": "\\updownarrow ",
122
+ "\u2196": "\\nwarrow ",
123
+ "\u2197": "\\nearrow ",
124
+ "\u2198": "\\searrow ",
125
+ "\u2199": "\\swarrow ",
126
+ "\u22ee": "\\vdots ",
127
+ "\u22ef": "\\cdots ",
128
+ "\u22f0": "\\adots ",
129
+ "\u22f1": "\\ddots ",
130
+ "\u2260": "\\ne ",
131
+ "\u2264": "\\leq ",
132
+ "\u2265": "\\geq ",
133
+ "\u2266": "\\leqq ",
134
+ "\u2267": "\\geqq ",
135
+ "\u2268": "\\lneqq ",
136
+ "\u2269": "\\gneqq ",
137
+ "\u226a": "\\ll ",
138
+ "\u226b": "\\gg ",
139
+ "\u2208": "\\in ",
140
+ "\u2209": "\\notin ",
141
+ "\u220b": "\\ni ",
142
+ "\u220c": "\\nni ",
143
+ # Ordinary symbols
144
+ "\u221e": "\\infty ",
145
+ # Binary relations
146
+ "\u00b1": "\\pm ",
147
+ "\u2213": "\\mp ",
148
+ # Italic, Latin, uppercase
149
+ "\U0001d434": "A",
150
+ "\U0001d435": "B",
151
+ "\U0001d436": "C",
152
+ "\U0001d437": "D",
153
+ "\U0001d438": "E",
154
+ "\U0001d439": "F",
155
+ "\U0001d43a": "G",
156
+ "\U0001d43b": "H",
157
+ "\U0001d43c": "I",
158
+ "\U0001d43d": "J",
159
+ "\U0001d43e": "K",
160
+ "\U0001d43f": "L",
161
+ "\U0001d440": "M",
162
+ "\U0001d441": "N",
163
+ "\U0001d442": "O",
164
+ "\U0001d443": "P",
165
+ "\U0001d444": "Q",
166
+ "\U0001d445": "R",
167
+ "\U0001d446": "S",
168
+ "\U0001d447": "T",
169
+ "\U0001d448": "U",
170
+ "\U0001d449": "V",
171
+ "\U0001d44a": "W",
172
+ "\U0001d44b": "X",
173
+ "\U0001d44c": "Y",
174
+ "\U0001d44d": "Z",
175
+ # Italic, Latin, lowercase
176
+ "\U0001d44e": "a",
177
+ "\U0001d44f": "b",
178
+ "\U0001d450": "c",
179
+ "\U0001d451": "d",
180
+ "\U0001d452": "e",
181
+ "\U0001d453": "f",
182
+ "\U0001d454": "g",
183
+ # U+1D455 is reserved: the math italic small h is unified with U+210E
184
+ "\u210e": "h",
185
+ "\U0001d456": "i",
186
+ "\U0001d457": "j",
187
+ "\U0001d458": "k",
188
+ "\U0001d459": "l",
189
+ "\U0001d45a": "m",
190
+ "\U0001d45b": "n",
191
+ "\U0001d45c": "o",
192
+ "\U0001d45d": "p",
193
+ "\U0001d45e": "q",
194
+ "\U0001d45f": "r",
195
+ "\U0001d460": "s",
196
+ "\U0001d461": "t",
197
+ "\U0001d462": "u",
198
+ "\U0001d463": "v",
199
+ "\U0001d464": "w",
200
+ "\U0001d465": "x",
201
+ "\U0001d466": "y",
202
+ "\U0001d467": "z",
203
+ }
204
+
205
+ FUNC = {
206
+ "sin": "\\sin({fe})",
207
+ "cos": "\\cos({fe})",
208
+ "tan": "\\tan({fe})",
209
+ "arcsin": "\\arcsin({fe})",
210
+ "arccos": "\\arccos({fe})",
211
+ "arctan": "\\arctan({fe})",
212
+ "arccot": "\\operatorname{arccot}({fe})",
213
+ "sinh": "\\sinh({fe})",
214
+ "cosh": "\\cosh({fe})",
215
+ "tanh": "\\tanh({fe})",
216
+ "coth": "\\coth({fe})",
217
+ "sec": "\\sec({fe})",
218
+ "csc": "\\csc({fe})",
219
+ "log": "\\log({fe})",
220
+ "ln": "\\ln({fe})",
221
+ "exp": "\\exp({fe})",
222
+ "det": "\\det({fe})",
223
+ "gcd": "\\gcd({fe})",
224
+ "lcm": "\\operatorname{lcm}({fe})",
225
+ "lim": "\\lim({fe})",
226
+ "max": "\\max({fe})",
227
+ "min": "\\min({fe})",
228
+ "sup": "\\sup({fe})",
229
+ "inf": "\\inf({fe})",
230
+ "dim": "\\dim({fe})",
231
+ "ker": "\\ker({fe})",
232
+ "hom": "\\hom({fe})",
233
+ "deg": "\\deg({fe})",
234
+ "arg": "\\arg({fe})",
235
+ }
236
+
237
+ FUNC_PLACE = "{fe}"
238
+
239
+ BRK = "\\\\"
240
+
241
+ CHR_DEFAULT = {
242
+ "ACC_VAL": "\\hat{{{0}}}",
243
+ "GROUP_CHR_VAL": "\\underbrace{{{0}}}",
244
+ }
245
+
246
+ POS = {
247
+ "top": "\\overline{{{0}}}", # not sure
248
+ "bot": "\\underline{{{0}}}",
249
+ }
250
+
251
+ POS_DEFAULT = {
252
+ "BAR_VAL": "\\overline{{{0}}}",
253
+ }
254
+
255
+ SUB = "_{{{0}}}"
256
+
257
+ SUP = "^{{{0}}}"
258
+
259
+ F = {
260
+ "bar": "\\frac{{{num}}}{{{den}}}",
261
+ "skw": r"^{{{num}}}/_{{{den}}}",
262
+ "noBar": "\\genfrac{{}}{{}}{{0pt}}{{}}{{{num}}}{{{den}}}",
263
+ "lin": "{{{num}}}/{{{den}}}",
264
+ }
265
+ F_DEFAULT = "\\frac{{{num}}}{{{den}}}"
266
+
267
+ D = "\\left{left}{text}\\right{right}"
268
+
269
+ D_DEFAULT = {
270
+ "left": "(",
271
+ "right": ")",
272
+ "null": ".",
273
+ }
274
+
275
+ RAD = "\\sqrt[{deg}]{{{text}}}"
276
+
277
+ RAD_DEFAULT = "\\sqrt{{{text}}}"
278
+
279
+ ARR = "\\begin{{array}}{{c}}{text}\\end{{array}}"
280
+
281
+ LIM_FUNC = {
282
+ "lim": "\\lim_{{{lim}}}",
283
+ "max": "\\max_{{{lim}}}",
284
+ "min": "\\min_{{{lim}}}",
285
+ }
286
+
287
+ LIM_TO = ("\\rightarrow", "\\to")
288
+
289
+ LIM_UPP = "\\overset{{{lim}}}{{{text}}}"
290
+
291
+ M = "\\begin{{matrix}}{text}\\end{{matrix}}"
@@ -0,0 +1,417 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Office Math Markup Language (OMML)
5
+ Adapted from https://github.com/xiilei/dwml/blob/master/dwml/omml.py
6
+ On 25/03/2025
7
+ """
8
+
9
+ from defusedxml import ElementTree as ET
10
+
11
+ from .latex_dict import (
12
+ CHARS,
13
+ CHR,
14
+ CHR_BO,
15
+ CHR_DEFAULT,
16
+ POS,
17
+ POS_DEFAULT,
18
+ SUB,
19
+ SUP,
20
+ F,
21
+ F_DEFAULT,
22
+ T,
23
+ FUNC,
24
+ D,
25
+ D_DEFAULT,
26
+ RAD,
27
+ RAD_DEFAULT,
28
+ ARR,
29
+ LIM_FUNC,
30
+ LIM_TO,
31
+ LIM_UPP,
32
+ M,
33
+ BRK,
34
+ BLANK,
35
+ BACKSLASH,
36
+ ALN,
37
+ FUNC_PLACE,
38
+ )
39
+
40
+ OMML_NS = "{http://schemas.openxmlformats.org/officeDocument/2006/math}"
41
+
42
+
43
+ def load(stream):
44
+ tree = ET.parse(stream)
45
+ for omath in tree.findall(OMML_NS + "oMath"):
46
+ yield oMath2Latex(omath)
47
+
48
+
49
+ def load_string(string):
50
+ root = ET.fromstring(string)
51
+ for omath in root.findall(OMML_NS + "oMath"):
52
+ yield oMath2Latex(omath)
53
+
54
+
55
+ def escape_latex(strs):
56
+ last = None
57
+ new_chr = []
58
+ strs = strs.replace(r"\\", "\\")
59
+ for c in strs:
60
+ if (c in CHARS) and (last != BACKSLASH):
61
+ new_chr.append(BACKSLASH + c)
62
+ else:
63
+ new_chr.append(c)
64
+ last = c
65
+ return BLANK.join(new_chr)
66
+
67
+
68
+ def get_val(key, default=None, store=CHR):
69
+ if key is None or not store:
70
+ return default
71
+ return store.get(key, default)
72
+
73
+
74
+ def get_char(key, default=None, store=CHR):
75
+ if key is None:
76
+ return default
77
+ return store.get(key, key) if store else key
78
+
79
+
80
+ class Tag2Method(object):
81
+ def call_method(self, elm, stag=None):
82
+ getmethod = self.tag2meth.get
83
+ if stag is None:
84
+ stag = elm.tag.replace(OMML_NS, "")
85
+ method = getmethod(stag)
86
+ if method:
87
+ return method(self, elm)
88
+ else:
89
+ return None
90
+
91
+ def process_children_list(self, elm, include=None):
92
+ """
93
+ process children of the elm,return iterable
94
+ """
95
+ for _e in list(elm):
96
+ if OMML_NS not in _e.tag:
97
+ continue
98
+ stag = _e.tag.replace(OMML_NS, "")
99
+ if include and (stag not in include):
100
+ continue
101
+ t = self.call_method(_e, stag=stag)
102
+ if t is None:
103
+ t = self.process_unknow(_e, stag)
104
+ if t is None:
105
+ continue
106
+ yield (stag, t, _e)
107
+
108
+ def process_children_dict(self, elm, include=None):
109
+ """
110
+ process children of the elm,return dict
111
+ """
112
+ latex_chars = dict()
113
+ for stag, t, e in self.process_children_list(elm, include):
114
+ latex_chars[stag] = t
115
+ return latex_chars
116
+
117
+ def process_children(self, elm, include=None):
118
+ """
119
+ process children of the elm,return string
120
+ """
121
+ return BLANK.join(
122
+ (
123
+ t if not isinstance(t, Tag2Method) else str(t)
124
+ for stag, t, e in self.process_children_list(elm, include)
125
+ )
126
+ )
127
+
128
+ def process_unknow(self, elm, stag):
129
+ return None
130
+
131
+
132
+ class Pr(Tag2Method):
133
+ text = ""
134
+
135
+ __val_tags = ("chr", "pos", "begChr", "endChr", "type")
136
+
137
+ __innerdict = None # can't use the __dict__
138
+
139
+ """ common properties of element"""
140
+
141
+ def __init__(self, elm):
142
+ self.__innerdict = {}
143
+ self.text = self.process_children(elm)
144
+
145
+ def __str__(self):
146
+ return self.text
147
+
148
+ def __unicode__(self):
149
+ return self.__str__(self)
150
+
151
+ def __getattr__(self, name):
152
+ return self.__innerdict.get(name, None)
153
+
154
+ def do_brk(self, elm):
155
+ self.__innerdict["brk"] = BRK
156
+ return BRK
157
+
158
+ def do_common(self, elm):
159
+ stag = elm.tag.replace(OMML_NS, "")
160
+ if stag in self.__val_tags:
161
+ t = elm.get("{0}val".format(OMML_NS))
162
+ self.__innerdict[stag] = t
163
+ return None
164
+
165
+ tag2meth = {
166
+ "brk": do_brk,
167
+ "chr": do_common,
168
+ "pos": do_common,
169
+ "begChr": do_common,
170
+ "endChr": do_common,
171
+ "type": do_common,
172
+ }
173
+
174
+
175
+ class oMath2Latex(Tag2Method):
176
+ """
177
+ Convert oMath element of omml to latex
178
+ """
179
+
180
+ _t_dict = T
181
+
182
+ __direct_tags = frozenset(
183
+ ("box", "sSub", "sSup", "sSubSup", "num", "den", "deg", "e")
184
+ )
185
+
186
+ def __init__(self, element):
187
+ self._latex = self.process_children(element)
188
+
189
+ def __str__(self):
190
+ return self.latex
191
+
192
+ def __unicode__(self):
193
+ return self.__str__(self)
194
+
195
+ def process_unknow(self, elm, stag):
196
+ if stag in self.__direct_tags:
197
+ return self.process_children(elm)
198
+ elif stag[-2:] == "Pr":
199
+ return Pr(elm)
200
+ else:
201
+ return None
202
+
203
+ @property
204
+ def latex(self):
205
+ return self._latex
206
+
207
+ def do_acc(self, elm):
208
+ """
209
+ the accent function
210
+ """
211
+ c_dict = self.process_children_dict(elm)
212
+ latex_s = get_val(
213
+ c_dict["accPr"].chr, default=CHR_DEFAULT.get("ACC_VAL"), store=CHR
214
+ )
215
+ return latex_s.format(c_dict["e"])
216
+
217
+ def do_bar(self, elm):
218
+ """
219
+ the bar function
220
+ """
221
+ c_dict = self.process_children_dict(elm)
222
+ pr = c_dict["barPr"]
223
+ latex_s = get_val(pr.pos, default=POS_DEFAULT.get("BAR_VAL"), store=POS)
224
+ return pr.text + latex_s.format(c_dict["e"])
225
+
226
+ def do_d(self, elm):
227
+ """
228
+ the delimiter object
229
+ """
230
+ c_dict = self.process_children_dict(elm)
231
+ pr = c_dict["dPr"]
232
+ null = D_DEFAULT.get("null")
233
+ s_val = get_char(pr.begChr, default=D_DEFAULT.get("left"), store=T)
234
+ e_val = get_char(pr.endChr, default=D_DEFAULT.get("right"), store=T)
235
+ return pr.text + D.format(
236
+ left=null if not s_val else escape_latex(s_val),
237
+ text=c_dict["e"],
238
+ right=null if not e_val else escape_latex(e_val),
239
+ )
240
+
241
+ def do_spre(self, elm):
242
+ """
243
+ the Pre-Sub-Superscript object -- Not support yet
244
+ """
245
+ pass
246
+
247
+ def do_sub(self, elm):
248
+ text = self.process_children(elm)
249
+ return SUB.format(text)
250
+
251
+ def do_sup(self, elm):
252
+ text = self.process_children(elm)
253
+ return SUP.format(text)
254
+
255
+ def do_f(self, elm):
256
+ """
257
+ the fraction object
258
+ """
259
+ c_dict = self.process_children_dict(elm)
260
+ pr = c_dict["fPr"]
261
+ latex_s = get_val(pr.type, default=F_DEFAULT, store=F)
262
+ return pr.text + latex_s.format(num=c_dict.get("num"), den=c_dict.get("den"))
263
+
264
+ def do_func(self, elm):
265
+ """
266
+ the Function-Apply object (Examples:sin cos)
267
+ """
268
+ c_dict = self.process_children_dict(elm)
269
+ func_name = c_dict.get("fName")
270
+ return func_name.replace(FUNC_PLACE, c_dict.get("e"))
271
+
272
+ def do_fname(self, elm):
273
+ """
274
+ the func name
275
+ """
276
+ latex_chars = []
277
+ # Word may split a single function name over several runs (e.g. on a
278
+ # formatting boundary), so join adjacent runs before looking it up.
279
+ name_parts = []
280
+
281
+ def flush_name():
282
+ if not name_parts:
283
+ return
284
+ name = BLANK.join(name_parts)
285
+ del name_parts[:]
286
+ latex_chars.append(FUNC.get(name) or r"\operatorname{%s}({fe})" % name)
287
+
288
+ for stag, t, e in self.process_children_list(elm):
289
+ if stag == "r":
290
+ name_parts.append(t)
291
+ else:
292
+ flush_name()
293
+ latex_chars.append(t)
294
+ flush_name()
295
+ t = BLANK.join(latex_chars)
296
+ return t if FUNC_PLACE in t else t + FUNC_PLACE # do_func will replace this
297
+
298
+ def do_groupchr(self, elm):
299
+ """
300
+ the Group-Character object
301
+ """
302
+ c_dict = self.process_children_dict(elm)
303
+ pr = c_dict["groupChrPr"]
304
+ latex_s = get_val(pr.chr, default=CHR_DEFAULT.get("GROUP_CHR_VAL"), store=CHR)
305
+ return pr.text + latex_s.format(c_dict["e"])
306
+
307
+ def do_rad(self, elm):
308
+ """
309
+ the radical object
310
+ """
311
+ c_dict = self.process_children_dict(elm)
312
+ text = c_dict.get("e")
313
+ deg_text = c_dict.get("deg")
314
+ if deg_text:
315
+ return RAD.format(deg=deg_text, text=text)
316
+ else:
317
+ return RAD_DEFAULT.format(text=text)
318
+
319
+ def do_eqarr(self, elm):
320
+ """
321
+ the Array object
322
+ """
323
+ return ARR.format(
324
+ text=BRK.join(
325
+ [t for stag, t, e in self.process_children_list(elm, include=("e",))]
326
+ )
327
+ )
328
+
329
+ def do_limlow(self, elm):
330
+ """
331
+ the Lower-Limit object
332
+ """
333
+ t_dict = self.process_children_dict(elm, include=("e", "lim"))
334
+ latex_s = LIM_FUNC.get(t_dict["e"])
335
+ if not latex_s:
336
+ raise NotImplementedError("Not support lim %s" % t_dict["e"])
337
+ else:
338
+ return latex_s.format(lim=t_dict.get("lim"))
339
+
340
+ def do_limupp(self, elm):
341
+ """
342
+ the Upper-Limit object
343
+ """
344
+ t_dict = self.process_children_dict(elm, include=("e", "lim"))
345
+ return LIM_UPP.format(lim=t_dict.get("lim"), text=t_dict.get("e"))
346
+
347
+ def do_lim(self, elm):
348
+ """
349
+ the lower limit of the limLow object and the upper limit of the limUpp function
350
+ """
351
+ return self.process_children(elm).replace(LIM_TO[0], LIM_TO[1])
352
+
353
+ def do_m(self, elm):
354
+ """
355
+ the Matrix object
356
+ """
357
+ rows = []
358
+ for stag, t, e in self.process_children_list(elm):
359
+ if stag == "mPr":
360
+ pass
361
+ elif stag == "mr":
362
+ rows.append(t)
363
+ return M.format(text=BRK.join(rows))
364
+
365
+ def do_mr(self, elm):
366
+ """
367
+ a single row of the matrix m
368
+ """
369
+ return ALN.join(
370
+ [t for stag, t, e in self.process_children_list(elm, include=("e",))]
371
+ )
372
+
373
+ def do_nary(self, elm):
374
+ """
375
+ the n-ary object
376
+ """
377
+ res = []
378
+ bo = ""
379
+ for stag, t, e in self.process_children_list(elm):
380
+ if stag == "naryPr":
381
+ bo = get_char(t.chr, store=CHR_BO)
382
+ else:
383
+ res.append(t)
384
+ return bo + BLANK.join(res)
385
+
386
+ def do_r(self, elm):
387
+ """
388
+ Get text from 'r' element,And try convert them to latex symbols
389
+ @todo text style support , (sty)
390
+ @todo \text (latex pure text support)
391
+ """
392
+ _str = []
393
+ for s in elm.findtext("./{0}t".format(OMML_NS)) or "":
394
+ # s = s if isinstance(s,unicode) else unicode(s,'utf-8')
395
+ _str.append(self._t_dict.get(s, s))
396
+ return escape_latex(BLANK.join(_str))
397
+
398
+ tag2meth = {
399
+ "acc": do_acc,
400
+ "r": do_r,
401
+ "bar": do_bar,
402
+ "sub": do_sub,
403
+ "sup": do_sup,
404
+ "f": do_f,
405
+ "func": do_func,
406
+ "fName": do_fname,
407
+ "groupChr": do_groupchr,
408
+ "d": do_d,
409
+ "rad": do_rad,
410
+ "eqArr": do_eqarr,
411
+ "limLow": do_limlow,
412
+ "limUpp": do_limupp,
413
+ "lim": do_lim,
414
+ "m": do_m,
415
+ "mr": do_mr,
416
+ "nary": do_nary,
417
+ }