-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtlatex2word.py
61 lines (47 loc) · 1.55 KB
/
htlatex2word.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import clipboard
import os.path
import pywinauto
import re
import sys
from time import sleep
import subprocess
if not os.path.exists("tex4ht.env"):
print "Creating empty tex4ht.env"
fl = open("tex4ht.env", "w")
fl.close()
subprocess.call(["htlatex", sys.argv[1] + ".tex", "xhtml,mathml"])
all=""
for ln in open(sys.argv[1] + ".html"): all += ln.strip() + " "
if all.find("footnote-mark"):
print "*** WARNING: your file contains footnotes. These may contain MathML code, even"
print "*** if they do not contain math. Please try removing them in case of problems."
maths = list(re.findall('<math.*?</math>', all))
fl = open("withoutmath.html", "w")
print >>fl, re.sub('<math.*?</math>', 'ASFLKJFASASFKJ', all)
fl.close()
print "Open \"withoutmath.html\" with Word and make sure the navigation pane is closed."
raw_input("Press Enter to continue")
app = pywinauto.Application().connect(title_re="withoutmath.html - Word")
main = app.window(title_re="withoutmath.html - Word")
main.Minimize()
main.Restore()
main.SetFocus()
sleep(0.1)
first = True
for math in maths:
clipboard.copy(math)
if first:
pywinauto.keyboard.SendKeys("^f")
sleep(0.05)
pywinauto.keyboard.SendKeys("ASFLKJFASASFKJ")
sleep(0.05)
pywinauto.keyboard.SendKeys("{ENTER}")
sleep(0.05)
pywinauto.mouse.click(button='left', coords=(400,250))
sleep(0.05)
first = False
else:
pywinauto.keyboard.SendKeys("+{VK_F4}")
sleep(0.05)
pywinauto.keyboard.SendKeys("^v")
sleep(0.05)