From eb595430ff261c0e2da9749831f76ae8fc15f5d3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 15 Mar 2022 22:53:32 +0100 Subject: [PATCH] initial --- README.md | 10 ++++ finalize.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 README.md create mode 100644 finalize.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..c6932af --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# finalize.py + +Some dirty hacks for pandoc + +## usage + +`python3 finalize.py input.tex` + + +## .... diff --git a/finalize.py b/finalize.py new file mode 100644 index 0000000..cc35f34 --- /dev/null +++ b/finalize.py @@ -0,0 +1,128 @@ +#!/usr/bin/python +import sys, os +from subprocess import Popen, PIPE + +if len(sys.argv) < 2: + print ("Something is missing! Please provide filename") + exit(1) + +replaces = [ + { + "replace" : "\section*{Abkürzungsverzeichnis}", + "with" :"\section{Abkürzungsverzeichnis}", + }, + { + "replace": "\section*{Literaturverzeichnis}\label{bibliography}}", + "with": "\section{Literaturverzeichnis}\label{bibliography}}" + }, + + { + "replace" : "\\addcontentsline{toc}{section}{Literaturverzeichnis}", + "with": "" + }, + { + "replace" : "\\addcontentsline{toc}{section}{Abkürzungsverzeichnis}", + "with": "" + }, + { + "replace" : "\hypertarget{bibliography}{%", + "with": """% -------------------------------------------------------------- +% Verzeichnisse +% -------------------------------------------------------------- +\pagebreak % wird benötigt um den header erst auf der folgeseite beginnen zu lassen. +\lhead{} % remove the left part of header + +% Nachspann +\\renewcommand{\\thesection}{\Roman{section}} +\\renewcommand{\\theHsection}{\Roman{section}} +\setcounter{section}{1} +\pagenumbering{Roman} +\setcounter{page}{3} + +\makeatletter +\\renewcommand\listoffigures{% + \section{\listfigurename}% + \@mkboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}% + \@starttoc{lof}% +} +\\renewcommand\listoftables{% + \section{\listtablename}% + \@mkboth{\MakeUppercase\listtablename}{\MakeUppercase\listtablename}% + \@starttoc{lot}% +} +\makeatother + + +\\rhead{LITERATURVERZEICHNIS} + + +\hypertarget{bibliography}{%""" + }, + { + "replace" : """\end{CSLReferences} + +% -------------------------------------------------------------- +% Verzeichnisse +% -------------------------------------------------------------- +\pagebreak % wird benötigt um den header erst auf der folgeseite beginnen zu lassen. +\lhead{} % remove the left part of header + + +% Nachspann +\\renewcommand{\\thesection}{\Roman{section}} +\\renewcommand{\\theHsection}{\Roman{section}} +\pagenumbering{Roman} + +% Pagebreak after each Section +%\let\oldsection\section +%\\renewcommand\section{\clearpage\oldsection} + +%\setcounter{section}{2} +%\setcounter{page}{2} + +% -------------------------------------------------------------- +% Abkürzungsverzeichnis +% --------------------------------------------------------------""", + "with": " " + + } + + ] + + +filename = sys.argv[1] + +try: + ffile = open(filename,"r") +except FileNotFoundError: + print( "Du dumm? File gibts nicht :O ...") + exit (1) + +filestr = ffile.read() + +outfile = open(filename + '.fixed', "w") + + +for replacer in replaces: + print ( "replace ", replacer["replace"] , " ---> ", replacer["with"] ) + filestr = filestr.replace(replacer["replace"], replacer["with"]) + + +print(filestr , file=outfile) + + +pdflatexcall = ["pdflatex","--interaction=batchmode", filename + '.fixed', "2>&1 > /dev/null"] + +print ("Calling pdflatex 3 times now...") +print ("Commandline: ", pdflatexcall) + +for i in range(1,5): + print ("Run #", str(i)) + #os.popen(pdflatexcall) + process = Popen(pdflatexcall, stdout=PIPE) + (output, err) = process.communicate() + exit_code = process.wait() + + +outfile.close() +ffile.close()