Lobster, a simple template engine for MATLAB

Lobster is a template engine for MATLAB with a syntax quite similar to Jinja, a template engine implemented in python. A template engine is useful if you need to create documents with a repetitive syntax. I use them for example to

  • generate C++ to convert enumeration fields to and from strings,

  • generate HTML content

  • generate latex contents from MATLAB variables.

Let’s start with a simple example of the syntax. Create a file called template.tpl with the following contents

Welcome {{ FirstName }},

Your grocery list contains:

{% for item in groceries %}
- {{ item.name }} {% if item.quantity > 1 %}(x{{ item.quantity}}){% endif %}
{% endfor %}

If you’ve downloaded Lobster and added it to your path then using the template is as simple as:

context = struct( ...
    'FirstName', 'Thibaud', ...
    'Groceries', {'Milk', 'Eggs', 'Bacon', 'Nutella'} ...
);

template = Lobster('template.tpl').render(context);

The rendered template is stored in the template variable. What you do with it is up to you. The full documentation can be found in the github repo.

Revision History

2026-01 Add summary end markers to files
2026-01 Migrate to date based urls

Instead of grouping articles by category, we just store them in date order in the content folder.

2025-10 Fix typos and spaces
2017-05 Add Lobster Intro