🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

latex-to-pdf

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

latex-to-pdf

## Overview **LaTeX to PDF** is a Node.js module that allows you to generate PDF reports from LaTeX templates with dynamic data injection. It provides functionalities for parsing templates, generating TypeScript interfaces for type safety, and compiling L

1.0.14
latest
npm
Version published
Weekly downloads
107
98.15%
Maintainers
0
Weekly downloads
 
Created
Source

LaTeX to PDF Documentation

Overview

LaTeX to PDF is a Node.js module that allows you to generate PDF reports from LaTeX templates with dynamic data injection. It provides functionalities for parsing templates, generating TypeScript interfaces for type safety, and compiling LaTeX files into PDFs.

Dependencies

  • pdflatex
    • Windows install: https://www.tug.org/texlive/
    • Mac install: brew install texlive
    • Debian/Ubuntu: sudo apt install texlive-latex-base then optionally sudo apt install texlive-latex-extra texlive-fonts-recommended

Installation

Using git

Setup the package in it's own directory

git clone https://github.com/TytoLtd/latext_to_pdf_ts.git
cd latex-to-pdf
yarn install
yarn build
yarn link

Link to another project. In the other project:

yarn link latex-to-pdf

Using the package manager if I decide to publish it (haven't yet)

yarn add latex-to-pdf

Usage

Generating TypeScript Interfaces from Templates

Before generating PDFs, you need to extract fields from LaTeX templates and generate TypeScript interfaces:

latex-to-pdf-setup <TEMPLATE_DIRECTORY>

This command scans the provided directory for .tex templates, extracts placeholders, and generates corresponding TypeScript interfaces. <TEMPLATE_DIRECTORY> is where you decide to keep your latex templates. An example latex template is provided below.

API Reference

LatexToPdf Class

class LatexToPdf {
  constructor(reportType: string);
  populate<T>(data: T, output: string): string;
}

Methods:

  • constructor(reportType: string): Initializes the generator with a report type. The type must be pre-generated using generateAllTypes.
  • populate<T>(data: T, output: string): string: Injects data into the LaTeX template and generates a PDF.

generateAllTypes

function generateAllTypes(templateDir: string): string[];

Scans a directory for .tex templates and generates TypeScript interfaces.

Configuration

Ensure the pdflatex command is installed and available in your system path to enable PDF generation. See above dependency.

Example

Latex Template



\documentclass{article}
\usepackage{longtable}
\begin{document}
{{let cust1:import<Customer,"../src/Customer.ts">}}
{{let results_table:[new<date:string,item:string,price:number>]}}
{{let meeps:[import<Meep,"../src/Meep.ts">]}}
{{let date:raw<string>}}
Invoice for {{cust1.name}}

Date: {{date}}

\begin{longtable}{|l|c|c|}
    \hline
    \textbf{Date} & \textbf{Item} & \textbf{Price (ZAR)} \\
    \hline
    {{table(results_table,[date,item,price])}}
    \hline
    \end{longtable}

\section{Meep}
{{for meep in meeps
    {\textbf{Meep ID:} {{meep.id}} \\}
}}

\section{Magic}
{{if ({{date}} == "Meep")
    {\textbf{Magic:} 1 \\}else{\textbf{Not Magic:} 0 \\}
}}

\end{document}

TS Code

import { LatexToPdf } from "latex-to-pdf";
import { Customer } from "./src/Customer";
import { InvoiceData } from "./latex_interfaces/invoice";


const pdfGenerator = new LatexToPdf("invoice"); // Same as template name just without .tex. So invoice.tex -> invoice

// The data type for a template will always be called {templateName}Data. 
// You can find the structure in the generated folder "node_modules/latex-to-pdf/generated"

let cust: Customer={
    name: "Mikey",
    id: 123
}

let data: InvoiceData={
    cust1: cust,
    results_table: [
        {
            date: "2021-01-01",
            item: "Item 1",
            price: 10
        },
        {
            date: "2021-01-02",
            item: "Item 2",
            price: 20
        }
    ],
    meeps: [
        {
            id: 999
        },
        {
            id: 9991
        }
    ],
    date: "not Meep"
}

const pdfPath = pdfGenerator.populate(data, "./output/test.pdf");
console.log(`Generated PDF at: ${pdfPath}`);

License

© 2025 Tyto Insights. All Rights Reserved.

FAQs

Package last updated on 20 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts