summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/pythontex/pythontex3.py
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/pythontex/pythontex3.py')
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/pythontex3.py54
1 files changed, 47 insertions, 7 deletions
diff --git a/Master/texmf-dist/scripts/pythontex/pythontex3.py b/Master/texmf-dist/scripts/pythontex/pythontex3.py
index b872dbaa2c4..cb96f97d336 100755
--- a/Master/texmf-dist/scripts/pythontex/pythontex3.py
+++ b/Master/texmf-dist/scripts/pythontex/pythontex3.py
@@ -13,7 +13,7 @@ should be in the same directory.
Licensed under the BSD 3-Clause License:
-Copyright (c) 2012-2016, Geoffrey M. Poore
+Copyright (c) 2012-2017, Geoffrey M. Poore
All rights reserved.
@@ -77,7 +77,7 @@ else:
# Script parameters
# Version
-__version__ = '0.15'
+__version__ = '0.16'
@@ -1286,7 +1286,8 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict):
engine_dict[family].warnings,
engine_dict[family].linenumbers,
engine_dict[family].lookbehind,
- keeptemps, hashdependencies)'''
+ keeptemps, hashdependencies,
+ pygments_settings)'''
tasks.append(pool.apply_async(run_code, [encoding, outputdir,
workingdir, code_dict[key],
engine_dict[family].language,
@@ -1299,7 +1300,8 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict):
engine_dict[family].warnings,
engine_dict[family].linenumbers,
engine_dict[family].lookbehind,
- keeptemps, hashdependencies]))
+ keeptemps, hashdependencies,
+ pygments_settings]))
if verbose:
print(' - Code process ' + key.replace('#', ':'))
@@ -1475,7 +1477,7 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict):
def run_code(encoding, outputdir, workingdir, code_list, language, commands,
command_created, extension, makestderr, stderrfilename,
code_index, errorsig, warningsig, linesig, stderrlookbehind,
- keeptemps, hashdependencies):
+ keeptemps, hashdependencies, pygments_settings):
'''
Function for multiprocessing code files
'''
@@ -1526,7 +1528,10 @@ def run_code(encoding, outputdir, workingdir, code_list, language, commands,
exec_cmd = shlex.split(bytes(command.format(file=script.replace('\\', '\\\\'), File=script_full.replace('\\', '\\\\'), workingdir=workingdir.replace('\\', '\\\\'))))
exec_cmd = [unicode(elem) for elem in exec_cmd]
else:
- exec_cmd = shlex.split(command.format(file=script.replace('\\', '\\\\'), File=script_full.replace('\\', '\\\\'), workingdir=workingdir.replace('\\', '\\\\')))
+ if family != 'juliacon':
+ exec_cmd = shlex.split(command.format(file=script.replace('\\', '\\\\'), File=script_full.replace('\\', '\\\\'), workingdir=workingdir.replace('\\', '\\\\')))
+ else:
+ exec_cmd = shlex.split(command.format(file=script.replace('\\', '/'), File=script_full.replace('\\', '/'), workingdir=workingdir.replace('\\', '/')))
# Add any created files due to the command
# This needs to be done before attempts to execute, to prevent orphans
try:
@@ -1563,6 +1568,22 @@ def run_code(encoding, outputdir, workingdir, code_list, language, commands,
messages.append(' Missing output file for ' + key_run.replace('#', ':'))
errors += 1
else:
+ if family == 'juliacon':
+ with open(out_file_name.rsplit('.', 1)[0] + '.tex', 'r', encoding=encoding) as f:
+ tex_data_lines = f.readlines()
+ inst = 0
+ for n, line in enumerate(tex_data_lines):
+ if line.rstrip() == '\\begin{juliaterm}':
+ tex_data_lines[n] = '=>PYTHONTEX:STDOUT#{0}#code#\n'.format(inst)
+ inst += 1
+ if n != 0:
+ tex_data_lines[n-1] = ''
+ if line.rstrip() == '\\end{juliaterm}':
+ tex_data_lines[n] = ''
+ tex_data_lines.append('=>PYTHONTEX:DEPENDENCIES#\n=>PYTHONTEX:CREATED#\n')
+ with open(out_file_name, 'w', encoding=encoding) as f:
+ f.write(''.join(tex_data_lines))
+
f = open(out_file_name, 'r', encoding=encoding)
out = f.read()
f.close()
@@ -1619,6 +1640,18 @@ def run_code(encoding, outputdir, workingdir, code_list, language, commands,
else:
dependencies[dep] = (os.path.getmtime(dep_file), '')
+ if family == 'juliacon':
+ from pygments import highlight
+ from pygments.lexers import get_lexer_by_name
+ from pygments.formatters import LatexFormatter
+ formatter = dict()
+ lexer = dict()
+ for codetype in pygments_settings:
+ if codetype != ':GLOBAL':
+ p = pygments_settings[codetype]['formatter_options'].copy()
+ p['commandprefix'] = 'PYG'
+ formatter[codetype] = LatexFormatter(**p)
+ lexer[codetype] = get_lexer_by_name(pygments_settings[codetype]['lexer'], **p)
for block in out.split('=>PYTHONTEX:STDOUT#')[1:]:
if block:
delims, content = block.split('#\n', 1)
@@ -1649,6 +1682,8 @@ def run_code(encoding, outputdir, workingdir, code_list, language, commands,
# Remove newline added by printing, prevent
# LaTeX from adding a space after content
content = content.rsplit('\n', 1)[0] + '\\endinput\n'
+ if family == 'juliacon':
+ content = highlight(content, lexer[family], formatter[family])
f.write(content)
f.close()
files.append(fname)
@@ -1658,6 +1693,8 @@ def run_code(encoding, outputdir, workingdir, code_list, language, commands,
messages.append('* PythonTeX error')
messages.append(' Missing stderr file for ' + key_run.replace('#', ':'))
errors += 1
+ elif family == 'juliacon':
+ pass
else:
# Open error and code files.
f = open(err_file_name, encoding=encoding)
@@ -2408,7 +2445,10 @@ def python_console(jobname, encoding, outputdir, workingdir, fvextfile,
sys.excepthook = sys.__excepthook__
old_stdout = sys.stdout
sys.stdout = self.iostdout
- self.interact(self.banner)
+ if sys.version_info.major == 3 and sys.version_info.minor >= 6:
+ self.interact(self.banner, exitmsg='')
+ else:
+ self.interact(self.banner)
sys.stdout = old_stdout
self.session_log = self.iostdout.getvalue()