LaTeX3 has some great concepts and functions. One is the ability to replace text in a token list. This opens up possibilities to create templates in a way that html
templates are used for example by handlebars
The only reason for the existence of such templates is to simplify the entering of mark-up, being either by humans or computers. Consider the case of having mark-up for multiple images such as the one below:
The mark-up can get very tedious. A markup of the form:
!!img amato!!
!!cap This is the first caption!!
would greatly simplify the mark-up. The !!img
is a marker to pick-up images and !!cap
to pickup captions. I have used the !!
as a marker but of course anything can be used as long as is allowed by a token list. The three letters that follow denote different mark-up, i.e. img
for image, cap
for caption.
Here is the code:
\documentclass{article}
\usepackage{expl3, graphicx,caption}
\begin{document}
\ExplSyntaxOn
\cs_set:Npn \putimage#1!!{%
\includegraphics[width=\linewidth]{./images/amato}%
}
\cs_set:Npn \putsomecaption#1!!{
\captionof{figure}{#1}
\par\endminipage\hfill
}
\tl_set:Nn \tempai {
\centering
!!img amato!!
!!cap This~is~the~first~caption!!
!!img amato!!
!!cap This~is~the~second~caption!!
!!img amato.jpg!!
!!cap This~is~the~third~caption!!
!!img amato!!
!!cap This~is~the~fourth~caption!!
!!img amato!!
!!cap This~is~the~fifth~caption!!
!!img amato!!
!!cap This~is~the~sixth~caption!!
}
\tl_replace_all:Nnn\tempai {!!img}{\minipage{3.6cm}\centering\putimage}
\tl_replace_all:Nnn\tempai {!!cap}{\putsomecaption}
\tl_use:N \tempai
\ExplSyntaxOff
\end{document}
I have difficulties turning the above code in a suitable environment. Can someone provide a solution. Say to have an environment multimages
.
\foo{ {amato}{The ~ caption} {amato}{Another ~ caption} .. }
and let expl3 handle all? – Manuel May 14 '15 at 18:58\begin{multimages}...\end{multimages}
to hold the user input. – Yiannis Lazarides May 14 '15 at 19:02~
? That was never intended for entering any kind of user text, although can be used for small fixed texts such as error messages within the program code of course. – David Carlisle May 14 '15 at 19:05environ
package allows to create a token list from an environment “\BODY
”, there, you replace{!!img}
and{!!cap}
and I think you are done. To be more “free”, you could take a look atl3regex
. – Manuel May 14 '15 at 19:06suitable environment
. – Yiannis Lazarides May 14 '15 at 19:13