Last active
March 9, 2017 02:20
-
-
Save filipemeneses/062299582f3beaa68cd12ad432472b4c to your computer and use it in GitHub Desktop.
Merge Latex files while working in individual files
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
% Many Latex configurations | |
\begin{document} | |
\section{File 1} | |
\end{document} |
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
% Many Latex configurations | |
\begin{document} | |
\section{File 2} | |
\end{document} |
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
% Many Latex configurations | |
\begin{document} | |
\input{./merged.tex} | |
\end{document} |
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
import re | |
def file_get_contents(filename): | |
with open(filename) as f: | |
return f.read() | |
def file_put_contents(filename, data): | |
with open(filename, 'w') as f: | |
f.write(data) | |
f.close() | |
files = [ | |
'./file_1.tex', | |
'./file_2.tex', | |
] | |
merge = '' | |
for _file in files: | |
a = file_get_contents(_file) | |
m = re.match(r'[\s\S]*begin\{document\}([\s\S]*)\\end\{document\}', a) | |
if (m): | |
merge += m.group(1) | |
else: | |
print('Document content not found.') | |
file_put_contents('./merged.tex', merge) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment