Skip to content
Snippets Groups Projects
Commit 80f3dce1 authored by BARTHES Nicolas's avatar BARTHES Nicolas
Browse files

report.py callable from anywhere (fixed Paths and cwd)

parent 8d393d66
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -23,7 +23,7 @@ def report(*argv): ...@@ -23,7 +23,7 @@ def report(*argv):
\headrulecolor{red!100}% \headrulecolor{red!100}%
\renewcommand{\footrulewidth}{1pt} \renewcommand{\footrulewidth}{1pt}
\footrulecolor{red!100}% \footrulecolor{red!100}%
\graphicspath{{images/}, {Figures/}}
\fancyhf{} \fancyhf{}
\fancyhead[R]{\includegraphics[width=0.1\textwidth]{logo_cefe.png}} \fancyhead[R]{\includegraphics[width=0.1\textwidth]{logo_cefe.png}}
\fancyhead[L]{PACE - NIRS Analysis Report} \fancyhead[L]{PACE - NIRS Analysis Report}
...@@ -187,33 +187,33 @@ def report(*argv): ...@@ -187,33 +187,33 @@ def report(*argv):
\end{document}""" \end{document}"""
# export the .tex file in the Report folder # export the .tex file in the Report folder
filename_path = Path("Report/")
filename = r'report.tex' filename = r'report.tex'
with open(filename, 'w') as latex_file: with open(filename_path / filename, 'w+') as latex_file:
latex_file.write(latex_report) latex_file.write(latex_report)
# create the Tex file - sections in args will be displayed: {'sample':'Sample Selection';'model':'Model Creation';'predict':'Predictions';'help':'LaTEX help for figs and tables';} # create the Tex file - sections in args will be displayed: {'sample':'Sample Selection';'model':'Model Creation';'predict':'Predictions';'help':'LaTEX help for figs and tables';}
# latex_report = report('sample', 'predict',) latex_report = report('sample', 'predict',)
def compile_latex(): def compile_latex():
# path to pdflatex # path to pdflatex
pdflatex_path = Path("C:/Donnees/Logiciels/Papps/PortableApps/Notepad++Portable/LaTEX/texmfs/install/miktex/bin/") pdflatex_path = Path("C:/Donnees/Logiciels/Papps/PortableApps/Notepad++Portable/LaTEX/texmfs/install/miktex/bin/")
filename_path = Path("Report/")
filename = 'report.tex' filename = 'report.tex'
# run pdflatex with bibtex compilation (2nd run) # run pdflatex with bibtex compilation (2nd run)
proc = subprocess.Popen([pdflatex_path / 'pdflatex.exe', filename]) for i in range(4):
proc.communicate() print(i)
proc = subprocess.Popen([pdflatex_path / 'bibtex.exe', filename[:-4]]) if i == 1:
proc.communicate() proc = subprocess.Popen([pdflatex_path / 'bibtex.exe', filename[:-4]], cwd = filename_path)
proc = subprocess.Popen([pdflatex_path / 'pdflatex.exe', filename]) proc.communicate()
proc.communicate() else:
proc = subprocess.Popen([pdflatex_path / 'pdflatex.exe', filename]) proc = subprocess.Popen([pdflatex_path / 'pdflatex.exe', filename], cwd = filename_path)
proc.communicate() proc.communicate()
# remove pdflatex compilation files # remove pdflatex compilation files
os.unlink(filename[:-4] + '.log') extensions = ['.log', '.aux', '.bbl', '.blg', '.out']
os.unlink(filename[:-4] + '.aux') for ext in extensions:
os.unlink(filename[:-4] + '.bbl') os.unlink(str(filename_path / filename[:-4]) + ext)
os.unlink(filename[:-4] + '.blg')
os.unlink(filename[:-4] + '.out')
# open the report # open the report
proc = subprocess.Popen([filename[:-4] + '.pdf'], shell=True) proc = subprocess.Popen([str(filename[:-4]) + '.pdf'], cwd = filename_path, shell=True)
proc.communicate() proc.communicate()
# compile_latex() compile_latex()
\ No newline at end of file \ No newline at end of file
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