summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/lua-placeholders/tex/lua-placeholders.sty
blob: e11b950f5aa8233535faa8aeacbc7f8504af29fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%% lua-placeholders.sty
%% 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

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lua-placeholders}[2024/01/23 1.0.0 Extended LaTeX Paramter Interface Package]

\RequirePackage{ifthen}
\RequirePackage{luapackageloader}
\RequirePackage{textcomp}
\RequirePackage{xspace}

\newcommand\curnamespace{\jobname}
\newcommand\paramplaceholder[1]{\texttt{\textbf{[}#1\textbf{]}}}
\newcommand\paramnotfound[1]{\paramplaceholder{{\textnormal{\textlangle unknown\textrangle}} #1}}
\newcommand\paramlistconjunction{,~}

\directlua{lua_placeholders = require('lua-placeholders')}

\newcommand\setnamespace[1]{\renewcommand\curnamespace{#1}}
\newcommand\strictparams{\directlua{lua_placeholders.set_strict()}}
\newcommand%! suppress = NonMatchingIf
\ifparam[4][\curnamespace]{%
    \directlua{local p = lua_placeholders.param_object('#2','#1') if p then p:set_bool('#2') end}%
    \ifthenelse{\boolean{#2}}{#3}{#4}}
\newcommand\param[2][\curnamespace]{\directlua{lua_placeholders.param('#2', '#1')}}
\newcommand\PARAM[2][\curnamespace]{\directlua{local p = lua_placeholders.param_object('#2', '#1') if p then tex.print(p:to_upper()) end}}
\def\rawparam#1#2{\directlua{local p = lua_placeholders.param_object('#2', '#1') if p then tex.print(p:val() or p.default or p.placeholder) end}}
\newcommand\numparam[2][\curnamespace]{\directlua{local n = lua_placeholders.param_object('#2', '#1') if n then n:print_num() end}}
\newcommand\hasparam[4][\curnamespace]{%
    \def\has@param@true{#3}%
    \def\has@param@false{#4}%
    \directlua{lua_placeholders.handle_param_is_set('#2', '#1')}}
\newcommand\paramfield[3][\curnamespace]{\directlua{lua_placeholders.field('#2','#3', '#1')}}
\newenvironment{paramobject}[2][\curnamespace]{\directlua{lua_placeholders.with_object('#2', '#1')}}{}
\newcommand\forlistitem[3][\curnamespace]{\directlua{lua_placeholders.for_item('#2', '#1', '#3')}}
\newcommand\fortablerow[3][\curnamespace]{\directlua{lua_placeholders.with_rows('#2', '#1', '#3')}}
\newcommand\loadrecipe[2][]{\directlua{lua_placeholders.recipe('#2', '#1')}}
\newcommand\loadpayload[2][]{\directlua{lua_placeholders.payload('#2', '#1')}}