Merge TEX

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Merger MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

GroupDocs.Merger for Python via .NET merges TeX documents into one file, for example to keep the sections of a report together or to send fewer attachments, without any TeX distribution or other software installed.

How to merge TEX files in Python

  1. Create an instance of the Merger class and pass the path to the first TEX file.
  2. Call merger.join() with the path to each TEX file to append.
  3. Call merger.save() with the path of the merged TEX file.
from groupdocs.merger import Merger

def merge_tex_files():
    # Load the first TEX file
    with Merger("./input.tex") as merger:
        # Append the second TEX file
        merger.join("./input2.tex")
        # Save the merged document
        merger.save("./output.tex")

if __name__ == "__main__":
    merge_tex_files()

input.tex is a sample file used in this example. Click here to download it.

input2.tex is a sample file used in this example. Click here to download it.

Explanation

  • Load the first file: Merger("./input.tex") opens the first TeX document inside a context manager.
  • Append another file: merger.join("./input2.tex") appends the second document. Call join again for each additional file.
  • Save the result: merger.save("./output.tex") writes the merged TeX document to disk.

About the TEX file format

TeX is a typesetting language, with programming as well as markup features, created by Donald Knuth at Stanford University. Authors and publishers around the world use it to produce technical documents, and it is known for typesetting complex mathematical expressions.

Merge TEX Live Demo

GroupDocs.Merger provides a free online TEX Merger App, which allows you to try it and check its quality.

API reference

  • Merger — main class; join, save methods.

See also