Hello,
I am a plain textmate user and a complete computer/programming illiterate who searches advice and input from other, potentially more experienced users of textmate. When writing latex based papers using the wonderful latex bundle I frequently want to do a quick and simple calculation. Unfortunately, this often involves other formats than those provided by the existing math bundle and I have to invoke an external calculator. Would it be possible to extend the math bundle to normal calculator capabilities? IE providing exponential/logarhithmic, power function, trigonometric functions, numbers in ecponential notation etc. ?
I don't know whether others miss this feature. I would certainly welcome such extended functionality or some experienced guidance how to achieve the same functionality with existing bundles. Using the R bundle I tried to send commands to R, which I found very slow (and not what I would find useful), and also to execute R on the selection, but only to the effect of receiving an error message.
JJ
On Dec 7, 2006, at 6:29 PM, janssen@ccr.jussieu.fr wrote:
I don't know whether others miss this feature. I would certainly welcome such extended functionality or some experienced guidance how to achieve the same functionality with existing bundles. Using the R bundle I tried to send commands to R, which I found very slow (and not what I would find useful), and also to execute R on the selection, but only to the effect of receiving an error message.
I personally use R for such things. You need to basically have R.app running on already for the shift-cmd-R thing to work, but then it does. And for your purposes, you can copy the command and modify it so that the output is set to replace selection. (Actually come to think of it, that would be a nice addition) Sorry I am running ahead of myself, I am talking about the command used by the "R Console" syntax, that's the one that tries to read the output and insert it at the current location. At some point in the future this will stop using applescript, and instead rely on something like running R in the background at all times, so it will be faster.
It will be a bit slow I guess, but I am assuming you are talking about computations here and there. Otherwise you'll probably want, if you are comfortable with R, to do most of the work there and import the results from there into your LaTeX document.
JJ
Haris
I personally use R for such things. You need to basically have R.app running on already for the shift-cmd-R thing to work, but then it does. And for your purposes, you can copy the command and modify it so that the output is set to replace selection. (Actually come to think of it, that would be a nice addition)
May be you can, but not me!
Sorry I am running ahead of myself, I am talking about the command used by the "R Console" syntax, that's the one that tries to read the output and insert it at the current location.
Using R > Console > Execute Selection I get this:
152:163: execution error: System Events got an error: NSReceiverEvaluationScriptError: 4 (1)
Unfortunately I don't know what that means. With R > Send Selection / Document to R, I am successful, but then the result is not automatically stored in my LaTeX document -- just in an R window, which is somewhat cumbersome to paste back into textmate.
As you pointed out, speed may be not the most important issue for occasional calculations. But how do I get rid of the error and how do I get the result into my LaTeX document? I really would love to keep these simple calculations as comments in my LateX source code. This way it would be easier for me to keep track of possible errors.
JJ
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Dec 7, 2006, at 7:07 PM, janssen@ccr.jussieu.fr wrote:
I personally use R for such things. You need to basically have R.app running on already for the shift-cmd-R thing to work, but then it does. And for your purposes, you can copy the command and modify it so that the output is set to replace selection. (Actually come to think of it, that would be a nice addition)
May be you can, but not me!
Ok, here is the best I can do for now, with Eridius's help: Create a textmate command that has input "Selected Text or Line", and output: "Replace Selected Text". The text of the command should be the following 8 lines:
#!/usr/bin/env ruby include Math class Float def inspect "%.#{ENV['TM_CALC_PREC'] || 3}f" % self end end print(eval(STDIN.read).inspect)
this should be improved, but it is a start. It will not do integer division properly unless you coerce it: 2/3=0, 2.0/3=0.667
You can use all the commands found here: http://www.ruby-doc.org/core/classes/Math.html without having to write the Math in front. Examples: cos(2.6) -> -0.836 log(3.4) -> 1.224 etc. You can adjust it by defining the TM_CALC_PREC variable to your desired number of precision (defaults to 3). Hopefully we can come up with something more robust etc etc, but this might serve most modest needs, and it is very fast.
Needless to say, you should bind this to your favorite shortcut. Haris
That should probably be
"%.#{ENV['TM_CALC_PREC'] || 3}g" % self
the g instead of f will allow for exponential notation.
If you want 2/3 to do float division, try
class Fixnum def /(n) self.to_f / n end end
That won't affect Bignums, but then again, converting a Bignum to a float could easily lose precision.
On Dec 7, 2006, at 10:22 PM, Charilaos Skiadas wrote:
Ok, here is the best I can do for now, with Eridius's help: Create a textmate command that has input "Selected Text or Line", and output: "Replace Selected Text". The text of the command should be the following 8 lines:
#!/usr/bin/env ruby include Math class Float def inspect "%.#{ENV['TM_CALC_PREC'] || 3}f" % self end end print(eval(STDIN.read).inspect)
this should be improved, but it is a start. It will not do integer division properly unless you coerce it: 2/3=0, 2.0/3=0.667
Using R > Console > Execute Selection I get this:
152:163: execution error: System Events got an error: NSReceiverEvaluationScriptError: 4 (1)
Did you check this:
System Preferences > Universal Access 'Enable access for assistive devices' = true
I had the same error. By changing that System Preference item every Applescript (also be used in R > Console > Execute Line) is working well.
-Hans
I think the answer to this question is yes. Using a German environment your suggestion likely corresponds to Systemeinstellungen... > Bedienungshilfen > 'Zugriff für Hilfsgeräte aktivieren'
But even though I have activated this option, I still observe the same error. Nevertheless, I learn that applescript is the direction to go. It would be really neat to get this running.
Cheers
JJ
System Preferences > Universal Access 'Enable access for assistive devices' = true
I had the same error. By changing that System Preference item every Applescript (also be used in R > Console > Execute Line) is working well.
On 8 Dec 2006, at 13:45, janssen@ccr.jussieu.fr wrote:
I think the answer to this question is yes. Using a German environment your suggestion likely corresponds to Systemeinstellungen... > Bedienungshilfen > 'Zugriff für Hilfsgeräte aktivieren'
But even though I have activated this option, I still observe the same error. Nevertheless, I learn that applescript is the direction to go. It would be really neat to get this running.
AAH, I believe I found your problem. You are working in a German environment. That's the problem.
Within the Applescript the needed windows are named in ENGLISH!
Two possibilities: 1) Change your environment to English or 2) Change the Applescript Code for the R bundle according to the window names which uses R.
Cheers,
-Hans
On 12/8/06, Hans-Joerg Bibiko bibiko@eva.mpg.de wrote:
On 8 Dec 2006, at 13:45, janssen@ccr.jussieu.fr wrote:
<snip problem ;)>
AAH, I believe I found your problem. You are working in a German environment. That's the problem.
Within the Applescript the needed windows are named in ENGLISH!
Two possibilities:
- Change your environment to English
I would suggest that - I gave up the German environment a long time ago since then I do not have anymore a mixed environment (a lot of apps are not localized or bad localized), those problems can't occur usually, a lot of instructions can be better understood because the majority of the users are in an english environment
Niels
This did the trick.
- Change your environment to English
Thanks for all who contributed. I am quite sure that this will improve my workflow. If not, at least it is for a better communication on this (and other) lists.
Nevertheless, since there is a discussion of streamlining / elegance and broad applicability of bundles in another thread. Shouldn't these things made to work under (well may be not all but) most language settings? If I was fluent in Applescript I would certainly contribute (Perhaps Xmas time is just the right time to change my current knowledge iof 'languages').
JJ
On Dec 8, 2006, at 8:31 AM, janssen@ccr.jussieu.fr wrote:
Shouldn't these things made to work under (well may be not all but) most language settings? If I was fluent in Applescript I would certainly contribute (Perhaps Xmas time is just the right time to change my current knowledge iof 'languages').
In some sense this is really a shortcoming of AppleScript. No developer should possibly have to know what name a menu item shows to the user, really. Just supporting a couple more languages is not the answer, this is really something that AppleScript should be fixing, and it's not likely to happen I'm afraid.
In general, AppleScript is really a last resort. We really don't want to be using it to communicate with R, but we haven't found another simple and clear way to do that.
It is really very slow, and for simple math calculations I would really recommend the Ruby or the bc way. Btw did you try the Ruby command? If so, what were its shortcomings, that made it unsuitable for what you want to do?
JJ
Haris
In some sense this is really a shortcoming of AppleScript. No developer should possibly have to know what name a menu item shows to the user, really.
I guess that's not AppleScript - it's System Events which is has an applescriptable interface.
In general, AppleScript is really a last resort...It is really very slow
There's a bit of overhead in context switching, but compiled AppleScript itself is not too shabby.
for simple math calculations I would really recommend the Ruby or the bc way.
Indeed. php also has good math library built in, including arbitrary precision stuff.
I think, given that all OS X system have cmd line php working out of the box, that it is underused as a scripting language for TextMate. There are a ton of easy to use functions to aid the scripter, and it is a very easy to learn language, in my experience.
There are lots of books on PHP 4-5 (amazon is your friend), helper apps like
http://www.artissoftware.com/phpfi/
And, as a freebee, you learn a nice web-programming language
tim
On Dec 8, 2006, at 10:28 AM, Charilaos Skiadas wrote:
On Dec 8, 2006, at 8:31 AM, janssen@ccr.jussieu.fr wrote:
Shouldn't these things made to work under (well may be not all but) most language settings? If I was fluent in Applescript I would certainly contribute (Perhaps Xmas time is just the right time to change my current knowledge iof 'languages').
In some sense this is really a shortcoming of AppleScript. No developer should possibly have to know what name a menu item shows to the user, really. Just supporting a couple more languages is not the answer, this is really something that AppleScript should be fixing, and it's not likely to happen I'm afraid.
To be clear, this is not a shortcoming of AppleScript, it's a shortcoming of the R app. If what you really want is to communicate with the data model of the app, you shouldn't have to address the UI elements. The application is supposed to export a proper AppleScript object model. If the application developers have implemented AppleScript support and you're still having to address the UI elements to get results, something is missing from the app's implementation.
Chris
On Dec 8, 2006, at 10:29 AM, janssen@ccr.jussieu.fr wrote:
I am a plain textmate user and a complete computer/programming illiterate who searches advice and input from other, potentially more experienced users of textmate. When writing latex based papers using the wonderful latex bundle I frequently want to do a quick and simple calculation. Unfortunately, this often involves other formats than those provided by the existing math bundle and I have to invoke an external calculator. Would it be possible to extend the math bundle to normal calculator capabilities? IE providing exponential/logarhithmic, power function, trigonometric functions, numbers in ecponential notation etc. ?
You have received other answers to your question, but unless I have misunderstood your question then the math bundle already has the functionality you are looking for. The math bundle uses the unix utlility 'bc' to do its calculations. See the manual by writing 'bc' in TextMate and then press ⌃h
If you look through the man file you will see that bc is quite powerful although the function names chosen might be a bit non- standard. Here is an excerpt:
s (x) The sine of x, x is in radians. c (x) The cosine of x, x is in radians. a (x) The arctangent of x, arctangent returns radians. l (x) The natural logarithm of x. e (x) The exponential function of raising e to the value x.
You can also set the number of decimals wanted for the result. E.g., to get the logarithm of 10 with 5 decimals, you could write:
scale=5; l(10)
Mark both lines (or put them on one) and then press ⌃⇧C.
You can even write programs which are C-like in syntax and you can define functions. This could be used to alter the Math bundle to always define some set of functions that you often use. Note though that there is no syntax highlighting for the bc language, yet :-)
But it does not seem to support exponential notation. I guess this could be added by piping it through some conversion utility first.
I hope this helps.
Kind regards, Benny