Last active
June 13, 2018 11:40
-
-
Save florianrusch/d9f2af5e71101248b1587c63ca0b4558 to your computer and use it in GitHub Desktop.
Replaces the `\import` LaTeX command with the contend of the imported file
This file contains 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 characters
#!/usr/bin/python | |
import re | |
_INPUT_FILE = 'input.tex' | |
_OUTPUT_FILE = 'output.tex' | |
_BASE_PATH = './Ausarbeitung/' | |
_PATTERN = r'(?<=\\import{)(.*)(?=})' | |
def file_get_contents(filename): | |
contents = "" | |
with open(_BASE_PATH + filename) as f: | |
for line in f.readlines(): | |
contents += line | |
return contents | |
def main(): | |
filecontent = file_get_contents(_INPUT_FILE) | |
pattern = re.compile(_PATTERN) | |
matches = pattern.findall(filecontent) | |
if matches is not None: | |
for match in matches: | |
subfile = file_get_contents(re.sub('}{', '', match) + '.tex') | |
filecontent = filecontent.replace('\import{' + match + '}', subfile) | |
output = open(_OUTPUT_FILE, "w"); | |
output.write(filecontent) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment