Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replaces the `\import` LaTeX command with the contend of the imported file
#!/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
You can’t perform that action at this time.