Making Templates

Note: We are currently exploring the best way for users to author and publish their own templates. Please give us suggestions in our Discord.

Need a custom template now? Please contact us with your specific use case and we will make it for you.

We are designing Texpile’s template system to be powerful yet familiar. Instead of learning a complex new configuration language, you define templates using a LaTeX-native format called .tpl.tex.

The .tpl.tex Format

A template definition file looks exactly like a normal LaTeX file, but with special commands to define metadata, user fields, and transpilation rules.

Basic Structure

Here is a simplified example of a template file:

% !TPL schema = 1

% 1. Metadata
\TemplateInfo{
  id   = {my_custom_report},
  name = {My Custom Report},
}

% 2. User Fields (What the user fills in)
\DefineField{student_id}[string]{
  name = {Student ID},
  default = {000000}
}
\UseExport{@texpile/base/author} % Import standard fields like Author

% 3. Document Structure
\DocumentClass[12pt, a4paper]{article}

\begin{preamble}
  \usepackage{geometry}
  \newcommand{\student}[1]{\def\thestudent{#1}}
\end{preamble}

\begin{frontmatter}
  \title{\field{title}}
  \author{\field{author}}
  \student{\field{student_id}} % Map user field to LaTeX command
  \maketitle
\end{frontmatter}

% 4. Rules (How Texpile content maps to LaTeX)
\begin{rules}
  \UsePreset{@texpile/base/v1} % Use standard rules
  
  % Override how a Level 1 Heading looks
  \DefineRule{heading/1}{\section*{#text#}}
\end{rules}

Key Concepts

1. Metadata

Every template needs basic metadata so Texpile knows what it is.

\TemplateInfo{
  id          = {university_lab_report},  % Unique identifier
  name        = {University Lab Report},  % Display name
  description = {A standard layout for physics labs},
  version     = {1.0},
}

2. User Fields

You can define custom fields that users fill out in the Document Settings menu.

String Field:

\DefineField{course_code}[string]{
  name     = {Course Code},
  default  = {PHYS 101},
  required = {true}
}

Boolean Toggle:

\DefineField{show_logo}[boolean]{
  name    = {Show University Logo},
  default = {true}
}

Usage in Document: You can access these values anywhere in your LaTeX code using the \field command:

\iffield{show_logo}
  \includegraphics{logo.png}
\fi

Course: \field{course_code}

3. Transpilation Rules

Rules tell Texpile how to convert the visual editor content into LaTeX code. We provide presets for 99% of use cases, but you can override them.

Example: Customizing Blockquotes If you want blockquotes to be wrapped in a special environment:

\DefineRule{blockquote}{
  \begin{fancyquote}
    #content#
  \end{fancyquote}
}

Example: Unnumbered Sections If you want all level 1 headings to be unnumbered:

\DefineRule{heading/1}{\section*{#text#}}

Get Involved

The template engine is powerful and flexible. If you have an existing LaTeX class you want to convert, or ideas for new templates:

Join our Discord Community

We are actively looking for feedback on this specification.