This commit is contained in:
Sebastian
2022-03-15 22:53:32 +01:00
commit eb595430ff
2 changed files with 138 additions and 0 deletions

10
README.md Normal file
View File

@@ -0,0 +1,10 @@
# finalize.py
Some dirty hacks for pandoc
## usage
`python3 finalize.py input.tex`
## ....

128
finalize.py Normal file
View File

@@ -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()