LaTeX Document Conversion in Java

LaTeX is a powerful tool used by academics, scientists, and professionals for creating well-formatted documents in TEX or LTX formats. It gives you control over how your documents look. However, because it’s a markup language, you need to convert LaTeX documents into other formats to share and view them. In this article, we’ll explore how to convert LaTeX documents to other formats in Java. Let’s start immediately!

This article covers the following topics:

Java LaTeX Document Conversion API

While LaTeX documents are helpful, not everyone can use them. So, if you want to share these documents with others, you have to convert them into formats that most people can read. These formats include PDFs, web pages, or pictures. This is where the LaTeX document conversion API comes in handy.

Aspose provides a dedicated Aspose.TeX for Java API to work with LaTeX documents. Aspose.TeX for Java is specifically designed for Java programming. It’s used to work with TeX documents in Java applications. Aspose.TeX for Java helps Java developers handle, manipulate, and convert TeX files into various formats like XPS, PDF, images, and more. This library simplifies working with TeX documents in Java-based projects.

Please download the API JAR or add the pom.xml file below to a Maven-based Java application.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository> 
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-tex</artifactId>
    <version>23.6</version>
</dependency>

LaTeX Document Conversion to Image in Java

We can easily convert a LaTeX document to an image by following the steps below:

  1. Create an instance of the TeXOptions class using the consoleAppOptions() method.
  2. Specify typesetting TeX configuration as TeXConfig.objectLaTeX().
  3. Set the file system working directory for the output.
  4. Optionally, specify a console or memory stream as an output terminal.
  5. After that, initialize specific image save options for saving in the desired format e.g. PngSaveOptions().
  6. Finally, call the run() method for the newly created TexJob class and save the output image with the ImageDevice class object.

The following code example shows how to convert a LaTeX document to a PNG image using Java.

You can read the complete conversion tutorial here:

Convert LaTeX Document to PDF in Java

Similarly, we can convert a LaTeX document to a PDF document by following the steps below:

  1. Create an instance of the TeXOptions class using the consoleAppOptions() method.
  2. Specify typesetting TeX configuration as TeXConfig.objectLaTeX().
  3. Specify the console or memory stream as an output terminal.
  4. Set PdfSaveOptions for rendering into PDF format.
  5. Call the TexJob class object and save the output PDF with the PdfDevice class object.

The following code example shows how to convert a LaTeX document to a PDF document in Java.

Please read more about generating PDFs from LaTeX in Java.

Convert LaTeX Document to XPS in Java

We can also convert a LaTeX document to XPS format by following the steps below:

  1. Create an instance of the TeXOptions class using the consoleAppOptions() method.
  2. Specify typesetting TeX configuration as TeXConfig.objectLaTeX().
  3. Specify console or memory stream as an output terminal.
  4. Set XpsSaveOptions for rendering into XPS format.
  5. Call the TexJob class object and save the output XPS with the XpsDevice class object.

The following code example shows how to convert a LaTeX document to an XPS document in Java.

You can read more about converting LaTeX to XPS.

Java Document Conversion – Free License

You can get a free temporary license to try the library for free without any limitations.

Try LaTeX Document Conversion Online

You may also convert TEX or LTX files online using LaTeX document conversion apps developed using the above API.

LaTeX Document Conversion in Java – Useful Resources

You can learn more about viewing, converting, and merging LaTeX documents and explore other features of the library using the resources given below:

Conclusion

In conclusion, LaTeX is a powerful tool for creating professional-looking documents. It is the go-to choice for many academics and researchers due to its ability to handle complex mathematical equations and a wide range of formatting options. However, converting LaTeX documents to other formats can be difficult. By leveraging Aspose.TeX, you can integrate the LaTeX document conversion API into your Java applications. The steps outlined above allow you to easily convert LaTeX documents to other formats. In case of any ambiguity, please contact us on our free support forum.

See Also