Skip to content

Commit 4ab50a8

Browse files
authored
Merge pull request #224 from Reissner/issPython311
Iss python311
2 parents 9287970 + 41b3e37 commit 4ab50a8

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

pythontex/depythontex3.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def replace_code_cmd(name, arglist, linenum, code_replacement,
121121
122122
Usually, code from a command is also typeset with a command. This
123123
function primarily deals with that case. In cases where code from a
124-
command is typeset with an environment (for example, `\inputpygments`),
124+
command is typeset with an environment (for example, `\\inputpygments`),
125125
this function performs some preprocessing and then uses
126126
replace_code_env() to do the real work. This approach prevents the two
127127
functions from unnecessarily duplicating each other, while still giving
@@ -161,7 +161,7 @@ def replace_code_cmd(name, arglist, linenum, code_replacement,
161161
# Make sure the introduction of an environment where a command was
162162
# previously won't produce errors with following content; make sure
163163
# that any following content is on a separate line
164-
if bool(match('[ \t]*\S', after)):
164+
if bool(match(r'[ \t]*\S', after)):
165165
after = '\n' + after
166166
# Rather than duplicating much of replace_code_env(), just use it
167167
return replace_code_env(name, arglist, linenum, code_replacement,
@@ -333,7 +333,7 @@ def replace_print_cmd(name, arglist, linenum,
333333
break
334334
print_replacement = r'\verb' + delim + print_replacement + delim
335335
elif print_replacement_mode == 'verbatim':
336-
if bool(match('\s*?\n', after)):
336+
if bool(match(r'\s*?\n', after)):
337337
# Usually, we would end the verbatim environment with a newline.
338338
# This is fine if there is content in `after` before the next
339339
# newline---in fact, it's desirable, because the verbatim package
@@ -405,11 +405,11 @@ def replace_print_cmd(name, arglist, linenum,
405405
# the `\input` content.
406406
print_replacement = print_replacement.rstrip(' \t\n')
407407
after = sub(r'^\\unskip\s+', '', after)
408-
elif bool(match('\S', after)):
408+
elif bool(match(r'\S', after)):
409409
# If the next character is not whitespace, we can just leave
410410
# the `\n`, and it will yield a space.
411411
pass
412-
elif bool(match('\s*$', after)):
412+
elif bool(match(r'\s*$', after)):
413413
# If the rest of the current line, and the next line, are
414414
# whitespace, we will get the correct spacing without needing
415415
# `\space{}`. We could leave `\n`, but it would be
@@ -421,14 +421,14 @@ def replace_print_cmd(name, arglist, linenum,
421421
# it's at the end of an environment, and thus is needed to
422422
# protect the following content
423423
print_replacement += '\\space{}'
424-
after = sub('^\s+', '', after)
424+
after = sub(r'^\s+', '', after)
425425
forced_double_space_list.append((name, linenum))
426426
else:
427-
if bool(match('\s+\S', after)):
427+
if bool(match(r'\s+\S', after)):
428428
# If the following line starts with whitespace, replace it
429429
# with a newline, to protect in the event that the printed
430430
# content ended with an end-of-environment command
431-
after = sub('^\s+', '\n', after)
431+
after = sub(r'^\s+', '\n', after)
432432
# Issue warnings, if warranted
433433
# Warn about `\endinput`
434434
if (r'\endinput' in print_replacement and
@@ -505,7 +505,7 @@ def replace_print_env(name, arglist, linenum,
505505
506506
#### The inlineverb and verb modes should work, but haven't been tested
507507
since there are currently no environments that use them; they are only
508-
used by `\printpythontex`, which is a command.
508+
used by `\\printpythontex`, which is a command.
509509
'''
510510
if print_replacement_mode == 'verb':
511511
if print_replacement.count('\n') > 1:
@@ -519,17 +519,17 @@ def replace_print_env(name, arglist, linenum,
519519
if delim not in print_replacement:
520520
break
521521
print_replacement = r'\verb' + delim + print_replacement + delim
522-
if not bool(match('[ \t]+\S', after)):
522+
if not bool(match(r'[ \t]+\S', after)):
523523
# If there is text on the same line as the end of the
524524
# environment, we're fine (this is unusual). Otherwise,
525525
# we need to toss the newline at the end of the environment
526526
# and gobble leading spaces. Leading spaces need to be
527527
# gobbled because previously they were at the beginning of a
528528
# line, where they would have been discarded.
529-
if not bool(match('\s*$', after)):
530-
after = sub('^\s*?\n\s*', '', after)
529+
if not bool(match(r'\s*$', after)):
530+
after = sub(r'^\s*?\n\s*', '', after)
531531
elif print_replacement_mode == 'verbatim':
532-
if bool(match('\s*?\n', after)):
532+
if bool(match(r'\s*?\n', after)):
533533
# Usually, we would end the verbatim environment with a newline.
534534
# This is fine if there is content in `after` before the next
535535
# newline---in fact, it's desirable, because the verbatim package
@@ -570,15 +570,15 @@ def replace_print_env(name, arglist, linenum,
570570
# printed content. Later, we issue a warning in case it appears
571571
# anywhere else.
572572
print_replacement = print_replacement.rsplit(r'\endinput', 1)[0]
573-
if not bool(match('[ \t]+\S', after)):
573+
if not bool(match(r'[ \t]+\S', after)):
574574
# If there is text on the same line as the end of the
575575
# environment, we're fine (this is unusual). Otherwise,
576576
# we need to toss the newline at the end of the environment
577577
# and gobble leading spaces. Leading spaces need to be
578578
# gobbled because previously they were at the beginning of a
579579
# line, where they would have been discarded.
580-
if not bool(match('\s*$', after)):
581-
after = sub('^\s*?\n\s*', '', after)
580+
if not bool(match(r'\s*$', after)):
581+
after = sub(r'^\s*?\n\s*', '', after)
582582
elif (print_replacement.endswith('%\n') and
583583
not print_replacement.endswith('\\%\n') and
584584
not print_replacement.endswith('\\string%\n')):
@@ -590,15 +590,15 @@ def replace_print_env(name, arglist, linenum,
590590
# warning if there is reason to think that a percent character
591591
# was active in the last line.
592592
print_replacement = print_replacement.rsplit(r'%', 1)[0]
593-
if not bool(match('[ \t]+\S', after)):
593+
if not bool(match(r'[ \t]+\S', after)):
594594
# If there is text on the same line as the end of the
595595
# environment, we're fine (this is unusual). Otherwise,
596596
# we need to toss the newline at the end of the environment
597597
# and gobble leading spaces. Leading spaces need to be
598598
# gobbled because previously they were at the beginning of a
599599
# line, where they would have been discarded.
600-
if not bool(match('\s*$', after)):
601-
after = sub('^\s*?\n\s*', '', after)
600+
if not bool(match(r'\s*$', after)):
601+
after = sub(r'^\s*?\n\s*', '', after)
602602
else:
603603
# By default, LaTeX strips newlines and adds a space at the end
604604
# of each line of content that is brought in by `\input`. This
@@ -611,13 +611,13 @@ def replace_print_env(name, arglist, linenum,
611611
# `\unskip`
612612
print_replacement = print_replacement.rstrip(' \t\n')
613613
after = sub(r'^\s*\\unskip\s+', '', after)
614-
elif bool(match('[ \t]+\S', after)):
614+
elif bool(match(r'[ \t]+\S', after)):
615615
# If the next character after the end of the environment is
616616
# not whitespace (usually not allowed), we can just leave
617617
# the `\n` in printed content, and it will yield a space.
618618
# So we need do nothing. But if there is text on that line
619619
# we need `\space{}`.
620-
after = sub('^\s+', '\\space', after)
620+
after = sub(r'^\s+', '\\space', after)
621621
forced_double_space_list.append((name, linenum))
622622
else:
623623
# If the line at the end of the environment is blank,
@@ -1080,7 +1080,7 @@ def replace_print_env(name, arglist, linenum,
10801080
else:
10811081
if obeylines:
10821082
# Take into account possible whitespace before arg
1083-
if bool(match('[ \t]*\[', after)):
1083+
if bool(match(r'[ \t]*\[', after)):
10841084
after = after.split('[', 1)[1]
10851085
while ']' not in after:
10861086
texlinenum += 1
@@ -1094,11 +1094,11 @@ def replace_print_env(name, arglist, linenum,
10941094
after = sub('^[ \t]*', '', after)
10951095
else:
10961096
# Allow peeking ahead a line for the argument
1097-
if bool(match('\s*$', after)) and after.count('\n') < 2:
1097+
if bool(match(r'\s*$', after)) and after.count('\n') < 2:
10981098
texlinenum += 1
10991099
after += tex[texlinenum]
11001100
# Take into account possible whitespace before arg
1101-
if bool(match('\s*\[', after)):
1101+
if bool(match(r'\s*\[', after)):
11021102
after = after.split('[', 1)[1]
11031103
while ']' not in after:
11041104
texlinenum += 1
@@ -1108,11 +1108,11 @@ def replace_print_env(name, arglist, linenum,
11081108
optarg = None
11091109
# Account for eating whitespace afterward, if arg not found
11101110
if argindex == len(depy_args) - 1:
1111-
if bool(match('\s*$', after)) and after.count('\n') < 2:
1111+
if bool(match(r'\s*$', after)) and after.count('\n') < 2:
11121112
texlinenum += 1
11131113
after += tex[texlinenum]
1114-
if not bool(match('\s*$', after)):
1115-
after = sub('^\s*', '', after)
1114+
if not bool(match(r'\s*$', after)):
1115+
after = sub(r'^\s*', '', after)
11161116
arglist.append(optarg)
11171117
elif arg == 'm':
11181118
# Account for possible line breaks or spaces before arg
@@ -1121,18 +1121,18 @@ def replace_print_env(name, arglist, linenum,
11211121
else:
11221122
if obeylines:
11231123
# Account for possible leading whitespace
1124-
if bool(match('[ \t\f\v]*\{', after)):
1124+
if bool(match(r'[ \t\f\v]*\{', after)):
11251125
after = after.split('{', 1)[1]
11261126
else:
11271127
print('* DePythonTeX error:')
11281128
print(' Flawed mandatory argument for "' + depy_name + '" on line ' + str(depy_linenum))
11291129
sys.exit(1)
11301130
else:
11311131
# Peek ahead a line if needed
1132-
if bool(match('\s*$', after)) and after.count('\n') < 2:
1132+
if bool(match(r'\s*$', after)) and after.count('\n') < 2:
11331133
texlinenum += 1
11341134
after += tex[texlinenum]
1135-
if bool(match('\s*\{', after)):
1135+
if bool(match(r'\s*\{', after)):
11361136
after = after.split('{', 1)[1]
11371137
else:
11381138
print('* DePythonTeX error:')
@@ -1338,7 +1338,7 @@ def replace_print_env(name, arglist, linenum,
13381338
after = tex[texlinenum]
13391339
break
13401340
after = after.split(end_environment, 1)[1]
1341-
if bool(match('\s*\n', after)):
1341+
if bool(match(r'\s*\n', after)):
13421342
# If the line following `after` is whitespace, it should
13431343
# be stripped, since most environments throw away
13441344
# anything after the end of the environment
@@ -1389,7 +1389,7 @@ def replace_print_env(name, arglist, linenum,
13891389
# Take care of graphicspath
13901390
if args.graphicspath and settings['graphicx']:
13911391
for n, line in enumerate(texout):
1392-
if '\\graphicspath' in line and not bool(match('\s*%', line)):
1392+
if '\\graphicspath' in line and not bool(match(r'\s*%', line)):
13931393
texout[n] = line.replace('\\graphicspath{', '\\graphicspath{{' + settings['outputdir'] +'/}')
13941394
break
13951395
elif line.startswith(r'\begin{document}'):

pythontex/pythontex3.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def do_upgrade_compatibility(data, old_data, temp_data):
554554
It will continue to use the output directory for now. To keep your
555555
current settings long-term and avoid seeing this message in the future,
556556
add the following command to the preamble of your document, right after
557-
the "\\usepackage{pythontex}": "\setpythontexworkingdir{<outputdir>}".
557+
the "\\usepackage{pythontex}": "\\setpythontexworkingdir{<outputdir>}".
558558
If you wish to continue with the new settings instead, simply delete
559559
the file with extension .pkl in the output directory, and run PythonTeX.
560560
**** End PythonTeX upgrade message ****
@@ -1807,7 +1807,7 @@ def run_code(encoding, outputdir, workingdir,
18071807
# Get the gobbleation. This is used to determine if
18081808
# other lines containing the basename are a continuation,
18091809
# or separate messages.
1810-
errgobble = match('(\s*)', line).groups()[0]
1810+
errgobble = match(r'(\s*)', line).groups()[0]
18111811
if start_errgobble is None:
18121812
start_errgobble = errgobble
18131813
# Only issue a message and track down the line numer if
@@ -2072,7 +2072,7 @@ def run_code(encoding, outputdir, workingdir,
20722072
# Get the gobbleation. This is used to determine if
20732073
# other lines containing the basename are a continuation,
20742074
# or separate messages.
2075-
errgobble = match('(\s*)', line).groups()[0]
2075+
errgobble = match(r'(\s*)', line).groups()[0]
20762076
if start_errgobble is None:
20772077
start_errgobble = errgobble
20782078
# Only issue a message and track down the line numer if

0 commit comments

Comments
 (0)