Here at Valletta Ventures we are pleased to announce Texpad API, a framework that allows any iOS application to typeset with LaTeX and BibTeX on the device, no internet connection required.

Since releasing The iOS version of Texpad, our LaTeX editor, a year ago, we have worked constantly on it’s on-board typesetter. After our initial refactor of TeX to run on iOS and produce PDFs, we have added support for almost all commonly used LaTeX extensions: e.g. e-TeX, colour, paper size and most recently pgf vector graphics drivers (used by Beamer, Tikz, Pgfplots..). Along with Texpad’s new font system and an integrated bundle manager, this work has made Texpad’s on board typesetter capable of almost everything that desktop TeXLive is. The Texpad API is a framework that uses iOS’s URL schemes to give any application access to this typesetter.

We started work on the API when we were contacted by the developer of UX Write, a high end iOS word processor designed for large documents. He was looking to improve the quality of the PDF output, and what better way to do that than with TeX? a typesetting system used by professionals and amateurs alike to create books, magazines and articles for forty years now.

In fact almost any application that outputs PDFs can benefit from the TeX’s high quality output. Very few PDF creation libraries possess even TeX’s most rudimentary typesetting abilities - for example accurate hyphenation, ligatures and elegant kerning - and the quality of the documents they create suffers as a result.

Texpad’s API is simple to use: link the framework in to your Xcode project, add a return URL scheme to your application’s Info.plist, and typesetting becomes as easy as

TPAPIRequest *request = [[TPAPIRequest alloc] init];
NSString *rootFile = @"\\documentclass{article}\n\\begin{document}\nHello world\n\\end{document}\n";
atPath:@"root.tex"];
[[TPAPIManager sharedManager] submitRequest:request];


Your application will go out of focus briefly while Texpad typesets the document, then focus will be returned, and the beautifully typeset PDF will be passed to TPAPIManager’s delegate

-(void)typesetRequestComplete:(TPAPIRequest*)request {
NSLog(@"Request %ld returned", request.tag);

if (request.status == TPAPIRequestStatusSuccess) {
// write the pdf data to a file for display
[request.pdfData writeToFile:outputFileName atomically:YES];
} else if (request.status == TPAPIRequestStatusTypesetFailure) {
// show the typeset log on the console
NSLog(@"%@", request.typesetLog);
}
}


The framework itself, detailed instructions on how to use it, and an example project can be found in the Texpad-API Github repo. If you have any queries or comments about this API get in touch at duncan@vallettaventures.com.

NB This framework only works with Texpad >= 1.5, so please update if you haven’t done so already.