I feel particularly bombarded by sub-atomic particles right now (and it's mostly Will's fault :)
). First, in Will's answer to this question today, he referred to expl3
's \prg_case_str:nnn
command. Digging into the package, I noticed the command involves an interestingly named macro called \quark_if_recursion_tail_stop_do:nn
. All I can gather from the expl3
documentation about things with the word (particle;)
) quark
in their name is that:
l3quark A ‘quark’ is a command that is defined to expand to itself! Therefore they must never be expanded as this will generate infinite recursion; they do however have many uses, e.g. as special markers and delimiters within code.
Hmmm.
Coincidentally, Will and Kevin's new hardwrap
package was released on CTAN today (many congrats guys!). Digging into the documented code, I notice:
\hw@scanstop
This is a ‘quark’ from expl3 designed to delimit scanning; it will never be executed, else an infinite loop results.
\protected\def\hw@scanstop{\hw@scanstop}
Reading the remainder of hardwrap
's code, yes, \hw@scanstop
is used in exactly the way described in the definition of l3quark, above.
Still, I'm perplexed. What's so special about self-referencing tokens as opposed to any other token assigned a special-purpose name, i.e., any other vanilla signifier, whether a command sequence or not? Are they self-referencing only for error-catching purposes?
If LaTeX quarks do have interesting properties beyond just being specially defined and used signifiers, where, when, how and why should I best employ them?
Are they really expl3
specific, or is it more a convention that has been adopted into the LaTeX3 programming patterns set?
Finally, out of interest (in the spirit of Yiannis's recent question about Lisp car
and cdr
"relics" in TeX's lexicon), what's the story about how the word quark
found its way into LaTeX3 vocabulary? (Please tell me that LaTeX3
quarks aren't envisioned to possess color, flavor, etc. properties!)
hardwarp
I'm afraid Will is not quite right: as he's\protected
the definition this is not a quark. I know that because I tried something similar and found it does not work. As Hendrik explains, the key is\ifx
testing, and there\protected
status is important. If you store a quark inside a variable, then the\ifx
will only be true if the quark is not protected (variables are not protected).hardwarp
apropos the question's quantum theme!:)
\protected
but the code documentation stuck. Oh well:)