Bug 135997 - KopeTeX doesnot display math and freezes Kopete
Summary: KopeTeX doesnot display math and freezes Kopete
Status: RESOLVED FIXED
Alias: None
Product: kopete
Classification: Applications
Component: Latex Plugin (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal with 20 votes (vote)
Target Milestone: ---
Assignee: Dennis Nienhüser
URL:
Keywords:
: 139582 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-10-20 01:52 UTC by Sonmez Sahutoglu
Modified: 2008-04-20 21:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fixes kopetex script to use correct shell (360 bytes, patch)
2006-11-18 14:56 UTC, Stefan Parviainen
Details
Alternate fix for the problem (267 bytes, patch)
2007-02-13 06:27 UTC, Simon80
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sonmez Sahutoglu 2006-10-20 01:52:52 UTC
Version:           0.12.2 (using KDE KDE 3.5.2)
Installed from:    Ubuntu Packages
Compiler:          Target:i486-linux-gnu 
OS:                Linux

When I enter math formulas between $$ $$ such as $$ \sum $$ Kopete freezes. I use Ubuntu Dapper. I can see the pictures produced in my tmp folder by somehow they don't show up in Kopete and it freezes.
Comment 1 David Patin 2006-11-09 11:20:07 UTC
It's the same for me with Kubuntu 6.10
Comment 2 Stefan Parviainen 2006-11-18 14:42:24 UTC
The problem is that /bin/sh is specified as the shell in the kopete_latexconvert.sh script, while /bin/bash really should be used. sh is linked to bash in most distributions, but in Ubuntu it is linked to dash.
It seems that the scripts creator assumed that it would work with any standard shell, while it actually requires bash.

Simply change the first line of /usr/bin/kopete_latexconvert.sh from "#!/bin/sh" to "#!/bin/bash" to make the script work properly.

Comment 3 Stefan Parviainen 2006-11-18 14:56:58 UTC
Created attachment 18601 [details]
Fixes kopetex script to use correct shell

kopete_latexconvert.sh seems to only work with bash, so change the shell
accordingly.
Comment 4 Philip Rodrigues 2006-11-18 17:01:49 UTC
Of course, this will break on FreeBSD, where /bin/sh exists, but bash (if it's installed) lives in /usr/local/bin/bash :-). Looks like the correct fix is to make the script not require bash (ie, use genuine sh syntax). 

Hrm, though it works here, and must be using sh. Can someone on kubuntu take a look at the script to see why dash doesn't like it?
Comment 5 Frank Roscher 2006-11-18 20:15:03 UTC
It seems to be the "let"-command (line 225 here) and this (line 194):
test -f ${f##*/} || ln -s $f . # multi-processing!

I'm no bash-monkey though, so someone else will have to figure out what's the problem :)

The actual error messages are this:
/usr/bin/kopete_latexconvert.sh: 1: let: not found
test: 1: out.eps: unexpected operator
ln: creating symbolic link `./*.eps' to `/home/frank/*.eps': File exists
Comment 6 Andrea Di Menna 2006-11-19 16:19:30 UTC
To solve this just change that line (kubuntu 6.10):

let OPTIND=$OPTIND+1

with:

OPTIND=`expr $OPTIND + 1`

It works with dash, at least it works on my system.

I have spotted another problem:
when you write something like $$ text $$ in a chatwindow and you are using the 
latex plugin text is sent to kopete_latexconvert.sh as an input parameter. 
Since this is a command line parameter characters like \f \t etc etc are 
interpreted as special character. It happens you have to write something like 
\frac which is of course misunderstood by the script. A solution would be 
escaping backslashes. 
In latex.ccp you should add in the handlelatex method (I think, I'm not a lot 
into Qt)

QRegExp backslash ( "\" );
latexformula.replace( backslash, "\\" ); 

Maybe other kind of characters should be escaped, like $.

Sorry, I can't provide any patch cause I haven't got kopete 0.12.3 source 
files. Hope some of the developpers can provide some kind of fix for this. 
Thank you
Andrea
Comment 7 Philip Rodrigues 2006-11-20 22:11:30 UTC
I made the suggested change here, and it still works, so it seems safe for non-kubuntu distributions (I'm running FreeBSD).

I can't reproduce the problem you mention with \frac - I can do something like:
$$\frac{3}{5}$$
and get a nice fraction in my kopete window.
Comment 8 Andrea Di Menna 2006-11-21 08:35:42 UTC
Can anyone else try that? Talking about people who is using dash or bash (I guess Philip you are using sh or maybe tcsh, don't know).
Philip can you try typing
$$\\frac{3}{5}$$ and see what happens? Thank you very much.

Andrea
Comment 9 Philip Rodrigues 2006-11-21 21:39:50 UTC
If I enter $$\\frac{3}{5}$$ I get "frac35" displayed in my kopete window. 
Comment 10 Frank Roscher 2006-11-21 21:55:56 UTC
That's because you only need one backslash. Remove the second and it will work.
Comment 11 Frank Roscher 2006-11-21 21:58:00 UTC
Whoops, sorry, never mind. I read that message out of context :(
Comment 12 Bram Schoenmakers 2007-01-04 13:44:48 UTC
*** Bug 139582 has been marked as a duplicate of this bug. ***
Comment 13 Simon80 2007-02-13 06:27:18 UTC
Created attachment 19657 [details]
Alternate fix for the problem

Here's another fix - this uses the built in $(( expression )) syntax instead of
the expr command. I'm not sure which is more portable.
Comment 14 Dennis Nienhüser 2008-04-20 19:27:21 UTC
SVN commit 799167 by nienhueser:

Increment variable using sh compatible arithmetic expansion $(( )), tested with dash and bash. Use -d parameter of mktemp to avoid removing and recreating the temporary file as a directory.
CCBUG: 135997


 M  +2 -4      kopete_latexconvert.sh  


WebSVN link: http://websvn.kde.org/?view=rev&revision=799167
Comment 15 Dennis Nienhüser 2008-04-20 19:30:24 UTC
The above fixes it for Kubuntu, thanks for the input everyone. I'll backport this later and see what can be done for escaping characters (the \frac problem for example happens with dash, but not bash).
Comment 16 Dennis Nienhüser 2008-04-20 20:35:37 UTC
SVN commit 799193 by nienhueser:

Use printf instead of echo to avoid escape sequence interpretation by the underlying shell. This means that latex commands don't get messed up by the shell anymore.
CCBUG: 135997


 M  +1 -1      kopete_latexconvert.sh  


WebSVN link: http://websvn.kde.org/?view=rev&revision=799193
Comment 17 Dennis Nienhüser 2008-04-20 21:11:26 UTC
SVN commit 799199 by nienhueser:

Increment variable using sh compatible arithmetic expansion $(( )), tested with dash and bash. Use -d parameter of mktemp to avoid removing and recreating the temporary file as a directory. 
Backport of revision 799167.
CCBUG: 135997


 M  +2 -4      kopete_latexconvert.sh  


WebSVN link: http://websvn.kde.org/?view=rev&revision=799199
Comment 18 Dennis Nienhüser 2008-04-20 21:13:24 UTC
SVN commit 799200 by nienhueser:

Use printf instead of echo to avoid escape sequence interpretation by the underlying shell. This means that latex commands don't get messed up by the shell anymore. 
Backport of revision 799193.
BUG: 135997


 M  +1 -1      kopete_latexconvert.sh  


WebSVN link: http://websvn.kde.org/?view=rev&revision=799200