Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
__version__ = "1.0"
__date__ = "20170621"
__author__ = "kthoden@mpiwg-berlin.mpg.de"
import sys
import re
# to be dealt with: EOAfigure
regex_replacements = {
r'\$\$(.*?)\$\$' : r"\\begin{EOAequationnonumber}\g<1>\\end{EOAequationnonumber}",
r'\$(.*?)\$' : r"\\EOAineq{\g<1>}",
r'\\section' : r"\\EOAsection",
r'{\\em' : r"\\EOAemph{",
r'\\begin{equation}' : r"\\begin{EOAequation}{equation_label}",
r'\\end{equation}' : r"\\end{EOAequation}",
r'\\(begin|end){quote}' : r"\\\g<1>{EOAquote}",
r'\\(begin|end){itemize}' : r"\\\g<1>{EOAitems}",
r'\\label' : r"\\EOAlabel",
r'\\ref' : r"\\EOAref",
r'\\citet' : r"\\EOAciteauthoryear",
r'{\\bf' : r"\\EOAbold{",
r'\\footnote' : r"\\EOAfn",
r'\\bibliography{' : r"\\EOAbibliographydatabase{"
}
def find_latex_commands(string):
"""Finds latex commands in a text, return a list of unique
occurrences.
"""
command_pattern = re.compile(r'\\[a-zA-Z0-9]+', re.UNICODE)
found_commands = set(re.findall(command_pattern, string))
return found_commands
# def find_latex_commands ends here
def main(infile):
"""The main bit"""
with open(infile, 'r') as input_file:
data = input_file.read()
# list_of_commands = find_latex_commands(data)
# print(list_of_commands)
for instance in regex_replacements.keys():
data = re.sub(instance, regex_replacements[instance], data)
print(data)
# def main ends here
if __name__ == '__main__':
infile = sys.argv[-1]
main(infile)
# finis