#! /usr/bin/python3 -t MODULE_NAME = "mformula" MODULE_DESC = "Utility function to create a formula image and its description" MODULE_VERS = "1.0" MODULE_COPYRIGHT = "Copyright © 2020-09-04 by the State University of Campinas (UNICAMP)" import mformula import mformula_svg def write_image_and_descr(md,style,back,prefix, *args): """The parameter {md} should be a module with three functions: {buld_formula(svg,*args)} that returns an {mformula.obj} object, {image_name(svg,*args)} that resturns the full name of the image, and {image_descr(svg,*args)} that returns its description. The {style} is passed to {mformula_svg.obj()} and is one of "B1", "B2", "S1", etc. The {*args} are optional parameters for {build_formula}. The resuts of by {image_name} and {image_descr} must depend on {svg.style} and those parameters. This function writes two files called "{prefix}_{iname}.svg" and "{prefix}{iname}_descr.txt" containing the formula's image in SVG format, where {iname} is the name returned by {image_name(svg,*args)}.""" iname = md.image_name(style,*args) wr = open(prefix + iname + '.svg', 'w') svg = mformula_svg.obj(wr,style,back) fm = md.build_formula(svg, *args) svg.output_figure(fm) wr.close() wr = open(prefix + iname + '_descr.txt', 'w') idescr = md.image_descr(style,*args) wr.buffer.write(idescr.encode('utf8')) wr.write("\n") wr.close()