0

I have written some code in Python 2.7 that will read a string from a .ini file and generate a .png image of the string in LaTeX format using sympy.preview. The idea is to use this script to generate the images in the background while I am typing them out. The problem is that even when I run the script in the background (using pythonw.exe), two empty command line windows will pop up for latex.exe and dvipng.exe and close immediately. This is annoying because it interrupts my typing. I want to be able to do it "on the fly" without being interrupted.

Is there a way to prevent these windows from opening?

Here is my minimum working example:

from sympy import preview   # for generating Latex images
import ConfigParser         # for reading .ini files

# read the latex commands from the .ini file:
config = ConfigParser.RawConfigParser()

config.read('mathPredictor.ini')
one = config.get('Words', 'one')

prefix = '\\Huge $' # make the Latex equations bigger
suffix = '$'
eqone =  prefix + one + suffix

# for generating Latex images:
preview(eqone, viewer='file', filename='one.png', euler=False)

for the .ini file

[Words]
one=\alpha

I am running Windows 8 64-bit with Python 2.7.10. This question is cross-posted at tex.SE.

Community
  • 1
  • 1
Wise Owl
  • 111
  • 3
  • Can you make use of http://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window. – Bill Bell Sep 22 '16 at 19:09

1 Answers1

1

I solved my own problem. If I ran the Python script from a previously-existing cmd instance, the windows didn't pop up. My solution then was to start a hidden instance of cmd and send the path location to the hidden cmd window. This enabled the Python code to be executed without the annoying popups from latex.exe and dvipng.exe.

I accomplished this in Autohotkey language using the following function:

Run, %comspec%, , max, pid2  ; runs cmd in hidden mode with instance name given by %pid%
WinWait, ahk_pid %pid2%  ; waits for instance to be active
ControlSend, ,python mypythonscript.py`r, ahk_pid %pid2%  ; send text for script execute
Wise Owl
  • 111
  • 3