ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
slide_maker.cpp
Go to the documentation of this file.
1 #include "core/slide_maker.hpp"
2 
3 #include "core/utilities.hpp"
4 
5 using namespace std;
6 
7 SlideMaker::SlideMaker(string fname, string aspect_ratio):
8  filename_(fname){
9  outfile_.open("slides/"+filename_, ofstream::out);
10  outfile_<<"\\documentclass[8pt,aspectratio="+aspect_ratio+"]{beamer}\n";
11  outfile_<<"\\usepackage{graphicx}\n\n";
12  outfile_<<"\\begin{document}\n";
13 }
14 
15 void SlideMaker::AddSlide(vector<string> pnames, int ncols, string title){
16  //set # of columns and rows
17  unsigned nplots = pnames.size();
18  if (nplots>15) cout<<"Too many plots for this slide: "<<nplots<<endl;
19  if (ncols==-1) ncols = nplots/2;
20  int nrows = nplots/ncols;
21  if (nplots%ncols!=0) nrows +=1;
22 
23  string width = RoundNumber(1./ncols,2).Data();
24  string height = RoundNumber(1./nrows,2).Data();
25  outfile_<<"\\frame{\n";
26  outfile_<<" \\frametitle{"+title+"}\n";
27  for (size_t i(0); i<nplots; i++){
28  if (pnames[i]=="") continue;
29  string line = " \\includegraphics[height="+height+"\\textheight,width="
30  +width+"\\textwidth,keepaspectratio]{plots/"+pnames[i]+"}";
31  if ((i+1)%unsigned(ncols)==0) line +="\\\\";
32  outfile_<<line<<endl;
33  }
34  outfile_<<"}\n";
35 }
36 
38  outfile_<<"\\end{document}\n";
39  outfile_.close();
40 
41  execute("pdflatex -output-directory=slides slides/"+filename_+" > /dev/null");
42  ReplaceAll(filename_, ".tex",".pdf");
43  cout<<"Written slides/"+filename_<<endl;
44 }
SlideMaker(std::string fname, std::string aspect_ratio="169")
Definition: slide_maker.cpp:7
std::ofstream outfile_
Definition: slide_maker.hpp:17
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:52
void Close()
Definition: slide_maker.cpp:37
STL namespace.
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
TString RoundNumber(double num, int decimals, double denom=1.)
Definition: utilities.cpp:361
std::string filename_
Definition: slide_maker.hpp:18
void AddSlide(std::vector< std::string > pnames, int ncols=-1, std::string title="")
Definition: slide_maker.cpp:15