home *** CD-ROM | disk | FTP | other *** search
/ Internet File Formats / InternetFileFormatsCD.bin / text / latex / mac / alpha60.hqx / Tcl / SystemCode / latexMacros.tcl < prev    next >
Encoding:
Text File  |  1995-07-09  |  85.1 KB  |  2,962 lines

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latexMacros.tcl (called from latex.tcl)
  5. #
  6. #############################################################################
  7. #
  8. # Author:  Tom Scavo (trscavo@syr.edu)
  9. #
  10. #############################################################################
  11. #############################################################################
  12.  
  13. #############################################################################
  14. # Basic Commands
  15. #
  16. #############################################################################
  17.  
  18. proc typeset {} {
  19.     global texPath PREFS TeXmodeVars
  20.     
  21.     # Initialization:
  22.     foreach flag {isOzTeX isTextures isCMacTeX isDirectTeX isDirectTeXPro} {
  23.         set $flag 0
  24.     }
  25.     set currentWin [lindex [winNames -f] 0]
  26.     set currentDir [file dirname $currentWin]
  27.     set currentDoc [file tail $currentWin]
  28.     set docBasename [file rootname $currentDoc]
  29.     set docExtension [file extension $currentDoc]
  30.     
  31.     # Is the window untitled or dirty?
  32.     if {[string match $currentWin $currentDoc]} {
  33.         case [askyesno -c "Save \"$currentDoc\"?"] in {
  34.             "yes" {
  35.                 if {[catch {set currentWin [saveAs "Untitled\.tex"]}]} then {return}
  36.             }
  37.             "no" {
  38.                 if {[regexp {<(.*)>} $currentDoc dummy num]} {
  39.                     set tmpFilename "Untitled$num\.tex"
  40.                 } else {
  41.                     set tmpFilename "Untitled\.tex"
  42.                 }
  43.                 set text [getText 0 [maxPos]]
  44.                 set newDoc "$PREFS:$tmpFilename"
  45.                 message "Saving $newDoc..."
  46.                 set fd [open $newDoc "w"]
  47.                 puts $fd $text
  48.                 close $fd
  49.                 set currentWin $newDoc
  50.             }
  51.             "cancel" {return}
  52.         }
  53.     } elseif {[winDirty]} {
  54.         case [askyesno -c "Save \"$currentDoc\"?"] in {
  55.             "yes" {save}
  56.             "no" {
  57.                 set text [getText 0 [maxPos]]
  58.                 set newDoc "$PREFS:temp-$currentDoc"
  59.                 message "Saving $newDoc..."
  60.                 set fd [open $newDoc "w"]
  61.                 puts $fd $text
  62.                 close $fd
  63.                 set currentWin $newDoc
  64.             }
  65.             "cancel" {return}
  66.         }
  67.     }
  68.     
  69.     # Check if a TeX app is running.  If not, open the app named in 
  70.     # $texPath (if defined) or have the user select an app via a
  71.     # standard file dialog.  Leave the TeX app in the background.
  72.     set appName [checkRunning TeX {OTEX *TEX *XeT MPS* TeX+} texPath 0]
  73.     
  74.     if {[string match {OzTeX*} $appName]} {
  75.         set isOzTeX 1
  76.     } elseif {[string match {Euro-OzTeX*} $appName]} {
  77.         set isOzTeX 1
  78.     } elseif {[string match {Textures*} $appName]} {
  79.         set isTextures 1
  80.     } elseif {[string match {DirectTeX*} $appName]} {
  81.         set isDirectTeXPro 1
  82.     } elseif {[string match {*tex} $appName]} {
  83.         set isCMacTeX 1
  84.     } elseif {[string match {MPW*} $appName]} {
  85.         set isDirectTeX 1
  86.     } else {
  87.         alertnote "Sorry, I don't know how to talk to \"$appName\"."
  88.         return
  89.     }
  90.     
  91.     # Conditionally bring the TeX app to the foreground:
  92.     if {$TeXmodeVars(runTeXInBackground) == 0} { switchTo $appName }
  93.     
  94.     # Typeset the document:
  95.     if {$isOzTeX} {
  96.         sendOpenEvent -n $appName $currentWin
  97.     } elseif {$isTextures} {
  98.         # Choose one of the following three options:
  99.         # dosc -c '*TEX' -s [getText 0 [maxPos]] -r
  100.         # sendOpenEvent -n $appName $currentWin
  101.         dosc -c '*TEX' -f [lindex [winNames -f] 0] -r
  102.     } elseif {$isDirectTeXPro} {
  103.         dosc -c 'TeX+' -s "ProjectMgr -t LaTeX \"$currentWin\"; SelectApp; MenuCommand 1 4"
  104.     } elseif {$isCMacTeX} {
  105.         dosc -n $appName -k 'aevt' -e 'odoc' -r -f $currentWin
  106.     } elseif {$isDirectTeX} {
  107.         set script "Begin; ChangeTeXProject '$currentWin' -check -confirm || Exit 0;\
  108.                       Execute \"{dt_TeXProject}\"; TeXMenu -tex -formats; End ╖ Dev:Null;\
  109.                       RunSession 1 ╖ Dev:Null"
  110.         dosc -r -n $appName -s $script
  111.     }
  112. }
  113.  
  114.  
  115. #--------------------------------------------------------------------------
  116. # Goto:
  117. #--------------------------------------------------------------------------
  118.  
  119. # Switch to (but don't execute) any of the following applications.
  120. proc latex {} {
  121.     global texPath
  122.     if {![catch {getFileSig $texPath} sig]} {
  123.         set appName [checkRunning TeX $sig texPath]
  124.     } else {
  125.         set appName [checkRunning TeX {OTEX *TEX *XeT MPS* TeX+} texPath]
  126.     }
  127.     if {[string length $appName] > 0} {
  128.         switchTo $appName
  129.     }
  130. }
  131. proc bibtex {} {
  132.     global bibtexPath
  133.     set appName [checkRunning BibTeX BIBt bibtexPath]
  134.     if {![string length $appName]} return
  135.     switchTo $appName
  136. }
  137. proc makeindex {} {
  138.     global makeindexPath
  139.     set appName [checkRunning MakeIndex Midx makeindexPath]
  140.     if {![string length $appName]} return
  141.     switchTo $appName
  142. }
  143.  
  144. # Find the next or previous environment.  Search forward (or backward, 
  145. # depending on $forward) for either \begin or \end.  If \begin is found, 
  146. # search forward for corresponding \end; otherwise, search backward for 
  147. # corresponding \begin.  Select the found environment, or display an 
  148. # error message if no environment is found.
  149. proc findEnvironment {forward} {
  150.     set searchString1 {^[ \t]*\\begin\{[^\{\}]*\}|\\end\{[^\{\}]*\}[ \t]*\r?}
  151.     set searchPos [getPos]
  152.     if { [isSelection] } then { 
  153.         if { $forward } then {
  154.             set searchPos [selEnd]
  155.         } else {
  156.             set searchPos [expr $searchPos - 1]
  157.         }
  158.     } else {
  159.         if { $forward } then {
  160.             set searchPos [expr $searchPos + 1]
  161.         } else {
  162.             set searchPos [expr $searchPos - 1]
  163.         }
  164.     }
  165.     set searchResult [search -s -f $forward -r 1 -n $searchString1 $searchPos]
  166.     if {[string length $searchResult]} then {
  167.         set begPos [lindex $searchResult 0]
  168.         set endPos [lindex $searchResult 1]
  169.         set searchText [getText $begPos $endPos]
  170.         regexp {\{(.*)\}} $searchText dummy envName
  171.         if {[string match {*begin*} $searchText]} {
  172.             set begEnv $begPos
  173.             append searchString2 {\\end\{} $envName {\}[ \t]*\r?}
  174.             set searchPos $endPos
  175.             set searchResult [search -s -f 1 -r 1 -n $searchString2 $searchPos]
  176.             if {[string length $searchResult]} {
  177.                 set endPos [lindex $searchResult 1]
  178.                 return [list $begPos $endPos]
  179.             } else {
  180.                 return "matching \\end not found"
  181.             }
  182.         } else {
  183.             set endEnv $endPos
  184.             append searchString2 {^[ \t]*\\begin\{} $envName {\}}
  185.             set searchPos $begPos
  186.             set searchResult [search -s -f 0 -r 1 -n $searchString2 $searchPos]
  187.             if {[string length $searchResult]} {
  188.                 set begPos [lindex $searchResult 0]
  189.                 return [list $begPos $endPos]
  190.             } else {
  191.                 return "matching \\begin not found"
  192.             }
  193.         }
  194.     } else {
  195.         if { $forward } then {
  196.             return "next environment not found"
  197.         } else {
  198.             return "previous environment not found"
  199.         }
  200.     }
  201. }
  202.  
  203. proc prevEnvironment {} {
  204.     global searchNoisily
  205.     set findResult [findEnvironment 0]
  206.     if {[llength $findResult] == 2} then {
  207.         goto [lindex $findResult 0]
  208.     } else {
  209.         if {$searchNoisily} {beep}
  210.         message $findResult
  211.     }
  212. }
  213. proc nextEnvironment {} {
  214.     global searchNoisily
  215.     set findResult [findEnvironment 1]
  216.     if {[llength $findResult] == 2} then {
  217.         goto [lindex $findResult 0]
  218.     } else {
  219.         if {$searchNoisily} {beep}
  220.         message $findResult
  221.     }
  222. }
  223. proc prevEnvironmentSelect {} {
  224.     global searchNoisily
  225.     set forward 0
  226.     set findResult [findEnvironment $forward]
  227.     if {[llength $findResult] == 2} then {
  228.         set endPos [lindex $findResult 1]
  229. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  230. #             set endPos [expr $endPos + 1]
  231. #         }
  232.         select [lindex $findResult 0] $endPos
  233.     } else {
  234.         if { $searchNoisily } {beep}
  235.         message $findResult
  236.     }
  237. }
  238. proc nextEnvironmentSelect {} {
  239.     global searchNoisily
  240.     set forward 1
  241.     set findResult [findEnvironment $forward]
  242.     if {[llength $findResult] == 2} then {
  243.         set endPos [lindex $findResult 1]
  244. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  245. #             set endPos [expr $endPos + 1]
  246. #         }
  247.         select [lindex $findResult 0] $endPos
  248.     } else {
  249.         if { $searchNoisily } {beep}
  250.         message $findResult
  251.     }
  252. }
  253.  
  254. # Find a LaTeX command in either direction.  It's up to the calling
  255. # procedure to pass the correct starting position of the search.
  256. proc findCommand {pos direction} {
  257. #    Handle "\ " and "\[" separately:
  258.     set searchString {(\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?)|([^\\]\\\ )|([^\\]\\\[)}
  259.     set searchResult [search -s -f $direction -r 1 -n $searchString $pos]
  260.     if { [string length $searchResult] } {
  261.         set begPos [lindex $searchResult 0]
  262.         set endPos [lindex $searchResult 1]
  263.         set lastChar [lookAt [expr $endPos - 1]]
  264.         if {$lastChar == "\ " || $lastChar == "\["} then {
  265.             return [list [expr $begPos + 1] $endPos]
  266.         } else {}
  267.     }
  268.     return $searchResult
  269. # Handles everything but "\ " and "\[":
  270. #     set searchString {\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?}
  271. #     return [search -s -f $direction -r 1 -n $searchString $pos]
  272. }
  273. # Find and goto the beginning of the previous LaTeX command.
  274. proc prevCommand {} {
  275.     global searchNoisily
  276.     set pos [getPos]
  277.     if {$pos > 0} then {
  278.         set searchResult [findCommand [expr $pos - 1] 0]
  279.         if { [string length $searchResult] } {
  280.             goto [lindex $searchResult 0]
  281.             return
  282.         } else {}
  283.     }
  284.     if { $searchNoisily } {beep}
  285.     message "previous command not found"
  286. }
  287. # Find and goto the beginning of the next LaTeX command.
  288. proc nextCommand {} {
  289.     global searchNoisily
  290.     set pos [getPos]
  291.     if {$pos < [maxPos]} then {
  292.         set searchResult [findCommand [expr $pos + 1] 1]
  293.         if { [string length $searchResult] } {
  294.             goto [lindex $searchResult 0]
  295.             return
  296.         } else {}
  297.     }
  298.     if { $searchNoisily } {beep}
  299.     message "next command not found"
  300. }
  301. # Select the previous LaTeX command, but do not attempt to select
  302. # any associated argument.
  303. proc prevCommandSelect {} {
  304.     global searchNoisily
  305.     set pos [getPos]
  306.     if {$pos > 0} then {
  307.         set searchResult [findCommand [expr $pos - 1] 0]
  308.         if { [string length $searchResult] } {
  309.             eval select $searchResult
  310.             return
  311.         } else {}
  312.     }
  313.     if { $searchNoisily } {beep}
  314.     message "previous command not found"
  315. }
  316. # Select the next LaTeX command, but do not attempt to select
  317. # any associated argument.
  318. proc nextCommandSelect {} {
  319.     global searchNoisily
  320.     set pos [getPos]
  321.     if {$pos < [maxPos]} then {
  322.         if { [isSelection] } then {
  323.             set pos [expr $pos + 1]
  324.         }
  325.         set searchResult [findCommand $pos 1]
  326.         if { [string length $searchResult] } {
  327.             eval select $searchResult
  328.             return
  329.         } else {}
  330.     }
  331.     if { $searchNoisily } {beep}
  332.     message "next command not found"
  333. }
  334.  
  335. # Find a LaTeX command with arguments in either direction.  It's up 
  336. # to the calling procedure to pass the starting position of the search.
  337. # (Handles everything but "\ " and commands whose arguments contain
  338. # embedded braces.)
  339. proc findCommandWithArgs {pos direction} {
  340.     set searchString {\\([^a-zA-Z\t\r]|[a-zA-Z]+\*?)(\[.*\])*({[^{}]*})*}
  341.     return [search -s -f $direction -r 1 -n $searchString $pos]
  342. }
  343. # Select the previous LaTeX command and any associated arguments.
  344. proc prevCommandSelectWithArgs {} {
  345.     global searchNoisily
  346.     set pos [getPos]
  347.     if {$pos > 0} then {
  348.         set searchResult [findCommandWithArgs [expr $pos - 1] 0]
  349.         if { [string length $searchResult] } {
  350.             eval select $searchResult
  351.             return
  352.         } else {}
  353.     }
  354.     if { $searchNoisily } {beep}
  355.     message "previous command not found"
  356. }
  357. # Select the next LaTeX command and any associated arguments.
  358. proc nextCommandSelectWithArgs {} {
  359.     global searchNoisily
  360.     set pos [getPos]
  361.     if {$pos < [maxPos]} then {
  362.         if { [isSelection] } then {
  363.             set pos [expr $pos + 1]
  364.         }
  365.         set searchResult [findCommandWithArgs $pos 1]
  366.         if { [string length $searchResult] } {
  367.             eval select $searchResult
  368.             return
  369.         } else {}
  370.     }
  371.     if { $searchNoisily } {beep}
  372.     message "next command not found"
  373. }
  374.  
  375. # Find a LaTeX sectioning command in either direction.  It's up to 
  376. # the calling procedure to pass the starting position of the search.
  377. proc findSection {pos direction} {
  378.     global funcExprAlt
  379.     return [search -s -f $direction -r 1 -n $funcExprAlt $pos]
  380. }
  381. # Select the previous LaTeX sectioning command.
  382. proc prevSection {} {
  383.     global searchNoisily
  384.     set pos [getPos]
  385.     if {$pos > 0} then {
  386.         set searchResult [findSection [expr $pos - 1] 0]
  387.         if { [string length $searchResult] } {
  388.             eval select $searchResult
  389.             return
  390.         } else {}
  391.     }
  392.     if { $searchNoisily } {beep}
  393.     message {previous section not found}
  394. }
  395. # Select the next LaTeX sectioning command.
  396. proc nextSection {} {
  397.     global searchNoisily
  398.     set pos [getPos]
  399.     if {$pos < [maxPos]} then {
  400.         if { [isSelection] } then {
  401.             set pos [expr $pos + 1]
  402.         }
  403.         set searchResult [findSection $pos 1]
  404.         if { [string length $searchResult] } {
  405.             eval select $searchResult
  406.             return
  407.         } else {}
  408.     }
  409.     if { $searchNoisily } {beep}
  410.     message {next section not found}
  411. }
  412. proc prevSectionSelect {} {
  413.     global searchNoisily
  414.     set pos [getPos]
  415.     if {$pos > 0} then {
  416.         set searchResult [findSection [expr $pos - 1] 0]
  417.         if { [string length $searchResult] } {
  418.             set begPos [lindex $searchResult 0]
  419.             set searchPos [expr [lindex $searchResult 1] + 1]
  420.             set searchResult [findSection $searchPos 1]
  421.             if { [string length $searchResult] } {
  422.                 set endPos [lindex $searchResult 0]
  423.             } else {
  424.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  425.                 set endPos [lindex $searchResult 0]
  426.             }
  427.             select $begPos $endPos
  428.             return
  429.         } else {}
  430.     }
  431.     if { $searchNoisily } {beep}
  432.     message {previous section not found}
  433. }
  434. # Select the next LaTeX sectioning command.
  435. proc nextSectionSelect {} {
  436.     global searchNoisily
  437.     set pos [getPos]
  438.     if {$pos < [maxPos]} then {
  439.         if { [isSelection] } then {
  440.             set pos [expr $pos + 1]
  441.         }
  442.         set searchResult [findSection $pos 1]
  443.         if { [string length $searchResult] } {
  444.             set begPos [lindex $searchResult 0]
  445.             set searchPos [expr [lindex $searchResult 1] + 1]
  446.             set searchResult [findSection $searchPos 1]
  447.             if { [string length $searchResult] } {
  448.                 set endPos [lindex $searchResult 0]
  449.             } else {
  450.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  451.                 set endPos [lindex $searchResult 0]
  452.             }
  453.             select $begPos $endPos
  454.             return
  455.         } else {}
  456.     }
  457.     if { $searchNoisily } {beep}
  458.     message {next section not found}
  459. }
  460.  
  461. # Find a LaTeX subsectioning command in either direction.  It's up to 
  462. # the calling procedure to pass the starting position of the search.
  463. proc findSubsection {pos direction} {
  464.     global funcExpr
  465.     return [search -s -f $direction -r 1 -n $funcExpr $pos]
  466. }
  467. proc prevSubsection {} {
  468.     global searchNoisily
  469.     set pos [getPos]
  470.     if {$pos > 0} then {
  471.         set searchResult [findSubsection [expr $pos - 1] 0]
  472.         if { [string length $searchResult] } {
  473.             eval select $searchResult
  474.             return
  475.         } else {}
  476.     }
  477.     if { $searchNoisily } {beep}
  478.     message {previous (sub)*section not found}
  479. }
  480. # Select the next LaTeX sectioning command.
  481. proc nextSubsection {} {
  482.     global searchNoisily
  483.     set pos [getPos]
  484.     if {$pos < [maxPos]} then {
  485.         if { [isSelection] } then {
  486.             set pos [expr $pos + 1]
  487.         }
  488.         set searchResult [findSubsection $pos 1]
  489.         if { [string length $searchResult] } {
  490.             eval select $searchResult
  491.             return
  492.         } else {}
  493.     }
  494.     if { $searchNoisily } {beep}
  495.     message {next (sub)*section not found}
  496. }
  497. proc prevSubsectionSelect {} {
  498.     global searchNoisily
  499.     set pos [getPos]
  500.     if {$pos > 0} then {
  501.         set searchResult [findSubsection [expr $pos - 1] 0]
  502.         if { [string length $searchResult] } {
  503.             set begPos [lindex $searchResult 0]
  504.             set endPos [lindex $searchResult 1]
  505.             set searchPos [expr $endPos + 1]
  506.             set commandName [extractCommandName [getText $begPos $endPos]]
  507.             if {[string match {section*} $commandName]} then {
  508.                 set searchResult [findSection $searchPos 1]
  509.             } else {
  510.                 set searchResult [findSubsection $searchPos 1]
  511.             }
  512.             if { [string length $searchResult] } {
  513.                 set endPos [lindex $searchResult 0]
  514.             } else {
  515.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  516.                 set endPos [lindex $searchResult 0]
  517.             }
  518.             select $begPos $endPos
  519.             return
  520.         } else {}
  521.     }
  522.     if { $searchNoisily } {beep}
  523.     message {previous (sub)*section not found}
  524. }
  525. # Select the next LaTeX sectioning command.
  526. proc nextSubsectionSelect {} {
  527.     global searchNoisily
  528.     set pos [getPos]
  529.     if {$pos < [maxPos]} then {
  530.         if { [isSelection] } then {
  531.             set pos [expr $pos + 1]
  532.         }
  533.         set searchResult [findSubsection $pos 1]
  534.         if { [string length $searchResult] } {
  535.             set begPos [lindex $searchResult 0]
  536.             set endPos [lindex $searchResult 1]
  537.             set searchPos [expr $endPos + 1]
  538.             set commandName [extractCommandName [getText $begPos $endPos]]
  539.             if {[string match {section*} $commandName]} then {
  540.                 set searchResult [findSection $searchPos 1]
  541.             } else {
  542.                 set searchResult [findSubsection $searchPos 1]
  543.             }
  544.             if { [string length $searchResult] } {
  545.                 set endPos [lindex $searchResult 0]
  546.             } else {
  547.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  548.                 set endPos [lindex $searchResult 0]
  549.             }
  550.             select $begPos $endPos
  551.             return
  552.         } else {}
  553.     }
  554.     if { $searchNoisily } {beep}
  555.     message {next (sub)*section not found}
  556. }
  557.  
  558. proc gotoTabStop {dirIndicator} {
  559.     set pos [getPos]
  560.     if {$dirIndicator} then {
  561.         if {$pos == [maxPos]} {return 0}
  562.     } else {
  563.         if {$pos == 0} {
  564.             set pos [expr $pos - 1]
  565.             return 0
  566.         }
  567.     }
  568.     set searchResult [search -s -n -f $dirIndicator -m 0 -i 1 -r 0 {Ñ} $pos]
  569.     if {[string length $searchResult]} then {
  570.         goto [lindex $searchResult 0]
  571.         return 1
  572.     } else {
  573.         return 0
  574.     }
  575. }
  576. proc nextTabStop {} {
  577.     global searchNoisily
  578.     set forward 1
  579.     if {[gotoTabStop $forward]} then {
  580.         deleteChar
  581.     } else {
  582.         if {$searchNoisily} {beep}
  583.         message "tab stop not found"
  584.     }
  585. }
  586. proc prevTabStop {} {
  587.     global searchNoisily
  588.     set forward 0
  589.     if {[gotoTabStop $forward]} then {
  590.         deleteChar
  591.     } else {
  592.         if {$searchNoisily} {beep}
  593.         message "tab stop not found"
  594.     }
  595. }
  596. # Goto the nth tab stop.  A nonzero argument is non-interactive
  597. # (for use in Tcl procs) and not validated.
  598. proc nthTabStop {{numTabStops 0}} {
  599.     global searchNoisily promptNoisily useStatusBar
  600.     if {$numTabStops == 0} then {
  601.         if {$promptNoisily && $useStatusBar} {beep}
  602.         catch {sPrompt "How many tab stops?" "3"} numTabStops
  603.         if {$numTabStops == "cancel" || $numTabStops == 0} then {
  604.             return
  605.         } elseif {![isInteger $numTabStops]} then {
  606.             beep
  607.             message "invalid input"
  608.             return
  609.         }
  610.     }
  611.     set currentPos [getPos]
  612.     if {$numTabStops > 0} {set forward 1} {set forward 0}
  613.     set maxits [expr abs($numTabStops)]
  614.     if {![gotoTabStop $forward]} then {
  615.         if {$searchNoisily} {beep}
  616.         message "tab stop not found"
  617.         goto $currentPos
  618.         return
  619.     }
  620.     for {set i 1} {$i < $maxits} {incr i} {
  621.         if {$forward} {forwardChar} {backwardChar}
  622.         if {![gotoTabStop $forward]} then {
  623.             if {$searchNoisily} {beep}
  624.             message "tab stop not found"
  625.             goto $currentPos
  626.             return
  627.         }
  628.     }
  629.     deleteChar
  630. }
  631.  
  632. #--------------------------------------------------------------------------
  633. # Utilities:
  634. #--------------------------------------------------------------------------
  635.  
  636. proc chooseCommand {{men {}} {prompt "LaTeX submenu:"}} {
  637.     watchCursor
  638.     if {![string length $men]} {
  639.         set men    [getTeXMenu]
  640.     }
  641.     foreach    item $men {
  642.         regsub -all {[<!/].} $item {} item
  643.         regsub -all {╔}    $item {} item
  644.         lappend    menOut $item
  645.         if {[string match "menu*" $item]} {
  646.             if {[set ind [lsearch $item {-n}]] >= 0} {
  647.                 lappend    top [lindex $item [incr    ind]]
  648.             }
  649.         } elseif {![string match "(*" $item]} {
  650.             lappend    top $item
  651.         }
  652.     }
  653.     set res    [listpick -p $prompt $top]
  654.     if {[lsearch $menOut $res] >= 0} {
  655.         interpretMenuItem dummy    $res
  656.     } else {
  657.         foreach    item $menOut {
  658.             if {[set ind [lsearch $item $res]] >= 0} {
  659.                 return [chooseCommand [lindex $item end] "LaTeX submenu command:"]
  660.             }
  661.         }
  662.     }
  663. }
  664.  
  665. proc insertLiteralTab {} {
  666.     if {[isSelection]} then {
  667.         deleteSelection
  668.     }
  669.     insertText "\t"
  670. }
  671.  
  672. proc insertTabStop {} {
  673.     if {[isSelection]} then {
  674.         deleteSelection
  675.     }
  676.     insertText "Ñ"
  677. }
  678.  
  679. proc insertReference {} {
  680.     set end [maxPos]
  681.     set pos 0
  682.     set labels {}
  683.     
  684.     set exp {\\label\{(.*)\}}
  685.     while {![catch {search -s -f 1 -r 1 -m 0 -i 0 $exp $pos} res]} {
  686.         set start [lindex $res 0]
  687.         set end [lindex $res 1]
  688.         set text [getText $start $end]
  689.         regexp {\{(.*)\}} $text dummy label
  690.         lappend labels $label
  691.         set pos [expr $end +1]
  692.     }
  693.  
  694.     set ref [listpick -p "Select a reference to insert" [lsort $labels]]
  695.     if {[string length $ref]} {
  696.         insertText "\\ref\{$ref\}"
  697.     }    
  698. }
  699.  
  700. # Removes all tab stops from the current selection (if there is one) 
  701. # or the current document, maintaining the cursor position in the 
  702. # latter case.
  703. proc deleteTabStops {} {
  704.     global searchNoisily
  705.     watchCursor
  706.     set subs1 0; set subs2 0; set subs3 0
  707.     set pos [getPos]
  708.     if {[set start $pos] == [set end [selEnd]]} {
  709.         set messageString "document"
  710.         set start 0
  711.         set end [maxPos]
  712.         set text1 [getText $start $pos]
  713.         set subs1 [regsub -all {Ñ} $text1 {} text1]
  714.         set text2 [getText $pos $end]
  715.         set subs2 [regsub -all {Ñ} $text2 {} text2]
  716.         append text $text1 $text2
  717.     } else {
  718.         set messageString "selection"
  719.         set text [getText $start $end]
  720.         set subs3 [regsub -all {Ñ} $text {} text]
  721.     }
  722.     if {$subs1 || $subs2 || $subs3} then {
  723.         replaceText $start $end $text
  724.         if {$messageString == "document"} then {
  725.             goto [expr $pos - $subs1]
  726.         } else {
  727.             set end [getPos]
  728.             select $start $end
  729.         }
  730.         set subs [expr $subs1 + $subs2 + $subs3]
  731.         message "$subs tab stops removed from $messageString"
  732.     } else {
  733.         if {$searchNoisily} {beep}
  734.         message "no tab stops found in $messageString"
  735.     }
  736. }
  737.  
  738. # Delete all unnecessary comments from the current document:
  739. proc deleteComments {} {
  740.     case [askyesno "Warning!  This operation can not be undone.  \
  741.                     Continue anyway?"] in {
  742.         "yes" {}
  743.         "no" { return }
  744.     }
  745.     replaceString {}
  746.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {^[ \t]*%.*\r} 0]
  747.     replaceAll
  748.     
  749.     replaceString {}
  750.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {[ \t]+%.*} 0]
  751.     replaceAll
  752.     
  753.     replaceString {\1%}
  754.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {([^\\](\\\\)*)%.*} 0]
  755.     replaceAll
  756. }
  757.  
  758. # Converts all straight quotes to their TeX equivalents.
  759. proc convertQuotes {} {
  760.     global searchNoisily
  761.     message "working╔"
  762.     watchCursor
  763.     set messageString "selection"
  764.     if {[set start [getPos]] == [set end [selEnd]]} {
  765.         set messageString "document"
  766.         set start 0
  767.         set end [maxPos]
  768.     }
  769.     set text [getText $start $end]
  770.     # Convert all left double quotes:
  771.     set convert1 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\"" $text {\1``} text]
  772.     # Convert all right double quotes:
  773.     set convert2 [regsub -all "\(\[\^\\\\\]\)\"" $text {\1''} text]
  774.     # Convert all left single quotes:
  775.     set convert3 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\'" $text {\1`} text]
  776.     if {$convert1 || $convert2 || $convert3} then {
  777.         replaceText $start $end $text
  778.         message "all quotes in $messageString converted"
  779.     } else {
  780.         if {$searchNoisily} {beep}
  781.         message "no quotes found in $messageString"
  782.     }
  783. }
  784.  
  785. # Returns true if the argument contains non-literal double dollar
  786. # signs, and false otherwise.
  787. proc containsDoubleDollarSigns {text} {
  788.     return [regexp {(^|[^\\])\$\$} $text]
  789. }
  790.  
  791. # Converts all $$...$$ pairs to \[...\] and returns the number of such 
  792. # pairs converted.  If the dollar signs are unbalanced, does nothing 
  793. # and returns -1.
  794. proc convertDoubleDollarSigns {} {
  795.     watchCursor
  796.     set messageString "selection"
  797.     if {[set start [getPos]] == [set end [selEnd]]} {
  798.         set messageString "document"
  799.         set start 0
  800.         set end [maxPos]
  801.     }
  802.     set text [getText $start $end]
  803.     set subs [regsub -all {(^|[^\\])\$\$([^$]*)\$\$} $text {\1\\[\2\\]} text]
  804.     if {[containsDoubleDollarSigns $text]} then {return -1}
  805.     if {$subs} then {
  806.         replaceText $start $end $text
  807.     }
  808.     return [expr $subs]
  809. }
  810.  
  811. # Returns true if the argument contains a non-literal dollar sign,
  812. # and false otherwise.
  813. proc containsSingleDollarSign {text} {
  814.     return [regexp {(^|[^\\])\$} $text]
  815. }
  816.  
  817. # Converts all $...$ pairs to \(...\), maintains the cursor position, 
  818. # and returns the number of such pairs converted.  If the dollar signs 
  819. # are unbalanced, does nothing and returns -1.
  820. proc convertSingleDollarSigns {} {
  821.     watchCursor
  822.     set subs1 0; set subs2 0; set subs3 0
  823.     set pos [getPos]; set pos2 $pos
  824.     if {[set start $pos] == [set end [selEnd]]} {
  825.         set isSelection 0
  826.         set start 0
  827.         set end [maxPos]
  828.         set text1 [getText $start $pos]
  829.         set subs1 [regsub -all {(^|[^\\])\$([^$]*)\$} $text1 {\1\\(\2\\)} text1]
  830.         # Is there a dollar sign left over?  If so, search backward for this
  831.         # dollar sign and prepare to do a substitution on the text to the right
  832.         # of this dollar sign.
  833.         if {[containsSingleDollarSign $text1]} then {
  834.             set searchString {[^\\]\$}
  835.             set searchResult [search -s -n -f 0 -m 0 -i 1 -r 1 $searchString [expr $pos-1]]
  836.             set pos2 [lindex $searchResult 0]
  837.             set text1 [string range $text1 0 [expr $pos2 + (2 * $subs1)]]
  838.             set pos [expr $pos + 2]
  839.         }
  840.         set text2 [getText $pos2 $end]
  841.         set subs2 [regsub -all {(^|[^\\])\$([^$]*)\$} $text2 {\1\\(\2\\)} text2]
  842.         # Is there a dollar sign left over?  If so, it's unbalanced.
  843.         if {[containsSingleDollarSign $text2]} then {return -1}
  844.         append text $text1 $text2
  845.     } else {
  846.         set isSelection 1
  847.         set text [getText $start $end]
  848.         set subs3 [regsub -all {(^|[^\\])\$([^$]*)\$} $text {\1\\(\2\\)} text]
  849.         # Is there a dollar sign left over?  If so, it's unbalanced.
  850.         if {[containsSingleDollarSign $text]} then {return -1}
  851.     }
  852.     if {$subs1 || $subs2 || $subs3} then {
  853.         replaceText $start $end $text
  854.         # If there is a selection, just put it back.  Otherwise, adjust the
  855.         # cursor position based on the number of substitutions.
  856.         if {$isSelection} then {
  857.             set end [getPos]
  858.             select $start $end
  859.         } else {
  860.             goto [expr $pos + (2 * $subs1)]
  861.         }
  862.     }
  863.     return [expr $subs1 + $subs2 + $subs3]
  864. }
  865.  
  866. proc convertDollarSigns {} {
  867.     global searchNoisily
  868.     if {[isSelection]} then {
  869.         set messageString "selection"
  870.     } else {
  871.         set messageString "document"
  872.     }
  873.     set subs2 [convertDoubleDollarSigns]
  874.     if {$subs2 == -1} then {
  875.         beep
  876.         alertnote "unmatched double dollar signs in $messageString"
  877.     } else {
  878.         set subs1 [convertSingleDollarSigns]
  879.         if {$subs1 == -1} then {
  880.             beep
  881.             alertnote "unmatched single dollar sign in $messageString"
  882.         } elseif {$subs1 == 0 && $subs2 == 0} then {
  883.             if {$searchNoisily} {beep}
  884.             message "no dollar signs found in $messageString"
  885.         } else {
  886.             message "$subs1 pairs of \$...\$ and $subs2 pairs of \$\$...\$\$ removed from $messageString"
  887.         }
  888.     }
  889. }
  890.  
  891. proc removeAuxiliaryFiles {} {
  892.     set word ""
  893.     set currentWin [lindex [winNames -f] 0]
  894.     set currentDir [file dirname $currentWin]
  895.     set currentDoc [file tail $currentWin]
  896.     set docBasename [file rootname $currentDoc]
  897.     set docExtension [file extension $currentDoc]
  898.     set extensions {.aux .bbl .dvi .glo .idx .ind .lof .log .lot \
  899.               .toc .blg .clg .ilg .ps}
  900.     foreach ext $extensions {
  901.         if {[file exists "$currentDir:$docBasename$ext"]} then {
  902.             set word " more"
  903.             case [askyesno -c "Remove \"$docBasename$ext\"?"] in {
  904.                 "yes" {
  905.                     if {[catch {rm "$currentDir:$docBasename$ext"}]} then {
  906.                         alertnote "\"$docBasename$ext\" not deleted"
  907.                     }
  908.                 }
  909.                 "no" {}
  910.                 "cancel" {return}
  911.             }
  912.         }
  913.     }
  914.     message "no$word files found"
  915. }
  916.  
  917.  
  918. #############################################################################
  919. # Paragraph Mode Macros
  920. #
  921. #############################################################################
  922.  
  923. #--------------------------------------------------------------------------
  924. # Documents:
  925. #--------------------------------------------------------------------------
  926.  
  927. proc letter {} {
  928.     set    preamble "\r\\address\{%\r"
  929.     append preamble "    Ñ    \\\\    % insert your name here\r"
  930.     append preamble "    Ñ    \\\\    % insert your address here\r"
  931.     append preamble "    Ñ    \\\\    % insert more address here\r"
  932.     append preamble "    Ñ          % insert city-state-zip here\r"
  933.     append preamble "\}\r\r"
  934.     append preamble "\\date\{Ñ\}  % optional\r"
  935.     append preamble "\\signature\{Ñ\}\r\r"
  936.     set    body "\r\\begin\{letter\}\{%\r"
  937.     append body "    Ñ    \\\\    % insert addressee's name here\r"
  938.     append body "    Ñ    \\\\    % insert addressee's address here\r"
  939.     append body "    Ñ    \\\\    % insert more address here\r"
  940.     append body "    Ñ          % insert addressee's city-state-zip here\r"
  941.     append body "\}\r\r"
  942.     append body "\\opening\{Dear Ñ,\}\r\r"
  943.     if {[isEmptyFile]} then {
  944.         append body "% BODY OF LETTER\r"
  945.         append body "Ñ\r\r"
  946.     } else {
  947.         if {[isDocumentSelected]} then {
  948.             set text [getSelect]
  949. #             deleteText 0 [maxPos]
  950.             append body "$text\r"
  951.         } else {
  952.             alertnote "nonempty file:  delete text or \'Select All\'\
  953.                 from the Edit menu"
  954.             return
  955.         }
  956.     }
  957.     append body "\\closing\{Sincerely,\}\r\r"
  958.     append body "\\encl\{Ñ\}\r"
  959.     append body "\\cc\{Ñ\}\r\r"
  960.     append body "\\end\{letter\}\r\r"
  961.     insertDocument "letter" $preamble $body
  962.     nextTabStop
  963.     message "enter option (or leave blank)"
  964. }
  965. proc article {} {
  966.     wrapDocument "article"
  967. }
  968. proc report {} {
  969.     wrapDocument "report"
  970. }
  971. proc book {} {
  972.     wrapDocument "book"
  973. }
  974. proc slides {} {
  975.     wrapDocument "slides"
  976. }
  977. proc custom {} {
  978.     catch {prompt "What documentclass?" "article"} documentType
  979.     if {$documentType != "cancel"} then {
  980.         wrapDocument "$documentType" 
  981.     }
  982. }
  983.  
  984. proc getOption {} {
  985.     catch {prompt "Choose an option:" "11pt" "" "10pt" "11pt" "12pt" "(-" \
  986.             "letterpaper" "legalpaper" "executivepaper" "a4paper" "a5paper" \
  987.             "b5paper" "(-" "landscape" "(-" "final" "draft" "(-" \
  988.             "oneside" "twoside" "(-" "openright" "openany" "(-" \
  989.             "onecolumn" "twocolumn" "(-" "notitlepage" "titlepage" \
  990.                   "openbib" "(-" "leqno" "(-" "fleqn"} optionName
  991.     if {$optionName != "cancel"} then {
  992.         return $optionName
  993.     } else {
  994.         return ""
  995.     }
  996. }
  997. proc insertOption {option} {
  998.     global searchNoisily
  999.     set searchString {\\documentclass}
  1000.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1001.     if {[llength $searchResult] == 0} then {
  1002.         if {$searchNoisily} {beep}
  1003.         message "can\'t find \\documentclass"
  1004.     } else {
  1005.         set nextCharPos [lindex $searchResult 1]
  1006.         goto $nextCharPos
  1007.         set nextChar [lookAt $nextCharPos]
  1008.         if {$nextChar == "\["} then {
  1009.             forwardChar
  1010.             insertText $option
  1011.             if {[lookAt [getPos]] != "\]"} then {
  1012.                 insertText ","
  1013.             }
  1014.         } elseif {$nextChar == "\{"} then {
  1015.             insertText "\[$option\]"
  1016.         } else {
  1017.             alertnote "unrecognizable \\documentclass statement"
  1018.         }
  1019.     }
  1020. }
  1021. proc options {} {
  1022.     set option [getOption]
  1023.     if {$option != ""} then {
  1024.         insertOption $option
  1025.     }
  1026. }
  1027. proc getPackage {} {
  1028.     catch {prompt "Choose a package:" "latexsym" "" \
  1029.                   "alltt" "amstex" "babel" "color" \
  1030.                   "graphics" "graphpap" "ifthen" "latexsym" "makeidx" \
  1031.                   "pict2e" "showidx"} packageName
  1032.     if {$packageName != "cancel"} then {
  1033.         return $packageName
  1034.     } else {
  1035.         return ""
  1036.     }
  1037. }
  1038. proc insertPackage {package} {
  1039.     global searchNoisily
  1040.     set begPos [getPos]
  1041.     set endPos [selEnd]
  1042.     append searchString {\\usepackage\{.*} $package {.*\}}
  1043.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1044.     if {[llength $searchResult] == 0} then {
  1045.         set searchString {\\documentclass(\[.*\])?\{.*\}}
  1046.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1047.         if {[llength $searchResult] == 0} then {
  1048.             if {$searchNoisily} {beep}
  1049.             message "can't find \\documentclass"
  1050.         } else {
  1051.             goto [lindex $searchResult 1]
  1052.             set txt "\r\\usepackage\{$package\}"
  1053.             set offset [string length $txt]
  1054.             set begPos [expr $begPos + $offset]
  1055.             set endPos [expr $endPos + $offset]
  1056.             insertText $txt
  1057.             select $begPos $endPos
  1058.         }
  1059.     } else {
  1060.         if {$searchNoisily} {beep}
  1061.         message "$package package already loaded"
  1062.     }
  1063. }
  1064. proc packages {} {
  1065.     set package [getPackage]
  1066.     if {$package != ""} then {
  1067.         insertPackage $package
  1068.     }
  1069. }
  1070. proc filecontents {} {
  1071.     global searchNoisily
  1072.     set searchString {\\documentclass}
  1073.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1074.     if {[llength $searchResult] == 0} then {
  1075.         if {$searchNoisily} {beep}
  1076.         message "can\'t find \\documentclass"
  1077.         return
  1078.     } else {
  1079.         set prompt "File to be included:"
  1080.         if {[catch {getfile $prompt} path]} then {
  1081.             return
  1082.         } else {
  1083.             set fd [open $path]
  1084.             set text [read $fd]
  1085.             close $fd
  1086.             regsub -all "\xa" $text "\xd" text
  1087.             goto 0
  1088.             set envName "filecontents"
  1089.             set envArg "{[file tail $path]}"
  1090.             replaceText 0 0 [buildEnvironment $envName $envArg "$text\r" "\r\r"]
  1091.             goto 0
  1092.             message "file included"
  1093.         }
  1094.     }
  1095. }
  1096.  
  1097. #--------------------------------------------------------------------------
  1098. # Page Layout:
  1099. #--------------------------------------------------------------------------
  1100.  
  1101. proc maketitle {} {
  1102.     global searchNoisily
  1103.     set searchString {\\document(class|style)(\[.*\])?\{.*\}}
  1104.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1105.     if {[llength $searchResult] == 0} then {
  1106.         if {$searchNoisily} {beep}
  1107.         message "can\'t find \\documentclass or \\documentstyle"
  1108.     } else {
  1109.         set searchPos [lindex $searchResult 1]
  1110.         set searchString {\\begin\{document\}}
  1111.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]
  1112.         if {[llength $searchResult] == 0} then {
  1113.             if {$searchNoisily} {beep}
  1114.             message "can\'t find \\begin\{document\}"
  1115.         } else {
  1116.             goto [lindex $searchResult 1]
  1117.             set currentPos [getPos]
  1118.             set txt "\r\r% Definition of title page:"
  1119.             append txt "\r\\title\{"
  1120.             append txt "\r\tÑ\r\}"
  1121.             append txt "\r\\author\{"
  1122.             append txt "\r\tÑ\t% insert author(s) here"
  1123.             append txt "\r\}"
  1124.             append txt "\r\\date\{Ñ\}\t% optional"
  1125.             append txt "\r\r\\maketitle"
  1126.             insertText $txt
  1127.             goto $currentPos
  1128.             nextTabStop
  1129.             message "insert title"
  1130.         }
  1131.     }
  1132. }
  1133. proc abstract {} { doWrapEnvironment "abstract" }
  1134. proc titlepage {} { doWrapEnvironment "titlepage" }
  1135. proc getPagestyle {} {
  1136.     catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" \
  1137.                   "headings" "myheadings"} pagestyleName
  1138.     if {$pagestyleName != "cancel"} then {
  1139.         return $pagestyleName
  1140.     } else {
  1141.         return ""
  1142.     }
  1143. }
  1144. proc pagestyle {} {
  1145.     set pagestyleName [getPagestyle]
  1146.     if {$pagestyleName != ""} then {
  1147.         openingCarriageReturn
  1148.         insertObject "\\pagestyle\{$pagestyleName\}"
  1149.         closingCarriageReturn
  1150.     }
  1151. }
  1152. proc thispagestyle {} {
  1153.     set pagestyleName [getPagestyle]
  1154.     if {$pagestyleName != ""} then {
  1155.         openingCarriageReturn
  1156.         insertObject "\\thispagestyle\{$pagestyleName\}"
  1157.         closingCarriageReturn
  1158.     }
  1159. }
  1160. proc getPagenumberingStyle {} {
  1161.     catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" \
  1162.                   "roman" "Roman" "alph" "Alph"} pagenumberingStyle
  1163.     if {$pagenumberingStyle != "cancel"} then {
  1164.         return $pagenumberingStyle
  1165.     } else {
  1166.         return ""
  1167.     }
  1168. }
  1169. proc pagenumbering {} {
  1170.     set pagenumberingStyle [getPagenumberingStyle]
  1171.     if {$pagenumberingStyle != ""} then {
  1172.         openingCarriageReturn
  1173.         insertObject "\\pagenumbering\{$pagenumberingStyle\}"
  1174.         closingCarriageReturn
  1175.     }
  1176. }
  1177. proc twocolumn {} {
  1178.     openingCarriageReturn
  1179.     insertObject "\\twocolumn"
  1180.     closingCarriageReturn
  1181. }
  1182. proc onecolumn {} {
  1183.     openingCarriageReturn
  1184.     insertObject "\\onecolumn"
  1185.     closingCarriageReturn
  1186. }
  1187.  
  1188. #--------------------------------------------------------------------------
  1189. # Sectioning:
  1190. #--------------------------------------------------------------------------
  1191.  
  1192. proc part {} {
  1193.     if {[wrapObject "\\part{" "}Ñ"]} then {
  1194.         message "don't forget the label"
  1195.     } else {
  1196.         message "type the part name and don't forget the label"
  1197.     }
  1198. }
  1199. proc chapter {} {
  1200.     if {[wrapObject "\\chapter{" "}Ñ"]} then {
  1201.         message "don't forget the label"
  1202.     } else {
  1203.         message "type the chapter name and don't forget the label"
  1204.     }
  1205. }
  1206. proc section {} {
  1207.     if {[wrapObject "\\section{" "}Ñ"]} then {
  1208.         message "don't forget the label"
  1209.     } else {
  1210.         message "type the section name and don't forget the label"
  1211.     }
  1212. }
  1213. proc subsection {} {
  1214.     if {[wrapObject "\\subsection{" "}Ñ"]} then {
  1215.         message "don't forget the label"
  1216.     } else {
  1217.         message "type the subsection name and don't forget the label"
  1218.     }
  1219. }
  1220. proc subsubsection {} {
  1221.     if {[wrapObject "\\subsubsection{" "}Ñ"]} then {
  1222.         message "don't forget the label"
  1223.     } else {
  1224.         message "type the subsubsection name and don't forget the label"
  1225.     }
  1226. }
  1227. proc paragraph {} {
  1228.     if {[wrapObject "\\paragraph{" "}Ñ"]} then {
  1229.         message "don't forget the label"
  1230.     } else {
  1231.         message "type the paragraph name and don't forget the label"
  1232.     }
  1233. }
  1234. proc subparagraph {} {
  1235.     if {[wrapObject "\\subparagraph{" "}Ñ"]} then {
  1236.         message "don't forget the label"
  1237.     } else {
  1238.         message "type the subparagraph name and don't forget the label"
  1239.     }
  1240. }
  1241. proc appendix {} {insertObject "\\appendix"}
  1242.  
  1243. #--------------------------------------------------------------------------
  1244. # Text Style:
  1245. #--------------------------------------------------------------------------
  1246.  
  1247. proc emph {} {
  1248.     if {[wrapObject "\\emph{" "}Ñ"]} then {
  1249.         message "selected text has been emphasized"
  1250.     } else {
  1251.         message "enter text to be emphasized"
  1252.     }
  1253. }
  1254. proc textup {} {
  1255.     if {[wrapObject "\\textup{" "}Ñ"]} then {
  1256.         message "selected text has upright shape"
  1257.     } else {
  1258.         message "enter text to have upright shape"
  1259.     }
  1260. }
  1261. proc textit {} {
  1262.     if {[wrapObject "\\textit{" "}Ñ"]} then {
  1263.         message "selected text has italic shape"
  1264.     } else {
  1265.         message "enter text to have italic shape"
  1266.     }
  1267. }
  1268. proc textsl {} {
  1269.     if {[wrapObject "\\textsl{" "}Ñ"]} then {
  1270.         message "selected text has slanted shape"
  1271.     } else {
  1272.         message "enter text to have slanted shape"
  1273.     }
  1274. }
  1275. proc textsc {} {
  1276.     if {[wrapObject "\\textsc{" "}Ñ"]} then {
  1277.         message "selected text has small caps shape"
  1278.     } else {
  1279.         message "enter text to have small caps shape"
  1280.     }
  1281. }
  1282. proc textmd {} {
  1283.     if {[wrapObject "\\textmd{" "}Ñ"]} then {
  1284.         message "selected text has been set in medium series"
  1285.     } else {
  1286.         message "enter text to be set in medium series"
  1287.     }
  1288. }
  1289. proc textbf {} {
  1290.     if {[wrapObject "\\textbf{" "}Ñ"]} then {
  1291.         message "selected text has been set in bold series"
  1292.     } else {
  1293.         message "enter text to be set in bold series"
  1294.     }
  1295. }
  1296. proc textrm {} {
  1297.     if {[wrapObject "\\textrm{" "}Ñ"]} then {
  1298.         message "selected text has been set with roman family"
  1299.     } else {
  1300.         message "enter text to be set using roman family"
  1301.     }
  1302. }
  1303. proc textsf {} {
  1304.     if {[wrapObject "\\textsf{" "}Ñ"]} then {
  1305.         message "selected text has been set with sans serif family"
  1306.     } else {
  1307.         message "enter text to be set using sans serif family"
  1308.     }
  1309. }
  1310. proc texttt {} {
  1311.     if {[wrapObject "\\texttt{" "}Ñ"]} then {
  1312.         message "selected text has been set with typewriter family"
  1313.     } else {
  1314.         message "enter text to be set using typewriter family"
  1315.     }
  1316. }
  1317. proc textnormal {} {
  1318.     if {[wrapObject "\\textnormal{" "}Ñ"]} then {
  1319.         message "selected text has been set with normal style"
  1320.     } else {
  1321.         message "enter text to be set using normal style"
  1322.     }
  1323. }
  1324.  
  1325. #--------------------------------------------------------------------------
  1326. # Text Size:
  1327. #--------------------------------------------------------------------------
  1328.  
  1329. proc tiny {} {
  1330.     if {[wrapObject "{\\tiny " "}Ñ"]} then {
  1331.         message "tiny text set"
  1332.     } else {
  1333.         message "enter tiny text"
  1334.     }
  1335. }
  1336. proc scriptsize {} {
  1337.     if {[wrapObject "{\\scriptsize " "}Ñ"]} then {
  1338.         message "scriptsize text set"
  1339.     } else {
  1340.         message "enter scriptsize text"
  1341.     }
  1342. }
  1343. proc footnotesize {} {
  1344.     if {[wrapObject "{\\footnotesize " "}Ñ"]} then {
  1345.         message "footnotesize text set"
  1346.     } else {
  1347.         message "enter footnotesize text"
  1348.     }
  1349. }
  1350. proc small {} {
  1351.     if {[wrapObject "{\\small " "}Ñ"]} then {
  1352.         message "small text set"
  1353.     } else {
  1354.         message "enter small text"
  1355.     }
  1356. }
  1357. proc normalsize {} {
  1358.     if {[wrapObject "{\\normalsize " "}Ñ"]} then {
  1359.         message "normalsize text set"
  1360.     } else {
  1361.         message "enter normalsize text"
  1362.     }
  1363. }
  1364. proc large {} {
  1365.     if {[wrapObject "{\\large " "}Ñ"]} then {
  1366.         message "large text set"
  1367.     } else {
  1368.         message "enter large text"
  1369.     }
  1370. }
  1371. proc Large {} {
  1372.     if {[wrapObject "{\\Large " "}Ñ"]} then {
  1373.         message "Large text set"
  1374.     } else {
  1375.         message "enter Large text"
  1376.     }
  1377. }
  1378. proc LARGE {} {
  1379.     if {[wrapObject "{\\LARGE " "}Ñ"]} then {
  1380.         message "LARGE text set"
  1381.     } else {
  1382.         message "enter LARGE text"
  1383.     }
  1384. }
  1385. proc huge {} {
  1386.     if {[wrapObject "{\\huge " "}Ñ"]} then {
  1387.         message "huge text set"
  1388.     } else {
  1389.         message "enter huge text"
  1390.     }
  1391. }
  1392. proc Huge {} {
  1393.     if {[wrapObject "{\\Huge " "}Ñ"]} then {
  1394.         message "Huge text set"
  1395.     } else {
  1396.         message "enter Huge text"
  1397.     }
  1398. }
  1399.  
  1400. #--------------------------------------------------------------------------
  1401. # International:
  1402. #--------------------------------------------------------------------------
  1403.  
  1404. proc {ÿ} {} {
  1405.     if {[wrapObject "\\`{" "}Ñ"]} then {
  1406.         message "accent set"
  1407.     } else {
  1408.         message "enter single character"
  1409.     }
  1410. }
  1411. proc {ù} {} {
  1412.     if {[wrapObject "\\'{" "}Ñ"]} then {
  1413.         message "accent set"
  1414.     } else {
  1415.         message "enter single character"
  1416.     }
  1417. }
  1418. proc {Ö} {} {
  1419.     if {[wrapObject "\\^{" "}Ñ"]} then {
  1420.         message "accent set"
  1421.     } else {
  1422.         message "enter single character"
  1423.     }
  1424. }
  1425. proc {Ü} {} {
  1426.     if {[wrapObject "\\\"{" "}Ñ"]} then {
  1427.         message "accent set"
  1428.     } else {
  1429.         message "enter single character"
  1430.     }
  1431. }
  1432. proc {¢} {} {
  1433.     if {[wrapObject "\\~{" "}Ñ"]} then {
  1434.         message "accent set"
  1435.     } else {
  1436.         message "enter single character"
  1437.     }
  1438. }
  1439. proc {ì} {} {insertObject "\\c\{c\}"}
  1440. proc {é} {} {insertObject "\\c\{C\}"}
  1441. proc {╧} {} {insertObject "\\oe"}
  1442. proc {╬} {} {insertObject "\\OE"}
  1443. proc {╛} {} {insertObject "\\ae"}
  1444. proc {«} {} {insertObject "\\AE"}
  1445. proc {î} {} {insertObject "\\aa"}
  1446. proc {ü} {} {insertObject "\\AA"}
  1447. proc {┐} {} {insertObject "\\o"}
  1448. proc {»} {} {insertObject "\\O"}
  1449. proc {º} {} {insertObject "\\ss"}
  1450. proc {└} {} {insertObject "?`"}
  1451. proc {┴} {} {insertObject "!`"}
  1452.  
  1453. #--------------------------------------------------------------------------
  1454. # Environments:
  1455. #--------------------------------------------------------------------------
  1456.  
  1457. proc enumerate {} {
  1458.     global promptNoisily useStatusBar
  1459.     set envName "enumerate"
  1460.     if {$promptNoisily && $useStatusBar} {beep}
  1461.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1462.     if {$numberItems == "cancel"} then {
  1463.         return
  1464.     } elseif {![isUnsignedInteger $numberItems]} then {
  1465.         beep
  1466.         message "invalid input"
  1467.         return
  1468.     }
  1469.     if {$numberItems} then {
  1470.         set body "\t\\item  Ñ"
  1471.         for {set i 1} {$i < $numberItems} {incr i} {
  1472.             append body "\r\r\t\\item  Ñ"
  1473.         }
  1474.         append body "\r"
  1475.     } else {
  1476.         set body "\tÑ\r"
  1477.     }
  1478.     if {[insertEnvironment $envName "" $body]} then {
  1479.         nextTabStop
  1480.         message "type first item"
  1481.     }
  1482. }
  1483. proc itemize {} {
  1484.     global promptNoisily useStatusBar
  1485.     set envName "itemize"
  1486.     if {$promptNoisily && $useStatusBar} {beep}
  1487.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1488.     if {$numberItems == "cancel"} then {
  1489.         return
  1490.     } elseif {![isUnsignedInteger $numberItems]} then {
  1491.         beep
  1492.         message "invalid input"
  1493.         return
  1494.     }
  1495.     if {$numberItems} then {
  1496.         set body "\t\\item  Ñ"
  1497.         for {set i 1} {$i < $numberItems} {incr i} {
  1498.             append body "\r\r\t\\item  Ñ"
  1499.         }
  1500.         append body "\r"
  1501.     } else {
  1502.         set body "\tÑ\r"
  1503.     }
  1504.     if {[insertEnvironment $envName "" $body]} then {
  1505.         nextTabStop
  1506.         message "type first item"
  1507.     }
  1508. }
  1509. proc description {} {
  1510.     global promptNoisily useStatusBar
  1511.     set envName "description"
  1512.     if {$promptNoisily && $useStatusBar} {beep}
  1513.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1514.     if {$numberItems == "cancel"} then {
  1515.         return
  1516.     } elseif {![isUnsignedInteger $numberItems]} then {
  1517.         beep
  1518.         message "invalid input"
  1519.         return
  1520.     }
  1521.     if {$numberItems} then {
  1522.         set body "\t\\item\[Ñ\]  Ñ"
  1523.         for {set i 1} {$i < $numberItems} {incr i} {
  1524.             append body "\r\r\t\\item\[Ñ\]  Ñ"
  1525.         }
  1526.         append body "\r"
  1527.     } else {
  1528.         set body "\tÑ\r"
  1529.     }
  1530.     if {[insertEnvironment $envName "" $body]} then {
  1531.         nextTabStop
  1532.         message "type first item label"
  1533.     }
  1534. }
  1535. proc thebibliography {} {
  1536.     global promptNoisily useStatusBar
  1537.     set envName "thebibliography"
  1538.     if {$promptNoisily && $useStatusBar} {beep}
  1539.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1540.     if {$numberItems == "cancel"} then {
  1541.         return
  1542.     } elseif {![isUnsignedInteger $numberItems]} then {
  1543.         beep
  1544.         message "invalid input"
  1545.         return
  1546.     }
  1547.     set arg "{9}"
  1548.     if {$numberItems} then {
  1549.         if {$numberItems > 9} then {set arg "{99}"}
  1550.         set body "\t\\bibitem{Ñ}  Ñ"
  1551.         for {set i 1} {$i < $numberItems} {incr i} {
  1552.             append body "\r\r\t\\bibitem{Ñ}  Ñ"
  1553.         }
  1554.         append body "\r"
  1555.     } else {
  1556.         set body "\tÑ\r"
  1557.     }
  1558.     if {[insertEnvironment $envName $arg $body]} then {
  1559.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(9)+} [getPos]]
  1560.         eval select $searchResult
  1561.         message "Change the length of the key field?"
  1562.     }
  1563. }
  1564. proc slide {} { doWrapEnvironment "slide" }
  1565. proc overlay {} { doWrapEnvironment "overlay" }
  1566. proc note {} { doWrapEnvironment "note" }
  1567. proc figure {} {
  1568.     global useBoxMacro boxMacroName
  1569.     set envName "figure"
  1570.     set envArg "tbp"
  1571.     set arg "\[$envArg\]"
  1572.     set body ""
  1573.     if {$useBoxMacro} then {
  1574.         append body "\t\\centerline{\\$boxMacroName{Ñ}}\r"
  1575.     }
  1576.     append body "\t\\caption{Ñ}\r"
  1577.     append body "\t\\protect\\label{Ñ}\r"
  1578.     if {$useBoxMacro} then {
  1579.         if {![insertEnvironment $envName $arg $body]} then {return}
  1580.     } else {
  1581.         wrapEnvironment $envName $arg $body
  1582.     }
  1583.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1584.     eval select $searchResult
  1585.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1586. }
  1587. proc table {} {
  1588.     set envName "table"
  1589.     set envArg "tbp"
  1590.     # The following statement puts the caption at the top:
  1591.     set arg "\[$envArg\]\r[getIndentation [getPos]]\t\\caption{Ñ}"
  1592.     # The following two statements put the caption at the bottom:
  1593. #     set arg "\[$envArg\]"
  1594. #     set body "\t\\caption{Ñ}\r"
  1595.     append body "\t\\protect\\label{Ñ}\r"
  1596.     wrapEnvironment $envName $arg $body
  1597.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1598.     eval select $searchResult
  1599.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1600. }
  1601. proc buildRow {jmax} {
  1602.     set txt "Ñ"
  1603.     for {set j 1} {$j < $jmax} {incr j} {
  1604.         append txt " & Ñ"
  1605.     }
  1606.     return $txt
  1607. }
  1608. proc tabular {} {
  1609.     global promptNoisily useStatusBar
  1610.     set envName "tabular"
  1611.     if {$promptNoisily && $useStatusBar} {beep}
  1612.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1613.     if {$numberRows == "cancel"} then {
  1614.         return
  1615.     } elseif {$numberRows == 0} then {
  1616.         beep
  1617.         message "positive number of rows required"
  1618.         return
  1619.     } elseif {![isUnsignedInteger $numberRows]} then {
  1620.         beep
  1621.         message "invalid input"
  1622.         return
  1623.     }
  1624.     if {$promptNoisily && $useStatusBar} {beep}
  1625.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  1626.     if {$numberCols == "cancel"} then {
  1627.         return
  1628.     } elseif {$numberCols == 0} then {
  1629.         beep
  1630.         message "positive number of columns required"
  1631.         return
  1632.     } elseif {![isUnsignedInteger $numberCols]} then {
  1633.         beep
  1634.         message "invalid input"
  1635.         return
  1636.     }
  1637.     set arg "{|"
  1638.     for {set j 1} {$j <= $numberCols} {incr j} {
  1639.         append arg "c|"
  1640.     }
  1641.     append arg "}"
  1642.     set body "\t\\hline\r"
  1643.     for {set i 1} {$i <= $numberRows} {incr i} {
  1644.         append body "\t[buildRow $numberCols]"
  1645.         append body "  \\\\\r\t\\hline\r"
  1646.     }
  1647.     if {[insertEnvironment $envName $arg $body]} then {
  1648.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(c|\|)+} [getPos]]
  1649.         select [lindex $searchResult 0] [lindex $searchResult 1]
  1650.         message "Modify this argument?"
  1651.     }
  1652. }
  1653. proc verbatim {} { doWrapEnvironment "verbatim" }
  1654. proc quote {} { doWrapEnvironment "quote" }
  1655. proc quotation {} { doWrapEnvironment "quotation" }
  1656. proc verse {} { doWrapEnvironment "verse" }
  1657. proc flushleft {} { doWrapEnvironment "flushleft" }
  1658. proc center {} { doWrapEnvironment "center" }
  1659. proc flushright {} { doWrapEnvironment "flushright" }
  1660. proc general {} {
  1661.     catch {prompt "What environment?" ""} environmentName
  1662.     if {$environmentName != "cancel"} {
  1663.         doWrapEnvironment "$environmentName"
  1664.     }
  1665. }
  1666.  
  1667. #--------------------------------------------------------------------------
  1668. # Boxes:
  1669. #--------------------------------------------------------------------------
  1670.  
  1671. proc mbox {} {
  1672.     if {[wrapObject "\\mbox{" "}Ñ"]} then {
  1673.         message "mbox set"
  1674.     } else {
  1675.         message "enter text"
  1676.     }
  1677. }
  1678. proc makebox {} {
  1679.     if {[wrapObject "\\makebox\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1680.         message "makebox set; enter the width and position"
  1681.     } else {
  1682.         message "enter the width and position of the makebox, then the text"
  1683.     }
  1684. }
  1685. proc fbox {} {
  1686.     if {[wrapObject "\\fbox{" "}Ñ"]} then {
  1687.         message "fbox set"
  1688.     } else {
  1689.         message "enter text"
  1690.     }
  1691. }
  1692. proc framebox {} {
  1693.     if {[wrapObject "\\framebox\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1694.         message "framebox set; enter the width and position"
  1695.     } else {
  1696.         message "enter the width and position of the framebox, then the text"
  1697.     }
  1698. }
  1699. proc newsavebox {} {
  1700.     if {[wrapObject "\\newsavebox{" "}Ñ"]} then {
  1701.         message "newsavebox defined"
  1702.     } else {
  1703.         message "enter the command name of the sbox or savebox"
  1704.     }
  1705. }
  1706. proc sbox {} {
  1707.     if {[wrapObject "\\sbox{Ñ}{" "}Ñ"]} then {
  1708.         message "sbox set; enter the command name"
  1709.     } else {
  1710.         message "enter the command name of the sbox, then the text"
  1711.     }
  1712. }
  1713. proc savebox {} {
  1714.     if {[wrapObject "\\savebox{Ñ}\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1715.         message "savebox set; enter the command name"
  1716.     } else {
  1717.         message "enter the command name of the savebox"
  1718.     }
  1719. }
  1720. proc usebox {} {
  1721.     if {[wrapObject "\\usebox{" "}Ñ"]} then {
  1722.         message "usebox declared"
  1723.     } else {
  1724.         message "enter the command name of the sbox or savebox"
  1725.     }
  1726. }
  1727. proc raisebox {} {
  1728.     if {[wrapObject "\\raisebox{Ñ}\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1729.         message "raisebox set; enter the displacement"
  1730.     } else {
  1731.         message "enter the displacement of the raisebox"
  1732.     }
  1733. }
  1734. proc parbox {} {
  1735.     if {[wrapObject "\\parbox\[Ñ\]\{Ñ\}{" "}Ñ"]} then {
  1736.         message "parbox set; enter the position and width"
  1737.     } else {
  1738.         message "enter the position \[b|c|t\] and width of the parbox, then the text"
  1739.     }
  1740. }
  1741. proc minipage {} {
  1742.     set arg "\[Ñ\]{Ñ}"
  1743.     wrapEnvironment "minipage" $arg ""
  1744.     nextTabStop
  1745.     message "enter the position \[b|c|t\] of the minipage, then the width"
  1746. }
  1747. proc rule {} {
  1748.     insertObject "\\rule\[Ñ\]\{Ñ\}{Ñ}Ñ"
  1749.     nthTabStop -4
  1750.     message "enter the displacement of the rule, then width and height"
  1751. }
  1752.  
  1753. #--------------------------------------------------------------------------
  1754. # Misc:
  1755. #--------------------------------------------------------------------------
  1756.  
  1757. proc ldots {} {insertObject "\\ldots"}
  1758. proc {en-dash} {} {insertObject "--"}
  1759. proc {em-dash} {} {insertObject "---"}
  1760. proc texLogo {} {insertObject "\\TeX"}
  1761. proc latexLogo {} {insertObject "\\LaTeX"}
  1762. proc latex2eLogo {} {insertObject "\\LaTeXe"}
  1763. proc today {} {insertObject "\\today"}
  1764. proc dag {} {insertObject "\\dag"}
  1765. proc ddag {} {insertObject "\\ddag"}
  1766. proc sectionMark {} {insertObject "\\S"}
  1767. proc paragraphMark {} {insertObject "\\P"}
  1768. proc copyright {} {insertObject "\\copyright"}
  1769. proc pounds {} {insertObject "\\pounds"}
  1770. proc quotes {} {
  1771.     if {[wrapObject "`" "'Ñ"]} then {
  1772.         message "text quoted"
  1773.     } else {
  1774.         message "enter text"
  1775.     }
  1776. }
  1777. proc dblQuotes {} {
  1778.     if {[wrapObject "``" "''Ñ"]} then {
  1779.         message "text double quoted"
  1780.     } else {
  1781.         message "enter text"
  1782.     }
  1783. }
  1784. proc marginalNote {} {
  1785.     if {[wrapObject "\\marginpar{" "}Ñ"]} then {
  1786.         message "marginal note set"
  1787.     } else {
  1788.         message "enter marginal note"
  1789.     }
  1790. }
  1791. proc footnote {} {
  1792.     if {[wrapObject "\\footnote{" "}Ñ"]} then {
  1793.         message "footnote set"
  1794.     } else {
  1795.         message "enter footnote"
  1796.     }
  1797. }
  1798. proc label {} {
  1799.     if {[wrapObject "\\label{" "}Ñ"]} then {
  1800.         message "label defined"
  1801.     } else {
  1802.         message "enter label"
  1803.     }
  1804. }
  1805. proc ref {} { 
  1806.     if {[wrapObject "\\ref{" "}Ñ"]} then {
  1807.         message "cross-reference made"
  1808.     } else {
  1809.         message "enter cross-reference"
  1810.     }
  1811. }
  1812. proc pageref {} { 
  1813.     if {[wrapObject "\\pageref{" "}Ñ"]} then {
  1814.         message "page reference made"
  1815.     } else {
  1816.         message "enter page reference"
  1817.     }
  1818. }
  1819. proc cite {} {
  1820.     if {[wrapObject "\\cite{" "}Ñ"]} then {
  1821.         message "citation made"
  1822.     } else {
  1823.         message "enter citation"
  1824.     }
  1825. }
  1826. # Insert an \item or a \bibitem, depending on the context.
  1827. proc insertItem {} {
  1828. #     global TeXmodeVars
  1829. #     if {$TeXmodeVars(expertMode) == 0} then {
  1830. #         if {![isInDocument]} then {
  1831. #             if {$TeXmodeVars(searchNoisily)} {beep}
  1832. #             case [askyesno "The cursor is not in the document environment.\
  1833. #                             \rContinue the operation?"] in {
  1834. #                 "yes" {}
  1835. #                 "no" {error "insertItem:  out of context"}
  1836. #             }
  1837. #         }
  1838. #     }
  1839.     set command [eval getText [searchEnvironment]]
  1840.     set environment [extractCommandArg $command]
  1841.     case $environment in {
  1842.         {itemize enumerate} {
  1843.             set text "\\item  Ñ"
  1844.         }
  1845.         "description" {
  1846.             set text "\\item\[Ñ\]  Ñ"
  1847.         }
  1848.         "thebibliography" {
  1849.             set text "\\bibitem{Ñ}  Ñ"
  1850.         }
  1851.         default {
  1852.             beep
  1853.             message "insertItem: cursor in $environment environment"
  1854.             return
  1855.         }
  1856.     }
  1857.     set pos [getPos]
  1858.     # Indentation should mirror that of an existing \item
  1859.     # (if it exists)
  1860.     insertText [openingCarriageReturn]$text
  1861.     goto $pos
  1862.     nextTabStop
  1863. }
  1864.  
  1865.  
  1866. #############################################################################
  1867. # Math Mode Macros
  1868. #
  1869. #############################################################################
  1870.  
  1871. #--------------------------------------------------------------------------
  1872. # Math Modes:
  1873. #--------------------------------------------------------------------------
  1874.  
  1875. proc texMath {} {
  1876.     checkMathMode "texMath" 0
  1877.     if {[wrapObject "$" "$Ñ"]} then {
  1878.         message "formula set"
  1879.     } else {
  1880.         message "enter formula"
  1881.     }
  1882. }
  1883. proc texDisplaymath {} {
  1884.     checkMathMode "texDisplaymath" 0
  1885.     if {[wrapObject "$$" "$$Ñ"]} then {
  1886.         message "displayed formula set"
  1887.     } else {
  1888.         message "enter displayed formula"
  1889.     }
  1890. }
  1891. proc latexMath {} {
  1892.     checkMathMode "latexMath" 0
  1893.     if {[wrapObject "\\( " " \\)Ñ"]} then {
  1894.         message "formula set"
  1895.     } else {
  1896.         message "enter formula"
  1897.     }
  1898. }
  1899. proc latexDisplaymath {} {
  1900.     checkMathMode "latexDisplaymath" 0
  1901.     if {[wrapObject "\\\[ " " \\\]Ñ"]} then {
  1902.         message "displayed formula set"
  1903.     } else {
  1904.         message "enter displayed formula"
  1905.     }
  1906. }
  1907.  
  1908. #--------------------------------------------------------------------------
  1909. # Math Style:
  1910. #--------------------------------------------------------------------------
  1911.  
  1912. proc mathit {} {
  1913.     checkMathMode "mathit" 1
  1914.     if {[wrapObject "\\mathit{" "}Ñ"]} then {
  1915.         message "selected text is math italic"
  1916.     } else {
  1917.         message "enter text to be math italic"
  1918.     }
  1919. }
  1920. proc mathrm {} {
  1921.     checkMathMode "mathrm" 1
  1922.     if {[wrapObject "\\mathrm{" "}Ñ"]} then {
  1923.         message "selected text is math roman"
  1924.     } else {
  1925.         message "enter text to be math roman"
  1926.     }
  1927. }
  1928. proc mathbf {} {
  1929.     checkMathMode "mathbf" 1
  1930.     if {[wrapObject "\\mathbf{" "}Ñ"]} then {
  1931.         message "selected text is math bold"
  1932.     } else {
  1933.         message "enter text to be math bold"
  1934.     }
  1935. }
  1936. proc mathsf {} {
  1937.     checkMathMode "mathsf" 1
  1938.     if {[wrapObject "\\mathsf{" "}Ñ"]} then {
  1939.         message "selected text is math sans serif"
  1940.     } else {
  1941.         message "enter text to be math sans serif"
  1942.     }
  1943. }
  1944. proc mathtt {} {
  1945.     checkMathMode "mathtt" 1
  1946.     if {[wrapObject "\\mathtt{" "}Ñ"]} then {
  1947.         message "selected text is math typewriter"
  1948.     } else {
  1949.         message "enter text to be math typewriter"
  1950.     }
  1951. }
  1952. proc mathcal {} {
  1953.     checkMathMode "mathcal" 1
  1954.     # Allow upper-case arguments only:
  1955.     if {[isSelection] && ![isUppercase]} then {
  1956.         alertnote "argument to \\mathcal must be uppercase"
  1957.         return
  1958.     }
  1959.     if {[wrapObject "\\mathcal{" "}Ñ"]} then {
  1960.         message "selected text is calligraphic"
  1961.     } else {
  1962.         message "enter text to be calligraphic (UPPERCASE letters only)"
  1963.     }
  1964. }
  1965. proc displaystyle {} {
  1966.     checkMathMode "displaystyle" 1
  1967.     if {[wrapObject "{\\displaystyle " "}Ñ"]} then {
  1968.         message "displaystyle set"
  1969.     } else {
  1970.         message "enter displaystyle text"
  1971.     }
  1972. }
  1973. proc textstyle {} {
  1974.     checkMathMode "textstyle" 1
  1975.     if {[wrapObject "{\\textstyle " "}Ñ"]} then {
  1976.         message "textstyle set"
  1977.     } else {
  1978.         message "enter textstyle text"
  1979.     }
  1980. }
  1981. proc scriptstyle {} {
  1982.     checkMathMode "scriptstyle" 1
  1983.     if {[wrapObject "{\\scriptstyle " "}Ñ"]} then {
  1984.         message "scriptstyle set"
  1985.     } else {
  1986.         message "enter scriptstyle text"
  1987.     }
  1988. }
  1989. proc scriptscriptstyle {} {
  1990.     checkMathMode "scriptscriptstyle" 1
  1991.     if {[wrapObject "{\\scriptscriptstyle " "}Ñ"]} then {
  1992.         message "scriptscriptstyle set"
  1993.     } else {
  1994.         message "enter scriptscriptstyle text"
  1995.     }
  1996. }
  1997.  
  1998. #--------------------------------------------------------------------------
  1999. # Math Environments:
  2000. #--------------------------------------------------------------------------
  2001.  
  2002. proc math {} { checkMathMode "math" 0; doWrapEnvironment "math" }
  2003. proc displaymath {} {
  2004.     checkMathMode "displaymath" 0
  2005.     doWrapEnvironment "displaymath"
  2006. }
  2007. proc equation {} {
  2008.     checkMathMode "equation" 0
  2009.     set envName "equation"
  2010.     set body "\t\\label{Ñ}\r"
  2011.     if {[wrapEnvironment $envName "" $body]} then {
  2012.         set msgText "equation wrapped"
  2013.     } else {
  2014.         set msgText "enter equation"
  2015.     }
  2016.     nextTabStop
  2017.     message $msgText
  2018. }
  2019. proc eqnarrayStar {} {
  2020.     global promptNoisily useStatusBar
  2021.     checkMathMode "eqnarrayStar" 0
  2022.     set envName "eqnarray*"
  2023.     if {$promptNoisily && $useStatusBar} {beep}
  2024.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2025.     if {$numberRows == "cancel"} then {
  2026.         return
  2027.     } elseif {$numberRows == 0} then {
  2028.         beep
  2029.         message "positive number of rows required"
  2030.         return
  2031.     } elseif {![isUnsignedInteger $numberRows]} then {
  2032.         beep
  2033.         message "invalid input"
  2034.         return
  2035.     }
  2036.     set row "\t[buildRow 3]"
  2037.     for {set i 1} {$i < $numberRows} {incr i} {
  2038.         append body $row
  2039.         append body "  \\\\\r"
  2040.     }
  2041.     append body $row
  2042.     append body "\r"
  2043.     if {[insertEnvironment $envName "" $body]} then {
  2044.         nextTabStop
  2045.         message "type first item"
  2046.     }
  2047. }
  2048. proc eqnarray {} {
  2049.     global promptNoisily useStatusBar
  2050.     checkMathMode "eqnarray" 0
  2051.     set envName "eqnarray"
  2052.     if {$promptNoisily && $useStatusBar} {beep}
  2053.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2054.     if {$numberRows == "cancel"} then {
  2055.         return
  2056.     } elseif {$numberRows == 0} then {
  2057.         beep
  2058.         message "positive number of rows required"
  2059.         return
  2060.     } elseif {![isUnsignedInteger $numberRows]} then {
  2061.         beep
  2062.         message "invalid input"
  2063.         return
  2064.     }
  2065.     set row "\t[buildRow 3]\r\t\\label{Ñ}"
  2066.     for {set i 1} {$i < $numberRows} {incr i} {
  2067.         append body $row
  2068.         append body "  \\\\\r"
  2069.     }
  2070.     append body $row
  2071.     append body "\r"
  2072.     if {[insertEnvironment $envName "" $body]} then {
  2073.         nextTabStop
  2074.         message "type first item"
  2075.     }
  2076. }
  2077. proc myArray {} {
  2078.     global promptNoisily useStatusBar
  2079.     checkMathMode "myArray" 1
  2080.     set envName "array"
  2081.     if {$promptNoisily && $useStatusBar} {beep}
  2082.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2083.     if {$numberRows == "cancel"} then {
  2084.         return
  2085.     } elseif {$numberRows == 0} then {
  2086.         beep
  2087.         message "positive number of rows required"
  2088.         return
  2089.     } elseif {![isUnsignedInteger $numberRows]} then {
  2090.         beep
  2091.         message "invalid input"
  2092.         return
  2093.     }
  2094.     if {$promptNoisily && $useStatusBar} {beep}
  2095.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  2096.     if {$numberCols == "cancel"} then {
  2097.         return
  2098.     } elseif {$numberCols == 0} then {
  2099.         beep
  2100.         message "positive number of columns required"
  2101.         return
  2102.     } elseif {![isUnsignedInteger $numberCols]} then {
  2103.         beep
  2104.         message "invalid input"
  2105.         return
  2106.     }
  2107.     set arg "{"
  2108.     for {set j 1} {$j <= $numberCols} {incr j} {
  2109.         append arg "c"
  2110.     }
  2111.     append arg "}"
  2112.     set row "\t[buildRow $numberCols]"
  2113.     for {set i 1} {$i < $numberRows} {incr i} {
  2114.         append body $row
  2115.         append body "  \\\\\r"
  2116.     }
  2117.     append body $row
  2118.     append body "\r"
  2119.     if {[insertEnvironment $envName $arg $body]} then {
  2120.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {c+} [getPos]]
  2121.         select [lindex $searchResult 0] [lindex $searchResult 1]
  2122.         message "Modify this argument?"
  2123.     }
  2124. }
  2125.  
  2126. #--------------------------------------------------------------------------
  2127. # Formulas:
  2128. #--------------------------------------------------------------------------
  2129.  
  2130. proc subscript {} {
  2131.     checkMathMode "subscript" 1
  2132.     if {[wrapObject "_{" "}Ñ"]} then {
  2133.         message "subscript set"
  2134.     } else {
  2135.         message "enter subscript"
  2136.     }
  2137. }
  2138. proc superscript {} {
  2139.     checkMathMode "superscript" 1
  2140.     if {[wrapObject "^{" "}Ñ"]} then {
  2141.         message "superscript set"
  2142.     } else {
  2143.         message "enter superscript"
  2144.     }
  2145. }
  2146. proc fraction {} {
  2147.     checkMathMode "fraction" 1
  2148.     set currentPos [getPos]
  2149.     if {[isSelection]} then {
  2150.         set selection [getSelect]
  2151.         set args [split $selection /]
  2152.         set len [llength $args]
  2153.         deleteText $currentPos [selEnd]
  2154.         if {$len == 1} then {
  2155.             insertObject "\\frac{$selection}{Ñ}Ñ"
  2156.             goto $currentPos
  2157.             nextTabStop
  2158.             message "enter denominator"
  2159.         } else {
  2160.             set firstArg [lindex $args 0]
  2161.             set restArgs [lrange $args 1 [expr $len-1]]
  2162.             insertObject "\\frac{$firstArg}{[join $restArgs /]}"
  2163.             if {$len > 2} {message "beware of multiple /"}
  2164.         }
  2165.     } else {
  2166.         insertObject "\\frac{Ñ}{Ñ}Ñ"
  2167.         goto $currentPos
  2168.         nextTabStop
  2169.         message "enter numerator"
  2170.     }
  2171. }
  2172. proc squareRoot {} {
  2173.     checkMathMode "squareRoot" 1
  2174.     if {[wrapObject "\\sqrt{" "}Ñ"]} then {
  2175.         message "square root set"
  2176.     } else {
  2177.         message "enter formula"
  2178.     }
  2179. }
  2180. proc nthRoot {} {
  2181.     checkMathMode "nthRoot" 1
  2182.     if {[wrapObject "\\sqrt\[Ñ\]{" "}Ñ"]} then {
  2183.         message "enter root"
  2184.     } else {
  2185.         message "enter root, then formula"
  2186.     }
  2187. }
  2188. proc oneParameter {} {
  2189.     checkMathMode "oneParameter" 1
  2190.     catch {prompt "Command name?" "sqrt"} commandName
  2191.     if {$commandName != "cancel"} {wrapObject "\\$commandName{" "}Ñ"}
  2192. }
  2193. proc twoParameters {} {
  2194.     checkMathMode "twoParameters" 1
  2195.     catch {prompt "Command name?" "frac"} commandName
  2196.     if {$commandName != "cancel"} then {
  2197.         set currentPos [getPos]
  2198.         if {[insertObject "\\$commandName{Ñ}{Ñ}Ñ"]} then {
  2199.             goto $currentPos
  2200.             nextTabStop
  2201.         }
  2202.     }
  2203. }
  2204.  
  2205. #--------------------------------------------------------------------------
  2206. # Greek:
  2207. #--------------------------------------------------------------------------
  2208.  
  2209. proc alpha {} {checkMathMode "alpha" 1; insertObject "\\alpha"}
  2210. proc beta {} {checkMathMode "beta" 1; insertObject "\\beta"}
  2211. proc gamma {} {checkMathMode "gamma" 1; insertObject "\\gamma"}
  2212. proc delta {} {checkMathMode "delta" 1; insertObject "\\delta"}
  2213. proc epsilon {} {checkMathMode "epsilon" 1; insertObject "\\epsilon"}
  2214. proc zeta {} {checkMathMode "zeta" 1; insertObject "\\zeta"}
  2215. proc eta {} {checkMathMode "eta" 1; insertObject "\\eta"}
  2216. proc theta {} {checkMathMode "theta" 1; insertObject "\\theta"}
  2217. proc iota {} {checkMathMode "iota" 1; insertObject "\\iota"}
  2218. proc kappa {} {checkMathMode "kappa" 1; insertObject "\\kappa"}
  2219. proc lambda {} {checkMathMode "lambda" 1; insertObject "\\lambda"}
  2220. proc mu {} {checkMathMode "mu" 1; insertObject "\\mu"}
  2221. proc nu {} {checkMathMode "nu" 1; insertObject "\\nu"}
  2222. proc xi {} {checkMathMode "xi" 1; insertObject "\\xi"}
  2223. proc omicron {} {checkMathMode "omicron" 1; insertObject "o"}
  2224. proc pi {} {checkMathMode "pi" 1; insertObject "\\pi"}
  2225. proc rho {} {checkMathMode "rho" 1; insertObject "\\rho"}
  2226. proc sigma {} {checkMathMode "sigma" 1; insertObject "\\sigma"}
  2227. proc tau {} {checkMathMode "tau" 1; insertObject "\\tau"}
  2228. proc upsilon {} {checkMathMode "upsilon" 1; insertObject "\\upsilon"}
  2229. proc phi {} {checkMathMode "phi" 1; insertObject "\\phi"}
  2230. proc chi {} {checkMathMode "chi" 1; insertObject "\\chi"}
  2231. proc psi {} {checkMathMode "psi" 1; insertObject "\\psi"}
  2232. proc omega {} {checkMathMode "omega" 1; insertObject "\\omega"}
  2233.  
  2234. proc Gamma {} {checkMathMode "Gamma" 1; insertObject "\\Gamma"}
  2235. proc Delta {} {checkMathMode "Delta" 1; insertObject "\\Delta"}
  2236. proc Theta {} {checkMathMode "Theta" 1; insertObject "\\Theta"}
  2237. proc Lambda {} {checkMathMode "Lambda" 1; insertObject "\\Lambda"}
  2238. proc Xi {} {checkMathMode "Xi" 1; insertObject "\\Xi"}
  2239. proc Pi {} {checkMathMode "Pi" 1; insertObject "\\Pi"}
  2240. proc Sigma {} {checkMathMode "Sigma" 1; insertObject "\\Sigma"}
  2241. proc Upsilon {} {checkMathMode "Upsilon" 1; insertObject "\\Upsilon"}
  2242. proc Phi {} {checkMathMode "Phi" 1; insertObject "\\Phi"}
  2243. proc Psi {} {checkMathMode "Psi" 1; insertObject "\\Psi"}
  2244. proc Omega {} {checkMathMode "Omega" 1; insertObject "\\Omega"}
  2245.  
  2246. proc varepsilon {} {checkMathMode "varepsilon" 1; insertObject "\\varepsilon"}
  2247. proc vartheta {} {checkMathMode "vartheta" 1; insertObject "\\vartheta"}
  2248. proc varpi {} {checkMathMode "varpi" 1; insertObject "\\varpi"}
  2249. proc varrho {} {checkMathMode "varrho" 1; insertObject "\\varrho"}
  2250. proc varsigma {} {checkMathMode "varsigma" 1; insertObject "\\varsigma"}
  2251. proc varphi {} {checkMathMode "varphi" 1; insertObject "\\varphi"}
  2252.  
  2253. #--------------------------------------------------------------------------
  2254. # Binary Ops:
  2255. #--------------------------------------------------------------------------
  2256.  
  2257. proc pm {} {checkMathMode "pm" 1; insertObject "\\pm"}
  2258. proc mp {} {checkMathMode "mp" 1; insertObject "\\mp"}
  2259. proc times {} {checkMathMode "times" 1; insertObject "\\times"}
  2260. proc div {} {checkMathMode "div" 1; insertObject "\\div"}
  2261. proc ast {} {checkMathMode "ast" 1; insertObject "\\ast"}
  2262. proc star {} {checkMathMode "star" 1; insertObject "\\star"}
  2263. proc circ {} {checkMathMode "circ" 1; insertObject "\\circ"}
  2264. proc bullet {} {checkMathMode "bullet" 1; insertObject "\\bullet"}
  2265. proc cdot {} {checkMathMode "cdot" 1; insertObject "\\cdot"}
  2266. proc cap {} {checkMathMode "cap" 1; insertObject "\\cap"}
  2267. proc cup {} {checkMathMode "cup" 1; insertObject "\\cup"}
  2268. proc uplus {} {checkMathMode "uplus" 1; insertObject "\\uplus"}
  2269. proc sqcap {} {checkMathMode "sqcap" 1; insertObject "\\sqcap"}
  2270. proc sqcup {} {checkMathMode "sqcup" 1; insertObject "\\sqcup"}
  2271. proc vee {} {checkMathMode "vee" 1; insertObject "\\vee"}
  2272. proc wedge {} {checkMathMode "wedge" 1; insertObject "\\wedge"}
  2273. proc setminus {} {checkMathMode "setminus" 1; insertObject "\\setminus"}
  2274. proc wr {} {checkMathMode "wr" 1; insertObject "\\wr"}
  2275. proc diamond {} {checkMathMode "diamond" 1; insertObject "\\diamond"}
  2276. proc bigtriangleup {} {
  2277.     checkMathMode "bigtriangleup" 1; insertObject "\\bigtriangleup"
  2278. }
  2279. proc bigtriangledown {} {
  2280.     checkMathMode "bigtriangledown" 1; insertObject "\\bigtriangledown"
  2281. }
  2282. proc triangleleft {} {
  2283.     checkMathMode "triangleleft" 1; insertObject "\\triangleleft"
  2284. }
  2285. proc triangleright {} {
  2286.     checkMathMode "triangleright" 1; insertObject "\\triangleright"
  2287. }
  2288. proc lhd {} {
  2289.     if {[isSymbolPackageLoaded]} then {
  2290.         checkMathMode "lhd" 1; insertObject "\\lhd"
  2291.     }
  2292. }
  2293. proc rhd {} {
  2294.     if {[isSymbolPackageLoaded]} then {
  2295.         checkMathMode "rhd" 1; insertObject "\\rhd"
  2296.     }
  2297. }
  2298. proc unlhd {} {
  2299.     if {[isSymbolPackageLoaded]} then {
  2300.         checkMathMode "unlhd" 1; insertObject "\\unlhd"
  2301.     }
  2302. }
  2303. proc unrhd {} {
  2304.     if {[isSymbolPackageLoaded]} then {
  2305.         checkMathMode "unrhd" 1; insertObject "\\unrhd"
  2306.     }
  2307. }
  2308. proc oplus {} {checkMathMode "oplus" 1; insertObject "\\oplus"}
  2309. proc ominus {} {checkMathMode "ominus" 1; insertObject "\\ominus"}
  2310. proc otimes {} {checkMathMode "otimes" 1; insertObject "\\otimes"}
  2311. proc oslash {} {checkMathMode "oslash" 1; insertObject "\\oslash"}
  2312. proc odot {} {checkMathMode "odot" 1; insertObject "\\odot"}
  2313. proc bigcirc {} {checkMathMode "bigcirc" 1; insertObject "\\bigcirc"}
  2314. proc dagger {} {checkMathMode "dagger" 1; insertObject "\\dagger"}
  2315. proc ddagger {} {checkMathMode "ddagger" 1; insertObject "\\ddagger"}
  2316. proc amalg {} {checkMathMode "amalg" 1; insertObject "\\amalg"}
  2317.  
  2318. #--------------------------------------------------------------------------
  2319. # Relations:
  2320. #--------------------------------------------------------------------------
  2321.  
  2322. proc leq {} {checkMathMode "leq" 1; insertObject "\\leq"}
  2323. proc prec {} {checkMathMode "prec" 1; insertObject "\\prec"}
  2324. proc preceq {} {checkMathMode "preceq" 1; insertObject "\\preceq"}
  2325. proc myLl {} {checkMathMode "myLl" 1; insertObject "\\ll"}
  2326. proc subset {} {checkMathMode "subset" 1; insertObject "\\subset"}
  2327. proc subseteq {} {checkMathMode "subseteq" 1; insertObject "\\subseteq"}
  2328. proc sqsubset {} {
  2329.     if {[isSymbolPackageLoaded]} then {
  2330.         checkMathMode "sqsubset" 1; insertObject "\\sqsubset"
  2331.     }
  2332. }
  2333. proc sqsubseteq {} {checkMathMode "sqsubseteq" 1; insertObject "\\sqsubseteq"}
  2334. proc in {} {checkMathMode "in" 1; insertObject "\\in"}
  2335. proc vdash {} {checkMathMode "vdash" 1; insertObject "\\vdash"}
  2336.  
  2337. proc geq {} {checkMathMode "geq" 1; insertObject "\\geq"}
  2338. proc succ {} {checkMathMode "succ" 1; insertObject "\\succ"}
  2339. proc succeq {} {checkMathMode "succeq" 1; insertObject "\\succeq"}
  2340. proc gg {} {checkMathMode "gg" 1; insertObject "\\gg"}
  2341. proc supset {} {checkMathMode "supset" 1; insertObject "\\supset"}
  2342. proc supseteq {} {checkMathMode "supseteq" 1; insertObject "\\supseteq"}
  2343. proc sqsupset {} {
  2344.     if {[isSymbolPackageLoaded]} then {
  2345.         checkMathMode "sqsupset" 1; insertObject "\\sqsupset"
  2346.     }
  2347. }
  2348. proc sqsupseteq {} {checkMathMode "sqsupseteq" 1; insertObject "\\sqsupseteq"}
  2349. proc ni {} {checkMathMode "ni" 1; insertObject "\\ni"}
  2350. proc dashv {} {checkMathMode "dashv" 1; insertObject "\\dashv"}
  2351.  
  2352. proc equiv {} {checkMathMode "equiv" 1; insertObject "\\equiv"}
  2353. proc sim {} {checkMathMode "sim" 1; insertObject "\\sim"}
  2354. proc simeq {} {checkMathMode "simeq" 1; insertObject "\\simeq"}
  2355. proc asymp {} {checkMathMode "asymp" 1; insertObject "\\asymp"}
  2356. proc approx {} {checkMathMode "approx" 1; insertObject "\\approx"}
  2357. proc cong {} {checkMathMode "cong" 1; insertObject "\\cong"}
  2358. proc neq {} {checkMathMode "neq" 1; insertObject "\\neq"}
  2359. proc doteq {} {checkMathMode "doteq" 1; insertObject "\\doteq"}
  2360. proc propto {} {checkMathMode "propto" 1; insertObject "\\propto"}
  2361.  
  2362. proc models {} {checkMathMode "models" 1; insertObject "\\models"}
  2363. proc perp {} {checkMathMode "perp" 1; insertObject "\\perp"}
  2364. proc mid {} {checkMathMode "mid" 1; insertObject "\\mid"}
  2365. proc parallel {} {checkMathMode "parallel" 1; insertObject "\\parallel"}
  2366. proc bowtie {} {checkMathMode "bowtie" 1; insertObject "\\bowtie"}
  2367. proc myJoin {} {
  2368.     if {[isSymbolPackageLoaded]} then {
  2369.         checkMathMode "myJoin" 1; insertObject "\\join"
  2370.     }
  2371. }
  2372. proc smile {} {checkMathMode "smile" 1; insertObject "\\smile"}
  2373. proc frown {} {checkMathMode "frown" 1; insertObject "\\frown"}
  2374.  
  2375. #--------------------------------------------------------------------------
  2376. # Arrows:
  2377. #--------------------------------------------------------------------------
  2378.  
  2379. proc leftarrow {} {checkMathMode "leftarrow" 1; insertObject "\\leftarrow"}
  2380. proc Leftarrow {} {checkMathMode "Leftarrow" 1; insertObject "\\Leftarrow"}
  2381. proc rightarrow {} {checkMathMode "rightarrow" 1; insertObject "\\rightarrow"}
  2382. proc Rightarrow {} {checkMathMode "Rightarrow" 1; insertObject "\\Rightarrow"}
  2383. proc leftrightarrow {} {
  2384.     checkMathMode "leftrightarrow" 1; insertObject "\\leftrightarrow"
  2385. }
  2386. proc Leftrightarrow {} {
  2387.     checkMathMode "Leftrightarrow" 1; insertObject "\\Leftrightarrow"
  2388. }
  2389. proc mapsto {} {checkMathMode "mapsto" 1; insertObject "\\mapsto"}
  2390. proc hookleftarrow {} {
  2391.     checkMathMode "hookleftarrow" 1; insertObject "\\hookleftarrow"
  2392. }
  2393. proc leftharpoonup {} {
  2394.     checkMathMode "leftharpoonup" 1; insertObject "\\leftharpoonup"
  2395. }
  2396. proc leftharpoondown {} {
  2397.     checkMathMode "leftharpoondown" 1; insertObject "\\leftharpoondown"
  2398. }
  2399. proc rightleftharpoons {} {
  2400.     checkMathMode "rightleftharpoons" 1; insertObject "\\rightleftharpoons"
  2401. }
  2402.  
  2403. proc longleftarrow {} {
  2404.     checkMathMode "longleftarrow" 1; insertObject "\\longleftarrow"
  2405. }
  2406. proc Longleftarrow {} {
  2407.     checkMathMode "Longleftarrow" 1; insertObject "\\Longleftarrow"
  2408. }
  2409. proc longrightarrow {} {
  2410.     checkMathMode "longrightarrow" 1; insertObject "\\longrightarrow"
  2411. }
  2412. proc Longrightarrow {} {
  2413.     checkMathMode "Longrightarrow" 1; insertObject "\\Longrightarrow"
  2414. }
  2415. proc longleftrightarrow {} {
  2416.     checkMathMode "longleftrightarrow" 1; insertObject "\\longleftrightarrow"
  2417. }
  2418. proc Longleftrightarrow {} {
  2419.     checkMathMode "Longleftrightarrow" 1; insertObject "\\Longleftrightarrow"
  2420. }
  2421. proc longmapsto {} {checkMathMode "longmapsto" 1; insertObject "\\longmapsto"}
  2422. proc hookrightarrow {} {
  2423.     checkMathMode "hookrightarrow" 1; insertObject "\\hookrightarrow"
  2424. }
  2425. proc rightharpoonup {} {
  2426.     checkMathMode "rightharpoonup" 1; insertObject "\\rightharpoonup"
  2427. }
  2428. proc rightharpoondown {} {
  2429.     checkMathMode "rightharpoondown" 1; insertObject "\\rightharpoondown"
  2430. }
  2431. proc leadsto {} {
  2432.     if {[isSymbolPackageLoaded]} then {
  2433.         checkMathMode "leadsto" 1; insertObject "\\leadsto"
  2434.     }
  2435. }
  2436. proc uparrow {} {checkMathMode "uparrow" 1; insertObject "\\uparrow"}
  2437. proc Uparrow {} {checkMathMode "Uparrow" 1; insertObject "\\Uparrow"}
  2438. proc downarrow {} {checkMathMode "downarrow" 1; insertObject "\\downarrow"}
  2439. proc Downarrow {} {checkMathMode "Downarrow" 1; insertObject "\\Downarrow"}
  2440. proc updownarrow {} {checkMathMode "updownarrow" 1; insertObject "\\updownarrow"}
  2441. proc Updownarrow {} {checkMathMode "Updownarrow" 1; insertObject "\\Updownarrow"}
  2442. proc nearrow {} {checkMathMode "nearrow" 1; insertObject "\\nearrow"}
  2443. proc searrow {} {checkMathMode "searrow" 1; insertObject "\\searrow"}
  2444. proc swarrow {} {checkMathMode "swarrow" 1; insertObject "\\swarrow"}
  2445. proc nwarrow {} {checkMathMode "nwarrow" 1; insertObject "\\nwarrow"}
  2446.  
  2447. #--------------------------------------------------------------------------
  2448. # Dots:
  2449. #--------------------------------------------------------------------------
  2450.  
  2451. proc cdots {} {checkMathMode "cdots" 1; insertObject "\\cdots"}
  2452. proc vdots {} {checkMathMode "vdots" 1; insertObject "\\vdots"}
  2453. proc ddots {} {checkMathMode "ddots" 1; insertObject "\\ddots"}
  2454.  
  2455. #--------------------------------------------------------------------------
  2456. # Symbols:
  2457. #--------------------------------------------------------------------------
  2458.  
  2459. proc aleph {} {checkMathMode "aleph" 1; insertObject "\\aleph"}
  2460. proc hbar {} {checkMathMode "hbar" 1; insertObject "\\hbar"}
  2461. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2462. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2463. proc ell {} {checkMathMode "ell" 1; insertObject "\\ell"}
  2464. proc wp {} {checkMathMode "wp" 1; insertObject "\\wp"}
  2465. proc Re {} {checkMathMode "Re" 1; insertObject "\\Re"}
  2466. proc Im {} {checkMathMode "Im" 1; insertObject "\\Im"}
  2467. proc mho {} {
  2468.     if {[isSymbolPackageLoaded]} then {
  2469.         checkMathMode "mho" 1; insertObject "\\mho"
  2470.     }
  2471. }
  2472. proc prime {} {checkMathMode "prime" 1; insertObject "\\prime"}
  2473. proc emptyset {} {checkMathMode "emptyset" 1; insertObject "\\emptyset"}
  2474. proc nabla {} {checkMathMode "nabla" 1; insertObject "\\nabla"}
  2475. proc surd {} {checkMathMode "surd" 1; insertObject "\\surd"}
  2476. proc top {} {checkMathMode "top" 1; insertObject "\\top"}
  2477. proc bot {} {checkMathMode "bot" 1; insertObject "\\bot"}
  2478. # proc | {} {checkMathMode "|" 1; insertObject "\\|"}
  2479. proc angle {} {checkMathMode "angle" 1; insertObject "\\angle"}
  2480. proc forall {} {checkMathMode "forall" 1; insertObject "\\forall"}
  2481. proc exists {} {checkMathMode "exists" 1; insertObject "\\exists"}
  2482. proc neg {} {checkMathMode "neg" 1; insertObject "\\neg"}
  2483. proc flat {} {checkMathMode "flat" 1; insertObject "\\flat"}
  2484. proc natural {} {checkMathMode "natural" 1; insertObject "\\natural"}
  2485. proc sharp {} {checkMathMode "sharp" 1; insertObject "\\sharp"}
  2486. proc backslash {} {checkMathMode "backslash" 1; insertObject "\\backslash"}
  2487. proc partial {} {checkMathMode "partial" 1; insertObject "\\partial"}
  2488. proc infty {} {checkMathMode "infty" 1; insertObject "\\infty"}
  2489. proc Box {} {
  2490.     if {[isSymbolPackageLoaded]} then {
  2491.         checkMathMode "Box" 1; insertObject "\\Box"
  2492.     }
  2493. }
  2494. proc Diamond {} {
  2495.     if {[isSymbolPackageLoaded]} then {
  2496.         checkMathMode "Diamond" 1; insertObject "\\Diamond"
  2497.     }
  2498. }
  2499. proc triangle {} {checkMathMode "triangle" 1; insertObject "\\triangle"}
  2500. proc clubsuit {} {checkMathMode "clubsuit" 1; insertObject "\\clubsuit"}
  2501. proc diamondsuit {} {checkMathMode "diamondsuit" 1; insertObject "\\diamondsuit"}
  2502. proc heartsuit {} {checkMathMode "heartsuit" 1; insertObject "\\heartsuit"}
  2503. proc spadesuit {} {checkMathMode "spadesuit" 1; insertObject "\\spadesuit"}
  2504.  
  2505. #--------------------------------------------------------------------------
  2506. # Functions:
  2507. #--------------------------------------------------------------------------
  2508.  
  2509. proc arccos {} {checkMathMode "arccos" 1; insertObject "\\arccos"}
  2510. proc arcsin {} {checkMathMode "arcsin" 1; insertObject "\\arcsin"}
  2511. proc arctan {} {checkMathMode "arctan" 1; insertObject "\\arctan"}
  2512. proc arg {} {checkMathMode "arg" 1; insertObject "\\arg"}
  2513. proc cos {} {checkMathMode "cos" 1; insertObject "\\cos"}
  2514. proc cosh {} {checkMathMode "cosh" 1; insertObject "\\cosh"}
  2515. proc cot {} {checkMathMode "cot" 1; insertObject "\\cot"}
  2516. proc coth {} {checkMathMode "coth" 1; insertObject "\\coth"}
  2517. proc csc {} {checkMathMode "csc" 1; insertObject "\\csc"}
  2518. proc deg {} {checkMathMode "deg" 1; insertObject "\\deg"}
  2519. proc det {} {checkMathMode "det" 1; insertObject "\\det"}
  2520. proc dim {} {checkMathMode "dim" 1; insertObject "\\dim"}
  2521. proc exp {} {checkMathMode "exp" 1; insertObject "\\exp"}
  2522. proc gcd {} {checkMathMode "gcd" 1; insertObject "\\gcd"}
  2523. proc hom {} {checkMathMode "hom" 1; insertObject "\\hom"}
  2524. proc inf {} {checkMathMode "inf" 1; insertObject "\\inf"}
  2525. proc ker {} {checkMathMode "ker" 1; insertObject "\\ker"}
  2526. proc lg {} {checkMathMode "lg" 1; insertObject "\\lg"}
  2527. proc lim {} {checkMathMode "lim" 1; insertObject "\\lim"}
  2528. proc liminf {} {checkMathMode "liminf" 1; insertObject "\\liminf"}
  2529. proc limsup {} {checkMathMode "limsup" 1; insertObject "\\limsup"}
  2530. proc ln {} {checkMathMode "ln" 1; insertObject "\\ln"}
  2531. proc log {} {checkMathMode "log" 1; insertObject "\\log"}
  2532. proc max {} {checkMathMode "max" 1; insertObject "\\max"}
  2533. proc min {} {checkMathMode "min" 1; insertObject "\\min"}
  2534. proc Pr {} {checkMathMode "Pr" 1; insertObject "\\Pr"}
  2535. proc sec {} {checkMathMode "sec" 1; insertObject "\\sec"}
  2536. proc sin {} {checkMathMode "sin" 1; insertObject "\\sin"}
  2537. proc sinh {} {checkMathMode "sinh" 1; insertObject "\\sinh"}
  2538. proc sup {} {checkMathMode "sup" 1; insertObject "\\sup"}
  2539. proc tan {} {checkMathMode "tan" 1; insertObject "\\tan"}
  2540. proc tanh {} {checkMathMode "tanh" 1; insertObject "\\tanh"}
  2541.  
  2542. proc bmod {} {checkMathMode "bmod" 1; insertObject "\\bmod"}
  2543. proc pmod {} {
  2544.     checkMathMode "pmod" 1
  2545.     if {[wrapObject "\\pmod{" "}Ñ"]} then {
  2546.         message "parenthesized mod set"
  2547.     } else {
  2548.         message "enter formula"
  2549.     }
  2550. }
  2551.  
  2552. #--------------------------------------------------------------------------
  2553. # Large Ops:
  2554. #--------------------------------------------------------------------------
  2555.  
  2556. proc insertLargeOp {commandName} {
  2557.     checkMathMode "$commandName" 1
  2558.     set currentPos [getPos]
  2559.     insertObject "\\$commandName\_{Ñ}^{Ñ}Ñ"
  2560.     goto $currentPos
  2561.     nextTabStop
  2562. }
  2563. proc sum {} {insertLargeOp "sum"}
  2564. proc prod {} {insertLargeOp "prod"}
  2565. proc coprod {} {insertLargeOp "coprod"}
  2566. proc int {} {insertLargeOp "int"}
  2567. proc oint {} {insertLargeOp "oint"}
  2568. proc bigcap {} {insertLargeOp "bigcap"}
  2569. proc bigcup {} {insertLargeOp "bigcup"}
  2570. proc bigsqcup {} {insertLargeOp "bigsqcup"}
  2571. proc bigvee {} {insertLargeOp "bigvee"}
  2572. proc bigwedge {} {insertLargeOp "bigwedge"}
  2573. proc bigodot {} {insertLargeOp "bigodot"}
  2574. proc bigotimes {} {insertLargeOp "bigotimes"}
  2575. proc bigoplus {} {insertLargeOp "bigoplus"}
  2576. proc biguplus {} {insertLargeOp "biguplus"}
  2577.  
  2578. #--------------------------------------------------------------------------
  2579. # Delimiters:
  2580. #--------------------------------------------------------------------------
  2581.  
  2582. proc delimitObject {leftDelim rightDelim} {
  2583.     if {[wrapObject $leftDelim $rightDelim]} then {
  2584.         message "formula delimited"
  2585.     } else {
  2586.         message "enter formula"
  2587.     }
  2588. }
  2589. proc parentheses {} { checkMathMode "parentheses" 1; delimitObject "(" ")Ñ" }
  2590. proc brackets {} { checkMathMode "brackets" 1; delimitObject "\[" "\]Ñ" }
  2591. proc braces {} { checkMathMode "braces" 1; delimitObject "\\\{" "\\\}Ñ" }
  2592. proc absoluteValue {} { checkMathMode "absoluteValue" 1; delimitObject "|" "|Ñ" }
  2593. proc getDelims {} {
  2594.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" \
  2595.                   "brackets" "braces" "angle brackets" "vertical bars" \
  2596.                   "double bars" "ceiling" "floor"} delimType
  2597.     if {$delimType != "cancel"} then {
  2598.         case $delimType in {
  2599.             "parentheses" {
  2600.                 set leftDelim "("
  2601.                 set rightDelim ")"
  2602.             }
  2603.             "brackets" {
  2604.                 set leftDelim "\["
  2605.                 set rightDelim "\]"
  2606.             }
  2607.             "braces" {
  2608.                 set leftDelim "\\\{"
  2609.                 set rightDelim "\\\}"
  2610.             }
  2611.             "{vertical bars}" {
  2612.                 set leftDelim "|"
  2613.                 set rightDelim "|"
  2614.             }
  2615.             "{double bars}" {
  2616.                 set leftDelim "\\|"
  2617.                 set rightDelim "\\|"
  2618.             }
  2619.             "{angle brackets}" {
  2620.                 set leftDelim "\\langle"
  2621.                 set rightDelim "\\rangle"
  2622.             }
  2623.             "ceiling" {
  2624.                 set leftDelim "\\lceil"
  2625.                 set rightDelim "\\rceil"
  2626.             }
  2627.             "floor" {
  2628.                 set leftDelim "\\lfloor"
  2629.                 set rightDelim "\\rfloor"
  2630.             }
  2631.             default {
  2632.                 alertnote "\"$delimType\" not recognized"
  2633.                 return ""
  2634.             }
  2635.         }
  2636.         return [list $leftDelim $rightDelim]
  2637.     } else {return ""}
  2638. }
  2639. proc otherDelims {} {
  2640.     checkMathMode "otherDelims" 1
  2641.     set delims [getDelims]
  2642.     if {$delims != ""} then {
  2643.         set leftDelim [lindex $delims 0]
  2644.         set rightDelim [lindex $delims 1]
  2645.         delimitObject "$leftDelim" "$rightDelimÑ"
  2646.     }
  2647. }
  2648. proc {half-openInterval} {} {
  2649.     checkMathMode "half-openInterval" 1; delimitObject "(" "\]Ñ"
  2650. }
  2651. proc {half-closedInterval} {} {
  2652.     checkMathMode "half-closedInterval" 1; delimitObject "\[" ")Ñ"
  2653. }
  2654.  
  2655. proc insertBigDelims {leftDelim rightDelim isMultiline} {
  2656.     checkMathMode "insertBigDelims" 1
  2657.     if {$isMultiline} then {
  2658.         alertnote "Multi-line delimiters not yet implemented."
  2659.     } else {
  2660.         if {[wrapObject $leftDelim $rightDelim]} then {
  2661.             message "formula delimited"
  2662.         } else {
  2663.             message "enter formula"
  2664.         }
  2665.     }
  2666. }
  2667. proc bigParentheses {} {
  2668.     checkMathMode "bigParentheses" 1; insertBigDelims "\\left(" "\\right)Ñ" 0
  2669. }
  2670. proc bigBrackets {} {
  2671.     checkMathMode "bigBrackets" 1; insertBigDelims "\\left\[" "\\right\]Ñ" 0
  2672. }
  2673. proc bigBraces {} {
  2674.     checkMathMode "bigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}Ñ" 0
  2675. }
  2676. proc bigAbsoluteValue {} {
  2677.     checkMathMode "bigAbsoluteValue" 1; insertBigDelims "\\left|" "\\right|Ñ" 0
  2678. }
  2679. proc otherBigDelims {} {
  2680.     checkMathMode "otherBigDelims" 1
  2681.     set delims [getDelims]
  2682.     if {$delims != ""} then {
  2683.         append leftDelim "\\left" [lindex $delims 0]
  2684.         append rightDelim "\\right" [lindex $delims 1]
  2685.         insertBigDelims "$leftDelim" "$rightDelimÑ" 0
  2686.     }
  2687. }
  2688. proc bigLeftBrace {} { checkMathMode "bigLeftBrace" 1; insertBigDelims "\\left\\\{" "\\right.Ñ" 0 }
  2689. proc otherMixedBigDelims {} {
  2690.     checkMathMode "otherMixedBigDelims" 1
  2691.     catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" \
  2692.                   "bracket" "brace" "vertical bar" "double bar" \
  2693.                   "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2694.                   "none"} delimType
  2695.     if {$delimType != "cancel"} then {
  2696.         case $delimType in {
  2697.             "parenthesis" {set leftDelim "("}
  2698.             "bracket" {set leftDelim "\["}
  2699.             "brace" {set leftDelim "\\\{"}
  2700.             "{vertical bar}" {set leftDelim "|"}
  2701.             "{double bar}" {set leftDelim "\\|"}
  2702.             "{angle bracket}" {set leftDelim "\\langle"}
  2703.             "ceiling" {set leftDelim "\\lceil"}
  2704.             "floor" {set leftDelim "\\lfloor"}
  2705.             "slash" {set leftDelim "/"}
  2706.             "backslash" {set leftDelim "\\backslash"}
  2707.             "none" {set leftDelim "."}
  2708.             default {
  2709.                 alertnote "\"$delimType\" not recognized"
  2710.                 return
  2711.             }
  2712.         }
  2713.         catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" \
  2714.                       "bracket" "brace" "vertical bar" "double bar" \
  2715.                       "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2716.                       "none"} delimType
  2717.         if {$delimType != "cancel"} then {
  2718.             case $delimType in {
  2719.                 "parenthesis" {set rightDelim ")"}
  2720.                 "bracket" {set rightDelim "\]"}
  2721.                 "brace" {set rightDelim "\\\}"}
  2722.                 "{vertical bar}" {set rightDelim "|"}
  2723.                 "{double bar}" {set rightDelim "\\|"}
  2724.                 "{angle bracket}" {set rightDelim "\\rangle"}
  2725.                 "ceiling" {set rightDelim "\\rceil"}
  2726.                 "floor" {set rightDelim "\\rfloor"}
  2727.                 "slash" {set rightDelim "/"}
  2728.                 "backslash" {set rightDelim "\\backslash"}
  2729.                 "none" {set rightDelim "."}
  2730.                 default {
  2731.                     alertnote "\"$delimType\" not recognized"
  2732.                     return
  2733.                 }
  2734.             }
  2735.             insertBigDelims "\\left$leftDelim" "\\right$rightDelimÑ" 0
  2736.         }
  2737.     }
  2738. }
  2739.  
  2740. #--------------------------------------------------------------------------
  2741. # Accents:
  2742. #--------------------------------------------------------------------------
  2743.  
  2744. proc acute {} {
  2745.     checkMathMode "acute" 1
  2746.     if {[isSelection] > 1} then {
  2747.         alertnote "Warning: only a single character may be accented!"
  2748.     }
  2749.     if {[wrapObject "\\acute{" "}Ñ"]} then {
  2750.         message "accent set"
  2751.     } else {
  2752.         message "enter one character"
  2753.     }
  2754. }
  2755. proc bar {} {
  2756.     checkMathMode "bar" 1
  2757.     if {[isSelection] > 1} then {
  2758.         alertnote "Warning: only a single character may be accented!"
  2759.     }
  2760.     if {[wrapObject "\\bar{" "}Ñ"]} then {
  2761.         message "accent set"
  2762.     } else {
  2763.         message "enter one character"
  2764.     }
  2765. }
  2766. proc breve {} {
  2767.     checkMathMode "breve" 1
  2768.     if {[isSelection] > 1} then {
  2769.         alertnote "Warning: only a single character may be accented!"
  2770.     }
  2771.     if {[wrapObject "\\breve{" "}Ñ"]} then {
  2772.         message "accent set"
  2773.     } else {
  2774.         message "enter one character"
  2775.     }
  2776. }
  2777. proc check {} {
  2778.     checkMathMode "check" 1
  2779.     if {[isSelection] > 1} then {
  2780.         alertnote "Warning: only a single character may be accented!"
  2781.     }
  2782.     if {[wrapObject "\\check{" "}Ñ"]} then {
  2783.         message "accent set"
  2784.     } else {
  2785.         message "enter one character"
  2786.     }
  2787. }
  2788. proc dot {} {
  2789.     checkMathMode "dot" 1
  2790.     if {[isSelection] > 1} then {
  2791.         alertnote "Warning: only a single character may be accented!"
  2792.     }
  2793.     if {[wrapObject "\\dot{" "}Ñ"]} then {
  2794.         message "accent set"
  2795.     } else {
  2796.         message "enter one character"
  2797.     }
  2798. }
  2799. proc ddot {} {
  2800.     checkMathMode "ddot" 1
  2801.     if {[isSelection] > 1} then {
  2802.         alertnote "Warning: only a single character may be accented!"
  2803.     }
  2804.     if {[wrapObject "\\ddot{" "}Ñ"]} then {
  2805.         message "accent set"
  2806.     } else {
  2807.         message "enter one character"
  2808.     }
  2809. }
  2810. proc grave {} {
  2811.     checkMathMode "grave" 1
  2812.     if {[isSelection] > 1} then {
  2813.         alertnote "Warning: only a single character may be accented!"
  2814.     }
  2815.     if {[wrapObject "\\grave{" "}Ñ"]} then {
  2816.         message "accent set"
  2817.     } else {
  2818.         message "enter one character"
  2819.     }
  2820. }
  2821. proc hat {} {
  2822.     checkMathMode "hat" 1
  2823.     if {[isSelection] > 1} then {
  2824.         alertnote "Warning: only a single character may be accented!"
  2825.     }
  2826.     if {[wrapObject "\\hat{" "}Ñ"]} then {
  2827.         message "accent set"
  2828.     } else {
  2829.         message "enter one character"
  2830.     }
  2831. }
  2832. proc tilde {} {
  2833.     checkMathMode "tilde" 1
  2834.     if {[isSelection] > 1} then {
  2835.         alertnote "Warning: only a single character may be accented!"
  2836.     }
  2837.     if {[wrapObject "\\tilde{" "}Ñ"]} then {
  2838.         message "accent set"
  2839.     } else {
  2840.         message "enter one character"
  2841.     }
  2842. }
  2843. proc vec {} {
  2844.     checkMathMode "vec" 1
  2845.     if {[isSelection] > 1} then {
  2846.         alertnote "Warning: only a single character may be accented!"
  2847.     }
  2848.     if {[wrapObject "\\vec{" "}Ñ"]} then {
  2849.         message "accent set"
  2850.     } else {
  2851.         message "enter one character"
  2852.     }
  2853. }
  2854.  
  2855. proc widehat {} {
  2856.     checkMathMode "widehat" 1
  2857.     if {[isSelection] > 3} then {
  2858.         alertnote "Warning: only a few characters may be accented!"
  2859.     }
  2860.     if {[wrapObject "\\widehat{" "}Ñ"]} then {
  2861.         message "accent set"
  2862.     } else {
  2863.         message "enter a few characters"
  2864.     }
  2865. }
  2866. proc widetilde {} {
  2867.     checkMathMode "widetilde" 1
  2868.     if {[isSelection] > 3} then {
  2869.         alertnote "Warning: only a few characters may be accented!"
  2870.     }
  2871.     if {[wrapObject "\\widetilde{" "}Ñ"]} then {
  2872.         message "accent set"
  2873.     } else {
  2874.         message "enter a few characters"
  2875.     }
  2876. }
  2877.  
  2878. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2879. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2880.  
  2881. #--------------------------------------------------------------------------
  2882. # Grouping:
  2883. #--------------------------------------------------------------------------
  2884.  
  2885. proc underline {} {
  2886.     checkMathMode "underline" 1
  2887.     if {[wrapObject "\\underline{" "}Ñ"]} then {
  2888.         message "selection underlined"
  2889.     } else {
  2890.         message "enter text"
  2891.     }
  2892. }
  2893. proc overline {} {
  2894.     checkMathMode "overline" 1
  2895.     if {[wrapObject "\\overline{" "}Ñ"]} then {
  2896.         message "selection overlined"
  2897.     } else {
  2898.         message "enter text"
  2899.     }
  2900. }
  2901. proc underbrace {} {
  2902.     checkMathMode "underbrace" 1
  2903.     if {[wrapObject "\\underbrace{" "}Ñ"]} then {
  2904.         message "selection underbraced"
  2905.     } else {
  2906.         message "enter text"
  2907.     }
  2908. }
  2909. proc overbrace {} {
  2910.     checkMathMode "overbrace" 1
  2911.     if {[wrapObject "\\overbrace{" "}Ñ"]} then {
  2912.         message "selection overbraced"
  2913.     } else {
  2914.         message "enter text"
  2915.     }
  2916. }
  2917. proc stackrel {} {
  2918.     checkMathMode "stackrel" 1
  2919.     set currentPos [getPos]
  2920.     if {[insertObject "\\stackrel{Ñ}{Ñ}Ñ"]} then {
  2921.         goto $currentPos
  2922.         nextTabStop
  2923.         message "1st arg scriptstyle"
  2924.     }
  2925. }
  2926.  
  2927. #--------------------------------------------------------------------------
  2928. # Spacing:
  2929. #--------------------------------------------------------------------------
  2930.  
  2931. proc negThin {} {checkMathMode "negThin" 1; insertObject "\\!"}
  2932. proc thin {} {checkMathMode "thin" 1; insertObject "\\,"}
  2933. proc medium {} {checkMathMode "medium" 1; insertObject "\\:"}
  2934. proc thick {} {checkMathMode "thick" 1; insertObject "\\;"}
  2935. proc quad {} {checkMathMode "quad" 1; insertObject "\\quad"}
  2936. proc qquad {} {checkMathMode "qquad" 1; insertObject "\\qquad"}
  2937. proc hspace {} {
  2938.     checkMathMode "hspace" 1
  2939.     if {[wrapObject "\\hspace{" "}Ñ"]} then {
  2940.         message "spacing set"
  2941.     } else {
  2942.         message "enter the desired horizontal spacing"
  2943.     }
  2944. }
  2945. proc vspace {} {
  2946.     checkMathMode "vspace" 1
  2947.     if {[wrapObject "\\vspace{" "}Ñ"]} then {
  2948.         message "spacing set"
  2949.     } else {
  2950.         message "enter the desired horizontal spacing"
  2951.     }
  2952. }
  2953. proc hfill {} {checkMathMode "hfill" 1; insertObject "\\hfill"}
  2954. proc vfill {} {checkMathMode "vfill" 1; insertObject "\\vfill"}
  2955. proc smallskip {} {checkMathMode "smallskip" 1; insertObject "\\smallskip"}
  2956. proc medskip {} {checkMathMode "medskip" 1; insertObject "\\medskip"}
  2957. proc bigskip {} {checkMathMode "bigskip" 1; insertObject "\\bigskip"}
  2958.  
  2959.