Debian Codegraph @

texmf-dist/doc/latex/scanpages/replicate.plist

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3 <plist version="1.0">
4 <dict>
5 <key>name</key>
6 <string>ROOT</string>
7 <key>submenu</key>
8 <array>
9 <dict>
10 <key>content</key>
11 <string>--applescript direct
12 --Michael Sharpe, 20140424
13 --This is free software, but Copyright (c) Michael Sharpe, 2014
14 --and subject to the LATEX Project Public License.
15 --This allows replication of a commented block of text as many times as specified, substituting
16 --values for 'variables' in the process
17
18 property trimitems : {" ", tab, linefeed, return}
19
20 set lf to linefeed
21 set cr to return
22 set crlf to cr &amp; lf
23
24 set oldtid to text item delimiters
25 tell application "TeXShop" to set s to content of selection of document 1
26 set tmp to (paragraphs of s)
27 set text item delimiters to {lf}
28 set s to (tmp as text)
29 set text item delimiters to "%Repetitions="
30 set tmp to (text items of s)
31 set text item delimiters to oldtid
32 if not ((count of tmp) = 2) then
33 display dialog "Bailing! The selection does not contain exactly one '%Repetitions='"
34 return
35 end if
36 set ss to (item 2 of tmp)
37 set tmp2 to (paragraphs of ss)
38 set numrep to (item 1 of tmp2) as integer
39 --next get variable names
40 set text item delimiters to {"%Variables="}
41 set tmp to (text items of s)
42 set text item delimiters to oldtid
43 if not ((count of tmp) = 2) then
44 display dialog "Bailing! The selection does not contain exactly one '%Variables='"
45 return
46 end if
47 set ss to (item 2 of tmp)
48 set tmp2 to (paragraphs of ss)
49 set vbllst to (item 1 of tmp2) --like {nnn,0:1+1,1:3+-2}
50 set vbllst2 to trim(vbllst)
51 set vbllst3 to (text 2 thru -2 of vbllst2)
52 set text item delimiters to {" , ", " ,", " ,", ","}
53 set vbles to (text items of vbllst3) -- line {nnn,0:1+1,1:3+-2}
54 --display dialog "vbles=" &amp; (vbles as text)
55 set n to (count of vbles)
56 set root to (item 1 of vbles)
57 set vlst to {}
58 set vinit to {}
59 set vinc to {}
60 set valt to {}
61 set text item delimiters to {":", "+"}
62 repeat with j from 2 to n
63 set x to (text items of (item j of vbles))
64 if not ((count of x) = 3) then
65 display dialog "Bad variable descriptor-- " &amp; item j of vbles
66 set text item delimiters to oldtid
67 return
68 end if
69 set end of vlst to (item 1 of x)
70 set nnn to 0
71 set hasp to 0
72 if (last character of (item 3 of x) = ")") then
73 set hasp to 1
74 set nnn to ((text -2 of (item 3 of x)) as integer)
75 set (item 3 of x) to (text 1 thru -4 of (item 3 of x))
76 else
77 if (first character of (item 2 of x) = "[") then set nnn to -100
78 end if
79 if (item 3 of x) ends with "/2" then
80 set (item 3 of x) to (text 1 thru -3 of (item 3 of x))
81 if hasp = 1 then
82 set nnn to -nnn
83 else
84 set nnn to -10
85 end if
86 end if
87 set end of valt to nnn
88 if (nnn = -100) then
89 set end of vinit to (text 2 thru -1 of (item 2 of x))
90 set end of vinc to (text 1 thru -2 of (item 3 of x))
91 else
92 set end of vinit to (item 2 of x)
93 set end of vinc to (item 3 of x)
94 end if
95
96 end repeat
97 set text item delimiters to oldtid
98 set viniti to {}
99 set vinci to {}
100 set kk to (count of vinit)
101 repeat with j from 1 to kk
102 try
103 set end of viniti to ((item j of vinit) as integer)
104 on error
105 set end of viniti to 0
106 end try
107 try
108 set end of vinci to ((item j of vinc) as integer)
109 on error
110 set end of vinci to 0
111 end try
112 end repeat
113 set tmp to (paragraphs of s)
114 set m to (count of tmp)
115 set tmp2 to {}
116 repeat with j from 3 to m
117 set t to (item j of tmp)
118 if ((count of t) &gt; 1) then
119 set t to (text 2 thru -1 of t)
120 else
121 set t to ""
122 end if
123 set end of tmp2 to t
124 end repeat
125 set text item delimiters to {lf}
126 set body to (tmp2 as text)
127 set text item delimiters to oldtid
128 set repl to {s}
129 set newbody to body
130 repeat with p from 1 to numrep
131 set newbody to body
132 repeat with k from 1 to kk
133 set v to ""
134 set alt to (item k of valt)
135 if (alt = -100) then
136 if (p mod 2) = 0 then
137 set v to (item k of vinc)
138 else
139 set v to (item k of vinit)
140 end if
141 else
142 set v to (item k of viniti)
143 if (alt &lt; 0) then
144 set v to (v div 2)
145 set alt to -alt
146 end if
147 if (alt is not 10) and (alt is not 0) then
148 set v to zero_pad(v, alt)
149 else
150 set v to (v as string)
151 end if
152 end if
153 set newbody to switchText of newbody from (root &amp; (item k of vlst)) to v
154 set item k of viniti to (((item k of viniti) as integer) + (item k of vinci))
155 end repeat
156 set end of repl to newbody
157 end repeat
158 set text item delimiters to lf
159 tell application "TeXShop" to set selection of document 1 to (repl as text)
160 set AppleScript's text item delimiters to oldtid
161
162 on zero_pad(value, string_length)
163 set tmp_string to "000000000" &amp; (value as string)
164 set padded_value to text ((count of tmp_string) - string_length + 1) thru -1 of tmp_string
165 return padded_value
166 end zero_pad
167
168 to switchText of t from s to r
169 set d to text item delimiters
170 set text item delimiters to s
171 set t to t's text items
172 set text item delimiters to r
173 tell t to set t to beginning &amp; ({""} &amp; rest)
174 set text item delimiters to d
175 t
176 end switchText
177
178 on trim(someText)
179 try
180 repeat until first character of someText is not in trimitems
181 set someText to text 2 thru -1 of someText
182 end repeat
183 on error
184 set someText to ""
185 end try
186
187 try
188 repeat until last character of someText is not in trimitems
189 set someText to text 1 thru -2 of someText
190 end repeat
191 on error
192 set someText to ""
193 end try
194 return someText
195 end trim
196
197 </string>
198 <key>key</key>
199 <string></string>
200 <key>name</key>
201 <string>Replicate</string>
202 </dict>
203 </array>
204 </dict>
205 </plist>