Last active
June 19, 2019 08:26
-
-
Save moritzschaefer/2c290cb92ebcab644819e1f87ff54adc to your computer and use it in GitHub Desktop.
Revisions
-
Moritz revised this gist
Jun 19, 2019 . 1 changed file with 20 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,21 +2,31 @@ import sys import re import argparse parser = argparse.ArgumentParser(description='Postprocess/fix org mode tex output') parser.add_argument('--dont-replace-fig-labels', action='store_true') parser.add_argument('--dont-delete-file-output', action='store_true') parser.add_argument('infile', type=str) parser.add_argument('outfile', type=str) args = parser.parse_args() with open(args.infile, 'r') as inf: content = inf.read() if not args.dont_delete_file_output: content = re.sub(r'\[\[file:\\# Out\[[0-9]*?\]:(.*?)\]\]', r'\1', content, flags=re.MULTILINE | re.DOTALL) # now rename the figures if not args.dont_replace_fig_labels: for i, label_match in enumerate(re.finditer(r'\\label\{(fig:.*?)\}', content)): label = label_match.groups()[0] content = content.replace(f'\\label{{{label}}}', f'Figure {i+1}: ') content = content.replace(f'\\ref{{{label}}}', f'{i+1}') with open(args.outfile, 'w') as outf: outf.write(content) -
Moritz revised this gist
May 27, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ with open(infile, 'r') as inf: content = inf.read() content = re.sub(r'\[\[file:\\# Out\[[0-9]*?\]:(.*?)\]\]', r'\1', content, flags=re.MULTILINE | re.DOTALL) # now rename the figures for i, label_match in enumerate(re.finditer(r'\\label\{(fig:.*?)\}', content)): label = label_match.groups()[0] -
Moritz created this gist
May 24, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/usr/bin/env python import sys import re infile, outfile = sys.argv[1:3] replace_labels_re = re.compile(r'\\label\{fig:(.*?)}') with open(infile, 'r') as inf: content = inf.read() content = re.sub(r'\[\[file:\\# Out\[[0-9]*?\]:(.*)\]\]', r'\1', content, flags=re.MULTILINE | re.DOTALL) # now rename the figures for i, label_match in enumerate(re.finditer(r'\\label\{(fig:.*?)\}', content)): label = label_match.groups()[0] content = content.replace(f'\\label{{{label}}}', f'\emph{{Figure {i+1}}}') content = content.replace(f'\\ref{{{label}}}', f'{i+1}') with open(outfile, 'w') as outf: outf.write(content)