# texcon # # IDE for latexing # # By Hao He # # Changes # # 1.00-1.01 a) ispell button is added; b) error catching is enabled. # 1.01-1.02 a) files ended with .tex .aux .bbl .dvi .blg are recognized as tex # files and their extensions are removed automatically. # b) open menu is enabled under file. A user now can select a file by # choosing open instead of typing. # 1.02-1.03 a) Now you can configure texcon and your configurations are remembered # even if you quit. # b) all file extensions are removed automatically. # # # 1.03-1.05 a) create .texconrc file so the config information can be saved # b) bibtex and xdvi buttons are configurable. # c) texcon now opens file when invoked by 'texcon filename'. # d) file must exist before using texcon. # e) in config window, the 'dismiss' button has been replaced by an 'apply' button and a # 'cancel' button has been added. # # Acknowledgment: # # 1) John Malos suggested ispell button. # 2) Peter Drummond suggested .tex removing feature and open menu. # # Tips: # # 1) Do not open several editors at the same time for the same file. # 2) Close your editor before ispelling. proc texcon {} { global normalbg global editcommand printcommand ispellcommand xdvicommand bibtexcommand wm title . "TeX Controller" wm withdraw . wm iconname . "TeX Controller" bind . exit global fn flag frame .file pack .file -side top -pady 2 -anchor e label .file.label -text "File Name" entry .file.entry -width 30 -relief sunken pack .file.label .file.entry -side right frame .but pack .but -side bottom -pady 2 -anchor center button .but.latex -text latex -command {getfn ; \ if {$flag==1} {exec_cmd "latex $fn" 0}} button .but.bibtex -text bibtex -command {getfn ; \ if {$flag ==1} {exec_cmd "$bibtexcommand $fn" 0}} button .but.xdvi -text xdvi -command {getfn ; \ if {$flag ==1 } {exec_cmd "$xdvicommand $fn " 1}} button .but.edit -text edit -command {getfn ; \ if {$flag ==1 } {exec_cmd "$editcommand $fn.tex " 1}} button .but.ispell -text ispell -command {getfn ;\ if {$flag ==1 } {exec_cmd "$ispellcommand $fn.tex" 0}} button .but.quit -text quit -command {exit} pack .but.latex .but.bibtex .but.xdvi .but.edit .but.ispell .but.quit -side left frame .menu -relief raised -borderwidth 1 pack .menu -before .file -side top -fill x menubutton .menu.file -text "File" -menu .menu.file.m -underline 0 menu .menu.file.m .menu.file.m add command -label "Open" -command Open -underline 0 .menu.file.m add command -label "Config" -command Config -underline 0 .menu.file.m add command -label "Print" -command Print -underline 0 .menu.file.m add command -label "Quit" -command {exit} -underline 0 pack .menu.file -side left menubutton .menu.help -text "Help" -menu .menu.help.m -underline 0 menu .menu.help.m .menu.help.m add command -label "About" -command {Help version} .menu.help.m add command -label "Thank You" -command {Help thankyou} pack .menu.help -side right .file.entry insert 0 $fn update set x [expr ([winfo screenwidth .] - [winfo reqwidth .] -[winfo reqwidth .]/20 )] set y [expr ([winfo reqheight .] )/8] wm geometry . +$x+$y wm deiconify . } proc exec_cmd {cmd background} { if $background {set err [catch {eval exec $cmd >@stdout &} errmsg];} else {set err [catch {eval exec $cmd >@stdout} errmsg];} if $err { bgerror "Hao Error: $errmsg";return -1;} } proc strips {s1} { set sl [string length $s1]; set i 1; while {$i<=$sl} { if {[string index $s1 $i]=="."} break; incr i; } set s1 [string range $s1 0 [expr "$i-1"]] return $s1 } proc getfn {} { global fn flag set flag 1 set fn [.file.entry get] set fn [strips $fn] set ex [file exists $fn.tex] puts $ex while {$ex!=1} { puts "File does not exist! Please choose file." Open;set fn [.file.entry get] set fn [strips $fn] set ex [file exists $fn.tex] } .file.entry delete 0 end .file.entry insert 0 $fn } proc Outstatus {string} { global statuswindow $statuswindow insert end "$string\n" $statuswindow see end update } proc Help {topic {x 0} {y 0}} { global helpTopics helpCmds if {$topic == ""} return while {[info exists helpCmds($topic)]} { set topic [eval $helpCmds($topic)] } if [info exists helpTopics($topic)] { set msg $helpTopics($topic) } else { set msg "Sorry, but no help is available for this topic" } tk_dialog .help {TeX Controller} "$msg" \ {} 0 OK } proc Config {} { global printcommand editcommand ispellcommand xdvicommand bibtexcommand global normalbg w set w .editsettings catch {destroy $w} toplevel $w bind $w "destroy $w" wm title $w "TeX Controller Config" wm iconname $w "TeX Controller" trace variable file w UpdateFileDisplay frame $w.frame -relief flat pack $w.frame -side top -fill y -anchor center frame $w.frame.edit pack $w.frame.edit -side top -pady 2 -anchor e label $w.frame.edit.label -text "Edit command" -anchor e entry $w.frame.edit.entry -width 30 -relief sunken pack $w.frame.edit.entry $w.frame.edit.label -side right frame $w.frame.print pack $w.frame.print -side top -pady 2 -anchor e label $w.frame.print.label -text "Print command" -anchor e entry $w.frame.print.entry -width 30 -relief sunken pack $w.frame.print.entry $w.frame.print.label -side right frame $w.frame.ispell pack $w.frame.ispell -side top -pady 2 -anchor e label $w.frame.ispell.label -text "ispell command" -anchor e entry $w.frame.ispell.entry -width 30 -relief sunken pack $w.frame.ispell.entry $w.frame.ispell.label -side right frame $w.frame.xdvi pack $w.frame.xdvi -side top -pady 2 -anchor e label $w.frame.xdvi.label -text "xdvi command" -anchor e entry $w.frame.xdvi.entry -width 30 -relief sunken pack $w.frame.xdvi.entry $w.frame.xdvi.label -side right frame $w.frame.bibtex pack $w.frame.bibtex -side top -pady 2 -anchor e label $w.frame.bibtex.label -text "bibtex command" -anchor e entry $w.frame.bibtex.entry -width 30 -relief sunken pack $w.frame.bibtex.entry $w.frame.bibtex.label -side right frame $w.buttons pack $w.buttons -side bottom -pady 2 -anchor center button $w.buttons.clear -text Clear button $w.buttons.default -text Default button $w.buttons.dismiss -text "Apply" -command {addAction; savecmds; destroy $w} button $w.buttons.cancel -text Cancel -command {setcmds; destroy $w} pack $w.buttons.clear $w.buttons.default \ $w.buttons.dismiss $w.buttons.cancel -side left -padx 2 $w.buttons.default config -command "filldefaultCard" $w.buttons.clear config -command clearCard fillCard update # set x [expr ([winfo screenwidth .] - [winfo reqwidth .] )/2] # set y [expr ([winfo screenheight .] - [winfo reqheight .] )/2] # wm geometry . +$x+$y wm deiconify . } proc filldefaultCard {} { clearCard global w; $w.frame.edit.entry insert 0 "nedit" $w.frame.print.entry insert 0 "lpr -Pps" $w.frame.ispell.entry insert 0 "xterm -exec ispell" $w.frame.xdvi.entry insert 0 "xdvi" $w.frame.bibtex.entry insert 0 "bibtex" } proc fillCard {} { clearCard global w; global editcommand printcommand ispellcommand xdvicommand bibtexcommand $w.frame.edit.entry insert 0 $editcommand $w.frame.print.entry insert 0 $printcommand $w.frame.ispell.entry insert 0 $ispellcommand $w.frame.xdvi.entry insert 0 $xdvicommand $w.frame.bibtex.entry insert 0 $bibtexcommand } proc clearCard {} { global w $w.frame.edit.entry delete 0 end $w.frame.print.entry delete 0 end $w.frame.ispell.entry delete 0 end $w.frame.xdvi.entry delete 0 end $w.frame.bibtex.entry delete 0 end } proc addAction {} { global w s1 global editcommand printcommand ispellcommand xdvicommand bibtexcommand set editcommand [$w.frame.edit.entry get] set printcommand [$w.frame.print.entry get] set ispellcommand [$w.frame.ispell.entry get] set xdvicommand [$w.frame.xdvi.entry get] set bibtexcommand [$w.frame.bibtex.entry get] } proc Print {} { global editcommand printcommand ispellcommand xdvicommand bibtexcommand global normalbg p s1 set p .print catch {destroy $p} catch all toplevel $p bind $p "destroy $p" wm title $p "Print" wm iconname $p "Print" frame $p.frame -relief flat pack $p.frame -side top -fill y -anchor center frame $p.frame.s pack $p.frame.s -side top -pady 2 -anchor e set s1 "All" radiobutton $p.frame.s.pa -width 10 -text "Print All" \ -variable s1 -value "All" -command \ {$p.frame.pn.entry1 config -state disabled; \ $p.frame.pn.entry2 config -state disabled;} radiobutton $p.frame.s.pp -width 10 -text "Print Part" \ -variable s1 -value "Part" -command \ {$p.frame.pn.entry1 config -state normal; \ $p.frame.pn.entry2 config -state normal;} pack $p.frame.s.pa $p.frame.s.pp -side right frame $p.frame.pn -relief flat pack $p.frame.pn -side top -fill y -anchor center label $p.frame.pn.lab1 -text "First page" entry $p.frame.pn.entry1 -width 5 -relief sunken -state disabled label $p.frame.pn.lab2 -text "Last page" entry $p.frame.pn.entry2 -width 5 -relief sunken -state disabled pack $p.frame.pn.lab1 $p.frame.pn.entry1 $p.frame.pn.lab2 $p.frame.pn.entry2 -side left frame $p.but pack $p.but -side top -fill y -anchor center button $p.but.print -text Print -command \ { getfn ; if {$flag ==1 } { if {$s1 == "All"} { puts "Printing All."; # getdvi; exec_cmd "dvips $fn -o $fn.ps" 0 exec_cmd "$printcommand $fn.ps" 1; destroy $p; return} set fp [$p.frame.pn.entry1 get]; set lp [$p.frame.pn.entry2 get]; puts "Print from page $fp to page $lp." # getdvi; exec_cmd "dvips $fn -p $fp -l $lp -o $fn.ps" 0 exec_cmd "$printcommand $fn.ps" 1; destroy $p; return } } button $p.but.cancel -text Cancel -command {destroy $p} pack $p.but.print $p.but.cancel -side left } proc getdvi {} { global fn flag getfn if {$flag == 1} { exec_cmd "latex $fn" 0 exec_cmd "bibtex $fn" 0 exec_cmd "latex $fn" 0 exec_cmd "latex $fn" 0 exec_cmd "latex $fn" 0} } # # fileselect.tcl -- # simple file selector. # # Mario Jorge Silva msilva@cs.Berkeley.EDU # University of California Berkeley Ph: +1(510)642-8248 # Computer Science Division, 571 Evans Hall Fax: +1(510)642-5775 # Berkeley CA 94720 # # Layout: # # file: +----+ # ____________________ | OK | # +----+ # # +------------------+ Cancel # | .. |S # | file1 |c # | file2 |r # | |b # | filen |a # | |r # +------------------+ # currrent-directory # # Copyright 1993 Regents of the University of California # Permission to use, copy, modify, and distribute this # software and its documentation for any purpose and without # fee is hereby granted, provided that this copyright # notice appears in all copies. The University of California # makes no representations about the suitability of this # software for any purpose. It is provided "as is" without # express or implied warranty. # # names starting with "fileselect" are reserved by this module # no other names used. # use the "option" command for further configuration # this is the default proc called when "OK" is pressed # to indicate yours, give it as the first arg to "fileselect" proc fileselect.default.cmd {f} { puts stderr "selected file $f" } # this is the default proc called when error is detected # indicate your own pro as an argument to fileselect proc fileselect.default.errorHandler {errorMessage} { puts stdout "error: $errorMessage" catch { cd ~ } } # this is the proc that creates the file selector box proc fileselect { {cmd fileselect.default.cmd} {purpose "Open file:"} {w .fileSelectWindow} {errorHandler fileselect.default.errorHandler}} { catch {destroy $w} toplevel $w grab $w wm title $w "Select File" # path independent names for the widgets global fileselect set fileselect(entry) $w.file.eframe.entry set fileselect(list) $w.file.sframe.list set fileselect(scroll) $w.file.sframe.scroll set fileselect(ok) $w.bframe.okframe.ok set fileselect(cancel) $w.bframe.cancel set fileselect(dirlabel) $w.file.dirlabel # widgets frame $w.file -bd 10 frame $w.bframe -bd 10 pack append $w \ $w.file {left filly} \ $w.bframe {left expand frame n} frame $w.file.eframe frame $w.file.sframe label $w.file.dirlabel -anchor e -width 24 -text [pwd] pack append $w.file \ $w.file.eframe {top frame w} \ $w.file.sframe {top fillx} \ $w.file.dirlabel {top frame w} label $w.file.eframe.label -anchor w -width 24 -text $purpose entry $w.file.eframe.entry -relief sunken pack append $w.file.eframe \ $w.file.eframe.label {top expand frame w} \ $w.file.eframe.entry {top fillx frame w} scrollbar $w.file.sframe.yscroll -relief sunken \ -command "$w.file.sframe.list yview" listbox $w.file.sframe.list -relief sunken \ -yscroll "$w.file.sframe.yscroll set" pack append $w.file.sframe \ $w.file.sframe.yscroll {right filly} \ $w.file.sframe.list {left expand fill} # buttons frame $w.bframe.okframe -borderwidth 2 -relief sunken button $w.bframe.okframe.ok -text OK -relief raised -padx 10 \ -command "fileselect.ok.cmd $w $cmd $errorHandler" button $w.bframe.cancel -text cancel -relief raised -padx 10 \ -command "fileselect.cancel.cmd $w" pack append $w.bframe.okframe $w.bframe.okframe.ok {padx 10 pady 10} pack append $w.bframe $w.bframe.okframe {expand padx 20 pady 20}\ $w.bframe.cancel {top} # Fill the listbox with a list of the files in the directory (run # the "/bin/ls" command to get that information). # to not display the "." files, remove the -a option and fileselect # will still work $fileselect(list) insert end ".." foreach i [exec /bin/ls [pwd]] { if {[string compare $i "."] != 0 && \ [string compare $i ".."] != 0 } { $fileselect(list) insert end $i } } # Set up bindings for the browser. bind $fileselect(entry) {eval $fileselect(ok) invoke; break} bind $fileselect(entry) {eval $fileselect(cancel) invoke; break} bind $w {eval $fileselect(cancel) invoke;break} bind $w {eval $fileselect(ok) invoke;break} # tk_listboxSingleSelect $fileselect(list) bind $fileselect(list) { # puts stderr "button 1 release" %W selection set [%W nearest %y] $fileselect(entry) delete 0 end $fileselect(entry) insert 0 [%W get [%W nearest %y]] break } bind $fileselect(list) { %W selection set [%W nearest %y] $fileselect(entry) delete 0 end $fileselect(entry) insert 0 [%W get [%W nearest %y]] break } bind $fileselect(list) { # puts stderr "double button 1" %W selection set [%W nearest %y] $fileselect(entry) delete 0 end $fileselect(entry) insert 0 [%W get [%W nearest %y]] $fileselect(ok) invoke break } bind $fileselect(list) { %W selection set [%W nearest %y] $fileselect(entry) delete 0 end $fileselect(entry) insert 0 [%W get [%W nearest %y]] $fileselect(ok) invoke break } # set kbd focus to entry widget focus $fileselect(entry) } # auxiliary button procedures proc fileselect.cancel.cmd {w} { # puts stderr "Cancel" destroy $w } proc fileselect.ok.cmd {w cmd errorHandler} { global fileselect set selected [$fileselect(entry) get] # some nasty file names may cause "file isdirectory" to return an error set sts [catch { file isdirectory $selected } errorMessage ] if { $sts != 0 } then { $errorHandler $errorMessage destroy $w return } # clean the text entry and prepare the list $fileselect(entry) delete 0 end $fileselect(list) delete 0 end $fileselect(list) insert end ".." # selection may be a directory. Expand it. if {[file isdirectory $selected] != 0} { cd $selected set dir [pwd] $fileselect(dirlabel) configure -text $dir foreach i [exec /bin/ls -a $dir] { if {[string compare $i "."] != 0 && \ [string compare $i ".."] != 0} { $fileselect(list) insert end $i } } return } destroy $w $cmd $selected } ##### end of fileselect code proc selectdone {f} { global selection set selection $f } proc select {var {message "Open File"}} { global selection set selection "" fileselect selectdone $message tkwait window .fileSelectWindow uplevel "set $var \"$selection\"" if { $selection == "" } { return 0 } else { return 1 } } proc Open {} { if ![select f "Open file:"] { return } if ![file exists $f] { bgerror "Error: $f doesn't exist." return } if ![file readable $f] { bgerror "Error: $f isn't readable." return } set file $f .file.entry delete 0 end .file.entry insert 0 $file } proc setdefaultcmds {} { global editcommand printcommand ispellcommand xdvicommand bibtexcommand set editcommand nedit set printcommand "lpr -Pps" set ispellcommand "xterm -exec ispell" set xdvicommand "xdvi" set bibtexcommand "bibtex" } proc savecmds {} { global editcommand printcommand ispellcommand xdvicommand bibtexcommand set fileid [open "~/.texconrc" w+] seek $fileid 0 start puts $fileid "$editcommand" puts $fileid "$printcommand" puts $fileid "$ispellcommand" puts $fileid "$xdvicommand" puts $fileid "$bibtexcommand" close $fileid } proc setcmds {} { global editcommand printcommand ispellcommand xdvicommand bibtexcommand #puts "setcmds is running\n" #exec_cmd "touch /home/he/.texconrc" 0 set fileid [open "~/.texconrc" a+] seek $fileid 0 start set nc [gets $fileid editcommand] #puts "nc = $nc\n$editcommand" if {$nc==-1} {setdefaultcmds;savecmds;return} set nc [gets $fileid printcommand] if {$nc==-1} {setdefaultcmds;savecmds;return} set nc [gets $fileid ispellcommand] if {$nc==-1} {setdefaultcmds;savecmds;return} set nc [gets $fileid xdvicommand] if {$nc==-1} {setdefaultcmds;savecmds;return} set nc [gets $fileid bibtexcommand] if {$nc==-1} {setdefaultcmds;savecmds;return} #puts "$editcommand" #puts "$printcommand" #puts "$ispellcommand" } global s1 fn global editcommand printcommand ispellcommand xdvicommand bibtexcommand set s1 "All" set helpTopics(version) "TeX Controller ver 1.04. \nby Hao He \nhe@physics.uq.edu.au" set helpTopics(thankyou) "I thank John Malos and Peter Drummond for suggesting new features." setcmds puts $argv set fn [lindex $argv 0] texcon