[OS X TeX] Insert a column

Alain Schremmer Schremmer.Alain at gmail.com
Thu Dec 21 22:26:48 CET 2006


Herbert Schulz wrote:

To add a column select the rows of the tabular and use the Add Column  
macro.

I copied what is below into a new TeXShop macro and tried it but I am 
getting an error:

    Expected """ but found unknown token.

I compared to the Robertson applescript I am using but couldn't see 
anything.

> --Applescript direct
>
> -- CUSTOMISE AS YOU LIKE:
> property indent : "  "
> property default_button : "After" -- or "Before"
> property cell_blob : "•"
>
> --BEGIN:
>
> tell application "TeXShop"
>     set q to display dialog "This macro adds a new column to the  
> selected tabular. Please enter the column number before or after  
> which you would like to add a new column." default answer "1" buttons  
> {"Before", "After"} default button default_button
>     
>     set add_where to the button returned of q
>     set col_num to the text returned of q
>     
>     tell application "TeXShop" to set tabular to the content of the  
> selection of the front document
>     
>     set new_tabular to ""
>     repeat with ii from 1 to the count of the paragraphs of tabular
>        
>         set this_line to paragraph ii of tabular
>        
>         if this_line contains "\\\\" and this_line does not contain "\ 
> \multicolumn" then
>            
>             --Transform "    a & b & c \\" to "a & b & c":
>             set trim_line to do shell script ¬
>                 "echo " & the quoted form of this_line & ¬
>                 " | sed 's/^[ ^t]*//' | sed 's/\\\\\\\\//'"
>             -- "\\\\\\\\" is a TeX newline escaped in both Applescript 
> and the  shell
>            
>            
>             set new_col to "& " & cell_blob & " &"
>             if add_where = "After" then
>                 set line_start to do shell script "echo " & the quoted 
> form of  trim_line & " | cut -f -" & col_num & " -d '&'"
>                 set line_end to do shell script "echo " & the quoted 
> form of  trim_line & " | cut -f " & col_num + 1 & "- -d '&'"
>                 if line_end = "" then
>                     set new_col to "& " & cell_blob & " "
>                 end if
>             else if add_where = "Before" then
>                 if col_num = "1" then
>                     set line_start to ""
>                     set new_col to cell_blob & " & "
>                     set line_end to trim_line
>                 else
>                     set line_start to do shell script "echo " & the 
> quoted form of  trim_line & " | cut -f -" & col_num - 1 & " -d '&'"
>                     set line_end to do shell script "echo " & the 
> quoted form of  trim_line & " | cut -f " & col_num & "- -d '&'"
>                     if line_end = "" then
>                         set new_col to "& " & cell_blob & " "
>                     end if
>                 end if
>             end if
>            
>             set new_line to indent & indent & line_start & new_col & 
> line_end  & "\\\\"
>             if new_tabular = "" then
>                 set new_tabular to new_line
>             else
>                 set new_tabular to new_tabular & return & new_line
>             end if
>         else
>             if new_tabular = "" then
>                 set new_tabular to this_line
>             else
>                 set new_tabular to new_tabular & return & this_line
>             end if
>         end if
>        
>     end repeat
>     
>     if tabular contains "\\multicolumn" then
>         display dialog "I cannot parse lines with “\\multicolumn” in 
> them.  You'll have to do them by hand. Sorry." buttons {"Cancel", 
> "Proceed"}  default button "Proceed" with icon caution
>     end if
>     
>     tell application "TeXShop" to set the selection of the front  
> document to new_tabular
>     
>     display dialog "Don't forget to change the column header!" 
> buttons  {"•"} giving up after 4
>     
> end tell
> End New Column----------------



------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list