Hi
I'm not an expert with Ruby so I need to know if the next command is safe
I want to select a "number" and to get $\numprint{number}$ if number is not empty and number is not inside a math environment or \numprint{number} if number is inside a math environment.
then if number is empty, I want to get \numprint{...} or $\numprint{...}$
I made this and I would like to know if this code is correct
#!/usr/bin/ruby # Created by Alain Matthes on 2009-11-15 (www.altermundus.com).
require ENV["TM_SUPPORT_PATH"] + "/lib/exit_codes.rb"
if ENV['TM_SELECTED_TEXT'].nil? input = ENV[''] else input = ENV['TM_SELECTED_TEXT'] end
if ENV['TM_SCOPE'].match(/math.((.*)|(la))tex/) $math_del = "" else $math_del = "\$" end
TextMate.exit_insert_snippet("#{$math_del}\numprint{#{input}$0}#{$math_del}")
Is it possible to use a shortcut to go out of the first environment {...} and then to go out of the math environment because the caret is inside {number} ?
Best regards
Alain Matthes
On Nov 15, 2009, at 2:22 AM, Alain Matthes wrote:
Hi
I'm not an expert with Ruby so I need to know if the next command is safe
I want to select a "number" and to get $\numprint{number}$ if number is not empty and number is not inside a math environment or \numprint{number} if number is inside a math environment.
then if number is empty, I want to get \numprint{...} or $\numprint{...}$
I made this and I would like to know if this code is correct
#!/usr/bin/ruby # Created by Alain Matthes on 2009-11-15 (www.altermundus.com).
require ENV["TM_SUPPORT_PATH"] + "/lib/exit_codes.rb"
if ENV['TM_SELECTED_TEXT'].nil? input = ENV[''] else input = ENV['TM_SELECTED_TEXT'] end
if ENV['TM_SCOPE'].match(/math.((.*)|(la))tex/) $math_del = "" else $math_del = "\$" end
TextMate.exit_insert_snippet("#{$math_del}\numprint{#{input}$0}#{$math_del}")
Is it possible to use a shortcut to go out of the first environment {...} and then to go out of the math environment because the caret is inside {number} ?
Hey Alain,
Your code looks safe. I'm not sure what you meant by safe, but I'm quite sure this won't hurt anything.
I simplified it a little bit, and added the features you wanted:
#!/usr/bin/ruby # Created by Alain Matthes on 2009-11-15 (www.altermundus.com). # Some simplification by Alex Ross (http://lasersox.net)
snippet = "\numprint{${1:#{$stdin.read || "..."}}}$2" snippet = "\$#{snippet}\$$0" unless ENV['TM_SCOPE'].match(/math/)
puts snippet
Set Input: Selected Text or Nothing Output: Insert as Snippet
Le 18 nov. 2009 à 01:00, Alex Ross a écrit :
Hey Alain,
Your code looks safe. I'm not sure what you meant by safe, but I'm quite sure this won't hurt anything.
I simplified it a little bit, and added the features you wanted:
#!/usr/bin/ruby # Created by Alain Matthes on 2009-11-15 (www.altermundus.com). # Some simplification by Alex Ross (http://lasersox.net)
snippet = "\numprint{${1:#{$stdin.read || "..."}}}$2" snippet = "\$#{snippet}\$$0" unless ENV['TM_SCOPE'].match(/math/)
puts snippet
Set Input: Selected Text or Nothing Output: Insert as Snippet
Super !
Best regards
Alain
PS : I work actually on a latex-author bundle for latex authors of packages. I made a new grammar because I need to see the changes between tex primitives and latex macros; I need also to see the ifthenelse structure, and a better grammar for Tikz etc ... I made a new theme more complete for LaTeX.
In a few days, I will upload all this work on a site for testing
Le 18 nov. 2009 à 01:00, Alex Ross a écrit :
I simplified it a little bit, and added the features you wanted:
#!/usr/bin/ruby # Created by Alain Matthes on 2009-11-15 (www.altermundus.com). # Some simplification by Alex Ross (http://lasersox.net)
snippet = "\numprint{${1:#{$stdin.read || "..."}}}$2" snippet = "\$#{snippet}\$$0" unless ENV['TM_SCOPE'].match(/math/)
puts snippet
Set Input: Selected Text or Nothing Output: Insert as Snippet
Hi Alex
Your code is interesting and it's very concise. Is it possible to have some details about the syntax?
I try to adapt this code. I would like to change "LaTeX Symbol Based on Current Word / Selection"
because the symbols are only used in math mode so I try
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb" @plist = Config.load shortcutHash = @plist['symbols'] currentWord = STDIN.read
if (shortcutHash.has_key?(currentWord)) then currentWord = shortcutHash[currentWord] currentWord = "$#{currentWord}$" unless ENV['TM_SCOPE'].match(/math/) print currentWord else TextMate.exit_discard end
but the caret is outside the math environment and I don't know how to keep it inside
Best regards
Alain Matthes
Hey Alain,
I modified you command as follows:
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
symbols = Config.load['symbols'] word = STDIN.read
if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/) print "\$#{symbols[word]}$0\$" else TextMate.exit_discard end
If you have any questions about the semantics feel free to ask.
—Alex
Le 6 déc. 2009 à 02:09, Alex Ross a écrit :
Hey Alain,
I modified you command as follows:
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
symbols = Config.load['symbols'] word = STDIN.read
if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/) print "\$#{symbols[word]}$0\$" else TextMate.exit_discard end
If you have any questions about the semantics feel free to ask.
Hi Alex,
I need to take time to read some books about Ruby, Regex and perhaps Ruby Object Oriented Programming. I learned programming with Pascal in the late '80s and it's not easy to write some lines of code without a good knowledge of the tools.
About the semantics
In the code about numprint, you use "puts" instead of "print". Why?
My book gives "puts" equivalent to $stdout.puts(obj,..) and "print" prints each object in turn to $stdout.
And why do you use "unless" in the code for numprint and not here ?
Best Regards
Alain Matthes
On 6 Dec 2009, at 11:15, Alain Matthes wrote:
In the code about numprint, you use "puts" instead of "print". Why?
My book gives "puts" equivalent to $stdout.puts(obj,..) and "print" prints each object in turn to $stdout.
puts() appends a newline to the object unless it already has one. print() doesn't.
And why do you use "unless" in the code for numprint and not here ?
Not read the other code, but probably because he's first checking for the existence of something, and thus wanting the if to bail out at that point before checking the second statement.
C --- Caius Durling caius@caius.name +44 (0) 7960 268 100 http://caius.name/
Le 6 déc. 2009 à 02:09, Alex Ross a écrit :
Hey Alain,
I modified you command as follows:
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
symbols = Config.load['symbols'] word = STDIN.read
if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/) print "\$#{symbols[word]}$0\$" else TextMate.exit_discard end
If you have any questions about the semantics feel free to ask.
@Caius thanks for your remarks
@Hans The code
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
symbols = Config.load['symbols'] word = STDIN.read
if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/) print "\$#{symbols[word]}$0\$" else TextMate.exit_discard end
does not work.
If I use Replace Selected Text and § for the shortcut
a§ gives $\alpha$0$
and $ a§ $ gives nothing
Now if I use insert as snippet,I get \alpha and not $\alpha$
If found a solution with
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes" require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb" shortcutHash = Config.load['symbols'] currentWord = STDIN.read
if (shortcutHash.has_key?(currentWord)) then currentWord = shortcutHash[currentWord] currentWord = "\$#{currentWord}$0\$" unless ENV['TM_SCOPE'].match(/math/) TextMate.exit_insert_snippet currentWord else TextMate.exit_discard end
I use Replace Selected Text and TextMate.exit_insert_snippet instead of puts and print but perhaps it's possible to simplify.
Now a§ ---> $\alpha $ and $\alpha + b§ $ -->$\alpha + \beta$
The command works but I understand only little things. I found TextMate.exit_insert_snippet in another command and I make a try
For example, why in some macros we have
@plist = Config.load shortcuts = @plist['commands']
if it's possible to write shortcuts = Config.load['commands']
Best regards
Alain Matthes