%% example.tex
%% Copyright 2024 E. Nijenhuis
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status ‘maintained’.
%
% The Current Maintainer of this work is E. Nijenhuis.
%
% This work consists of the files lua-placeholders.sty lua-placeholders-manual.pdf
% lua-placeholders.lua lua-placeholders-common.lua lua-placeholders-namespace.lua lua-placeholders-parser.lua
% and lua-placeholders-types.lua

\documentclass{article}
\usepackage{gitinfo-lua}
\usepackage{lua-placeholders}
\usepackage{listings}
\usepackage{amsmath}
\usepackage{calc}
\usepackage[dutch,english]{babel}
\usepackage[autolanguage]{numprint}

\loadrecipe[\jobname]{example-specification.yaml}

\setlength{\parindent}{0pt}

\begin{document}
    \title{Lua \paramplaceholder{placeholders} Example\thanks{This example corresponds to \texttt{lua-placeholders} version \gitversion{} written on \gitdate.}}
    \author{\dogitauthors[\\]}
    \maketitle

    \section*{Basics}
    Wrong parameter:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{non existing}|
    $\implies$
    \param{non existing}\\

    Conditional Parameter:\\

    \lstinline[style=TeX,morekeywords={hasparam}]|\hasparam{list example}{is set}{is not set}|
    $\implies$
    \hasparam{list example}{is set}{is not set}

    \section*{Before values loaded}

    Boolean example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{bool example}|
    $\implies$
    \param{bool example}\\

    \lstinline[style=TeX,morekeywords={ifparam}]|\ifparam{bool example}{TRUE}{FALSE}|
    $\implies$
    \ifparam{bool example}{TRUE}{FALSE}\\

    String example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{string example}|
    $\implies$
    ``\param{string example}''\\

    Number example:\\

    \lstinline[style=TeX,morekeywords={rawparam}]|\rawparam{\jobname}{number example}|
    $\implies$
    \rawparam{\jobname}{number example}\\

    \lstinline[style=TeX,morekeywords={param}]|\param{number example}|
    $\implies$
    \lstinline[style=TeX,morekeywords={numprint}]|\numprint{|\rawparam{\jobname}{number example}\verb|}|
    $\implies$
    \param{number example}\\

    \clearpage

    Number in foreign language:\\

    \lstinline[style=TeX,morekeywords={param,selectlanguage}]|\selectlanguage{dutch}\param{number example}|\\
    $\implies$
    \begingroup\selectlanguage{dutch}\param{number example}\endgroup\\

    List example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{list example}|
    $\implies$
    \param{list example}\\

    \begin{lstlisting}[language={[LaTeX]TeX},morekeywords={formatitem,forlistitem}]
\begin{enumerate}
    \newcommand\formatitem[1]{\item #1}
    \forlistitem{list example}{formatitem}
\end{enumerate}
    \end{lstlisting}
    $\implies$
    \begin{enumerate}
        \newcommand\formatitem[1]{\item #1}
        \forlistitem{list example}{formatitem}
    \end{enumerate}

    Object example:\\

    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{name}|\\
    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{email}|\\
    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{grade}|\\
    $\implies$
    \paramfield{object example}{name}
    \paramfield{object example}{email}
    \paramfield{object example}{grade}\\

    \begin{lstlisting}[style=TeX,morekeywords={name,email,grade}]
\newcommand\name{...}
\begin{paramobject}{object example}
    \name \email \grade
\end{paramobject}
% And here it works again
\name
    \end{lstlisting}
    $\implies$
    \newcommand\name{...}%
    \parbox{\linewidth}{
    \begin{paramobject}{object example}
        \name \email \grade
    \end{paramobject}
    \name
    }\\

    Table example:\\

    \begin{lstlisting}[style=TeX,morekeywords={nprounddigits,npnoround,formatrow,fortablerow,description,price}]
\nprounddigits{2}
\newcommand\formatrow{\description & \price \\}%
\begin{tabular}{l | l}
    \textbf{Description} & \textbf{Price} \\ \hline
    \fortablerow{table example}{formatrow}
\end{tabular}
\npnoround
    \end{lstlisting}
    $\implies$
    \nprounddigits{2}
    \newcommand\formatrow{\description & \price \\}%
    \begin{tabular}{l | l}
        \textbf{Description} & \textbf{Price} \\ \hline
        \fortablerow{table example}{formatrow}
    \end{tabular}
    \npnoround


    \section*{After values loaded}
    \loadpayload[\jobname]{example.yaml}

    Boolean example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{bool example}|
    $\implies$
    \param{bool example}\\

    \lstinline[style=TeX,morekeywords={ifparam}]|\ifparam{bool example}{TRUE}{FALSE}|
    $\implies$
    \ifparam{bool example}{TRUE}{FALSE}\\

    String example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{string example}|
    $\implies$
    ``\param{string example}''\\

    Number example:\\

    \lstinline[style=TeX,morekeywords={rawparam}]|\rawparam{\jobname}{number example}|
    $\implies$
    \rawparam{\jobname}{number example}\\

    \lstinline[style=TeX,morekeywords={param}]|\param{number example}|
    $\implies$
    \lstinline[style=TeX,morekeywords={numprint}]|\numprint{|\rawparam{\jobname}{number example}\verb|}|
    $\implies$
    \param{number example}\\

    Number in foreign language:\\

    \lstinline[style=TeX,morekeywords={param,selectlanguage}]|\selectlanguage{dutch}\param{number example}|\\
    $\implies$
    \lstinline[style=TeX,morekeywords={numprint}]|\numprint{|\rawparam{\jobname}{number example}\lstinline|}|
    $\implies$
    \begingroup\selectlanguage{dutch}\param{number example}\endgroup\\

    List example:\\

    \lstinline[style=TeX,morekeywords={param}]|\param{list example}|
    $\implies$
    \param{list example}\\

    \begin{lstlisting}[language={[LaTeX]TeX},morekeywords={formatitem,forlistitem}]
\begin{enumerate}
    \newcommand\formatitem[1]{\item #1}
    \forlistitem{list example}{formatitem}
\end{enumerate}
    \end{lstlisting}
    $\implies$
    \begin{enumerate}
        \newcommand\formatitem[1]{\item #1}
        \forlistitem{list example}{formatitem}
    \end{enumerate}

    Object example:\\

    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{name}|\\
    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{email}|\\
    \lstinline[style=TeX,morekeywords={paramfield}]|\paramfield{object example}{grade}|\\
    $\implies$
    \paramfield{object example}{name}
    \paramfield{object example}{email}
    \paramfield{object example}{grade}\\

    \begin{lstlisting}[style=TeX,morekeywords={name,email,grade}]
\newcommand\name{...}
\begin{paramobject}{object example}
    \name \email \grade
\end{paramobject}
% And here it works again
\name
    \end{lstlisting}
    $\implies$
    \parbox{\linewidth}{
    \begin{paramobject}{object example}
        \name \email \grade
    \end{paramobject}
    \name
    }\\

    Table example:\\

    \begin{lstlisting}[style=TeX,morekeywords={nprounddigits,npnoround,formatrow,fortablerow,description,price}]
\nprounddigits{2}
\newcommand\formatrow{\description & \price \\}%
\begin{tabular}{l | l}
    \textbf{Description} & \textbf{Price} \\ \hline
    \fortablerow{table example}{formatrow}
\end{tabular}
\npnoround
    \end{lstlisting}
    $\implies$
    \nprounddigits{2}%
    \begin{tabular}{l | l}
        \textbf{Description} & \textbf{Price} \\ \hline
        \fortablerow{table example}{formatrow}
    \end{tabular}

    \section*{Payload File}
    \lstinputlisting[language=YAML,numbers=left,xleftmargin={15pt},caption={example.yaml},columns=fullflexible]{example.yaml}

    \section*{Specification File}
    \lstinputlisting[language=YAML,numbers=left,xleftmargin=15pt,caption={example-specification.yaml},columns=fullflexible]{example-specification.yaml}
\end{document}
