@@ -121,7 +121,7 @@ def replace_code_cmd(name, arglist, linenum, code_replacement,
121
121
122
122
Usually, code from a command is also typeset with a command. This
123
123
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`),
125
125
this function performs some preprocessing and then uses
126
126
replace_code_env() to do the real work. This approach prevents the two
127
127
functions from unnecessarily duplicating each other, while still giving
@@ -161,7 +161,7 @@ def replace_code_cmd(name, arglist, linenum, code_replacement,
161
161
# Make sure the introduction of an environment where a command was
162
162
# previously won't produce errors with following content; make sure
163
163
# that any following content is on a separate line
164
- if bool (match ('[ \t ]*\S' , after )):
164
+ if bool (match (r '[ \t]*\S' , after )):
165
165
after = '\n ' + after
166
166
# Rather than duplicating much of replace_code_env(), just use it
167
167
return replace_code_env (name , arglist , linenum , code_replacement ,
@@ -333,7 +333,7 @@ def replace_print_cmd(name, arglist, linenum,
333
333
break
334
334
print_replacement = r'\verb' + delim + print_replacement + delim
335
335
elif print_replacement_mode == 'verbatim' :
336
- if bool (match ('\s*?\n ' , after )):
336
+ if bool (match (r '\s*?\n' , after )):
337
337
# Usually, we would end the verbatim environment with a newline.
338
338
# This is fine if there is content in `after` before the next
339
339
# newline---in fact, it's desirable, because the verbatim package
@@ -405,11 +405,11 @@ def replace_print_cmd(name, arglist, linenum,
405
405
# the `\input` content.
406
406
print_replacement = print_replacement .rstrip (' \t \n ' )
407
407
after = sub (r'^\\unskip\s+' , '' , after )
408
- elif bool (match ('\S' , after )):
408
+ elif bool (match (r '\S' , after )):
409
409
# If the next character is not whitespace, we can just leave
410
410
# the `\n`, and it will yield a space.
411
411
pass
412
- elif bool (match ('\s*$' , after )):
412
+ elif bool (match (r '\s*$' , after )):
413
413
# If the rest of the current line, and the next line, are
414
414
# whitespace, we will get the correct spacing without needing
415
415
# `\space{}`. We could leave `\n`, but it would be
@@ -421,14 +421,14 @@ def replace_print_cmd(name, arglist, linenum,
421
421
# it's at the end of an environment, and thus is needed to
422
422
# protect the following content
423
423
print_replacement += '\\ space{}'
424
- after = sub ('^\s+' , '' , after )
424
+ after = sub (r '^\s+' , '' , after )
425
425
forced_double_space_list .append ((name , linenum ))
426
426
else :
427
- if bool (match ('\s+\S' , after )):
427
+ if bool (match (r '\s+\S' , after )):
428
428
# If the following line starts with whitespace, replace it
429
429
# with a newline, to protect in the event that the printed
430
430
# content ended with an end-of-environment command
431
- after = sub ('^\s+' , '\n ' , after )
431
+ after = sub (r '^\s+' , '\n ' , after )
432
432
# Issue warnings, if warranted
433
433
# Warn about `\endinput`
434
434
if (r'\endinput' in print_replacement and
@@ -505,7 +505,7 @@ def replace_print_env(name, arglist, linenum,
505
505
506
506
#### The inlineverb and verb modes should work, but haven't been tested
507
507
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.
509
509
'''
510
510
if print_replacement_mode == 'verb' :
511
511
if print_replacement .count ('\n ' ) > 1 :
@@ -519,17 +519,17 @@ def replace_print_env(name, arglist, linenum,
519
519
if delim not in print_replacement :
520
520
break
521
521
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 )):
523
523
# If there is text on the same line as the end of the
524
524
# environment, we're fine (this is unusual). Otherwise,
525
525
# we need to toss the newline at the end of the environment
526
526
# and gobble leading spaces. Leading spaces need to be
527
527
# gobbled because previously they were at the beginning of a
528
528
# 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 )
531
531
elif print_replacement_mode == 'verbatim' :
532
- if bool (match ('\s*?\n ' , after )):
532
+ if bool (match (r '\s*?\n' , after )):
533
533
# Usually, we would end the verbatim environment with a newline.
534
534
# This is fine if there is content in `after` before the next
535
535
# newline---in fact, it's desirable, because the verbatim package
@@ -570,15 +570,15 @@ def replace_print_env(name, arglist, linenum,
570
570
# printed content. Later, we issue a warning in case it appears
571
571
# anywhere else.
572
572
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 )):
574
574
# If there is text on the same line as the end of the
575
575
# environment, we're fine (this is unusual). Otherwise,
576
576
# we need to toss the newline at the end of the environment
577
577
# and gobble leading spaces. Leading spaces need to be
578
578
# gobbled because previously they were at the beginning of a
579
579
# 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 )
582
582
elif (print_replacement .endswith ('%\n ' ) and
583
583
not print_replacement .endswith ('\\ %\n ' ) and
584
584
not print_replacement .endswith ('\\ string%\n ' )):
@@ -590,15 +590,15 @@ def replace_print_env(name, arglist, linenum,
590
590
# warning if there is reason to think that a percent character
591
591
# was active in the last line.
592
592
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 )):
594
594
# If there is text on the same line as the end of the
595
595
# environment, we're fine (this is unusual). Otherwise,
596
596
# we need to toss the newline at the end of the environment
597
597
# and gobble leading spaces. Leading spaces need to be
598
598
# gobbled because previously they were at the beginning of a
599
599
# 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 )
602
602
else :
603
603
# By default, LaTeX strips newlines and adds a space at the end
604
604
# of each line of content that is brought in by `\input`. This
@@ -611,13 +611,13 @@ def replace_print_env(name, arglist, linenum,
611
611
# `\unskip`
612
612
print_replacement = print_replacement .rstrip (' \t \n ' )
613
613
after = sub (r'^\s*\\unskip\s+' , '' , after )
614
- elif bool (match ('[ \t ]+\S' , after )):
614
+ elif bool (match (r '[ \t]+\S' , after )):
615
615
# If the next character after the end of the environment is
616
616
# not whitespace (usually not allowed), we can just leave
617
617
# the `\n` in printed content, and it will yield a space.
618
618
# So we need do nothing. But if there is text on that line
619
619
# we need `\space{}`.
620
- after = sub ('^\s+' , '\\ space' , after )
620
+ after = sub (r '^\s+' , '\\ space' , after )
621
621
forced_double_space_list .append ((name , linenum ))
622
622
else :
623
623
# If the line at the end of the environment is blank,
@@ -1080,7 +1080,7 @@ def replace_print_env(name, arglist, linenum,
1080
1080
else :
1081
1081
if obeylines :
1082
1082
# Take into account possible whitespace before arg
1083
- if bool (match ('[ \t ]*\[' , after )):
1083
+ if bool (match (r '[ \t]*\[' , after )):
1084
1084
after = after .split ('[' , 1 )[1 ]
1085
1085
while ']' not in after :
1086
1086
texlinenum += 1
@@ -1094,11 +1094,11 @@ def replace_print_env(name, arglist, linenum,
1094
1094
after = sub ('^[ \t ]*' , '' , after )
1095
1095
else :
1096
1096
# 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 :
1098
1098
texlinenum += 1
1099
1099
after += tex [texlinenum ]
1100
1100
# Take into account possible whitespace before arg
1101
- if bool (match ('\s*\[' , after )):
1101
+ if bool (match (r '\s*\[' , after )):
1102
1102
after = after .split ('[' , 1 )[1 ]
1103
1103
while ']' not in after :
1104
1104
texlinenum += 1
@@ -1108,11 +1108,11 @@ def replace_print_env(name, arglist, linenum,
1108
1108
optarg = None
1109
1109
# Account for eating whitespace afterward, if arg not found
1110
1110
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 :
1112
1112
texlinenum += 1
1113
1113
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 )
1116
1116
arglist .append (optarg )
1117
1117
elif arg == 'm' :
1118
1118
# Account for possible line breaks or spaces before arg
@@ -1121,18 +1121,18 @@ def replace_print_env(name, arglist, linenum,
1121
1121
else :
1122
1122
if obeylines :
1123
1123
# Account for possible leading whitespace
1124
- if bool (match ('[ \t \f \v ]*\{' , after )):
1124
+ if bool (match (r '[ \t\f\v]*\{' , after )):
1125
1125
after = after .split ('{' , 1 )[1 ]
1126
1126
else :
1127
1127
print ('* DePythonTeX error:' )
1128
1128
print (' Flawed mandatory argument for "' + depy_name + '" on line ' + str (depy_linenum ))
1129
1129
sys .exit (1 )
1130
1130
else :
1131
1131
# 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 :
1133
1133
texlinenum += 1
1134
1134
after += tex [texlinenum ]
1135
- if bool (match ('\s*\{' , after )):
1135
+ if bool (match (r '\s*\{' , after )):
1136
1136
after = after .split ('{' , 1 )[1 ]
1137
1137
else :
1138
1138
print ('* DePythonTeX error:' )
@@ -1338,7 +1338,7 @@ def replace_print_env(name, arglist, linenum,
1338
1338
after = tex [texlinenum ]
1339
1339
break
1340
1340
after = after .split (end_environment , 1 )[1 ]
1341
- if bool (match ('\s*\n ' , after )):
1341
+ if bool (match (r '\s*\n' , after )):
1342
1342
# If the line following `after` is whitespace, it should
1343
1343
# be stripped, since most environments throw away
1344
1344
# anything after the end of the environment
@@ -1389,7 +1389,7 @@ def replace_print_env(name, arglist, linenum,
1389
1389
# Take care of graphicspath
1390
1390
if args .graphicspath and settings ['graphicx' ]:
1391
1391
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 )):
1393
1393
texout [n ] = line .replace ('\\ graphicspath{' , '\\ graphicspath{{' + settings ['outputdir' ] + '/}' )
1394
1394
break
1395
1395
elif line .startswith (r'\begin{document}' ):
0 commit comments