Skip to content
Snippets Groups Projects
Verified Commit cbe34878 authored by Simon Josef Thür's avatar Simon Josef Thür
Browse files

fix references, compile all .tex with \begindocument

parent 44e9d6fc
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,7 @@
\usepackage{enumitem}
\setlist[itemize]{noitemsep}
\usepackage{xr-hyper}
\usepackage{url}
\usepackage[pdfusetitle]{hyperref}
\hypersetup{
......
......@@ -29,7 +29,10 @@ outfile = 'Formelblatt.tex'
COMPILE_IMMEDIATELY = True # if False, you need to compile manually
PRECOMPILE_DEPENDENCIES = True # if False, may cause incorrect references
precompile_files = ['semiconductor_summary.tex']
AUTOMATICALLY_FIND_DEPENDENCIES = True # if True, will compile all main .tex
# files. If False, specify dependencies below
PRECOMPILE_FILES = ['semiconductor_summary.tex'] # specify dependencies here
shell_command = f"latexmk -pdf"
......@@ -136,31 +139,44 @@ def get_section(filename):
return re.findall(r'\\section{(.+)}', data)[0]
def is_main_tex(filename):
with open(filename, 'r') as f:
data = f.read()
return bool(re.findall(r'\\begin{document}', data))
def main():
print("==============================\n"
"Generate Cheat Sheet\n"
"==============================")
ref_list = ""
parse_list = ""
eq_list = ""
dep = []
print("Writing preamble...")
print("Parsing files...")
for f in get_files():
print(4*' '+f)
tags = get_tags(f)
if is_main_tex(f):
ref_list += f"\externaldocument{{{f[:-4]}}}\n"
dep.append(f)
if tags:
print(8*' '+str(tags))
eq_list += f" {get_section(f)}\n"
for t in tags:
st = "\\"+t
parse_list += f" \\CatchFileBetweenTags{{{st}}}{{{f}}}{{{t}}}\n"
eq_list += f" \\Eq{{{st}}}{{{t}}}\n"
print("Writing document...")
with open(outfile, 'w') as o:
o.write(packages)
o.write("\n\n")
o.write(new_commands)
o.write("\n\n")
print("Parsing files...")
for f in get_files():
print(4*' '+f)
tags = get_tags(f)
if tags:
print(8*' '+str(tags))
o.write(f"\externaldocument{{{f[:-4]}}}\n")
eq_list += f" {get_section(f)}\n"
for t in tags:
st = "\\"+t
parse_list += f" \\CatchFileBetweenTags{{{st}}}{{{f}}}{{{t}}}\n"
eq_list += f" \\Eq{{{st}}}{{{t}}}\n"
print("Writing document...")
o.write(ref_list)
o.write(start_doc)
o.write("\n %%%%%%%%%%\n")
o.write(parse_list)
......@@ -170,8 +186,10 @@ def main():
o.write(end_doc)
sh = shell_command
if PRECOMPILE_DEPENDENCIES and precompile_files:
sh = shell_command + f" {' '.join(precompile_files)}"
compile_list = dep if AUTOMATICALLY_FIND_DEPENDENCIES else PRECOMPILE_FILES
if PRECOMPILE_DEPENDENCIES and compile_list:
sh = shell_command + f" {' '.join(compile_list)}"
sh = sh + f" {outfile}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment