GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
CompileLatex.hpp
Go to the documentation of this file.
1 #ifndef GL_COMPILE_LATEX_HPP
2 #define GL_COMPILE_LATEX_HPP
3 
4 #include <string>
5 
6 namespace gl {
7 namespace io {
8 
14 void compileLatex(const char *filename, const char *arguments = "")
15 {
16  std::cout << "Compiling latex..." << std::endl
17  << "If this fails because of permissions within the \"convert\" command, do the following:" << std::endl
18  << "In the files /etc/ImageMagick-6/policy.xml && /etc/ImageMagick-7/policy.xml" << std::endl
19  << "change the line containing" << std::endl
20  << "<policy domain=\"coder\" rights=\"none\" pattern=\"PDF\" />" << std::endl
21  << "to" << std::endl
22  << "<policy domain=\"coder\" rights=\"read\" pattern=\"PDF\" />" << std::endl;
23 
24  std::string command = "lualatex --interaction=nonstopmode ";
25 
26  command += std::string(arguments);
27  command += " " + std::string(filename);
28 
29  std::string file = std::string(filename);
30  std::size_t pos = file.find_last_of(".");
31 
32  std::string filename_without_extension = file.substr(0, pos);
33 
34  std::string command2 = "convert -density 500 " +
35  filename_without_extension + ".pdf -quality 100 " + filename_without_extension + ".png";
36 
37  // supress latex output, but save as log
38  command += " > " + filename_without_extension + "_latex_output.txt";
39  system(command.data()); // pdflatex
40  system(command2.data()); // convert to png
41 
42  std::cout << "Generated " << filename_without_extension << ".png" << std::endl;
43 }
44 
45 } // namespace io
46 } // namespace gl
47 
48 #endif // GL_COMPILE_LATEX_HPP
void compileLatex(const char *filename, const char *arguments="")
Invokes lualatex command to compile tex to pdf.
Definition: CompileLatex.hpp:14