I have read the documentation of sockets and I was wondering how sockets can be used for practical use-cases. While surfing SE, I found this discussion around the topic and this mesmerizing picture-mode-illustrated answer 😛, but still didn't find a straight forward example. I asked AI to give a sample code and got the following (some manual cleanup done and some deprecated commands removed from the original AI-response):
\DocumentMetadata{tagging=on}
\documentclass{article}
\begin{document}
\NewSocket{greeting-socket}{0}
\NewSocketPlug{greeting-socket}{formal}{Dear ma’am/sir,}
\NewSocketPlug{greeting-socket}{informal}{Hi there,}
\NewSocketPlug{greeting-socket}{friendly}{Hello, friend!}
\NewSocket{closing-socket}{0}
\NewSocketPlug{closing-socket}{formal}{Sincerely,}
\NewSocketPlug{closing-socket}{informal}{Cheers,}
\section*{Formal Letter}
\AssignSocketPlug{greeting-socket}{formal}
\AssignSocketPlug{closing-socket}{formal}
\UseSocket{greeting-socket}
This is a formal letter content.
\UseSocket{closing-socket}
John Doe
\section*{Informal Note}
\AssignSocketPlug{greeting-socket}{informal}
\AssignSocketPlug{closing-socket}{informal}
\UseSocket{greeting-socket}
This is an informal note.
\UseSocket{closing-socket}
Jane
\section*{Friendly Message}
\AssignSocketPlug{greeting-socket}{friendly}
\AssignSocketPlug{closing-socket}{informal}
\UseSocket{greeting-socket}
Just a quick message to say hi.
\UseSocket{closing-socket}
Your pal
\end{document}
Now the question is if this type of usage can be called "standard"? Imagine I have some code instead of the un-expandable text in the given example. Here are some questions:
Are the names used here recommendable? What names do the kernel use-cases of sockets use? What should package authors use? (The documentation says:
Best practice naming conventions are . . . to be documented
but it is dated 2024-12-27 which is quite old now, so I assume some recommendations can be given?)
Usually it is said that sockets are to be used only once unlike hooks. Does that mean multiple usages of
\AssignSocketPlugwrong? The documentation does say:If the programming logic should change, then all that is necessary is to make a new assignment with \AssignSocketPlug to a different {⟨socket-plug-name⟩}.
but it also says:
A socket is typically only used in one place in code, but this is not a requirement, i.e., if the same operation with the same inputs need to be carried out in several places the same named socket can be used.
So I am confused. In the given example, what exactly is wrong (or atypical)? The multiple uses of
\AssignSocketPlugor\UseSocket? Theoretically both seem to be fine, but not sure what is expected.Is there any general consensus on what should not be used in sockets?
Anything else regarding sockets based on the example or beyond it?
tableaux/tagsupport/tableau/init. I don't know that format is documented, but I copied what I found in kernel code. so that might have e.g.tagsupport/tikz/init. I named minetableaux/tagsupport/tableau/init.tableauxis intended as a module identifier/prefix.tagsupport/tableau/initis intended as a hierarchy of descriptors.tagsupport/tikz/picture/end, wheretagsupportindicates the module andtikz/picture/endis a hierarchy of descriptors.\UseSocket{}in a document. probably you'd have a class or package for letters which would use the<module>/letter/closingsocket once, because each letter only gets one closing. so it would be used in one place in the template for letters. but you might have several letters in a document.