Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import os
import subprocess
def report(*argv):
to_report=[]
for arg in argv:
to_report.append(arg)
latex_report = ""
latex_report += r"""\documentclass[a4paper,10pt]{article}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{geometry}
\geometry{a4paper, left=2cm, right=2cm, top=1.5cm, bottom=3cm }
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}
\usepackage{hyphenat}
\usepackage{etoolbox,fancyhdr,xcolor}
\newcommand{\headrulecolor}[1]{\patchcmd{\headrule}{\hrule}{\color{#1}\hrule}{}{}}
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\headrulewidth}{1pt}
\headrulecolor{red!100}%
\renewcommand{\footrulewidth}{1pt}
\footrulecolor{red!100}%
\fancyhf{}
\fancyhead[R]{\includegraphics[width=0.1\textwidth]{logo_cefe.png}}
\fancyhead[L]{PACE - NIRS Analysis Report}
\fancyfoot[L]{Project Name to fill}
\fancyfoot[C]{Plateforme d'Analyses Chimiques en Ecologie}
\fancyfoot[R]{\thepage}
\setlength{\headheight}{15mm}
\pagestyle{fancy}
\usepackage{times}
\begin{document}
\noindent
\begin{center}
\textbf{{\Large NIRS WORKFLOW REPORT}} \\
\end{center}"""
if 'sample' in to_report:
latex_report += r"""\noindent
\textbf{QUERY: } You asked for Sample selection.
Specify bibliographic refs \cite{Lesnoff2020} to describe the algorithms used.\\
\noindent
\textbf{INPUTS:} Specify here input file names \& parameters.\\
"""
if 'model' in to_report:
latex_report += r"""\noindent
\textbf{QUERY: } You asked for Model creation.
Specify bibliographic refs \cite{scikit-learn} to describe the algorithms used.\\
\noindent
\textbf{INPUTS:} Specify here input file names \& parameters.
"""
if 'predict' in to_report:
latex_report += r"""\noindent
\textbf{QUERY: } You asked for Predictions.
Specify bibliographic refs \cite{scikit-learn} to describe the algorithms used.\\
\noindent
\textbf{INPUTS:} Specify here input file names \& parameters.
"""
latex_report += r"""\section*{RESULTS}
Please follow this template exactly and DO NOT CHANGE THE FONT SIZE, MARGINS, HEADER, FOOTER, ETC OF THE TEMPLATE.
Start typing your paper in this font in this way. Section headings are to be in 10pt bold and full caps. Number headings consecutively. Leave a single blank line before each Section Heading and one blank line between the heading and the first line of text. When you want to start a new paragraph do not drop a line do it simply like this. Use MS Word/Latex formatting exactly as given in this paragraph. Do NOT change the spacing 'before' and 'after' to try and squeeze more in.
This is now a new paragraph which starts with a tab space and when you are starting new sentences you must put a space after the full stop. Just like this. Text should be single spaced, left and right justified, providing 25.4mm left margin and 25.4mm right margin. Leave a 25.4mm margin at top and a 25.4mm margin at bottom and the page size should be set as A4. You will also notice that the font to use is Times New Roman and the font size is 10pt.
"""
if 'sample' in to_report:
latex_report += r"""\subsection*{Data Visualization}
Here we have a sub-heading. There is no blank line after the sub-heading. You can have one level of subheadings but not a third i.e. you cannot have Section 1.1.1 as a subheading.
\begin{itemize}
\item If you want to list bullet points you can do so;
\item This is the second point;
\item This is a third bullet point;
\item A fourth bullet point;
\item But you can.
\end{itemize}
After a list you must leave a single blank line and remember to add the indent if you are starting a new paragraph.
"""
if 'model' in to_report:
latex_report += r"""
\subsection*{Sample Selection}
You can have as many sub-headings in a section as you want to. Note that sub-headings have a 6pt spacing after them rather than a blank line but they are preceded by a blank line. The number of sections and sub-sections is up to you, as are the titles of each of them and this will be driven by the content of your report.
\subsection*{Model Creation}
You can have as many sub-headings in a section as you want to. Note that sub-headings have a 6pt spacing after them rather than a blank line but they are preceded by a blank line. The number of sections and sub-sections is up to you, as are the titles of each of them and this will be driven by the content of your report.
"""
if 'predict' in to_report:
latex_report += r"""
\subsection*{Predictions}
You can have as many sub-headings in a section as you want to. Note that sub-headings have a 6pt spacing after them rather than a blank line but they are preceded by a blank line. The number of sections and sub-sections is up to you, as are the titles of each of them and this will be driven by the content of your report.
"""
if 'help' in to_report:
latex_report += r"""\subsection*{How to include equations, figures and tables?}
Some of us like to include a formula or two and these should be referred to in the test in the form equation 1. You must type in equations using the equation editor and all symbols should be explained within the text of your manuscript. However you may prefer to include a separate section detailing all nomenclature. Never paste equations in from a paper or other source. Leave a blank line before and after the equation:
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac} }{2a}
\end{equation}
where $x$ is a number; $a$, $b$, and $c$ are other numbers.
\begin{equation}
BCP = 176R+28G+46B
\end{equation}
where, $BCP$, $R$, $G$ and $B$ are also useful numbers.
Figure \ref{fig_regression} shows a graph. Figures / diagrams / photos are to be centred, with the reference and caption printed below the figure. The lettering used in the illustrations should be easily legible. Illustrations are to be referred to as figures, and must be quoted in the text. One blank line should be left between the figure caption and the next paragraph. Please ensure that all figures are of the highest quality. Keep figures as simple as possible. Avoid excessive notes. Photographs must have a resolution of at least 300 dpi. The use of colour is allowed on figures. Note that the test does not wrap around the figure but if you do not like the wasted space then it is acceptable to put two figures side by side but they must be e.g. a 'Figure \ref{fig_bridge1}' and 'Figure \ref{fig_bridge2}' and not 'Figure 1' and 'Figure 2'. See the example given as Figure \ref{fig_twobridges}. However all figures must be as close as possible to the location where they are first referred to in the text. The figure is also not surrounded by an unnecessary box/border. Remove this when inserting figures from MS Excel.
\begin{figure}[ht]
\centering
\includegraphics[height=6.6cm]{figures/fig_regression}
\caption{An interesting plot (note that figure captions go BELOW THE FIGURE).}
\label{fig_regression}
\end{figure}
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/fig_bridge1}
\caption{Bridge 1}
\label{fig_bridge1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{figures/fig_bridge2}
\caption{Bridge 2}
\label{fig_bridge2}
\end{subfigure}
\caption{Walton-on-Thames Bridge (a) wide shot and (b) the underside of the deck
(photos taken by P. J. Vardanega, used with permision)}
\label{fig_twobridges}
\end{figure}
\begin{table}[h]
\begin{center}
\caption{Summary of the database (note that table captions go ABOVE THE TABLE)}
\begin{tabular}{ |l|c|l| }
\hline
\textbf{Column heading} & \textbf{Column heading} & \textbf{Column heading} \\ \hline
Table Text & 10 & Falling head permeameter \\ \hline
Concrete & 2 & Strong \\ \hline
Steel & 1 & Stronger \\ \hline
Timber & 3 & Weak \\
\hline
\end{tabular}
\label{tab_materials}
\end{center}
\end{table}
"""
latex_report += r"""\newpage
\section*{ACKNOWLEDGEMENTS}
This tool is provided by the Chemical Analysis Platform for Ecology - Montpellier, France.\\
Thanks to Abderrahim DIANE, Mouhcine MAIMOUNI, Alexandre Granier, Remy Beugnon, Vincent Negre et Nicolas Barthes.\\
Source code available at \href{https://src.koda.cnrs.fr/cefe/pace/nirs_workflow}{CNRS forge}.
\fontsize{8}{9}\selectfont
\bibliographystyle{apalike}
% \bibliographystyle{abbrv}
\bibliography{refs.bib}
\clearpage
\end{document}"""
# export the .tex file in the Report folder
filename = r'report.tex'
with open(filename, 'w') as latex_file:
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';}
latex_report = report('sample', 'predict',)
def compile_latex():
# path to pdflatex
pdflatex = "C:/Donnees/Logiciels/Papps/PortableApps/Notepad++Portable/LaTEX/texmfs/install/miktex/bin/"
filename = 'report.tex'
# run pdflatex with bibtex compilation (2nd run)
proc = subprocess.Popen([pdflatex + 'pdflatex.exe', filename])
proc.communicate()
proc = subprocess.Popen([r'C:\Donnees\Logiciels\Papps\PortableApps\Notepad++Portable\LaTEX\texmfs\install\miktex\bin\bibtex.exe', filename[:-4]])
proc.communicate()
proc = subprocess.Popen([r'C:\Donnees\Logiciels\Papps\PortableApps\Notepad++Portable\LaTEX\texmfs\install\miktex\bin\pdflatex.exe', filename])
proc.communicate()
proc = subprocess.Popen([r'C:\Donnees\Logiciels\Papps\PortableApps\Notepad++Portable\LaTEX\texmfs\install\miktex\bin\pdflatex.exe', filename])
proc.communicate()
# remove pdflatex compilation files
os.unlink(filename[:-4] + '.log')
os.unlink(filename[:-4] + '.aux')
os.unlink(filename[:-4] + '.bbl')
os.unlink(filename[:-4] + '.blg')
os.unlink(filename[:-4] + '.out')
# open the report
proc = subprocess.Popen([filename[:-4] + '.pdf'], shell=True)
proc.communicate()
compile_latex()