rbtex 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/rblatex +566 -0
- data/lib/rbtex.rb +117 -0
- data/rbtex.gemspec +21 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42bdca948bc59d0c62d2c239bbf8f9ff4ae9e7db
|
4
|
+
data.tar.gz: 9d8b08d16afaa14451f50f0fd876e07e770ffbe4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76eaa5830d558bb87dcb27a76a39280cef27072ee54385b4bae48438d550e07924dbb9301de46db7d902aad06f0280115330497c277ef5a8bd17c39479366bf7
|
7
|
+
data.tar.gz: cd309360956ab1da0f41964bfddbd35a184ae189abfd1cffd287bd13569fff77763a13f1899000f384a2a79b0ff96f430d0b7ae8990c6d599a1324528889d3bc
|
data/bin/rblatex
ADDED
@@ -0,0 +1,566 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'colorize'
|
5
|
+
require 'table_flipper'
|
6
|
+
|
7
|
+
################################################################################
|
8
|
+
#
|
9
|
+
# rblatex -- The RbTeX processor.
|
10
|
+
#
|
11
|
+
# @author Steven Rosendahl
|
12
|
+
# @version 0.1.6
|
13
|
+
#
|
14
|
+
# This is the processor for the RbTeX package. This processor does not handle
|
15
|
+
# any of the TeX heavy lifting; rather, the processor only looks for certain
|
16
|
+
# environments in a supplied TeX document. After several steps, control is
|
17
|
+
# returned back over to TeX, where pdflatex is called on the generated .rtx
|
18
|
+
# file. If no rbtex environments were found, then this program tells pdflatex
|
19
|
+
# to compile the original document.
|
20
|
+
#
|
21
|
+
# The MIT License (MIT)
|
22
|
+
#
|
23
|
+
# Copyright (c) 2016 Steven Rosendahl
|
24
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
25
|
+
# this software and associated documentation files (the "Software"), to deal in
|
26
|
+
# the Software without restriction, including without limitation the rights to
|
27
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
28
|
+
# of the Software, and to permit persons to whom the Software is furnished to do
|
29
|
+
# so, subject to the following conditions:
|
30
|
+
#
|
31
|
+
# The above copyright notice and this permission notice shall be included in all
|
32
|
+
# copies or substantial portions of the Software.
|
33
|
+
#
|
34
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
35
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
36
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
37
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
38
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
39
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
40
|
+
# SOFTWARE.
|
41
|
+
################################################################################
|
42
|
+
|
43
|
+
TEX_ENV_01_S = '\\begin{rbtex}'
|
44
|
+
TEX_ENV_01_E = '\\end{rbtex}'
|
45
|
+
|
46
|
+
VERSION='0.1.6'
|
47
|
+
|
48
|
+
RB_REQUIRE = "require 'rbtex'"
|
49
|
+
|
50
|
+
OUT_DELIM = "\u00b6".encode('utf-8')
|
51
|
+
|
52
|
+
RB_METHOD_S = "def"
|
53
|
+
RB_METHOD_E = "end"
|
54
|
+
|
55
|
+
LOOP_START = "\#\#\#LOOP_START\#\#\#"
|
56
|
+
LOOP_END = "\#\#\#LOOP_END\#\#\#"
|
57
|
+
RBT_ENV_BEGIN = "\#\#\#RBT_ENV_BEGIN\#\#\#"
|
58
|
+
RBT_ENV_END = "\#\#\#RBT_ENV_END\#\#\#"
|
59
|
+
|
60
|
+
RB_CLASS_CREATE = "new"
|
61
|
+
|
62
|
+
RB_KEYWORD_END = [
|
63
|
+
'begin',
|
64
|
+
'case',
|
65
|
+
'def',
|
66
|
+
'do',
|
67
|
+
'for',
|
68
|
+
'if',
|
69
|
+
'redo',
|
70
|
+
'rescue',
|
71
|
+
'unless',
|
72
|
+
'until',
|
73
|
+
'while'
|
74
|
+
]
|
75
|
+
|
76
|
+
RB_LOOP_SIGNIT = [
|
77
|
+
'while',
|
78
|
+
'for',
|
79
|
+
'until',
|
80
|
+
'.times',
|
81
|
+
'.upto',
|
82
|
+
'.each'
|
83
|
+
]
|
84
|
+
|
85
|
+
TEX_MOD = 'Tex.print'
|
86
|
+
|
87
|
+
RBTEX_INSERT_LINE = "rbtexinsertedlinenumber"
|
88
|
+
|
89
|
+
TEX_FILE = ARGV[0]; # The user supplied TeX document
|
90
|
+
RB_FILE = "#{TEX_FILE}.rb" # The generated Ruby File
|
91
|
+
RBTEX_OUT = "#{TEX_FILE}.aux.rtx" # The generated output file
|
92
|
+
RBTEX_FILE = "#{File.basename(TEX_FILE,".tex")}.rtx" # The generated TeX File
|
93
|
+
$rbenvs = 0; # The number of rbtex environments found
|
94
|
+
$defstack = [] # A mechanism for dertermining when fcns end
|
95
|
+
$loopstack = []
|
96
|
+
$customclasses = []
|
97
|
+
$fcnref = {}
|
98
|
+
$console = ""
|
99
|
+
|
100
|
+
def main
|
101
|
+
if TEX_FILE
|
102
|
+
result = 0
|
103
|
+
puts "Welcome to rblatex v#{VERSION}!"
|
104
|
+
puts "Beginning to preprocess #{TEX_FILE}"
|
105
|
+
result = preprocess
|
106
|
+
if result == 0
|
107
|
+
if $rbenvs > 0
|
108
|
+
puts "#{$rbenvs} RbTeX envrioment(s) found"
|
109
|
+
puts 'Beginning interpretation of Ruby code!'
|
110
|
+
result = interp
|
111
|
+
if result == 0
|
112
|
+
result = postprocess
|
113
|
+
else
|
114
|
+
puts 'Failed to interpret.'
|
115
|
+
puts 'Check stdio for the error.'
|
116
|
+
return 2
|
117
|
+
end
|
118
|
+
else
|
119
|
+
puts 'No uses of RbTeX found'
|
120
|
+
puts 'Falling back to LaTeX with a --shell-escape'
|
121
|
+
end
|
122
|
+
else
|
123
|
+
puts 'Failed to preprocess for some reason.'
|
124
|
+
return 2
|
125
|
+
end
|
126
|
+
if result == 0
|
127
|
+
puts 'Giving control over to pdflatex.'
|
128
|
+
puts 'Thank you for choosing RbTeX!'
|
129
|
+
# Thread.new {
|
130
|
+
result = latexit
|
131
|
+
# }.join
|
132
|
+
if result == 0
|
133
|
+
puts 'done'
|
134
|
+
exit 0
|
135
|
+
else
|
136
|
+
puts "Oops, there was a LaTeX error".colorize(:red).on_black
|
137
|
+
end
|
138
|
+
else
|
139
|
+
puts 'Failed to postprocess.'
|
140
|
+
puts 'This is likely RbTeX\'s fault :('
|
141
|
+
return 2
|
142
|
+
end
|
143
|
+
else
|
144
|
+
puts 'No TeX file supplied. Try again with a valid TeX file!'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
################################################################################
|
149
|
+
# def preprocess
|
150
|
+
#
|
151
|
+
# Handles the inital ripping of code from the original TeX document supplied by
|
152
|
+
# the user. Upon successful completion, the method will return 0.
|
153
|
+
#
|
154
|
+
################################################################################
|
155
|
+
def preprocess
|
156
|
+
lineno = 0
|
157
|
+
shouldWrite = false
|
158
|
+
inFunction = false
|
159
|
+
inLoop = false
|
160
|
+
printer = File.open(RB_FILE,'w')
|
161
|
+
scanner = File.open(TEX_FILE,'r')
|
162
|
+
if printer && scanner
|
163
|
+
printer.puts RB_REQUIRE
|
164
|
+
scanner.each_line do |line|
|
165
|
+
lineno = lineno + 1
|
166
|
+
if (line.include? TEX_ENV_01_E) && !determineTexCommented(line, TEX_ENV_01_E)
|
167
|
+
puts "Encountered #{TEX_ENV_01_E} on line #{lineno}"
|
168
|
+
printer.puts "Tex.print('', 8888, ['nrbtev'])"
|
169
|
+
shouldWrite = false
|
170
|
+
end
|
171
|
+
if shouldWrite
|
172
|
+
stripped = line.strip
|
173
|
+
#parse custom class names
|
174
|
+
if stripped.include? 'class'
|
175
|
+
$customclasses.push stripped[stripped.index(' ')..stripped.length].strip
|
176
|
+
end
|
177
|
+
# parse lines containing the Tex.print method
|
178
|
+
if (stripped.include? TEX_MOD) && !determineRubyCommented(stripped, TEX_MOD) && !inFunction
|
179
|
+
printer.print appendLineNumberToTexPrintCall(stripped, lineno)
|
180
|
+
# parse situations containing classes
|
181
|
+
elsif (stripped.include? RB_CLASS_CREATE) && !determineRubyCommented(stripped, RB_CLASS_CREATE) && !inFunction
|
182
|
+
shoudlDoPrintThing = false
|
183
|
+
$customclasses.each do |saved|
|
184
|
+
if stripped.include? saved
|
185
|
+
shoudlDoPrintThing = true
|
186
|
+
break
|
187
|
+
end
|
188
|
+
end
|
189
|
+
if shoudlDoPrintThing
|
190
|
+
printer.print appendLineNumberToInitialization(stripped, lineno)
|
191
|
+
else
|
192
|
+
printer.print stripped
|
193
|
+
end
|
194
|
+
# parse methods
|
195
|
+
elsif (stripped.include? RB_METHOD_S) && !determineRubyCommented(stripped, RB_METHOD_S) && !inFunction
|
196
|
+
puts "Processing function definition: found line containing #{stripped}"
|
197
|
+
inFunction = true
|
198
|
+
extracted = extractFunctionMeta stripped
|
199
|
+
$fcnref.store(extracted[0], extracted[1])
|
200
|
+
$defstack.push 1
|
201
|
+
if (stripped.include? '(') && (stripped.include? ')')
|
202
|
+
puts "Injection into formatted def as \( \)! Boo!"
|
203
|
+
else
|
204
|
+
puts "Injection into formatted def as _,_! This is preferrable."
|
205
|
+
end
|
206
|
+
printer.print appendLineNumberArgToFunctionDefinition stripped
|
207
|
+
# if we are in a function, things work differently
|
208
|
+
elsif inFunction
|
209
|
+
puts "Parsing #{stripped} inside function..."
|
210
|
+
printer.print stripped
|
211
|
+
if (line.include? TEX_MOD) && !determineRubyCommented(line, "Tex")
|
212
|
+
printer.print inLoop ?
|
213
|
+
", (#{RBTEX_INSERT_LINE}=#{RBTEX_INSERT_LINE}+1)" :
|
214
|
+
", #{RBTEX_INSERT_LINE}"
|
215
|
+
end
|
216
|
+
#determine if the line contains a block keyword
|
217
|
+
RB_KEYWORD_END.each do |kwd|
|
218
|
+
if line.include? kwd
|
219
|
+
puts "Encountered '#{kwd}'; pushing onto stack..."
|
220
|
+
$defstack.push kwd
|
221
|
+
break
|
222
|
+
end
|
223
|
+
end
|
224
|
+
#determine if the line contains a looping keyword
|
225
|
+
RB_LOOP_SIGNIT.each do |kwd|
|
226
|
+
# if line.include? kwd
|
227
|
+
if loopcheck(kwd,line)
|
228
|
+
puts "Located a loop of the form '#{kwd}'; pushing onto stack..."
|
229
|
+
$loopstack.push kwd
|
230
|
+
inLoop = true
|
231
|
+
printer.seek(-1 * (stripped.length), IO::SEEK_CUR)
|
232
|
+
printer.print "\nTex.print('',#{RBTEX_INSERT_LINE},['loop'])"
|
233
|
+
printer.print "\n#{stripped}"
|
234
|
+
break
|
235
|
+
end
|
236
|
+
end
|
237
|
+
if line.include? 'end'
|
238
|
+
puts "Encountered 'end'; popping off of stack..."
|
239
|
+
$defstack.pop
|
240
|
+
# puts "LOOPSTACK SIZE: #{$loopstack.any?}"
|
241
|
+
if inLoop
|
242
|
+
$loopstack.pop
|
243
|
+
inLoop = $loopstack.any?
|
244
|
+
if !inLoop
|
245
|
+
printer.puts "\nTex.print('',#{RBTEX_INSERT_LINE},['nloop'])"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
inFunction = $defstack.any?
|
250
|
+
else
|
251
|
+
print "STRIPPED: #{stripped} "
|
252
|
+
deffed = false
|
253
|
+
#look for looping mechanisms first
|
254
|
+
RB_LOOP_SIGNIT.each do |loopsig|
|
255
|
+
# if stripped.include? loopsig
|
256
|
+
if loopcheck(loopsig, stripped)
|
257
|
+
$loopstack.push loopsig
|
258
|
+
printer.puts "\nTex.print('',0,['loop'])"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
printer.print stripped
|
262
|
+
$fcnref.each do |fcn, args|
|
263
|
+
if stripped.include? fcn
|
264
|
+
if (line.include? '(') && (line.include? ')')
|
265
|
+
|
266
|
+
else
|
267
|
+
printer.print (args != 0) ? (", #{lineno}") : (" #{lineno}")
|
268
|
+
break
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
printer.puts ""
|
274
|
+
printer.puts ""
|
275
|
+
end
|
276
|
+
if (line.include? TEX_ENV_01_S) && !determineTexCommented(line, TEX_ENV_01_S)
|
277
|
+
puts "Encountered #{TEX_ENV_01_S} on line #{lineno}"
|
278
|
+
$rbenvs = $rbenvs + 1
|
279
|
+
shouldWrite = true
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
printer.close
|
284
|
+
scanner.close
|
285
|
+
return 0
|
286
|
+
end
|
287
|
+
|
288
|
+
################################################################################
|
289
|
+
# def interp
|
290
|
+
#
|
291
|
+
# Runs the generated ruby file. This function returns the result of the system's
|
292
|
+
# ruby call.
|
293
|
+
#
|
294
|
+
################################################################################
|
295
|
+
def interp
|
296
|
+
rboutput = `ruby #{RB_FILE} #{RBTEX_OUT}`
|
297
|
+
if rboutput == ''
|
298
|
+
puts 'Your ruby file had no puts statments'.green
|
299
|
+
end
|
300
|
+
return 0
|
301
|
+
end
|
302
|
+
|
303
|
+
################################################################################
|
304
|
+
# def postprocess
|
305
|
+
#
|
306
|
+
# Generates a new LaTeX document for compilation via pdflatex. This function
|
307
|
+
# will return 0 upon successful completion.
|
308
|
+
#
|
309
|
+
################################################################################
|
310
|
+
def postprocess
|
311
|
+
scannerB = File.open(TEX_FILE,'r')
|
312
|
+
printer = File.open(RBTEX_FILE,'w')
|
313
|
+
scannerA = nil
|
314
|
+
|
315
|
+
lineno = 1
|
316
|
+
csvcount = 0
|
317
|
+
inRb = false
|
318
|
+
repline = ""
|
319
|
+
replineno = -1
|
320
|
+
|
321
|
+
empty = File.zero?(RBTEX_OUT)
|
322
|
+
|
323
|
+
if !empty
|
324
|
+
# process the out file and the original tex file
|
325
|
+
scannerA = File.open(RBTEX_OUT)
|
326
|
+
scannerB.each_line do |line|
|
327
|
+
if (line.include? TEX_ENV_01_S) && !determineTexCommented(line, TEX_ENV_01_S)
|
328
|
+
inRb = true
|
329
|
+
end
|
330
|
+
if !inRb
|
331
|
+
# if we aren't in an rbtex environment, just go ahead and print the line verbatim
|
332
|
+
if !(line.include? LOOP_START)
|
333
|
+
printer.puts line
|
334
|
+
end
|
335
|
+
else
|
336
|
+
# grab a line from the scanner
|
337
|
+
outline = scannerA.gets
|
338
|
+
puts "OUTLINE: #{outline}"
|
339
|
+
if outline != nil
|
340
|
+
if outline.include? LOOP_START
|
341
|
+
# there was once a loop, so print out the stuff all at once
|
342
|
+
while (outline = scannerA.gets)
|
343
|
+
if outline.include? LOOP_END
|
344
|
+
break
|
345
|
+
end
|
346
|
+
printer.puts (outline.split(OUT_DELIM)[0])
|
347
|
+
end
|
348
|
+
elsif outline.include? RBT_ENV_END
|
349
|
+
nln = scannerB.gets
|
350
|
+
while nln != nil
|
351
|
+
if nln.include? TEX_ENV_01_E
|
352
|
+
break
|
353
|
+
end
|
354
|
+
nln = scannerB.gets
|
355
|
+
end
|
356
|
+
inRb = false
|
357
|
+
else
|
358
|
+
# just go along as normal
|
359
|
+
split = outline.split(OUT_DELIM)
|
360
|
+
puts "SPLIT: #{split}"
|
361
|
+
replineno = split[1]
|
362
|
+
repline = split[0]
|
363
|
+
puts "Injecting '#{repline}' into rtx file"
|
364
|
+
printer.puts repline
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
if (line.include? TEX_ENV_01_E) && !determineTexCommented(line, TEX_ENV_01_E)
|
369
|
+
inRb = false
|
370
|
+
end
|
371
|
+
lineno = lineno + 1
|
372
|
+
end
|
373
|
+
else
|
374
|
+
scannerB.each_line do |line|
|
375
|
+
if (line.include? TEX_ENV_01_S) && !determineTexCommented(line, TEX_ENV_01_S)
|
376
|
+
inRb = true
|
377
|
+
end
|
378
|
+
if !inRb
|
379
|
+
printer.puts line
|
380
|
+
end
|
381
|
+
if (line.include? TEX_ENV_01_E) && !determineTexCommented(line, TEX_ENV_01_E)
|
382
|
+
inRb = false
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
printer.close
|
388
|
+
scannerB.close
|
389
|
+
finalScan
|
390
|
+
puts 'Finishing postprocess'
|
391
|
+
return 0
|
392
|
+
end
|
393
|
+
|
394
|
+
def finalScan
|
395
|
+
f = File.open(RBTEX_FILE, 'r+')
|
396
|
+
f.each do |line|
|
397
|
+
if (line.include? LOOP_END) || (line.include? LOOP_START)
|
398
|
+
f.seek(-1 * line.length, IO::SEEK_CUR)
|
399
|
+
f.write(' ' * (line.length - 1))
|
400
|
+
f.puts("")
|
401
|
+
end
|
402
|
+
if line.include? RBT_ENV_END
|
403
|
+
f.seek(-1 * line.length, IO::SEEK_CUR)
|
404
|
+
f.write(' ' * (line.length - 1))
|
405
|
+
f.puts("")
|
406
|
+
end
|
407
|
+
end
|
408
|
+
f.close()
|
409
|
+
end
|
410
|
+
|
411
|
+
################################################################################
|
412
|
+
# def latexit
|
413
|
+
#
|
414
|
+
# Runs pdflatex on the generated TeX file.
|
415
|
+
################################################################################
|
416
|
+
def latexit
|
417
|
+
ret = -1
|
418
|
+
if $rbenvs > 0
|
419
|
+
ret = system("pdflatex --shell-escape #{RBTEX_FILE}") ? 0 : -1
|
420
|
+
else
|
421
|
+
ret = system("pdflatex --shell-escape #{TEX_FILE}") ? 0 : -1
|
422
|
+
end
|
423
|
+
return ret
|
424
|
+
end
|
425
|
+
|
426
|
+
################################################################################
|
427
|
+
# def getLineFromString(line)
|
428
|
+
#
|
429
|
+
# Returns the RbTeX stored line number on a line.
|
430
|
+
################################################################################
|
431
|
+
def getLineFromString(line)
|
432
|
+
return line.slice!(line.index("\#~~!!") + 6)
|
433
|
+
end
|
434
|
+
|
435
|
+
def determineTexCommented(line, haystack)
|
436
|
+
in1 = line.index("\%")
|
437
|
+
in2 = line.index(haystack)
|
438
|
+
if in1 && in2
|
439
|
+
return in1 < in2
|
440
|
+
end
|
441
|
+
return false
|
442
|
+
end
|
443
|
+
|
444
|
+
def determineRubyCommented(line, haystack)
|
445
|
+
in1 = line.index("\#")
|
446
|
+
in2 = line.index(haystack)
|
447
|
+
if in1 && in2
|
448
|
+
return in1 < in2
|
449
|
+
end
|
450
|
+
return false
|
451
|
+
end
|
452
|
+
|
453
|
+
################################################################################
|
454
|
+
# def extractFunctionMeta(line)
|
455
|
+
#
|
456
|
+
# Pulls out the function name and the number of arguments, and returns both.
|
457
|
+
#
|
458
|
+
# Methods in ruby can be formatted in several ways, so this method needs to
|
459
|
+
# be able to parse out any of the different variations
|
460
|
+
################################################################################
|
461
|
+
def extractFunctionMeta(line)
|
462
|
+
res = ""
|
463
|
+
numret = 0
|
464
|
+
if line.include? '('
|
465
|
+
mindex = line.index('(')
|
466
|
+
sindex = line.index(')')
|
467
|
+
res = line[3..(mindex - 1)]
|
468
|
+
numret = line[(mindex - 1)..(sindex - 1)].length
|
469
|
+
else
|
470
|
+
spindex = (line.strip[3..line.length]).strip.index(' ')
|
471
|
+
if spindex != nil
|
472
|
+
res = line[3..spindex]
|
473
|
+
numret = 2
|
474
|
+
else
|
475
|
+
res = line[3..line.length]
|
476
|
+
numret = 0
|
477
|
+
end
|
478
|
+
end
|
479
|
+
return res.strip, numret
|
480
|
+
end
|
481
|
+
|
482
|
+
def appendLineNumberToTexPrintCall(line, number)
|
483
|
+
# if line.include? TEX_MOD && !determineRubyCommented(line, 'Tex')
|
484
|
+
# Three possibilities:
|
485
|
+
# => Tex.print(thing)
|
486
|
+
# => Tex.print(otherMethodCall())
|
487
|
+
# => Tex.print thing
|
488
|
+
# Output: Tex.print((thing), lineno)
|
489
|
+
if !line.include?("\"")
|
490
|
+
mline = line.gsub(/\s+/, "")
|
491
|
+
else
|
492
|
+
mline = line
|
493
|
+
end
|
494
|
+
return "#{TEX_MOD}(#{mline[9..(mline.length-1)]},#{number})"
|
495
|
+
# end
|
496
|
+
end
|
497
|
+
|
498
|
+
def appendLineNumberArgToFunctionDefinition(line)
|
499
|
+
# Four possibilities:
|
500
|
+
# => def fcn args => def fcn(args,macro)
|
501
|
+
# => def fcn(args) => def fcn((args),macro)
|
502
|
+
# => def fcn => def fcn(macro)
|
503
|
+
# => def fcn() => def fcn((macro))
|
504
|
+
# puts "APPEND LINE #{line}"
|
505
|
+
defgone = line.strip[3..line.length]
|
506
|
+
defgone = defgone.strip
|
507
|
+
# puts "APPEND DEFGONE #{defgone}"
|
508
|
+
if defgone.include? '('
|
509
|
+
defgone = defgone.gsub(/\s+/, "")
|
510
|
+
midn1 = defgone.index('(')
|
511
|
+
midn2 = defgone.index(')')
|
512
|
+
if defgone[midn1..midn2] == "()"
|
513
|
+
#case 4
|
514
|
+
return "def #{defgone[0..(defgone.index('(') - 1)]} #{RBTEX_INSERT_LINE}=0"
|
515
|
+
else
|
516
|
+
#case 2
|
517
|
+
return "def #{defgone[0..(defgone.index('(') - 1)]}(#{defgone[defgone.index('(')..defgone.length]},#{RBTEX_INSERT_LINE}=0)"
|
518
|
+
end
|
519
|
+
else
|
520
|
+
#either have case 1 or 3
|
521
|
+
if defgone.index(" ") != nil
|
522
|
+
#case 3
|
523
|
+
return "def #{defgone}, #{RBTEX_INSERT_LINE}=0"
|
524
|
+
else
|
525
|
+
#case 1
|
526
|
+
return "def #{defgone} #{RBTEX_INSERT_LINE}=0"
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
def appendLineNumberToInitialization(line, number)
|
532
|
+
newSpot = line.index(RB_CLASS_CREATE)
|
533
|
+
args = line[(newSpot + 3)..line.length].strip
|
534
|
+
defin = line[0..(newSpot + 3)].strip
|
535
|
+
if args.length != 0
|
536
|
+
return "#{defin}(#{args},#{number})"
|
537
|
+
else
|
538
|
+
return "#{defin}(#{number})"
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
def loopcheck(word, line)
|
543
|
+
ret = line.include? word
|
544
|
+
index = 0
|
545
|
+
indexa = -1
|
546
|
+
indexb = -1
|
547
|
+
line.split("").each do |char|
|
548
|
+
if char == "\"" && indexa == -1
|
549
|
+
indexa = index
|
550
|
+
elsif char == "\"" && indexb == -1
|
551
|
+
indexb = index
|
552
|
+
end
|
553
|
+
if indexa != -1 && indexb != -1
|
554
|
+
substr = line[indexa..indexb]
|
555
|
+
indexa = -1
|
556
|
+
indexb = -1
|
557
|
+
if substr.include? word
|
558
|
+
return false
|
559
|
+
end
|
560
|
+
end
|
561
|
+
index = index + 1
|
562
|
+
end
|
563
|
+
return ret
|
564
|
+
end
|
565
|
+
|
566
|
+
main
|
data/lib/rbtex.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
$out_file = ARGV[0]
|
2
|
+
|
3
|
+
OUT_DELIM = "\u00b6".encode('utf-8')
|
4
|
+
|
5
|
+
LOOP_START = "\#\#\#LOOP_START\#\#\#"
|
6
|
+
LOOP_END = "\#\#\#LOOP_END\#\#\#"
|
7
|
+
|
8
|
+
RBT_ENV_BEGIN = "\#\#\#RBT_ENV_BEGIN\#\#\#"
|
9
|
+
RBT_ENV_END = "\#\#\#RBT_ENV_END\#\#\#"
|
10
|
+
|
11
|
+
$pLoop = false
|
12
|
+
|
13
|
+
if $out_file
|
14
|
+
File.new($out_file,"w").close
|
15
|
+
end
|
16
|
+
|
17
|
+
module Tex
|
18
|
+
|
19
|
+
def Tex.print(latex, number, bundle=[])
|
20
|
+
printToOutFile(latex, number, bundle)
|
21
|
+
end
|
22
|
+
|
23
|
+
def Tex.imath(math)
|
24
|
+
return "$#{math}$"
|
25
|
+
end
|
26
|
+
|
27
|
+
def Tex.cmath(math)
|
28
|
+
return "\\[#{math}\\]"
|
29
|
+
end
|
30
|
+
|
31
|
+
def Tex.center(latex)
|
32
|
+
return "\\begin{center}#{latex}\\end{center}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def Tex.n
|
36
|
+
return "\\\\"
|
37
|
+
end
|
38
|
+
|
39
|
+
def Tex.logo
|
40
|
+
return "$\\RbTeX$"
|
41
|
+
end
|
42
|
+
|
43
|
+
def Tex.printToOutFile(line, number, bundle)
|
44
|
+
file = File.open($out_file, 'a')
|
45
|
+
if bundle.length == 0
|
46
|
+
file.puts "#{line}#{OUT_DELIM}#{number}"
|
47
|
+
else
|
48
|
+
case bundle[0]
|
49
|
+
when "loop"
|
50
|
+
$pLoop = true
|
51
|
+
file.puts LOOP_START
|
52
|
+
when "nloop"
|
53
|
+
$pLoop = false
|
54
|
+
file.puts LOOP_END
|
55
|
+
when "rbtev"
|
56
|
+
file.puts RBT_ENV_BEGIN
|
57
|
+
when "nrbtev"
|
58
|
+
file.puts RBT_ENV_END
|
59
|
+
else
|
60
|
+
file.puts $pLoop ? "#{line}" : "#{line}#{OUT_DELIM}#{number}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
file.close
|
64
|
+
end
|
65
|
+
|
66
|
+
class Table
|
67
|
+
|
68
|
+
def initialize(twodee, tabx=false)
|
69
|
+
@array = twodee
|
70
|
+
# @rowlines = rowlines
|
71
|
+
@tabx = tabx
|
72
|
+
end
|
73
|
+
|
74
|
+
def create
|
75
|
+
pme = "\\begin{#{@tabx ? "tabularx" : "tabular"}}#{@tabx ? "{\\textwidth}" : ""}{|"
|
76
|
+
i = 0
|
77
|
+
while i < @array[0].length
|
78
|
+
pme << "#{@tabx ? "X|" : "c|"}"
|
79
|
+
i = i + 1
|
80
|
+
end
|
81
|
+
pme << "} "
|
82
|
+
@array.each do |row|
|
83
|
+
pme << "\\hline "
|
84
|
+
rc = 0
|
85
|
+
row.each do |elem|
|
86
|
+
pme << " #{elem} "
|
87
|
+
if rc < row.length - 1
|
88
|
+
pme << "&"
|
89
|
+
end
|
90
|
+
rc = rc + 1
|
91
|
+
end
|
92
|
+
pme << "\\\\ "
|
93
|
+
end
|
94
|
+
pme << "\\hline \\end{#{@tabx ? "tabularx" : "tabular"}}"
|
95
|
+
return pme
|
96
|
+
end
|
97
|
+
|
98
|
+
def colSum col
|
99
|
+
total = 0
|
100
|
+
i = 0
|
101
|
+
while i < @array.length
|
102
|
+
total = total + @array[i][col]
|
103
|
+
i = i + 1
|
104
|
+
end
|
105
|
+
return total
|
106
|
+
end
|
107
|
+
|
108
|
+
def rowSum row
|
109
|
+
total = 0
|
110
|
+
@array[row].each do |elem|
|
111
|
+
total = total + elem
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/rbtex.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
LANG="en_US.UTF-8"
|
4
|
+
LC_ALL="en_US.UTF-8"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'rbtex'
|
8
|
+
s.version = '0.1.8'
|
9
|
+
s.date = '2016-03-26'
|
10
|
+
s.description = 'The rubylatex gem'
|
11
|
+
s.summary = 'RbTeX'
|
12
|
+
s.authors = ['Steven Rosendahl']
|
13
|
+
s.email = 'fsnewline@gmail.com'
|
14
|
+
s.files = ['./lib/rbtex.rb', './rbtex.gemspec']
|
15
|
+
s.executables << 'rblatex'
|
16
|
+
s.homepage = 'https://github.com/RubyLatex/RbTeX'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.add_development_dependency 'colorize', ['>= 0']
|
20
|
+
s.add_development_dependency 'table_flipper', ['>= 0']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbtex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Rosendahl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: table_flipper
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: The rubylatex gem
|
42
|
+
email: fsnewline@gmail.com
|
43
|
+
executables:
|
44
|
+
- rblatex
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- "./lib/rbtex.rb"
|
49
|
+
- "./rbtex.gemspec"
|
50
|
+
- bin/rblatex
|
51
|
+
homepage: https://github.com/RubyLatex/RbTeX
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.5.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: RbTeX
|
75
|
+
test_files: []
|