Compare commits
2 Commits
1118341f26
...
5e34464718
Author | SHA1 | Date | |
---|---|---|---|
5e34464718 | |||
c6ce3bbd23 |
44
unifytex
Executable file
44
unifytex
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/python3
|
||||
|
||||
import os
|
||||
import argparse
|
||||
|
||||
def dynamic_includes(folder_path):
|
||||
"""Generate separate LaTeX files recursively"""
|
||||
consolidated_dir = os.path.join(os.getcwd(), "consolidated")
|
||||
os.makedirs(consolidated_dir, exist_ok=True)
|
||||
|
||||
for root, dirs, files in os.walk(folder_path):
|
||||
if not files or os.path.abspath(root) == os.path.abspath(consolidated_dir):
|
||||
continue
|
||||
|
||||
if root == folder_path:
|
||||
folder_name = os.path.basename(folder_path) or "root"
|
||||
else:
|
||||
folder_name = os.path.basename(root)
|
||||
|
||||
output_file = os.path.join(consolidated_dir, f"{folder_name}.tex")
|
||||
|
||||
with open(output_file, "w") as f:
|
||||
f.write("% Autogenerated by unifytex (git.confest.im/boyan_k/Coding_Tools/)\n")
|
||||
for file in sorted(files):
|
||||
if file.endswith(".tex"):
|
||||
relative_path = os.path.relpath(os.path.join(root, file), folder_path)
|
||||
f.write(f"\\input{{{relative_path}}}\n")
|
||||
|
||||
print(f"Generated {output_file}")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Generate separate LaTeX include files for .tex files recursively")
|
||||
parser.add_argument("directory", help="The directory to process.")
|
||||
args = parser.parse_args()
|
||||
|
||||
directory = args.directory
|
||||
|
||||
if not os.path.isdir(directory):
|
||||
raise FileNotFoundError(f"Error: The directory '{directory}' does not exist.")
|
||||
|
||||
dynamic_includes(directory)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user