Getting Started¶
Basic Syntax¶
Commands (code islands)¶
The simplest thing that you can do with latest
is to insert python expressions or command or code island inside a document. For a command to be evaluated a data context (python dictionary) had to be set up.
By default commands are bracketed between \latest[options]{$
and $}
. You can change these in the configuration file (see code_entry and code_exit options in lang section).
A plain text with code islands in between is called expression.
For example the expression
If a = \latest{$ a $} and b = \latest{$ b $}, then a + b = \latest{$ a+b $}
with a data context {a: '1', b: '2'}
evaluates to
If a = 1 and b = 2, then a + b = 3
Namespaces¶
Namespaces are a powerful concept in latest
. A namespace is a branch of a data context (python dictionary). It can be a single data context or a list of data contexts.
A namespace can be useful to simplify variable names within python code with deep nested data contexts.
More interestingly, namespaces allow to creates loops without standard loop syntax.
Environments¶
A more advanced concept is that of environments. An environment is defined by a namespace and an expression. The namespace define the branch of the data context in which to look for variable names in python code islands. If the namespace selects a list of dictionaries the environment is evaluated for each one of them and the results are joined by a special sequence of characters defined in a configuration file or as the option join_items
. This is effectively a for
loop implementation without the standard for
loop syntax.
Creating a template¶
A template file can be of any type but latest searches in it for commands and enviroments.
The latest cli¶
Run latest script from the command line
$ latest template data
where
- template is the path to a template file
- data is the path to a json or yaml formatted data file.
An example template file can be something like
\documentclass{article}
\title{\latest{$ title $}}
\begin{document}
\begin{latest}{content}
x = \latest{$ x $} so that $x^2$ = \latest{$ x**2 $}.
\end{latest}
\section{Prime Numbers}
\begin{itemize}
\begin{latest}{content.primes}[join_items={\n}]
\item \latest{$ n $}
\end{latest}
\end{itemize}
\section{Fibonacci}
\begin{latest}{content.fibonacci}[join_items={\n}]
\latest{$ _index $}. \latest{$ _value $}
\end{latest}
\end{document}
while the data file can be something like (yaml)
title: Testing latest
author: Flavio Grandin
date: Today
content:
x: 3
primes:
- n: 2
- n: 3
- n: 5
- n: 7
- n: 11
fibonacci:
- 1
- 1
- 2
- 3
- 5
- 8
- 13
The expected output is
\documentclass{article}
\title{Testing latest}
\begin{document}
x = 3 so that $x^2$ = 9.
\section{Prime Numbers}
\begin{itemize}
\item 2
\item 3
\item 5
\item 7
\item 11
\end{itemize}
\section{Fibonacci}
0. 1
1. 1
2. 2
3. 3
4. 5
5. 8
6. 13
\end{document}