Skip to content

Instantly share code, notes, and snippets.

@aw31
Created November 28, 2013 21:56
Show Gist options
  • Save aw31/7698630 to your computer and use it in GitHub Desktop.
Save aw31/7698630 to your computer and use it in GitHub Desktop.
Beamer presentation generator.
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
using namespace std;
const string start =
"\\documentclass{beamer}\n"
"\\usetheme{default}\n"
"\\begin{document}\n";
const string end = "\\end{document}\n";
struct page;
ostream& operator<<(ostream &o, page p);
struct page{
string title;
vector<string> content;
page(){}
page(string t){
title = t;
}
void add(string s){
content.push_back(s);
}
void add_list(vector<string> lst){
add("\\begin{enumerate}\n");
for(int i = 0; i<lst.size(); i++) add("\\item "+lst[i]+"\n");
add("\\end{enumerate}\n");
}
};
ostream& operator<<(ostream &o, page p){
o << "\\begin{frame}{" << p.title << "}\n";
for(int i = 0; i<p.content.size(); i++) o << p.content[i];
o << "\\end{frame}\n";
return o;
}
vector<page> make_standings(string title, vector<string> result){
vector<page> res;
vector<string> rev(result.size());
for(int i = (int)result.size()-1; i>=0; i--){
rev[i] = result[i];
page p(title);
p.add_list(vector<string>(rev.begin(), rev.end()));
res.push_back(p);
}
return res;
}
struct presentation{
vector<page> pages;
void add(page p){
pages.push_back(p);
}
int create(string name){
ofstream fout(name.c_str());
fout << start;
for(int i = 0; i<pages.size(); i++) fout << pages[i];
fout << end;
fout.close();
return system(("pdflatex "+name).c_str());
}
};
int main(){
string arr[] = {"I", "Like", "Cookies", "Yaaaaay!"};
vector<string> v(arr, arr+4);
vector<page> st = make_standings("Test", v);
presentation pr;
for(int i = 0; i<st.size(); i++) pr.add(st[i]);
cout << pr.create("out.tex") << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment