Skip to content

Instantly share code, notes, and snippets.

@florianrusch
Last active June 13, 2018 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianrusch/d9f2af5e71101248b1587c63ca0b4558 to your computer and use it in GitHub Desktop.
Save florianrusch/d9f2af5e71101248b1587c63ca0b4558 to your computer and use it in GitHub Desktop.
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