flat argument passing #38

Open
opened 2026-05-06 13:21:42 +00:00 by lukas · 0 comments
Owner

This argument passing which may look weird in the beginning is not needed for the scoping:

\documentclass[a4paper]{article}

\usepackage{pgfkeys}
\usepackage{tikz}

\pgfkeys{
	/kata/.cd,
	every head/.style={red},
	head/.style={/kata/every head/.append style={#1}}
}


\NewDocumentEnvironment{kata}{O{}}{\pgfqkeys{/kata}{#1}}{}

\NewDocumentEnvironment{step}{O{}}{%
	\pgfqkeys{/kata}{#1}
	\begin{tikzpicture}
		\node[/kata/every head] {head};
	\end{tikzpicture}
}{}

\begin{document}

\begin{kata}[head=brown]
	\begin{step}[head={blue}]
	\end{step}
	\begin{step}
	\end{step}
\end{kata}

\hrule

\begin{kata}
	\begin{step}
	\end{step}
	\begin{step}
	\end{step}
\end{kata}

\end{document}

image

also works perfectly fine.

The only reason for this hierarchy thinking really is that I want to avoid that the user passes arguments at places where they do not belong and don't have an impact unnoticed.

But I see this is a bit weird at some places. Thus maybe it makes sense to change this somewhen in the future and implement a truely flat interface where everything is only defined once at the same "folder". The question then is if this allows "shortcuts" like using the key color at \waza while the actual key is something like waza color. Maybe this is possible be setting a .forward to before passing the arguments for waza (but then setting this up for every \waza command also feels wrong).

This argument passing which may look weird in the beginning is not needed for the scoping: ```latex \documentclass[a4paper]{article} \usepackage{pgfkeys} \usepackage{tikz} \pgfkeys{ /kata/.cd, every head/.style={red}, head/.style={/kata/every head/.append style={#1}} } \NewDocumentEnvironment{kata}{O{}}{\pgfqkeys{/kata}{#1}}{} \NewDocumentEnvironment{step}{O{}}{% \pgfqkeys{/kata}{#1} \begin{tikzpicture} \node[/kata/every head] {head}; \end{tikzpicture} }{} \begin{document} \begin{kata}[head=brown] \begin{step}[head={blue}] \end{step} \begin{step} \end{step} \end{kata} \hrule \begin{kata} \begin{step} \end{step} \begin{step} \end{step} \end{kata} \end{document} ``` ![image](/attachments/440a5b6c-9155-4b24-bb04-408d4224ead0) also works perfectly fine. The only reason for this hierarchy thinking really is that I want to avoid that the user passes arguments at places where they do not belong and don't have an impact unnoticed. But I see this is a bit weird at some places. Thus maybe it makes sense to change this somewhen in the future and implement a truely flat interface where everything is only defined once at the same "folder". The question then is if this allows "shortcuts" like using the key `color` at `\waza` while the actual key is something like `waza color`. Maybe this is possible be setting a `.forward to` before passing the arguments for `waza` (but then setting this up for every `\waza` command also feels wrong).
3.8 KiB
lukas self-assigned this 2026-05-06 13:21:42 +00:00
lukas changed title from Argument passing to flat argument passing 2026-05-06 13:21:55 +00:00
Sign in to join this conversation.
No description provided.