Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0612bbb4c8859ca06406cec4513759ea to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0612bbb4c8859ca06406cec4513759ea to your computer and use it in GitHub Desktop.
Create Custom TeX (LaTeX) Format and Typeset or Convert to PDF, XPS in Java
String dataDir = "D://Test//";
// Create typesetting options for no format on ObjectTeX engine extension.
TeXOptions options = TeXOptions.consoleAppOptions(TeXConfig.objectIniTeX());
// Specify a file system working directory for input.
options.setInputWorkingDirectory(new InputFileSystemDirectory(dataDir));
// Specify a file system working directory for output.
options.setOutputWorkingDirectory(new OutputFileSystemDirectory(dataDir));
// Run format creation.
TeXJob.createFormat("customtex", options);
String dataDir = "D://Test//";
// Create a file system input working directory.
IInputWorkingDirectory wd = new InputFileSystemDirectory(dataDir);
// Create a format provider.
final FormatProvider formatProvider = new FormatProvider(wd, "customtex");
try {
// Create typesetting options for a custom format on ObjectTeX engine extension.
TeXOptions options = TeXOptions.consoleAppOptions(TeXConfig.objectTeX(formatProvider));
options.setJobName("typeset-with-custom-format");
// Specify the input working directory.
options.setInputWorkingDirectory(wd);
// Specify a file system working directory for output.
options.setOutputWorkingDirectory(new OutputFileSystemDirectory(dataDir));
// Set PdfSaveOptions
options.setSaveOptions(new PdfSaveOptions());
// Run typesetting.
new TeXJob(new ByteArrayInputStream(
"Congratulations! You have successfully typeset this text with your own TeX format!\\end".getBytes("ASCII")), new PdfDevice(), options);
} finally {
formatProvider.close();
}
String dataDir = "D://Test//";
// Create a file system input working directory.
IInputWorkingDirectory wd = new InputFileSystemDirectory(dataDir);
// Create a format provider.
final FormatProvider formatProvider = new FormatProvider(wd, "customtex");
try {
// Create typesetting options for a custom format on ObjectTeX engine extension.
TeXOptions options = TeXOptions.consoleAppOptions(TeXConfig.objectTeX(formatProvider));
options.setJobName("typeset-with-custom-format");
// Specify the input working directory.
options.setInputWorkingDirectory(wd);
// Specify a file system working directory for output.
options.setOutputWorkingDirectory(new OutputFileSystemDirectory(dataDir));
// Run typesetting.
new TeXJob(new ByteArrayInputStream(
"Congratulations! You have successfully typeset this text with your own TeX format!\\end".getBytes("ASCII")), new rendering.XpsDevice(), options);
} finally {
formatProvider.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment