diff options
author | Karl Berry <karl@freefriends.org> | 2014-01-07 23:07:05 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-01-07 23:07:05 +0000 |
commit | 57d395428d45725bb0bae19829460622dbbb124f (patch) | |
tree | 9d944e5b0c4f73b721323ab19758a7b83a0bf4c6 /Master/texmf-dist/doc/latex/scanpages/replicate.plist | |
parent | ea751c100642b9b81c97ad32b1b492c917d5a93c (diff) |
scanpages (7jan14)
git-svn-id: svn://tug.org/texlive/trunk@32600 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/scanpages/replicate.plist')
-rw-r--r-- | Master/texmf-dist/doc/latex/scanpages/replicate.plist | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/scanpages/replicate.plist b/Master/texmf-dist/doc/latex/scanpages/replicate.plist new file mode 100644 index 00000000000..e4a09ea1772 --- /dev/null +++ b/Master/texmf-dist/doc/latex/scanpages/replicate.plist @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>name</key> + <string>ROOT</string> + <key>submenu</key> + <array> + <dict> + <key>content</key> + <string>--applescript direct +--Michael Sharpe, 20140106 +--This is free software, but Copyright (c) Michael Sharpe, 2014 +--and subject to the LATEX Project Public License. +--This allows replication of a commented block of text as many times as specified, substituting +--values for 'variables' in the process + +set TSLibAlias to alias ((path to home folder as string) & "Library:TeXShop:Scripts:TSLib.scpt") +set TSLib to (load script TSLibAlias) +set lf to (ASCII character 10) +tell application "TeXShop" to set s to content of selection of document 1 +set AppleScript's text item delimiters to {""} + +set oldtid to AppleScript's text item delimiters +set AppleScript's text item delimiters to "%Repetitions=" +set tmp to (text items of s) +set AppleScript's text item delimiters to oldtid +if not ((count of tmp) = 2) then + display dialog "Bailing! The selection does not contain exactly one '%Repetitions='" + return +end if +set AppleScript's text item delimiters to {lf} +set ss to (item 2 of tmp) +set tmp2 to (text items of ss) +set AppleScript's text item delimiters to oldtid +set numrep to (item 1 of tmp2) as integer +--next get variable names +set AppleScript's text item delimiters to {"%Variables="} +set tmp to (text items of s) +set AppleScript's text item delimiters to oldtid +if not ((count of tmp) = 2) then + display dialog "Bailing! The selection does not contain exactly one '%Variables='" + return +end if +set ss to (item 2 of tmp) +set AppleScript's text item delimiters to {lf} +set tmp2 to (text items of ss) +--display dialog "tmp2=" & (tmp2 as text) +set AppleScript's text item delimiters to oldtid +set vbllst to (item 1 of tmp2) --like {nnn,0:1+1,1:3+-2} +--tell TSLib to set trimitems to {" ", tab, "{", "}"} +tell TSLib to set vbllst2 to trim(vbllst) +set vbllst3 to (text 2 thru -2 of vbllst2) +set AppleScript's text item delimiters to {" , ", " ,", " ,", ","} +set vbles to (text items of vbllst3) -- line {nnn,0:1+1,1:3+-2} +--display dialog "vbles=" & (vbles as text) +set n to (count of vbles) +set root to (item 1 of vbles) +set vlst to {} +set vinit to {} +set vinc to {} +set valt to {} +set AppleScript's text item delimiters to {":", "+"} +repeat with j from 2 to n + set x to (text items of (item j of vbles)) + if not ((count of x) = 3) then + display dialog "Bad variable descriptor-- " & item j of vbles + set AppleScript's text item delimiters to oldtid + return + end if + set end of vlst to (item 1 of x) + set nnn to 0 + set hasp to 0 + if (last character of (item 3 of x) = ")") then + set hasp to 1 + set nnn to ((text -2 of (item 3 of x)) as integer) + set (item 3 of x) to (text 1 thru -4 of (item 3 of x)) + else + if (first character of (item 2 of x) = "[") then set nnn to -100 + end if + if (item 3 of x) ends with "/2" then + set (item 3 of x) to (text 1 thru -3 of (item 3 of x)) + if hasp = 1 then + set nnn to -nnn + else + set nnn to -10 + end if + end if + set end of valt to nnn + if (nnn = -100) then + set end of vinit to (text 2 thru -1 of (item 2 of x)) + set end of vinc to (text 1 thru -2 of (item 3 of x)) + else + set end of vinit to (item 2 of x) + set end of vinc to (item 3 of x) + end if + +end repeat +set AppleScript's text item delimiters to oldtid +--set v to (vlst as text) +set viniti to {} +set vinci to {} +set kk to (count of vinit) +repeat with j from 1 to kk + try + set end of viniti to ((item j of vinit) as integer) + on error + set end of viniti to 0 + end try + try + set end of vinci to ((item j of vinc) as integer) + on error + set end of vinci to 0 + end try +end repeat +set AppleScript's text item delimiters to {lf} +set tmp to (text items of s) +set AppleScript's text item delimiters to oldtid +set m to (count of tmp) +set tmp2 to {} +repeat with j from 3 to m + set t to (item j of tmp) + if ((count of t) > 1) then + set t to (text 2 thru -1 of t) + else + set t to "" + end if + set end of tmp2 to t +end repeat +set AppleScript's text item delimiters to {lf} +set body to (tmp2 as text) +set AppleScript's text item delimiters to oldtid +--Start new method +set repl to {s} +set newbody to body +repeat with p from 1 to numrep + --copy tmp to newtmp + set newbody to body + repeat with k from 1 to kk + set v to "" + set alt to (item k of valt) + if (alt = -100) then + if (p mod 2) = 0 then + set v to (item k of vinc) + else + set v to (item k of vinit) + end if + else + set v to (item k of viniti) + if (alt < 0) then + set v to (v div 2) + set alt to -alt + end if + if (alt is not 10) and (alt is not 0) then + set v to zero_pad(v, alt) + else + set v to (v as string) + end if + end if + set newbody to switchText of newbody from (root & (item k of vlst)) to v + set item k of viniti to (((item k of viniti) as integer) + (item k of vinci)) + end repeat + set end of repl to newbody +end repeat +set AppleScript's text item delimiters to lf +tell application "TeXShop" to set selection of document 1 to (repl as text) +set AppleScript's text item delimiters to oldtid + +on zero_pad(value, string_length) + set tmp_string to "000000000" & (value as string) + set padded_value to text ((count of tmp_string) - string_length + 1) thru -1 of tmp_string + return padded_value +end zero_pad + +to switchText of t from s to r + set d to text item delimiters + set text item delimiters to s + set t to t's text items + set text item delimiters to r + tell t to set t to beginning & ({""} & rest) + set text item delimiters to d + t +end switchText +</string> + <key>name</key> + <string>Replicate</string> + </dict> + </array> +</dict> +</plist> |