40 size_t nPlots = figure.
GetPlots().size();
42 LOG(warn) <<
"No plots provided for figure " << figure.
GetLabel() <<
". Ignoring.";
46 std::stringstream out;
47 out <<
"\\begin{figure}[H]\n";
48 out <<
" \\centering\n";
54 std::vector<size_t> vPlotGrid;
55 bool bDefineDefaultGrid = figure.
GetPlotGrid().empty();
56 if (!bDefineDefaultGrid) {
58 if (nPlotsByGrid < nPlots) {
59 LOG(warn) <<
"Figure " << figure.
GetLabel()
60 <<
": provided grid does not fit the subfigures, define the default one";
61 bDefineDefaultGrid =
true;
65 if (bDefineDefaultGrid) {
66 constexpr size_t nX = 3;
67 auto nY =
static_cast<size_t>(std::ceil(
static_cast<double>(nPlots) / nX));
68 vPlotGrid.resize(nY, nX);
74 for (
auto& i : vPlotGrid) {
75 LOG(info) <<
"- " << i;
79 for (
size_t iY = 0; iY < vPlotGrid.size(); ++iY) {
80 if (iPlot >= nPlots) {
83 size_t nX = vPlotGrid[iY];
87 double wSize = 0.90 / std::min(nX, nPlots - iPlot);
88 for (
size_t iX = 0; iX < nX; ++iX) {
89 if (iPlot >= nPlots) {
92 const auto& plot = figure.
GetPlots()[iPlot];
93 out <<
" \\begin{subfigure}[t]{" << wSize <<
"\\textwidth}\n";
94 out <<
" \\centering\n";
95 out <<
" \\includegraphics[width=\\linewidth]{" << plot.fsPath <<
"}\n";
96 out <<
" \\caption{" << plot.fsCaption <<
"}\n";
97 if (!plot.fsLabel.empty()) {
98 out <<
" \\label{" << figure.
GetLabel() <<
":" << plot.fsLabel <<
"}\n";
100 out <<
" \\end{subfigure}\n";
103 if (iY != vPlotGrid.size() - 1) {
104 out <<
"\\vspace{3mm}\n";
118 out <<
" \\label{" << figure.
GetLabel() <<
"}\n";
119 out <<
"\\end{figure}\n";
127 std::stringstream out;
131 out <<
"\\documentclass[12pt]{article}\n";
132 out <<
"\\usepackage[english]{babel}\n";
133 out <<
"\\usepackage{array}\n";
134 out <<
"\\usepackage{graphicx}\n";
135 out <<
"\\usepackage{float}\n";
136 out <<
"\\usepackage{longtable}\n";
137 out <<
"\\usepackage{helvet}\n";
138 out <<
"\\usepackage{sansmath}\n\\sansmath\n";
139 out <<
"\\usepackage{geometry}\n";
140 out <<
"\\usepackage{subcaption}\n";
141 out <<
"\\geometry{a4paper, total={170mm,257mm}, left=25mm, right=25mm, top=30mm, bottom=30mm}\n";
143 out <<
"\\usepackage{hyperref}\n";
152 out <<
"\\newcolumntype{L}[1]{>{\\flushleft\\arraybackslash}p{#1}}\n";
158 auto timeNow = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
159 out <<
"\\date{Generated on " << std::put_time(std::localtime(&timeNow),
"%a %d.%m.%Y, %X") <<
"}\n";
163 out <<
"\\begin{document}\n";
164 out <<
"\\begin{titlepage}\n";
165 out <<
" \\maketitle\n";
166 out <<
" \\thispagestyle{empty}\n";
170 out <<
"\\end{titlepage}\n";
171 out <<
"\\newpage\n";
172 out <<
"\\tableofcontents\n";
173 out <<
"\\newpage\n";
183 std::stringstream out;
184 std::string sSectionType =
"";
186 sSectionType =
"section";
189 sSectionType =
"subsection";
192 sSectionType =
"subsubsection";
196 out <<
"\\newpage\n";
198 out <<
"\\" << sSectionType <<
"{" << section.
GetTitle() <<
"}\n\n";
200 out << pElement->GetBody(*
this) <<
'\n';
211 std::stringstream out;
216 out <<
"\\begin{table}\n";
217 out <<
"\\footnotesize\n";
222 out <<
" \\begin{longtable}{" << std::string(nCols,
'c') <<
"}\n";
226 for (
int iCol = 0; iCol < nCols; ++iCol) {
227 out << table.
GetColumnTitle(iCol) << ((iCol < nCols - 1) ?
" & " :
" \\\\\n");
231 for (
int iRow = 0; iRow < nRows; ++iRow) {
233 for (
int iCol = 0; iCol < nCols; ++iCol) {
234 out << table(iRow, iCol) << ((iCol < nCols - 1) ?
" & " :
" \\\\\n");
239 out <<
" \\end{longtable}\n";
240 out <<
" \\label{" << table.
GetLabel() <<
"}\n";
241 out <<
"\\end{table}\n";
250 std::stringstream out;
251 out <<
"\\end{document}\n";
261 int bCompilerFonud =
false;
263 std::stringstream stream(getenv(
"PATH"));
265 while (!bCompilerFonud && std::getline(stream, dir,
':')) {
266 bCompilerFonud = fs::exists(fs::path(dir) / compiler);
270 if (!bCompilerFonud) {
271 LOG(error) <<
"cbm::qa::report::LatexEngine::Compile(): compiler \"" <<
fsLatexCompiler <<
"\" not found in PATH. "
272 <<
"Please use another compiler or compile the sourec in external program";
277 fs::path sourceDir = fs::path(source).parent_path();
278 fs::path currPath = fs::current_path();
279 fs::current_path(sourceDir);
281 std::string logFile = compiler +
".log";
282 std::string command = fmt::format(
"{} {} > {}",
fsLatexCompiler, source, logFile);
283 command = command +
";" + command;
285 LOG(info) <<
"cbm::qa::report::LatexEngine::Compile(): executing command: \n\t" << command;
286 int res = std::system(command.c_str());
287 fs::current_path(currPath);
289 LOG(info) <<
"cbm::qa::report::LatexEngine::Compile(): compillation " << (res == 0 ?
"succeed" :
"failed")
290 <<
"(compiler log: \"" << logFile <<
"\")";
LaTeX Beamer engine for the cbm::qa::report (source)
Base class for the report section (header)
Base class for the report table (header)
const std::vector< std::shared_ptr< Element > > GetDaughterElements() const
Get daughter elements.
const std::string & GetTitle() const
Gets name.
const std::string & GetLabel() const
Gets label.
Plain LaTeX document engine.
std::string TailBody(const Tail &tail) const override
Creates a body for tail.
void Compile(const std::string &source) const override
Compiles source.
std::string FigureBody(const Figure &figure) const override
Creates a body for figure.
static constexpr double kFigureWidth
Figure width [in textwidth].
std::string SectionBody(const Section §ion) const override
Creates a body for section.
std::string TableBody(const Table &table) const override
Creates a body for table.
std::string HeaderBody(const Header &header) const override
Creates a body for header.
std::string fsLatexCompiler
int GetLevel() const
Gets level of the section.
Table element in the report.
const std::string & GetColumnTitle(int iCol) const
Gets column title.
int GetNofRows() const
Gets number of rows.
int GetNofCols() const
Gets number of columns.
const std::string & GetCaption() const
Gets caption.