protz/LatexIt

dvipng failed with error code 1. Aborting.

Closed this issue · 66 comments

Hello,
since some time ago I'm not being able of generating images with Latex It!. Today I tried to fix it and I saw I had to add
\usepackage[active,displaymath,textmath]{preview}_ to the preamble. Still not working, now I'm getting:

I ran C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe -output-directory=C:\Users\Fernando\AppData\Local\Temp -interaction=batchmode C:\Users\Fernando\AppData\Local\Temp\tblatex-1.tex error code 1
LaTeX process returned 1
Proceeding anyway...
*** Surrounding text has font size of 17px
*** Calculated resolution is 122.859 dpi
I ran C:\WINDOWS\system32\cmd.exe -c 'C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe --depth -T tight -D 122.859 -o C:\Users\Fernando\AppData\Local\Temp\tblatex-1.png C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi > C:\Users\Fernando\AppData\Local\Temp\tblatex-1-depth.txt'
!!! dvipng failed with error code 1. Aborting.
--> Failed, not inserting

Any idea of how could i solve this?
Thank you,
Fernando

sphh commented

Can you run all those programs from the command prompt?

C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe -output-directory=C:\Users\Fernando\AppData\Local\Temp C:\Users\Fernando\AppData\Local\Temp\tblatex-1.tex

which should produce a tblatex-1.dvi file in C:\Users\Fernando\AppData\Local\Temp\

C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe --depth -T tight -D 122.859 -o C:\Users\Fernando\AppData\Local\Temp\tblatex-1.png C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi > C:\Users\Fernando\AppData\Local\Temp\tblatex-1-depth.txt

which finally should produce the tblatex-1.png and tblatex-1-depth.txt files in C:\Users\Fernando\AppData\Local\Temp\

Please post the outputs and also the C:\Users\Fernando\AppData\Local\Temp\tblatex-1.tex file here.

I also noticed that you have a final underscore after \usepackage[active,displaymath,textmath]{preview}_. Maybe that's the problem?

I would be extremely embarrased if it was an underscore, it wasn't writen in the preamble, don't know where dir it appear.
I get both images and this output from first command:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6745 64-bit)
**
! End of file on the terminal... why?
C:\Program Files\MiKTeX 2.9\miktex\bin\x64>latex.exe -output-directory=C:\Users\Fernando\AppData\Local\Temp C:\Users\Fernando\AppData\Local\Temp\tblatex-1.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6745 64-bit)
entering extended mode
(C:/Users/Fernando/AppData/Local/Temp/tblatex-1.tex
LaTeX2e <2018-04-01> patch level 5
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\inputenc.sty"
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\utf8x.def))
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\ucs.sty
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\uni-global.def))
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\preview\preview.sty
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\generic\luatex85\luatex85.sty
))
No file tblatex-1.aux.
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\ucsencs.def)
Preview: Fontsize 10pt
! Undefined control sequence.
l.6 \tiny{$\pm\pi-2\tetha
                         $} %this is where your LaTeX expression goes
?
[1] (C:\Users\Fernando\AppData\Local\Temp\tblatex-1.aux) )
Output written on C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi (1 page, 2
72 bytes).
Transcript written on C:\Users\Fernando\AppData\Local\Temp\tblatex-1.log.

No output from the second one.
Content of tblatex-1.tex:

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[active,displaymath,textmath]{preview}
\pagestyle{empty}
\begin{document}
\tiny{$\pm\pi-2\tetha$} %this is where your LaTeX expression goes
\end{document}

Thanks!

sphh commented

Shouldn't it read \theta instead of \tetha?

Yes it should, but nothing changes.

sphh commented

As you can see from the output of the latex command, that failed. I replaced \tetha with \theta and this runs on my system.

Can you please post again the outputs of both commands and the LaTeX file. Thanks.

You can replace the second – the dvipng – command with the following:

C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe --depth -T tight -D 122.859 -o C:\Users\Fernando\AppData\Local\Temp\tblatex-1.png C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi

so that you can see all output, not just the errors.

Sure,
here it is:
latex.exe -output-directory=C:\Users\Fernando\AppData\Local\Temp C:\Users\Fernando\AppData\Local\Temp\tblatex-1.tex

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6745 64-bit)
entering extended mode
(C:/Users/Fernando/AppData/Local/Temp/tblatex-1.tex
LaTeX2e <2018-04-01> patch level 5
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\inputenc.sty"
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\utf8x.def))
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\ucs.sty
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\uni-global.def))
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\preview\preview.sty
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\generic\luatex85\luatex85.sty
)) (C:\Users\Fernando\AppData\Local\Temp\tblatex-1.aux)
(C:\Users\Fernando\AppData\Roaming\MiKTeX\2.9\tex\latex\ucs\ucsencs.def)
Preview: Fontsize 10pt
[1] (C:\Users\Fernando\AppData\Local\Temp\tblatex-1.aux) )
Output written on C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi (1 page, 2
76 bytes).
Transcript written on C:\Users\Fernando\AppData\Local\Temp\tblatex-1.log.

dvipng.exe --depth -T tight -D 122.859 -o C:\Users\Fernando\AppData\Local\Temp\tblatex-1.png C:\Users\Fernando\AppData\Local\Temp\tblatex-1.dvi

This is dvipng.exe (dvipng) 1.15 Copyright 2002-2015 Jan-Ake Larsson
[1 depth=1]

I get the PNG out of it but when I try it on Thunderbird it doesn't work.
Thanks!

sphh commented

Now that the LaTeX expression is correct and that we know, that the .png file can be created, can you please run everything again from Thunderbird with debug outputs enabled in the configuration settings and post the output here.

Since you called the latex and dvipng commands without their full path, please check that C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe and C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe exists indeed.

@protz: Could this be due to the spaces in the path? Do we have to encapsulate it in quotation marks ""?

Hi guys, I have the same issue and can confirm, that the commands works outside thunderbird (when I encapsulate the spaces), but when I try to run the addon on a real email it fails... I tried to rename the folder in question to MiKTeX_2.9 and fix all the paths, to avoid the spaces. However something else broke at that point (I think Miktex didn't like this renaming of the main folder) and therefore I cannot confirm whether the issue is related to the spaces :(
Also tried to escape the spaces in the addon options using different methods such as putting the path inside "" or putting / in front of the spaces, but always got an error saying the path was malformed.

If there is anything I can try to help out, I would be glad to do so.

protz commented

Are we going through the shell as well on windows? If so, yes, I believe spaces would be good.

Let's see what the debug output is.

sphh commented

The latex command is called without invoking the shell, the dvipng does need the shell, because of the > redirection of its output into a file. It is not possible for JavaScript to capture the standard output …

I also have this issue - with the latest version of LatexIt automatically updated from the Mozilla site (0.7.3) on Windows 10 with MiKTeX 2.9. After much trial and error I worked around the issue by copying dvipng.exe from the MiKTeX install location (where the path includes spaces) to another location with no spaces in the path (I used C:\Users...\bin\dvipng). After pointing LatexIt at the new location everything seems to be working again.

Unfortunately, sanitize_path doesn't work for me giving this error in Thunderbird's console:

'\"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe\"' is not recognized as an internal or external command,
operable program or batch file.

Moving dvipng.exe to a space without paths removes the error in the console, but dvipng.exe doesn't run, giving the catch-all Missing package error.

I have tried various combinations of file paths in line 341 of main.js to replace sanitize_path(dvipng_bin.path) but at best I get the Missing package error.

I can confirm that running the dvipng command outside Thunderbird works fine.

I have done lots more tests (with dvipng path with no spaces and \ replaced by \\ ) though without much luck. Inserting log statements into main.js shows that the error occurs in line 342 of main.js
shell_process.run(true, [shell_option, dvipng_args.join(" ")], 2);
with the png file not created and the depth not put into the depth file.

However, subsequently running the contents of dvipng_args.join(" ")] in a command prompt works flawlessly. I can only assume there's a problem with running dvipng.exe in the shell, though there's no error in the console to show this.
I think I'm out of ideas!

sphh commented

Thanks for checking my fudged sanitize_path()! Well, since I don't have a Windows machine available to test, this was just the best guess I came up with. Since I have never developed on Windows, I have no clue how to do this …

What I believe should be done in sanitize_path(), is to add double quotation marks around the dvipng.exe command (line 156 of patched main.js):

            return "\""+path+"\"";

to give

"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe"

and not

\"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe\"

How would I do this?

I wish I knew! The best I could come up with was using

dvipng_path = 'C:\\"Program Files"\\"MiKTeX 2.9"\\miktex\\bin\\x64\\dvipng.exe';

(without sanitize_path) which stopped the console error about not finding the command, but then I get the same problem as with no file spaces, where dvipng doesn't run but no error.

Thus there are 2 problems:

  1. file spaces;
  2. dvipng doesn't run.

I have worked on this for too long 😔 but the two problems I mentioned above are connected - the shell can't cope with double quotes, escaped or otherwise. dvipng does run, but fails because of the escaped quotes in line 341 of main.js:

"-fg", "\""+font_color+"\""

https://stackoverflow.com/a/31413730/9822548 and
https://docs.microsoft.com/en-gb/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way
are interesting reads on this topic but I haven't been able to use what they say successfully. Maybe someone else more capable than me can do so?

I have a temporary workaround that works for me:

  1. change sanitize_path so it returns the path unaltered (lines 152-157);
  2. copy dvipng.exe to a directory with no spaces then use double backslashes;
    eg C:\\some\\directory\\or\\other\\dvipng.exe and insert this into line 341 or use a var to do so;
  3. remove "-fg", "\""+font_color+"\"" from line 341.
  4. get round loss of font color by adding \usepackage{color} to the template to get coloured symbols using LaTeX code.

Now I can use LaTeX in Thunderbird in Windows and it works perfectly. Of course an even better workaround is to use Linux 😄

PS It doesn't help that the Windows version of dvipng has been compiled so that it can't use the debug option - if it had I would probably have found what goes wrong much sooner.

sphh commented

Thanks for investigating!!

Let me comment on your workarounds (for everybody else who is coming here with this problem):

  1. sanitize_path was introduced in PR #75 and is not part of the main branch. It was introduced to solve the problem on Windows, if the path to dvipng.exe contains spaces. (It was not tested and as you showed, it does not work.)
  2. Copy dvipng.exe to a path without spaces will always work (but unfortunately is not a very elegant solution).
  3. The -fg font_color option only changes the colour of the generate .png file to that of the surrounding text. You can include \usepackage{color} in our LaTeX preamble and change it manually.
  4. You can always include \usepackage{color} and change any symbol in your formula to any colour you like.

I would be interested, if a path to dvipng.exe without spaces and "-fg", "\""+font_color+"\"" left in line 341 works. If the -fg option does not work, than we are dealing with two different (but related) problems.

Does calling the dvipng.exe with the -fg option from the command prompt work?

sphh commented

@stevem6: I just had a read through the two links you kindly provided. It looks, like this is the solution: Escape the " quotation marks with ^" (this is also mentioned in the answer on stackoverflow).

Do you think you can try and replace the \" with ^"?

To answer your questions:

  1. I would be interested, if a path to dvipng.exe without spaces and "-fg", "\""+font_color+"\"" left in line 341 works.
    Unfortunately not. The backslashes are the cause of dvipng not working. I couldn't find a working alternative.
  2. Does calling the dvipng.exe with the -fg option from the command prompt work?
    Yes it does
  3. Do you think you can try and replace the " with ^"?
    I had tried that but that is seen as a JavaScript error so LatexIt doesn't load. Similarly for " ' " or ' " '. I couldn't make any of the suggestions in those links work.

Not good news I'm afraid.

sphh commented

I would have suggested to change line 341 of PR #75 to:

      var dvipng_args = [sanitize_path(dvipng_bin.path), '--depth', '-T', 'tight', '-z', '3', '-bg', 'Transparent', '-D', dpi, '-fg', '"'+font_color+'"', '-o', sanitize_path(png_file.path), sanitize_path(dvi_file.path), '>', sanitize_path(depth_file.path)];

or

      var dvipng_args = [sanitize_path(dvipng_bin.path), `--depth`, `-T`, `tight`, `-z`, `3`, `-bg`, `Transparent`, `-D`, dpi, `-fg`, `"`+font_color+`"`, `-o`, sanitize_path(png_file.path), sanitize_path(dvi_file.path), `>`, sanitize_path(depth_file.path)];

while having dvipng.exe under a path without spaces.

But obviously you have already tried that one …

Sorry, but that's out of my league and someone cleverer than me has to look into this!

Just in case I had made a mistake, I retried both of your suggestions and they do indeed fail (LatexIt loads but dvipng, without spaces, fails). I do hope someone can help.

sphh commented

One final favour: Can you please post the error from Thunderbird's error console (if any) and the output of LatexIt! inside the message (with debug messages enabled in the configuration) with the changes suggested in #74 (comment)). That might help the wizards! Thanks.

That's the frustrating thing, there's no message at all in the console and the Windows version of dvipng was compiled without the debug option so cannot use -d switch.

To eliminate the spaces in path problem, instead of sanitize_path(dvipng_bin.path) in line 341 I used, with your first suggestion:

var mydvipng_path = 'C:\\my\\directory\\dvipng.exe';
var dvipng_args = [mydvipng_path, '--depth', '-T', 'tight', '-z', '3', '-bg', 'Transparent', '-D', dpi, '-fg', '"'+font_color+'"', '-o', sanitize_path(png_file.path), sanitize_path(dvi_file.path), '>', sanitize_path(depth_file.path)];

The debug line at line 345 is not reached due to try-catch so I added it between lines 341 and 342:

if (debug) {
   log += "I ran "+shell_bin.path+" /C '"+dvipng_args.join(" ")+"'\n";
}

The debug message was (note that the default Windows temp path has no spaces):

I ran C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe -output-directory=C:\Users\Steve\AppData\Local\Temp -interaction=batchmode C:\Users\Steve\AppData\Local\Temp\tblatex-27.tex error code 0
*** Surrounding text has font size of 17px
*** Calculated resolution is 122.859 dpi
I ran C:\WINDOWS\system32\cmd.exe /C 'C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-28.png C:\Users\Steve\AppData\Local\Temp\tblatex-28.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-28-depth.txt'
!!! Severe error. Missing package?
We left the .tex file there: C:\Users\Steve\AppData\Local\Temp\tblatex-28.tex, try to run 'latex' and 'dvipng --depth' on it by yourself...
--> Failed, not inserting

The debug message tells you what JavaScript sees but not what the shell sees.
tblatex-28-depth.txt is created but empty and tblatex-28.png isn't created.

sphh commented

Thanks! This confirms what I was investigating in the last hour. Read on …

This is now my last take (or actual: guess) on this one.

According to this answer, the whole string to the command interpreter has to be inside double quotes. James Boston also points out:

I'm not sure off hand if nsIProcess auto-quotes arguments, so you many need to experiment with that.

Equipped with this information, we could conclude, that Windows command interpreter would like to see this:

CMD.EXE [options] "<dvipng> --depth -T tight -z 3 -bg Transparent -D <dpi> -fg ^"<font_color>^" -o <png_file> <dvi_file> > <depth_file>"

for file paths without spaces and the placeholders <> replaced by their values or

CMD.EXE [options] "^"<dvipng>^" --depth -T tight -z 3 -bg Transparent -D <dpi> -fg ^"<font_color>^" -o ^"<png_file>^" ^"<dvi_file>^" > ^"<depth_file>^""

if we have spaces in the file paths.

Let us now implement this (mind you, this is just a prove of concept and will only work on Windows – if it works):
Change the line with var dvipng_args to:

var dvipng_args = [dvipng_bin.path, '--depth', '-T', 'tight', '-z', '3', '-bg', 'Transparent', '-D', dpi, '-fg', '^"'+font_color+'^"', '-o', png_file.path, dvi_file.path, '>', depth_file.path];

and the line with shell_process.run(…) to

shell_process.run(true, [shell_option, '"'+dvipng_args.join(" ")+'"'], 2);

(Alternatively keeping James Boston's comment in mind, do not change this line.)

Maybe that works. If yes, the next step would be to add double quotes around the file paths and finally making it conditional on Windows system. If it does not work, I throw in my towel.

Sadly no improvement. All testing done with dvipng in a no-spaces path.
With

shell_process.run(true, [shell_option, '"'+dvipng_args.join(" ")+'"'], 2);

it gives the same try-catch error as before.

With that line unchanged it gets to line 345 but must have a non-zero shell_process.exitValue as it then gives:

!!! dvipng failed with error code 1. Aborting.

I think I need a hitchhiker's towel 😞.

sphh commented

What are the debug outputs? How does the command called look like? And is there anything on the error console? Can you run the command displayed in the debug output: cmd.exe /C … (please note, that the log output adds single quotes!)

BTW: This might be the easiest and quickest way to debug this: In the command prompt call

cmd.exe /C "… > …"

with all the options filled in. You have to use the cmd.exe /C in front of it, because that's how it is called from LatexIt!. If we have it working there, we might be able to generate the correct command in LatexIt!

I was told, that you can check the error code with

echo %errorlevel%

Can you please also check, if your dvipng supports all the arguments used?

Back to LatexIt:
What files (and with which contents) were left behind with "that line unchanged"? Was the .png file generated?

This says, that you don't need the ^ escape character. Worth a try (with "that line" changed and unchanged, but try it out first in the command prompt):

var dvipng_args = [dvipng_bin.path, '--depth', '-T', 'tight', '-z', '3', '-bg', 'Transparent', '-D', dpi, '-fg', '"'+font_color+'"', '-o', png_file.path, dvi_file.path, '>', depth_file.path];

The debug output is the same as before which is why I didn't post it and anyway only reflects what JavaScript sees not what cmd.exe sees.

The 'I ran' debug output runs fine in a command window, creating the png, so there's no error and dvipng supports all the arguments, just not -d.

Using
var dvipng_args = [dvipng_bin.path, '--depth', '-T', 'tight', '-z', '3', '-bg', 'Transparent', '-D', dpi, '-fg', '"'+font_color+'"', '-o', png_file.path, dvi_file.path, '>', depth_file.path];

in LatexIt creates a tex, dvi (both with the correct content) and an empty -depth.txt file but no png. LatexIt doesn't reach line 345 because line 342 trips try-catch so bailing out with the messages in lines 411-412.

Running cmd.exe /C "… > …" with the above contents, works perfectly with no errors.

In other words either:

  1. LatexIt causes an error in line 342 or
  2. it does run the shell command but that fails without any shell error being generated.

Adding && echo %errorlevel% when running dvipng from the command prompt gives a value of 0, so shows it's fine

sphh commented

Can you please post, which commands you actually run on the command line. It's a bit difficult to keep track … Thanks.

C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt

sphh commented

Thanks. What you actually should have tested on the command prompt is this:

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

That fails giving
The system cannot find the path specified.
and no png is created

If instead I use the command cmd.exe /C start "C:\my... then I get a different error message
The system cannot find the file 0.

sphh commented

OK.

Can you run

cmd.exe

(you have to exit the shell in shell with exit after it)?

If not, try

C:\WINDOWS\system32\cmd.exe

(leave the shell in the shell with exit).

If that works, try to run

cmd.exe /C "C:\my\directory\dvipng.exe -h"

or

C:\WINDOWS\system32\cmd.exe /C "C:\my\directory\dvipng.exe -h"

What are the outputs of all these commands?

I'm really sorry but I have just realised that

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

doesn't give an error, it does nothing at all with no error output. I'd forgotten to replace C:\my\directory\dvipng.exe with the non-spaces path I was actually using. But it still fails to create a png.

So using the correct version of

cmd.exe /C "C:\my\directory\dvipng.exe -h"

it gives

This is C:\my\directory\dvipng.exe (dvipng) 1.15 Copyright 2002-2015 Jan-Ake Larsson
C:\my\directory\dvipng.exe warning: -h is not a valid option
Usage: C:\my\directory\dvipng.exe [OPTION]... FILENAME[.dvi]
Options are chosen to be similar to dvips' options where possible:
...

cmd.exe /C "C:\my\directory\dvipng.exe --help" works as it should

C:\WINDOWS\system32\cmd.exe isn't required as cmd.exe opens in C:\WINDOWS\system32 by default. I can confirm cmd.exe creates a new shell, with exit going back to the parent shell.

I believe that the problem with

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

is the double quote in the middle so cmd.exe sees

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "

sphh commented

Ok. We have established, that cmd.exe /C can call dvinpng.exe, but the full command line does not give any result. Let us remove the redirections and then call it once with and once without the -fg parameter (please check, that the file C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi still exists and has a – sensible – contents):

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi"
echo %errorlevel%
cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi"
echo %errorlevel%

What is the output?

Can you please also upload the file C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi here.

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi" && echo %errorlevel%
gives

This is C:\my\directory\dvipng.exe (dvipng) 1.15 Copyright 2002-2015 Jan-Ake Larsson
[1 depth=0]
0

and creates the png.

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi" && echo %errorlevel%

gives identical results.

thblatex-30.dvi is attached and is fine (GitHub insists that it is zipped).

tblatex-30.zip

sphh commented

Great! Thanks!

So we finally know, that the command line is correct and works when called as an argument to the command line interpreter cmd.exe – even using the -fg parameter with the double quote, which is not escaped (which is one of the many non-intuitive Microsoft ways)

Now let us tackle the redirection …
You previously said, that

cmd.exe /C "[…]\dvipng.exe […] > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

did not produce any output. That is the correct behaviour, because the output ([1 depth=0] in your case) is redirected (written) into the file C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt. This is done by the > operator near the end.

Let us test it!
Can you please delete these two files

C:\Users\Steve\AppData\Local\Temp\tblatex-30.png
C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt

and run the command

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

Please post again the output, the %errorlevel% and upload the two generated files (tblatex-30.png and blatex-30-depth.txt) here. Thanks.

Some good news for a change! Putting > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt outside the quotes works:

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi" > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt && echo %errorlevel%

creates the png, puts

This is C:\my\directory\dvipng.exe (dvipng) 1.15 Copyright 2002-2015 Jan-Ake Larsson
[1 depth=0] 

into tblatex-30-depth.txt

and gives error level 0

Our posts crossed. Deleting the png and depth files and running

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt" && echo %errorlevel%

also works with png created, correct entry into tblatex-30-depth.txt and error level 0

Forgot to upload the files you requested:
tblatex-30
tblatex-30-depth.txt

This also worked with the default directory of dvipng.exe containing spaces:

cmd.exe /C ""C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe" --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

but coding that initial "" I imagine could be tough.

sphh commented

Excellent!, because I am not sure, if it would have been able to implement the first option in LatexIt!

So now we know, what is working on the command prompt. Let us work to get it working from LatexIt! Let us make small steps, so that we know, where exactly it goes wrong.

First I would suggest to hardcode the command line.
Replace the shell_process.run(…) with

//      shell_process.run(true, [shell_option, dvipng_args.join(" ")], 2);
      var png_file = init_file("C:\Users\Steve\AppData\Local\Temp\tblatex-30.png");
      var depth_file = init_file("C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt");
      shell_process.run(true, [shell_option, '"C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg "RGB 0 0 0 " -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"'], 2);

Please also remove the catch-all clause, so that we can see errors in Thunderbird's error console:

//    try {
        
//    } catch (e) {
//      // alert("Latex It! Error\n\nSevere error. Missing package?\n\nSolution:\n\tWe left the .tex file there:\n\t\t"+temp_file.path+"\n\tTry to run 'latex' and 'dvipng --depth' on it by yourself...");
//      dump(e+"\n");
//      dump(e.stack+"\n");
//      log += "!!! Severe error. Missing package?\n";
//      log += "We left the .tex file there: "+temp_file.path+", try to run 'latex' and 'dvipng --depth' on it by yourself...\n";
//      return [2, "", 0, log];
//    }

Now remove the tblatex-30.png. and tblatex-30-depth.txt files and LatexIt! a message and please post the debug output from that message and any error from Thunderbird's error console. (Note, that this generates a new set of latex and dvi files, but will work on the existing hardcoded tblatex-30.dvi file.)

This also worked with the default directory of dvipng.exe containing spaces:
[…]
but coding that initial "" I imagine could be tough.

Let us deal with one problem after the other! ;-) (And no, I don't think, that's tough; that was one approach, which I already tried previously.) I will keep it in mind, that this works. Thanks for checking!!

The console shows latex was run and the dvi is created:

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (MiKTeX 2.9 64-bit)
entering extended mode
The system cannot find the path specified.

but then I get:

LatexIt! run report...

*** Found expression $x$

but nothing else happens. Changing the expression doesn't help

sphh commented

Can you please copy the whole output from the message window and any error message from the error console (Tools > Developer Tools > Error Console). You can filter there for tblatex.

A little background, what I want to achieve: If you run LatexIt!, the latex file is generated and run through latex to generate the .dvi file. Then the modifications from my last post uses the previously generated tblatex-30.dvi to produce the tblatex-30.png and the depth file (because this is hardcoded).

BTW your output shows, that pdfLaTeX was run. Are you sure, that pdfLaTeX produces a .dvi file?

That was the whole output I posted, there was nothing else - debug and log options were true. Unlike Linux (and Firefox in Windows) there are no Developer Tools for Thunderbird in Windows so there's nothing else that I can post.

pdfLaTeX does produce a dvi file and that was the one I uploaded. I deleted the dvi and pdflatex created a new copy with the correct contents. Indeed as I said earlier, everything works properly if I exclude the font color option.

The system cannot find the path specified. error is the output when trying to run dvipng as latex has been successfully run and the dvi file created.

sphh commented

I wonder, if you have not accidentally deleted the file C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi? This file is needed, because it is hardcoded.

On Linux, the error messages are also displayed in the terminal, if I start Thunderbird from the command prompt. Worth to try on Windows …

When I run LatexIt!, I get the following output:

LatexIt! run report...

*** Found expression $x$

$PATH is /home/sph/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

*** Generating LaTeX expression:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[active,displaymath,textmath]{preview} % DO NOT DELETE - this is required for baseline alignment
\pagestyle{empty}
\begin{document}
$x$ % this is where your LaTeX expression goes between $$
\end{document}

I ran /usr/bin/latex -output-directory=/tmp -interaction=batchmode /tmp/tblatex-1.tex error code 0
*** Surrounding text has font size of 16px
*** Calculated resolution is 115.63199999999999 dpi
I ran /bin/sh -c '/usr/bin/dvipng --depth -T tight -D 115.63199999999999 -o /tmp/tblatex-1.png /tmp/tblatex-1.dvi > /tmp/tblatex-1-depth.txt'
*** Status is 0
*** Path is /tmp/tblatex-1.png
*** Depth is 0
--> Replacing node... done

As you can see, there is a lot of output before the dvipng command is run. Please check, that you have both of these options enabled:

  • Generate a log report
  • Generate debug info

Please also always post the full LatexIt! run report in one piece. Please put your comments afterwards.

BTW so that we speak of the same things: What do you mean when you say "console"? For me, this is the error console, but since you cannot open this due to missing "Developer Tools", I am uncertain, what you mean.

In a nutshell, I would be grateful, if you could

  1. Check, that the three replacement lines are correct.
  2. Check, that you have commented out the right try - catch clause (line 96 and 393-400).
  3. Check, that the file C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi still exists.
  4. Start Thunderbird from the command line.
  5. Check, that Generate debug info is enabled in LatexIt!'s settings.
  6. Run LatexIt! on a message.
  7. Post the "LatexIt! run report..." in its full glory.
  8. Check the command line for any error message and post them here.
  9. Check, if the files C:\Users\Steve\AppData\Local\Temp\tblatex-30.png and C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt were generated.

Thanks.

Normally I get the full error report as you show, but deleting the try-catch lines means that it no longer shows.
Reinstating try-catch gives

LatexIt! run report...

*** Found expression $x$

*** Generating LaTeX expression:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[active,displaymath,textmath]{preview} % DO NOT DELETE - this is required for baseline alignment
\pagestyle{empty}
\usepackage{color}
\begin{document}
$x$ % this is where your LaTeX expression goes between $$
\end{document}

I ran C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe -output-directory=C:\Users\Steve\AppData\Local\Temp -interaction=batchmode C:\Users\Steve\AppData\Local\Temp\tblatex-30.tex error code 0
*** Surrounding text has font size of 17px
*** Calculated resolution is 122.859 dpi
!!! Severe error. Missing package?
We left the .tex file there: C:\Users\Steve\AppData\Local\Temp\tblatex-30.tex, try to run 'latex' and 'dvipng --depth' on it by yourself...
--> Failed, not inserting

The only error on the command line is
The system cannot find the path specified.

I have double-checked steps 1-9 and they are all correct.

I used the -console in the shortcut, Target box which is the equivalent of starting Thunderbird from the command line.

(If you are thinking that Windows is an awkward customer, then I agree with you.)

sphh commented

Thanks for clarifying the "console" thing and for checking the steps.

By removing the try – catch clause, I was hoping to get more output on the console/command prompt/terminal …

And you are saying, that these lines would work?

//      shell_process.run(true, [shell_option, dvipng_args.join(" ")], 2);
      var png_file = init_file("C:\Users\Steve\AppData\Local\Temp\tblatex-30.png");
      var depth_file = init_file("C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt");
      shell_process.run(true, [shell_option, '"C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"'], 2);

Could you please be so kind to change the line with shell_process.run() and run it again (just to be absolutely sure). Thanks.

No that doesn't work as the output from console shows:

'\"C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -o C:UsersSteveAppDataLocalTemp blatex-30.png C:UsersSteveAppDataLocalTemp      blatex-30.dvi > C:UsersSteveAppDataLocalTemp    blatex-30-depth.txt\"' is not recognized as an internal or external command,
operable program or batch file.

Note the problem with missing backslashes.


LatexIt! run report...

*** Found expression $x$

*** Generating LaTeX expression:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[active,displaymath,textmath]{preview} % DO NOT DELETE - this is required for baseline alignment
\pagestyle{empty}
\usepackage{color}
\begin{document}
$x$ % this is where your LaTeX expression goes between $$
\end{document}

I ran C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latex.exe -output-directory=C:\Users\Steve\AppData\Local\Temp -interaction=batchmode C:\Users\Steve\AppData\Local\Temp\tblatex-30.tex error code 0
*** Surrounding text has font size of 17px
*** Calculated resolution is 122.859 dpi
!!! Severe error. Missing package?
We left the .tex file there: C:\Users\Steve\AppData\Local\Temp\tblatex-30.tex, try to run 'latex' and 'dvipng --depth' on it by yourself...
--> Failed, not inserting

sphh commented

Oh, thanks.

I think, I finally found what is going on!

Problem

nsIProcess.run() (JavaScript's class handling external commands) is called with a list of arguments. If any of these arguments contains a space, this argument is enclosed in double quotes "…" and every double quote inside this argument is escaped as \".

To get nsIProcess to accept a redirection, we have to use cmd.exe /C and pass the command including the redirection as a string inside double quotes after the /C option, e.g. cmd.exe /C "our_cmd > our_output_file". This is easy to achieve, if we call it as

nsIProcess.run(true, ['/C', 'our_cmd > our_output_file'], 2)

This is translated to

cmd.exe /C "our_cmd > our_output_file"

The problem occurs, if we need to encapsulate an argument, which contains spaces (in our case, the -fg parameter), e.g.

nsIProcess.run(true, ['/C', 'our_cmd -fg "RGB 0 0 0" > our_output_file'], 2)

which is translated to

cmd.exe /C "our_cmd -fg \"RGB 0 0 0\" > our_output_file"

If we use

nsIProcess.run(true, ['/C', 'our_cmd',  '-fg, 'RGB 0 0 0', '>', 'our_output_file'], 6)

we get

cmd.exe /C our_cmd -fg "RGB 0 0 0" > our_output_file

which would not work, since cmd.exe /C expects the command as a string in double quotes.

Solutions

There are these possible solutions for Windows systems:

  1. Do without aligning the formula to the the surrounding text.
  2. Do without having the formula's colour adapt to the colour of the surrounding text.
  3. Using an external batch file, which does the redirection.
  4. Getting the author of dvipng to add an option to save the depth to an external file.
  5. Getting the authors of nsIProcess to make the standard output available for the program as a string.

Some comments:
1.+2. I don't know, which one I would prefer.
1 . This would get rid of the redirection.
2. This would get rid of the quotes inside the command. (But then we still face the problem of possible spaces in the paths.)
1.+2. Hence 1. is the only sensible way forward.
3. This is complicated, because the LatexIt! add-on would have to install that batch file. (Or write it every time as a temporary batch file.)
4.+5. Good luck with that one! (Actually, the approach to use cmd.exe /C … > … is a workaround for the deficiencies of 4. and/or 5.)

sphh commented

There is a slight hope to replace the double quotes around the -fg parameter with single quotes.

@stevem6 could you please try this on the command prompt:

cmd.exe /C "C:\my\directory\dvipng.exe --depth -T tight -z 3 -bg Transparent -D 122.859 -fg 'RGB 0 0 0' -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi" > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt

but I don't have much hope, nor do I think, this will work (could you please try this too):

cmd.exe /C "'C:\Program Files\MiKTeX 2.9\miktex\bin\x64\dvipng.exe' --depth -T tight -z 3 -bg Transparent -D 122.859 -o C:\Users\Steve\AppData\Local\Temp\tblatex-30.png C:\Users\Steve\AppData\Local\Temp\tblatex-30.dvi > C:\Users\Steve\AppData\Local\Temp\tblatex-30-depth.txt"

If the second command does not work either, the only ways to get LatexIt! working with spaces in paths are the options 1., 3., 4., or 5. of my last post.

At least you have found the source of the problem, frustrating though it may be.

For myself I have decided on 2. since it's easy to implement and I can use \usepackage{color} instead. But I have combined it with a path with no spaces for dvipng. I realise that's not for everyone but it works well for me.

Your suspicions are correct. Neither of those cmd.exe lines work, the first doesn't give any message but the second says:
The filename, directory name, or volume label syntax is incorrect.

In both cases the png is not created and no text put in the depth file

sphh commented

Thank you for your help and your patience in this remote debugging session!!!!

Yes, 2. is only possible, if you don't have a space in the path, not that everybody is willing to do …

This StackOverflow answer suggests that triple quotes might be an answer: could that work? https://stackoverflow.com/questions/7760545/escape-double-quotes-in-parameter

@sphh why does this answer of yours not work?

cmd.exe /C "our_cmd -fg \"RGB 0 0 0\" > our_output_file"

sphh commented

Because the \ is escaped with another \ and " becomes \" and we end up with

"our_cmd -fg \\\"RGB 0 0 0\\"" > our_output_file"

🤷‍♂

Hello,
First of all I want to say that I really like this add-on but because of this bug I could not use it any more.
Since it was taking a long time to fix, I tried find a temporary solution for myself and found something that works on my Windows machine (replace line 341 and 342 with):

var prefix_hack = ["echo ", "\"", "&"];
var suffix_hack = ["&", "echo", "\""];
var dvipng_args = [dvipng_bin.path, "--depth", "-T", "tight", "-z", "3", "-bg", "Transparent", "-D", dpi, "-fg", font_color, "-o", png_file.path, dvi_file.path, ">", depth_file.path];
var process_args = [shell_option].concat(prefix_hack, dvipng_args, suffix_hack);
shell_process.run(true, process_args, process_args.length);

Note that the echo in the prefix contains a space while the echo in the suffix does not. The main idea of this hack is to add additional quotes around the command while removing the unwanted quotes and backslashes with the echo command. The command that then gets executed is:

cmd.exe /C "echo " \" & <dvipng cmd> & echo \"

Here is <dvipng cmd> the correct dvipng command. Note that nsIProcess adds quotes around font_color and all paths that contain spaces. It will thus execute the following three commands: echo " \" , <dvipng cmd> and echo \. I also found the source code of the subfunction in nsIProcess that adds the additional quotes and backslashes:

https://searchfox.org/mozilla-central/source/toolkit/xre/AssembleCmdLine.h#24

I have no idea if this will be useful or not. I just wanted to share the things that I have found.

Brilliant! Works for me with correct font colour.

sphh commented

@sfrcorne: Great!! Do you want to make a pull request?

BTW replacing the lines 341 and 342 does not give any sense for me. Which branch are you in? Do you have the PR #75 applied? Could you please give a context to those two lines to be replaced? Many thanks!

protz commented

This is at the same time both horrifying and awe-inspiring. Congratulations on the hack!

If you want, I could try to make a pull request. It is a while since I used git, so I will have to look at it again after work.

I started from the mailextension branch, since that one was the most likely one to work with the new thunderbird. Also it looks like the changes made in PR #75 where also added to the "mailextension" branch in this commit.

I simply downloaded that branch as a .zip, changed the appropriate lines, compressed it as a .xpi and then installed it into thunderbird. These original two lines should contain the following two lines of code:

var dvipng_args = [sanitize_path(dvipng_bin.path), "--depth", "-T", "tight", "-z", "3", "-bg", "Transparent", "-D", dpi, "-fg", "\""+font_color+"\"", "-o", sanitize_path(png_file.path), sanitize_path(dvi_file.path), ">", sanitize_path(depth_file.path)];
shell_process.run(true, [shell_option, dvipng_args.join(" ")], 2);

I also noticed while looking at the source code that nsIProcess handles the arguments differently when called from a Windows/Unix/Macosx machine. I did not look at the Unix and Macosx cases/source codes in detail but it seems that nsIProcess does not modify the arguments on these machines but this still needs to be tested.

Also note that the latex_process on line 243 and 244 of main.js of the "mailextension" branch will also not work correctly on Windows when there are spaces inside the temp_dir and temp_file.path strings. However, I think this one can be fixed without using prefix_hack and suffix_hack.

sphh commented

Ah, great! Thanks for clarifying the branch, now I know where to look! And chapeau for the hack!!

You are absolutely right, that spaces in any path (temp_dir and temp_file) will cause problems. We just didn't encounter them, because up to now, everybody used the default temporary directory (which luckily does not include spaces, so I closed my eyes and was hoping, that nobody changes this to a path with spaces ;-)!)

I would guess, that this hack only works on Windows (and MacOS and Linux would stumble)?

BTW @sfrcorne: If you don't want to do the PR, because you are not familiar with git anymore, I can do it for you. Just tell me, what you prefer!

You can do the PR if you want, it saves me the work of relearning the git commands.

I would guess, that this hack only works on Windows (and MacOS and Linux would stumble)?

So I looked at the nsIProcess source code in some more detail. As far as I can tell, the arguments are not altered in any way on Unix or MacOSX. In Unix the arguments are passed to the execve function in Unix (manual), while on MacOSX they are passed to the posix_spawnp function in MacOSX (manual). This means that on Unix/MacOSX nsIProcess will execute the following command:

/bin/sh -c echo  " & <dvipng cmd> & echo "

In other words it will successfully run the echo command and return the string & <dvipng cmd> & echo. After that latexit will complain that it cannot find the png file (because it was not created) even though the nsIProcess call returned successfully.

To solve this you could try something like the following: (Warning not yet tested!)

replace line 341 and 342 of main.js of the "mailextension" branch with:

if (isWindows) {
    var prefix_args = ["echo ", "\"", "&"];
    var suffix_args = ["&", "echo", "\""];
} else {
    var prefix_args = ["\""];
    var suffix_args = ["\""];
}
var dvipng_args = [sanitize_path(dvipng_bin.path), "--depth", "-T", "tight", "-z", "3", "-bg", "Transparent", "-D", dpi, "-fg", sanitize_path(font_color), "-o", sanitize_path(png_file.path), sanitize_path(dvi_file.path), ">", sanitize_path(depth_file.path)];
var process_args = [shell_option].concat(prefix_args, dvipng_args, suffix_args);
shell_process.run(true, process_args, process_args.length);

and replace sanitize_path function of line 152 of main.js of the "mailextension" branch with:

var sanitize_path = function(path) {
    if (isWindows)
        return path;
    else if (path.indexOf(" ") < 0)
        return path;
    else
        return "\""+path+"\"";
}
sphh commented

@sfrcorne: I just remembered that you can edit files directly here in github. This automatically clones the repository for you and after finishing the editing, you can easily make a PR. None of the non-memorable git-hub commands involved. Do you want to do this, so that this ingenious hack is credited to you?

Just go to this link https://github.com/protz/LatexIt/blob/mailextension/content/main.js and press the pencil at the top of the file.

sphh commented

Great, thanks!!!!

@sfrcorne Do you want to do the same for the master branch, so that the people stuck with TB 68 can enjoy your ingenious hack as well?

sphh commented

This is now solved for the mailextension branch and wait to be merged into the master branch by @protz. Then this issue can be closed.