I recently figured this out in order to call the server to convert the LaTeX user string into an equation image. The call is made through VBA using the command MacScript:
command = "do shell script """ & pyPath & "python " & getURLpath & "getURL.py --formula '" _
& Latex_Str & "' --fontsize " & Font_Size & " " & WebAdd & """"
result = MacScript(command)
, do shell script /usr/bin/python {path to script}/getURL.py --formula '{LaTeX formula string}' --fontsize {int} {myurl} . Python script argparse , , urllib urllib2 . MacScript stdout Python script result.
urllib2 Python script.
EDIT: , . Python script .
from urllib import urlencode
from urllib2 import Request, urlopen, URLError, ProxyHandler, build_opener, install_opener
import argparse
parser = argparse.ArgumentParser(description='Sends LaTeX string to web server and returns meta data used by LaTeX in Word project')
parser.add_argument('webAddr', type=str, help='Web address of LaTeX in Word server')
parser.add_argument('--formula', metavar='FRML', type=str, help='A LaTeX formula string')
parser.add_argument('--fontsize', metavar='SIZE', type=int, default=10, help='Integer representing font size (can be 10, 11, or 12. Default 10)')
parser.add_argument('--proxServ', metavar='SERV', type=str, help='Web address of proxy server, i.e. http://proxy.server.com:80')
parser.add_argument('--proxType', metavar='TYPE', type=str, default='http', help='Type of proxy server, i.e. http')
args = parser.parse_args()
if args.formula:
values = {'formula': str(args.fontsize) + '.' + args.formula}
else:
values = {}
if args.proxServ:
proxySupport = ProxyHandler({args.proxType: args.proxServ})
opener = build_opener(proxySupport)
install_opener(opener)
data = urlencode(values)
data = data.encode('utf-8')
try:
req = Request(args.webAddr, data)
response = urlopen(req)
print response.read()
except URLError, e:
if hasattr(e, 'reason'):
print 'Error: Failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'Error: The server could not fulfill the request.'
print 'Error code: ', e.code