What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Basic Questions - LaTeX

Pages: (6): « First « 1 2 [ 3 ] 4 5 6 » Last »
Basic Questions - LaTeX
Author: Message:
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
1) I am probably doing something wrong, as I don't know much about command line commands at all... However, even if I try it manually (eg, open cmd.exe) and then use the command "latex C:\Test\file.tex" or with quotes, double quotes, I've tried everything, but for some reason whenever I do this, it keeps looking in some random folder of the latex installation.

The installation I'm using is just MikTex, probably the most used in windows. It comes with the latex and dvipng command line commands. I'm sure there are others out there that allow me to do it in one go however.

But now the question... Why? Does it really matter that much that I use a batch file? Why go through all this trouble of piping etc, if I can just fire up a batch file? I'm not trying to sound like I know it better lol (cause i dont) but I'm just asking, maybe there's an important reason...

And the two commands on one line, didn't know that, I might use that than, thanks!


2) I thought so, as I am now running into the problem. As soon as I show the window that should show the latex png image, it is actually showing the old equation. It seems that the png file is shown before it is created (it already existed from my previous tests of course), so it is showing the old png file. I'll look into timers, thanks.

3) Well, then a big compliment for that. Believe me, I've tried, and failed hehe. Perhaps I can place a feature request? I am really missing the comment/uncomment selection, and possibly the format selection features. The comment/uncomment selection feature would insert (or remove) a comment (//) before each selected line, allowing users to quickly comment out pieces of code.
The format selection is not very hard to implement either I think since the language has a pretty easy construct (not like the language I had to create a parser for... eugh).

Those features would really make it more complete. Of course, more Intellisense would be a real improvement too, but I realize that is probably too much to ask, since it requires parsing the code completely. And if you're going that way, you might as well create your own scripting language hehe...
06-17-2009 07:38 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Basic Questions - LaTeX
quote:
Originally posted by Flippy
But now the question... Why? Does it really matter that much that I use a batch file? Why go through all this trouble of piping etc, if I can just fire up a batch file? I'm not trying to sound like I know it better lol (cause i dont) but I'm just asking, maybe there's an important reason...
Simplicity. And thus a lot less prone to errors and stuff. It might seem 'more trouble' but it actually isn't.

You could ask the same thing ("why?") the oher way around:
Why using a lot of code, doing a lot of stuff, requiring external files, etc if you can simply do it in 1 very readable line of code?

Or why do people always try to write short and efficient code or improve their code when you can also do it the long way around using all sorts of unneeded and/or depricted stuff....

quote:
Originally posted by Flippy
And the two commands on one line, didn't know that, I might use that than, thanks!
The DOS command line is actually a hell of lot more powerful than most people know... ;)

quote:
Originally posted by Flippy
3) Perhaps I can place a feature request?
of course, by all means do! Create a new thread in Msgplus! General Talk.

quote:
Originally posted by Flippy
And if you're going that way, you might as well create your own scripting language hehe...
Actually... The JScript engine in Plus! already contains a lot of added functions and events specific for Plus! and Messenger. That is what makes Plus! scripting so powerful. It isn't just JScript (since you can't do much in pure JScript in this regards), it is JScript on steriods :p

For example timers, which are not available in pure JScript, you can also use any Windows API you like, etc... Making it extremely powerful (and just as dangerous as any other language).
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-17-2009 08:27 PM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Of course, the one line DOS command is much better. But I was talking about the piping etc, which seems to be alot more trouble than a single DOS command :p

I wanted to try the Run command, with the boolean you mentioned to make it synchronous, but I can't find the documentation for it. The Windows scripting guide I download won't work, every page shows as 'page not found' for some reason :S Ive tried downloading it numerous times, there must be something wrong with the file on their end I guess... Could you tell me how to use the Run command synchronously?

In the mean time I'm looking at user timers. It doens't seem very complicated, I might get it this way too.
06-17-2009 08:32 PM
Profile E-Mail PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Meh, I can't get it using timers either... Whatever I try, I always end up with a while loop that basically does the same thing I had before (the Sleep function).

How do I use the timers for this?
06-17-2009 08:38 PM
Profile E-Mail PM Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: Basic Questions - LaTeX
quote:
Originally posted by Flippy
Meh, I can't get it using timers either... Whatever I try, I always end up with a while loop that basically does the same thing I had before (the Sleep function).

How do I use the timers for this?
look in the scripting documentation under Objects Reference > MsgPlus Object > Functions
06-17-2009 09:02 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Basic Questions - LaTeX
You use piping and redirecting as an alternative in case the DOS tool you use doesn't support the proper parameters (like paths in filenames, etc).

----------

The reason why you get a "page not found" is not because of a damaged file or faulty download, but because your Windows is propbably not up to date or is set to block certain file content.
Also make sure you first download the file and then open it (so don't open it directly from the download dialog in MSIE as it will block the contents by default when the file is opened directly from the download).

see here:
http://geekswithblogs.net/evjen/archive/2006/06/29/83567.aspx
or here:
http://www.helpscribble.com/chmnetwork.html
Everything is also recapped here:
Silentdragon's reply to Official Scripting Documentation doesn't work.

----------

In regards to timers, see the Plus! Scripting documentation. Timers are event driven, you don't need any loop at all.

----------

PS, quickly looking at http://docs.miktex.org/manual/texfeatures.html#includedirectory
I see there is a command line parameter "-include-directory=dir".
Then there is also an output directory parameter:
http://docs.miktex.org/manual/texfeatures.html#outputdirectory
etc...

So there sure are a lot more possebilities and at first sight it looks like you can do everything from one command line using only the LATEX command and the proper parameters to create the DVI file.

And by very quickly skimming over the docs I found there are also some commands you can use inside a tex file to run other latex related things, so it might even be possible to also integrate the convertion to PNG in that same TEX file, dunno.

----------

So, everything boils down to reading the documentations of the stuff you wanna use. This means the docs for MikTeX, The Plus! Scripting Docs, and the Windows Script Docs.

;)

This post was edited on 06-17-2009 at 09:31 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-17-2009 09:27 PM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Alright, the docs now work, thanks for that :)

I got the Run command to work, including the -include-directory switch and -output-directory switch. So I have been able to run the latex command without the use of the cd command, great!

But, it appears the dvipng command does not use these switches. It reports several fatal errors there...

So, I tried to use the & symbol to string the three commands (cd, latex, dvipng) together:
JScript code:
        var cmd = "cd " + path + " & " +
                "latex file.tex & " +
                "dvipng -T tight -x 1200 -z 9 file.dvi";
               
        Debug.Trace("Executing command: \"" + cmd + "\".");
 
        var oShell = new ActiveXObject('WScript.Shell');
        oShell.Run(cmd, 0, true);  
        oShell = null;


Since the debugger tells me the command exactly, I tried it manually, simply pasting it in the cmd window. And it worked perfectly fine. Created the dvi and the png file!

But... The script errors on the Run command. It tells me it's an unknown error, error code -2147024894 (which googling found nothing).

The debugger output is this (dutch I know, but many of you seem to be from belgium ;) so you might understand):
code:
Executing command: "cd C:\Program Files\Messenger Plus! Live\Scripts\MSNLaTeX & latex file.tex & dvipng -T tight -x 1200 -z 9 file.dvi".
> Fout gedetecteerd in regel 100 van "MSNLaTeX.js": <onbekende fout>.
  (Code: -2147024894)
> Fout gedetecteerd in "OnEvent_ChatWndReceiveMessage".
  (Code: -2147352567)

The command itself cannot be the problem as it works when I use it manually... What's going on?
06-17-2009 10:01 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Basic Questions - LaTeX
quote:
Originally posted by Flippy
> Fout gedetecteerd in regel 100 van "MSNLaTeX.js": <onbekende fout>.
What is on line 100?
06-17-2009 10:42 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Basic Questions - LaTeX
You could debug that code yourself by stripping down the command line and testing it part by part... starting with the CD command...

Doing this it shows two things:

- You get the error because you start your command line with an internal DOS command (the CD command). Apparently you can't use the Run method to run an internal DOS command since the Run method does not start a DOS interpreter on its own.

The reason normal programs work is because they are executables. An internal DOS command isn't an executable, but is actually part of the DOS interpreter.

This can be solved by starting the interpreter yourself like so:
    cmd /c cd c:\blahblah

- Second, you forgot to enclose long path and file names with quotes:
    cd "c:\Program Files\Messenger Plus!\etc"

So, your command line in the script should be:
JScript code:
var cmd = "cmd /c cd \"" + path + "\" & " +
                "latex file.tex & " +
                "dvipng -T tight -x 1200 -z 9 file.dvi";

And that will work...

However, for testing and debugging purposes you could temporarly do two things:

- change "cmd /c" to "cmd /k". This will keep the command window open and gives you the chance to actually see and check the output (more info on this if you type cmd /? in the interpreter). You must type "exit" to close the window and continue the script!

- change the second parameter of the Run method to 1, so the command window isn't hidden.

Thus for testing purposes, you could use:
JScript code:
var cmd = "cmd /k cd \"" + path + "\" & " +
                "latex file.tex & " +
                "dvipng -T tight -x 1200 -z 9 file.dvi";
 
var oShell = new ActiveXObject('WScript.Shell');
oShell.Run(cmd, 1, true);  
oShell = null;

and when everything works ok, you change it to:
JScript code:
var cmd = "cmd /c cd \"" + path + "\" & " +
                "latex file.tex & " +
                "dvipng -T tight -x 1200 -z 9 file.dvi";
 
var oShell = new ActiveXObject('WScript.Shell');
oShell.Run(cmd, 0, true);  
oShell = null;


;)


PS: however, note that using the CD command to work around the dvipng limitation (you are absolutly sure you can't provide absolute paths in some way to dvipng, or set the input path to the script folder?) could cause a failure in case the script (and Plus!) wasn't installed on the default Windows drive.

The command "CD C:\blahblah" will not change the current drive to C. It will only change the path on the C-drive. So, if the current drive is D, the whole command line will fail again.

This is also easly solved by simply adding the command "C:" right before the "CD" command:
    cmd /c C: & CD "c:\blahblah" & etc...

or:
JScript code:
var cmd = "cmd /c " + path.substring(0, 2) + " & cd \"" + path + "\" & " +
                "latex file.tex & " +
                "dvipng -T tight -x 1200 -z 9 file.dvi";

This also applies in the same way if you use batch files or whatever though!. So you see, in the end, and to come back to your question of "why?", if you want to make things bug proof, using an absolute path name and using the proper command line parameters is much easier and way more efficient and shorter than using batch files and trying to work around all sorts of stuff like external files. (Provided the tools do support the needed parameters of course. Otherwise you are forced to use a workaround. But in that case you still should use the most efficient workaround - which batch files are certainly not).

This post was edited on 06-18-2009 at 03:14 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-18-2009 01:42 AM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Wow thanks, I learned something new again :p

I've got it nearly done now. The latex png is created and shows in a window.

Only thing left now is to resize the window depending on the size of the image.

I have been trying first to simply resize the window, without caring for the size of the image yet. I have very limited experience with API calls from VB/C#. I'm looking at the SetWindowPos function now, and apparently it needs the window handle (wnd.Handle, correct?), the X, Y, width and height obviously, and then two other parameters I can't really understand.

First, there's the hWndInsertAfter parameter, which I assume is to determine whether the window is going to be on top, bottom etc of the z-order. OK. I want it to be on top (but not topmost), so apparently I need the HWND_TOP value.

Now... What is the value I need to use??!! That is the main reason I always have trouble with API programming. The MSDN entries never list the actual values for their constants?! How am I supposed to know what value to use?
I'm probably missing something... In the end I googled HWND_TOP SetWindowPos and found the value by accident in some obscure site... Why can't the MSDN page simply tell me what the value is?

Oh well, in the end I got it working with this:
JScript code:
Interop.Call("user32.dll", "SetWindowPos", wnd.Handle, 0, 1, 1, 800, 600, 0x0040);

It puts the window in the top-left corner, with a size of 800x600. Great.


Now a problem: The ImageElement displaying the equation is not resized. Do I need to resize that manually, too? Or can I use some kind of docking/anchoring to ensure that it stretches with the window when resized?

And, how can I find the size (not in kb, but width/height) of the PNG image? Ideally I want the window to be resized accordingly.

Finally, is it possible to find the location of the current chatwindow, so I can have the equation window pop up to the side, bottom, top, of it (depending on where the window is)?

I could calculate the 'free area' to the sides of the window, and then determine whether to display it to the right or left of it, to ensure that it does not pop up out of view.

If I can just find the location and size of the chat window that would be enough.



Oh yeah one more thing, there seems to be a bug in the editor. For the ImageElmt_SetImageFile function to accept a full path ("C:\Program Files\...") instead of a path relative to the Images folder, I needed to insert a backslash before the file path, so in my case this becomes:
JScript code:
wnd.ImageElmt_SetImageFile("EquationImage", "\\" + path + "\\file1.png");

The problem is that the editor (or at least the syntax highlighting) thinks that "+ path + ..." is part of the string.
When I run this code it works fine however, so it must be just a bug in the syntax highlighting.

Here's a screenshot to clarify the problem:
[Image: 144hfb.jpg]

This post was edited on 06-18-2009 at 11:33 AM by Flippy.
06-18-2009 11:29 AM
Profile E-Mail PM Find Quote Report
Pages: (6): « First « 1 2 [ 3 ] 4 5 6 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On