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 » Last »
Basic Questions - LaTeX
Author: Message:
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. Basic Questions - LaTeX
Hi,

I have been trying to write a LaTeX add-in using C#.NET for Windows Live Messenger, and I came pretty close actually. I tried it in a normal windows application first, and it worked fine. Whenever a message received contains one or more "$$" tokens, the whole message is seen as a tex string, and the double signs "$$" are replaced by a single "$". The string is stored in a .tex file (including the \begin{document} etc preamble) and then converted to a .dvi file using the command line. Finally a PNG image is created from the dvi file, again using the command line. The PNG image is shown in a separate window (I am pretty sure it's not possible to show it inline in the actual MSN window, so I'm not even going to bother trying that).

When I tried it in my MSN Add-in however, it failed, because it seems I cannot create folders, files, or anything, from within the MSN Add-in. I keep getting security exceptions on the most silly things...


So I had a look at Plus! scripting, which may work for me.


I have the following questions. If the answers to these are all yes then I am pretty confident I can get it to work.

1. Can I use basic file I/O, like creating a folder in the Common Application Data directory for example? Can I also create files on the fly without getting security exceptions?

2. Can I use the command line (cmd.exe) and determine what commands to send? If not, can I execute a batch file?

3. Can I display a PNG image (somewhere on the hard disk), either in the current MSN window (probably not), or in a separate window??


Thanks for any help!


EDIT
I thought of another question, not of grave importance, but still useful:

4. If I receive a message with emoticons, does the Message string in the script (in the ReceiveMessage event I guess) display the shortcut of the emoticon, or does it simply skip it? In other words, does the :) emoticon come out as :) or will it be gone from the string?


5. Can I turn emoticons off temporarily when the user is typing a message the contains the "$$" string? Otherwise, you may get emoticons in your latex string...

This post was edited on 06-17-2009 at 09:23 AM by Flippy.
06-17-2009 09:14 AM
Profile E-Mail PM Find Quote Report
ryxdp
Senior Member
****


Posts: 804
Reputation: 16
29 / Male / Flag
Joined: Jun 2006
RE: Basic Questions - LaTeX
The short answers to all three of these questions are indeed "yes", as the language used in Plus!'s scripting engine is JScript, a rather flexible and easy to learn language.

quote:
Originally posted by Flippy
1. Can I use basic file I/O, like creating a folder in the Common Application Data directory for example? Can I also create files on the fly without getting security exceptions?

Yes, you can, by creating an ActiveXObject:

jscript code:
var x=new ActiveXObject('Scripting.FileSystemObject');

You will have to look up the functions you want on MSDN, though.

quote:
2. Can I use the command line (cmd.exe) and determine what commands to send? If not, can I execute a batch file?

Again, this can be solved using an ActiveXObject:

jscript code:
var y=new ActiveXObject('WScript.Shell');
y.Run('cmd.exe');

quote:
3. Can I display a PNG image (somewhere on the hard disk), either in the current MSN window (probably not), or in a separate window??

This one is a little harder to do, but thanks to Messenger Plus!, we can make our own windows using the Plus! interface, using XML. If you read the Scripting documentation, it has a small introduction to creating your own windows that can be combined with the extra functions in the scripting engine to create a fully functional interface for your scripts.

quote:
4. If I receive a message with emoticons, does the Message string in the script (in the ReceiveMessage event I guess) display the shortcut of the emoticon, or does it simply skip it? In other words, does the :) emoticon come out as :) or will it be gone from the string?

The returned message will show the emoticon's shortcut.

quote:
5. Can I turn emoticons off temporarily when the user is typing a message the contains the "$$" string? Otherwise, you may get emoticons in your latex string...

As all emotions will be returned as their shortcuts, including custom emotions, it would be impossible to remove their strings from the message. If you mean preventing the actual emoticons displaying while the LaTeX string is being written, there may be some sort of registry edit, for example, that you can change temporarily, but I don't think its effect would be immediate.

Hope this helped :P

This post was edited on 06-17-2009 at 09:34 AM by ryxdp.
06-17-2009 09:26 AM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Thanks, that gives me hope.

For 1, 2 and 3 I will see what I can do. I'm not completely comfortable with the FSO object but I may get it to work anyway. Thanks.

For 4, and 5, that's ok. If the returned message shows the emoticon as string I suppose there isn't really a problem. The only 'problem' would be for the user typing the latex, as he would see emoticons when he's typing latex. But since the emoticons don't effect the message string, anything like (x) (little girl :p) will still be seen as (x), and not as (x), so the latex will work correctly.

Thanks!

This post was edited on 06-17-2009 at 09:49 AM by Flippy.
06-17-2009 09:48 AM
Profile E-Mail PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Erm, one thing lol, perhaps this deserves a new thread but I'll ask here first.

How do I replace all instances of a string with another string?
I want to replace every "$$" with a single "$" in the Message, so I tried this:
jscript code:
var texCode = Message.replace("$$", "$");
The result is that only the first "$$" is replaced... The next occurences are not touched.
06-17-2009 10:01 AM
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 ryxdp
As all emotions will be returned as their shortcuts, including custom emotions, it would be impossible to remove their strings from the message. If you mean preventing the actual emoticons displaying while the LaTeX string is being written, there may be some sort of registry edit, for example, that you can change temporarily, but I don't think its effect would be immediate.

if you want to remove them from the whole message you can just use /noicon at the start of the message... it removes all icons

just looking up the stuff about getting all instances with a regex...

This post was edited on 06-17-2009 at 10:14 AM by NanaFreak.
06-17-2009 10:11 AM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: RE: Basic Questions - LaTeX
quote:
Originally posted by NanaFreak
quote:
Originally posted by ryxdp
As all emotions will be returned as their shortcuts, including custom emotions, it would be impossible to remove their strings from the message. If you mean preventing the actual emoticons displaying while the LaTeX string is being written, there may be some sort of registry edit, for example, that you can change temporarily, but I don't think its effect would be immediate.

if you want to remove them from the whole message you can just use /noicon at the start of the message... it removes all icons

No I mean that you can't type icons at all, so typing :) will not result in :). Basically, I want to check what the user is typing (so he has not sent it yet! He is still typing), and if his message so far contains any "$$", then I want to disable the Show Emoticons option, so that he can type latex without emoticons interfering.

I realize this is probably not possible, but it doesn't hurt to ask ;)
06-17-2009 10:14 AM
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
the best bet is to just do it as the message is sent...

also with your regex you want:

javascript code:
var texCode = Message.replace(/\$\$/g, "$");
06-17-2009 10:17 AM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: RE: Basic Questions - LaTeX
quote:
Originally posted by NanaFreak
the best bet is to just do it as the message is sent...

also with your regex you want:

javascript code:
var texCode = Message.replace(/\$\$/g, "$");

Ahh, I was already trying regex but I forgot about the \$ instead of just $ :p
Thanks!

And (according to ryxdp) any emoticons in the message will be replaced by their shortcut, so even if the user is typing emoticons such as f(x), the latex will still read f(x) correctly. It's only a little annoying to the user writing the latex, but he can just turn his emoticons off manually I guess...
06-17-2009 10:25 AM
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
And (according to ryxdp) any emoticons in the message will be replaced by their shortcut, so even if the user is typing emoticons such as f(x), the latex will still read f(x) correctly. It's only a little annoying to the user writing the latex, but he can just turn his emoticons off manually I guess...

it will actually turn out as f(X) as messenger likes to make emoticons capitals... just to let you know ;)

This post was edited on 06-17-2009 at 10:53 AM by NanaFreak.
06-17-2009 10:30 AM
Profile PM Find Quote Report
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. RE: Basic Questions - LaTeX
Oh darn, that will be a problem... Oh well, let's tackle it one at a time lol.


I have decided not to use the command line directly, but rather just execute a batch file. My code right now is this:
jscript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{
    if (Message.indexOf("$$") != -1)
    {
        var fso = new ActiveXObject('Scripting.FileSystemObject');
       
        // -----------------
        // Create .tex file
        // -----------------
        var texFile = fso.CreateTextFile(path + "\\file.tex", true);
        texFile.WriteLine("\\documentclass{article}\n\\pagestyle{empty}\n\\begin{document}\n");
       
        // Replace all $$ with $
        var texCode = Message.replace(/\$\$/g, "$");
               
        texFile.WriteLine(texCode);
        texFile.WriteLine("\n\\end{document}");
        texFile.Close();
       
        // -----------------
        // Create DVI file and PNG file
        // -----------------
        var batFile = fso.CreateTextFile(path + "\\batFile.bat", true);
        batFile.WriteLine("cd " + path);
        batFile.WriteLine("latex file.tex");
        batFile.WriteLine("dvipng -T tight -x 1200 -z 9 file.dvi");
        batFile.Close();
       
        var shell = new ActiveXObject('WScript.Shell');
        shell.Run(path + "\\batFile.bat");
    }
}
(path is the ScriptFilesPath)

It creates the .tex (latex) file with the correct equation and text, and then creates the batch file with three commands that will convert the tex file into a dvi, and then into a png image file.
(Of course, you need something like MikTex installed for this to work!)

However, the batch file is not running. I just guessed that I could run it with the Run command but apparently not... How do I run it?

This post was edited on 06-17-2009 at 10:41 AM by Flippy.
06-17-2009 10:37 AM
Profile E-Mail PM Find Quote Report
Pages: (6): « First [ 1 ] 2 3 4 5 » 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