Texcaller
Functions
Texcaller C++ interface

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. More...
 
std::string texcaller::escape_latex (const std::string &s) throw (std::runtime_error)
 Escape a string for direct use in LaTeX. More...
 

Detailed Description

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`

Function Documentation

◆ convert()

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.

Parameters
resultwill contain the generated document.
infowill contain additional information such as TeX warnings.
sourcethe source to convert
source_formatmust be one of:
  • "TeX"
  • "LaTeX"
  • "XeTeX"
  • "XeLaTeX"
  • "LuaTeX"
  • "LuaLaTeX"
result_formatmust be one of:
  • "DVI" (only for source formats "TeX" and "LaTeX")
  • "PDF"
max_runsmaximum number of TeX runs, must be ≥ 2.
Exceptions
std::domain_errorthe TeX source was invalid. That is, the TeX interpreter exited with an error, or the output didn't stabilize after max_runs runs.

◆ escape_latex()

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.

Parameters
sthe string to escape
Returns
the escaped value