(s, wrap, color='Black', scale=1.0)
| 130 | |
| 131 | |
| 132 | def latex_to_png_dvipng(s, wrap, color='Black', scale=1.0): |
| 133 | try: |
| 134 | find_cmd('latex') |
| 135 | find_cmd('dvipng') |
| 136 | except FindCmdError: |
| 137 | return None |
| 138 | try: |
| 139 | workdir = tempfile.mkdtemp() |
| 140 | tmpfile = os.path.join(workdir, "tmp.tex") |
| 141 | dvifile = os.path.join(workdir, "tmp.dvi") |
| 142 | outfile = os.path.join(workdir, "tmp.png") |
| 143 | |
| 144 | with open(tmpfile, "w", encoding='utf8') as f: |
| 145 | f.writelines(genelatex(s, wrap)) |
| 146 | |
| 147 | with open(os.devnull, 'wb') as devnull: |
| 148 | subprocess.check_call( |
| 149 | ["latex", "-halt-on-error", "-interaction", "batchmode", tmpfile], |
| 150 | cwd=workdir, stdout=devnull, stderr=devnull) |
| 151 | |
| 152 | resolution = round(150*scale) |
| 153 | subprocess.check_call( |
| 154 | ["dvipng", "-T", "tight", "-D", str(resolution), "-z", "9", |
| 155 | "-bg", "transparent", "-o", outfile, dvifile, "-fg", color], |
| 156 | cwd=workdir, stdout=devnull, stderr=devnull) |
| 157 | |
| 158 | with open(outfile, "rb") as f: |
| 159 | return f.read() |
| 160 | except subprocess.CalledProcessError: |
| 161 | return None |
| 162 | finally: |
| 163 | shutil.rmtree(workdir) |
| 164 | |
| 165 | |
| 166 | def kpsewhich(filename): |
nothing calls this directly
no test coverage detected