protz / LatexIt

An extension for Thunderbird that allows you to generate LaTeX in your emails and send it as inline images
http://www.xulforum.org/go_code
37 stars 16 forks source link

dvipng failed with error code 1. Aborting. #74

Closed Fcornetg closed 3 years ago

Fcornetg commented 4 years ago

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 4 years ago

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?

Fcornetg commented 4 years ago

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 4 years ago

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

Fcornetg commented 4 years ago

Yes it should, but nothing changes.

sphh commented 4 years ago

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.

Fcornetg commented 4 years ago

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 4 years ago

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 ""?

err4re commented 4 years ago

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 4 years ago

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 4 years ago

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 …

maharper commented 4 years ago

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.

stevem6 commented 3 years ago

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.

stevem6 commented 3 years ago

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 3 years ago

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?

stevem6 commented 3 years ago

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.
stevem6 commented 3 years ago

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 3 years ago

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 3 years ago

@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 ^"?

stevem6 commented 3 years ago

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 3 years ago

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!

stevem6 commented 3 years ago

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 3 years ago

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 https://github.com/protz/LatexIt/issues/74#issuecomment-782842859). That might help the wizards! Thanks.

stevem6 commented 3 years ago

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 3 years ago

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.

stevem6 commented 3 years ago

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 3 years ago

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];
stevem6 commented 3 years ago

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.
stevem6 commented 3 years ago

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

sphh commented 3 years ago

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

stevem6 commented 3 years ago

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 3 years ago

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"
stevem6 commented 3 years ago

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 3 years ago

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?

stevem6 commented 3 years ago

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.

stevem6 commented 3 years ago

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 3 years ago

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.

stevem6 commented 3 years ago

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 3 years ago

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.

stevem6 commented 3 years ago

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

stevem6 commented 3 years ago

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

stevem6 commented 3 years ago

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

stevem6 commented 3 years ago

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 3 years ago

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!!

stevem6 commented 3 years ago

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 3 years ago

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?

stevem6 commented 3 years ago

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 3 years ago

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:

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.

stevem6 commented 3 years ago

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 3 years ago

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.

stevem6 commented 3 years ago

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