[SVN] r2362 (Latex)

Charilaos Skiadas cskiadas at uchicago.edu
Fri Dec 2 15:09:02 UTC 2005


Actually the following should be fixing it. Can someone test it and  
tell me, without any extra variables set?

#!/usr/bin/env ruby
#
# This script will expand the current word either to
# \word{} (if it's matched by the commands pattern),
# to one of the shortcuts in the shortcut dictionary,
# otherwise to \begin{word} … \end{word} with the caret
# inbetween.
#
# With no selection, it will insert \begin{environment}
# … \end{environment} and allow you to overwrite the
# environment name.

if(ENV.has_key?('TM_LATEX_COMMANDS'))
     testing = ENV['TM_LATEX_COMMANDS'].to_s
     commands = /^cite|footcite|footnote|label|ref|text(it|bf|tt|sf| 
sc)|#{testing}$/
else
     commands = /^cite|footcite|footnote|label|ref|text(it|bf|tt|sf| 
sc)$/
end
customShortcuts = Hash.new
ENV['TM_LATEX_SHORTCUTS'].to_s.split(',').each { |x|
   temp = x.split('=>')
   customShortcuts["#{temp[0]}"]="#{temp[1]}"
}
shortcuts = { "it" => "textit", "bf" => "textbf", "tt" => "texttt",
"sf" => "textsf", "sc" => "textsc",    "em" => "emph", "fc" =>  
"footcite", "fn" => "footnote",  "eqn" => "equation", "item" =>  
"itemize", "enum" => "enumerate" }.update(customShortcuts)

name = STDIN.read
if(!shortcuts[name].nil?)
   name = shortcuts[name]
end
if(name == '')
   print("\\begin{${1:environment}}\n\t$2\n\\end{$1}")
elsif(commands.match(name))
   print("\\#{name}{$1}")
else
   lab = ENV['TM_LATEX_INSERT_LABEL'].to_i
   if(lab == 1)
     labPrefix = name.slice(0,3)
     print("\\begin{#{name}}\n\\label{#{labPrefix}:$1}\n\t$2\n\\end{# 
{name}}")
   else
     print("\\begin{#{name}}\n\t$1\n\\end{#{name}}")
   end
end




More information about the textmate-dev mailing list