Skip to content

Commit f019e55

Browse files
committed
extractsagecode: add option for extracting only environments
Also, use a different comment prefix for comments output by the extraction tool.
1 parent 5905bd8 commit f019e55

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

scripts.dtx

+16-11
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def argparser():
238238
p.add_argument('outputfile', nargs='?', default=None, help="Output file name")
239239
p.add_argument('-o', '--overwrite', action="store_true", default=False,
240240
help="Overwrite output file if it exists")
241+
p.add_argument('--no-inline', action="store_true", default=False,
242+
help="Extract code only from Sage environments")
241243
return p
242244
243245
def run(args):
@@ -249,9 +251,9 @@ def run(args):
249251
sys.exit(1)
250252
251253
src, ext = os.path.splitext(src)
252-
sagecode = SageCodeExtractor(src + '.tex')
253-
header = ("# This file contains Sage code extracted from %s%s.\n"
254-
"# Processed %s.\n"
254+
sagecode = SageCodeExtractor(src + '.tex', inline=not args.no_inline)
255+
header = ("#> This file contains Sage code extracted from %s%s.\n"
256+
"#> Processed %s.\n"
255257
"" % (src, ext, time.strftime('%a %d %b %Y %H:%M:%S', time.localtime())))
256258
257259
if dst is not None:
@@ -470,7 +472,7 @@ class DeSageTex():
470472
% Sage.
471473
% \begin{macrocode}
472474
class SageCodeExtractor():
473-
def __init__(self, texfn):
475+
def __init__(self, texfn, inline=True):
474476
smacro = sagemacroparser
475477
smacro.setParseAction(self.macroout)
476478
@@ -497,7 +499,10 @@ class SageCodeExtractor():
497499
sunpause = sagetexunpause
498500
sunpause.setParseAction(self.unpause)
499501
500-
doit = smacro | splot | senv | spause | sunpause
502+
if inline:
503+
doit = smacro | splot | senv | spause | sunpause
504+
else:
505+
doit = senv | spause | sunpause
501506
doit.ignore('%' + restOfLine)
502507
503508
str = ''.join(open(texfn, 'r').readlines())
@@ -506,26 +511,26 @@ class SageCodeExtractor():
506511
doit.transformString(str)
507512
508513
def macroout(self, s, l, t):
509-
self.result += '# \\sage{} from line %s\n' % lineno(l, s)
514+
self.result += '#> \\sage{} from line %s\n' % lineno(l, s)
510515
self.result += t.code[1:-1] + '\n\n'
511516
512517
def plotout(self, s, l, t):
513-
self.result += '# \\sageplot{} from line %s:\n' % lineno(l, s)
518+
self.result += '#> \\sageplot{} from line %s:\n' % lineno(l, s)
514519
if t.format != '':
515-
self.result += '# format: %s' % t.format[0][1:-1] + '\n'
520+
self.result += '#> format: %s' % t.format[0][1:-1] + '\n'
516521
self.result += t.code[1:-1] + '\n\n'
517522
518523
def envout(self, s, l, t):
519-
self.result += '# %s environment from line %s:' % (t.env,
524+
self.result += '#> %s environment from line %s:' % (t.env,
520525
lineno(l, s))
521526
self.result += ''.join(t.code) + '\n'
522527
523528
def pause(self, s, l, t):
524-
self.result += ('# SageTeX (probably) paused on input line %s.\n\n' %
529+
self.result += ('#> SageTeX (probably) paused on input line %s.\n\n' %
525530
(lineno(l, s)))
526531
527532
def unpause(self, s, l, t):
528-
self.result += ('# SageTeX (probably) unpaused on input line %s.\n\n' %
533+
self.result += ('#> SageTeX (probably) unpaused on input line %s.\n\n' %
529534
(lineno(l, s)))
530535
% \end{macrocode}
531536
% \end{macro}

0 commit comments

Comments
 (0)