Texcaller
|
The texcaller.h
header does not only provide the C functions, but also the corresponding C++ wrappers.
More...
Functions | |
void | texcaller::convert (std::string &result, std::string &info, const std::string &source, const std::string &source_format, const std::string &result_format, int max_runs) throw (std::domain_error, std::runtime_error) |
Convert a TeX or LaTeX source to DVI or PDF. | |
std::string | texcaller::escape_latex (const std::string &s) throw (std::runtime_error) |
Escape a string for direct use in LaTeX. |
The texcaller.h
header does not only provide the C functions, but also the corresponding C++ wrappers.
The following example program demonstrates how these are meant to be used:
#include <texcaller.h> #include <iostream> int main() { // // Generate a PDF document // std::string latex = "\\documentclass{article}" "\\begin{document}" "Hello world!" "\\end{document}"; try { std::string pdf; std::string info; texcaller::convert(pdf, info, latex, "LaTeX", "PDF", 5); std::cout << "Generated PDF of " << pdf.size() << " bytes."; std::cout << " Details:" << std::endl << std::endl << info; } catch (std::domain_error &e) { std::cout << "Error: " << e.what() << std::endl; } // // Escape a string for LaTeX // const std::string s = "Téxt → \"with\" $peciäl <characters>"; std::cout << std::endl; std::cout << "Original: " << s << std::endl; std::cout << "Escaped: " << texcaller::escape_latex(s) << std::endl; return 0; }
Since the C++ wrappers are defined completely inline, there is no need for an extra C++ library. The compiler and linker options of the Texcaller C interface also work perfectly for C++:
c++ -o example example.cxx `pkg-config texcaller --cflags --libs`
void texcaller::convert | ( | std::string & | result, |
std::string & | info, | ||
const std::string & | source, | ||
const std::string & | source_format, | ||
const std::string & | result_format, | ||
int | max_runs | ||
) | throw (std::domain_error, std::runtime_error) [inline] |
Convert a TeX or LaTeX source to DVI or PDF.
This is a simple wrapper around texcaller_convert.
result | will contain the generated document. |
info | will contain additional information such as TeX warnings. |
source | the source to convert |
source_format | must be one of:
|
result_format | must be one of:
|
max_runs | maximum number of TeX runs, must be ≥ 2. |
std::domain_error | the TeX source was invalid. That is, the TeX interpreter exited with an error, or the output didn't stabilize after max_runs runs. |
std::string texcaller::escape_latex | ( | const std::string & | s | ) | throw (std::runtime_error) [inline] |
Escape a string for direct use in LaTeX.
This is a simple wrapper around texcaller_escape_latex.
s | the string to escape |