Is there a list of expandable TeX primitives? LaTeX? e-TeX? others?












7














According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro numexpr being expandable, calculations are possible.



Hence the interest in knowing which macros are and which are not expandable from TeX, LaTeX, e-TeX, etc.



I am not asking if there is a test, but if there is a list already made.










share|improve this question




















  • 1




    Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    8 hours ago
















7














According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro numexpr being expandable, calculations are possible.



Hence the interest in knowing which macros are and which are not expandable from TeX, LaTeX, e-TeX, etc.



I am not asking if there is a test, but if there is a list already made.










share|improve this question




















  • 1




    Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    8 hours ago














7












7








7


2





According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro numexpr being expandable, calculations are possible.



Hence the interest in knowing which macros are and which are not expandable from TeX, LaTeX, e-TeX, etc.



I am not asking if there is a test, but if there is a list already made.










share|improve this question















According to Christian Hupfer's comment I understood that calculations are possible in a keyval list when the macro is expandable. The macro numexpr being expandable, calculations are possible.



Hence the interest in knowing which macros are and which are not expandable from TeX, LaTeX, e-TeX, etc.



I am not asking if there is a test, but if there is a list already made.







macros expansion






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago

























asked 11 hours ago









AndréC

7,48411440




7,48411440








  • 1




    Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    8 hours ago














  • 1




    Comments are not for extended discussion; this conversation has been moved to chat.
    – Joseph Wright
    8 hours ago








1




1




Comments are not for extended discussion; this conversation has been moved to chat.
– Joseph Wright
8 hours ago




Comments are not for extended discussion; this conversation has been moved to chat.
– Joseph Wright
8 hours ago










2 Answers
2






active

oldest

votes


















13














Joseph has already answered, interpreting the "expandable` in your question as "fully expandable" (or what is perhaps better named as "safe in an expansion only context" see



Advantages and disadvantages of fully expandable macros



However to answer the question as actually asked, note that numexpr is neither a macro nor expandable.



All macros are by definition expandable, a macro works by expanding to its replacement text. There is no list of these as it is any command defined via def or its variants edef, gdef, xdef.



The TeXBook lists all the TeX primitivies, these are marked by a * in the index, although you need to check the description of each individually to see if they are expandable.





In classic TeX, the expandable primitives are (I think:-)



expandafter
csname
the
number
romannumeral
if
ifx
ifcat
ifcase
ifnum
ifodd
ifdim
ifeof
iftrue
iffalse
ifhbox
ifvbox
ifvoid
ifinner
ifvnode
ifhmode
ifmmode
else
or
fi
input % (@@input in LaTeX)
jobname
meaning
noexpand
string
topmark
firstmark
botmark




in etex the additional expandable primitives are



topmarks
firstmarks
botmarks
ifdefined
ifcsname
iffontchar
unless
eTeXrevision
unexpanded
detokenize
scantokens




in addition to all the above pdftex adds the following expandable primitives



pdfescapestring
pdfescapename
pdfescapehex
pdfstrcmp
pdfmatch
ifpdfabsnum
ifpdfabsdim
pdfuniformdeviate
pdfnormaldeviate
pdffilemoddate
pdffilesize
pdfmdffivesum
pdffiledump
pdfcolorstackinit
ifincsname
ifpdfprimitive
pdfcreationdate
pdfinsertht
pdftexbanner
pdftexrevision
expanded % (in development versions for texlive 2019)




XeTeX has the primitives of etex, and adds the following expandable primitives



ifincsname
ifprimitive
normaldeviate
uniformdeviate
filedump
filemoddate
filesize
mdfivesum
expanded % for texlive 2019
XeTeXrevision
Uchar
Ucharcat




LuaTeX has the expandable primitives of etex plus (at least)



luatexbanner
luatexrevision
formatname
Uchar
directlua
luaescapestring
scantextokens
csstring
expanded
pdfextension
pdfvariable
pdffeedback




If any Japanese Tex user wants to add the list for (u)(e)ptex, feel free to edit this answer here....






share|improve this answer



















  • 2




    @AndréC yes sorry, my tex is rather better than my typing:-)
    – David Carlisle
    7 hours ago










  • If numexpr is not a macro, what is it? A e-TeX primitive ?
    – AndréC
    7 hours ago








  • 1




    @AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
    – David Carlisle
    7 hours ago








  • 1




    @Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
    – David Carlisle
    6 hours ago






  • 1




    @DavidCarlisle I believe csname should also be on the list
    – Anton
    3 hours ago



















7














A list of all expandable macros is entirely impossible to provide: there are an open-ended number of cases. What one can do is provide a list of primitives which work by expansion, and general rules for macros.



Essentially, any primitives which carry out assignment or typesetting are not expandable, whilst other primitives are. Thus for example def, let, etc. are all non-expandable, as are hbox, raise, setbox, whereas expandafter, the and ifx are all expandable. Note that some primitives will be expandable in the right context: numexpr is not expandable in itself, but is a valid token coming after the or number:



edeftesta{numexpr 1+2relax}showtesta
edeftestb{numbernumexpr 1+2relax}showtestb


In terms of macros, we have to be clear what we mean by 'expandable'. TeX is a macro expansion language, so if we have for example



defbaz{}
deffoo{defbaz{bar}}


then we can do



edeftest{foo}showtest


although the result is not what is likely wanted/useful. As such, when we talk about expandable macros we normally mean macros which contain only expandable primitives and which thus can be used 'safely' inside an edef or similar. With e-TeX, it' possible to ensure that macros which don't meet this criterion don't 'blow up':



defbaz{}
protecteddeffoo{defbaz{bar}}
edeftest{foo}showtest


Where does that take us? Any macro which contains:




  • Any assignment primitive

  • Any typesetting primitive

  • Any protected macro

  • Any macro which itself meets one of the three criteria above


is not expandable. That is the majority of 'useful' macros, so as mentioned in comments, if you are not sure, assume non-expandable.





Note that the list of non-expandable primitives is quite long, and we do have to remember about the context. For example, something like tracingcommands acts like a count register, so is non-expandable unless if follows the. Thus unless we implement a token-by-token processor, just seeing tracingcommands doesn't tell us that a macro containing this token is not expandable.



deffoo{tracingcommands=1 }% Not expandable
defbaz{thetracingcommands}% Expandable




In LaTeX3/expl3, all macros are either fully expandable or are protected. Moreover, the expandable ones are all marked as such (with a star) in the documentation. The reason is that it requires some knowledge to see if something is expandable, in particular checking all macro 'dependencies'. As such, one has to work carefully to track expandable macros.






share|improve this answer



















  • 2




    There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
    – Joseph Wright
    8 hours ago






  • 1




    oops I just noticed this comment, which accurately predicts my answer:-)
    – David Carlisle
    7 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467360%2fis-there-a-list-of-expandable-tex-primitives-latex-e-tex-others%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









13














Joseph has already answered, interpreting the "expandable` in your question as "fully expandable" (or what is perhaps better named as "safe in an expansion only context" see



Advantages and disadvantages of fully expandable macros



However to answer the question as actually asked, note that numexpr is neither a macro nor expandable.



All macros are by definition expandable, a macro works by expanding to its replacement text. There is no list of these as it is any command defined via def or its variants edef, gdef, xdef.



The TeXBook lists all the TeX primitivies, these are marked by a * in the index, although you need to check the description of each individually to see if they are expandable.





In classic TeX, the expandable primitives are (I think:-)



expandafter
csname
the
number
romannumeral
if
ifx
ifcat
ifcase
ifnum
ifodd
ifdim
ifeof
iftrue
iffalse
ifhbox
ifvbox
ifvoid
ifinner
ifvnode
ifhmode
ifmmode
else
or
fi
input % (@@input in LaTeX)
jobname
meaning
noexpand
string
topmark
firstmark
botmark




in etex the additional expandable primitives are



topmarks
firstmarks
botmarks
ifdefined
ifcsname
iffontchar
unless
eTeXrevision
unexpanded
detokenize
scantokens




in addition to all the above pdftex adds the following expandable primitives



pdfescapestring
pdfescapename
pdfescapehex
pdfstrcmp
pdfmatch
ifpdfabsnum
ifpdfabsdim
pdfuniformdeviate
pdfnormaldeviate
pdffilemoddate
pdffilesize
pdfmdffivesum
pdffiledump
pdfcolorstackinit
ifincsname
ifpdfprimitive
pdfcreationdate
pdfinsertht
pdftexbanner
pdftexrevision
expanded % (in development versions for texlive 2019)




XeTeX has the primitives of etex, and adds the following expandable primitives



ifincsname
ifprimitive
normaldeviate
uniformdeviate
filedump
filemoddate
filesize
mdfivesum
expanded % for texlive 2019
XeTeXrevision
Uchar
Ucharcat




LuaTeX has the expandable primitives of etex plus (at least)



luatexbanner
luatexrevision
formatname
Uchar
directlua
luaescapestring
scantextokens
csstring
expanded
pdfextension
pdfvariable
pdffeedback




If any Japanese Tex user wants to add the list for (u)(e)ptex, feel free to edit this answer here....






share|improve this answer



















  • 2




    @AndréC yes sorry, my tex is rather better than my typing:-)
    – David Carlisle
    7 hours ago










  • If numexpr is not a macro, what is it? A e-TeX primitive ?
    – AndréC
    7 hours ago








  • 1




    @AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
    – David Carlisle
    7 hours ago








  • 1




    @Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
    – David Carlisle
    6 hours ago






  • 1




    @DavidCarlisle I believe csname should also be on the list
    – Anton
    3 hours ago
















13














Joseph has already answered, interpreting the "expandable` in your question as "fully expandable" (or what is perhaps better named as "safe in an expansion only context" see



Advantages and disadvantages of fully expandable macros



However to answer the question as actually asked, note that numexpr is neither a macro nor expandable.



All macros are by definition expandable, a macro works by expanding to its replacement text. There is no list of these as it is any command defined via def or its variants edef, gdef, xdef.



The TeXBook lists all the TeX primitivies, these are marked by a * in the index, although you need to check the description of each individually to see if they are expandable.





In classic TeX, the expandable primitives are (I think:-)



expandafter
csname
the
number
romannumeral
if
ifx
ifcat
ifcase
ifnum
ifodd
ifdim
ifeof
iftrue
iffalse
ifhbox
ifvbox
ifvoid
ifinner
ifvnode
ifhmode
ifmmode
else
or
fi
input % (@@input in LaTeX)
jobname
meaning
noexpand
string
topmark
firstmark
botmark




in etex the additional expandable primitives are



topmarks
firstmarks
botmarks
ifdefined
ifcsname
iffontchar
unless
eTeXrevision
unexpanded
detokenize
scantokens




in addition to all the above pdftex adds the following expandable primitives



pdfescapestring
pdfescapename
pdfescapehex
pdfstrcmp
pdfmatch
ifpdfabsnum
ifpdfabsdim
pdfuniformdeviate
pdfnormaldeviate
pdffilemoddate
pdffilesize
pdfmdffivesum
pdffiledump
pdfcolorstackinit
ifincsname
ifpdfprimitive
pdfcreationdate
pdfinsertht
pdftexbanner
pdftexrevision
expanded % (in development versions for texlive 2019)




XeTeX has the primitives of etex, and adds the following expandable primitives



ifincsname
ifprimitive
normaldeviate
uniformdeviate
filedump
filemoddate
filesize
mdfivesum
expanded % for texlive 2019
XeTeXrevision
Uchar
Ucharcat




LuaTeX has the expandable primitives of etex plus (at least)



luatexbanner
luatexrevision
formatname
Uchar
directlua
luaescapestring
scantextokens
csstring
expanded
pdfextension
pdfvariable
pdffeedback




If any Japanese Tex user wants to add the list for (u)(e)ptex, feel free to edit this answer here....






share|improve this answer



















  • 2




    @AndréC yes sorry, my tex is rather better than my typing:-)
    – David Carlisle
    7 hours ago










  • If numexpr is not a macro, what is it? A e-TeX primitive ?
    – AndréC
    7 hours ago








  • 1




    @AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
    – David Carlisle
    7 hours ago








  • 1




    @Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
    – David Carlisle
    6 hours ago






  • 1




    @DavidCarlisle I believe csname should also be on the list
    – Anton
    3 hours ago














13












13








13






Joseph has already answered, interpreting the "expandable` in your question as "fully expandable" (or what is perhaps better named as "safe in an expansion only context" see



Advantages and disadvantages of fully expandable macros



However to answer the question as actually asked, note that numexpr is neither a macro nor expandable.



All macros are by definition expandable, a macro works by expanding to its replacement text. There is no list of these as it is any command defined via def or its variants edef, gdef, xdef.



The TeXBook lists all the TeX primitivies, these are marked by a * in the index, although you need to check the description of each individually to see if they are expandable.





In classic TeX, the expandable primitives are (I think:-)



expandafter
csname
the
number
romannumeral
if
ifx
ifcat
ifcase
ifnum
ifodd
ifdim
ifeof
iftrue
iffalse
ifhbox
ifvbox
ifvoid
ifinner
ifvnode
ifhmode
ifmmode
else
or
fi
input % (@@input in LaTeX)
jobname
meaning
noexpand
string
topmark
firstmark
botmark




in etex the additional expandable primitives are



topmarks
firstmarks
botmarks
ifdefined
ifcsname
iffontchar
unless
eTeXrevision
unexpanded
detokenize
scantokens




in addition to all the above pdftex adds the following expandable primitives



pdfescapestring
pdfescapename
pdfescapehex
pdfstrcmp
pdfmatch
ifpdfabsnum
ifpdfabsdim
pdfuniformdeviate
pdfnormaldeviate
pdffilemoddate
pdffilesize
pdfmdffivesum
pdffiledump
pdfcolorstackinit
ifincsname
ifpdfprimitive
pdfcreationdate
pdfinsertht
pdftexbanner
pdftexrevision
expanded % (in development versions for texlive 2019)




XeTeX has the primitives of etex, and adds the following expandable primitives



ifincsname
ifprimitive
normaldeviate
uniformdeviate
filedump
filemoddate
filesize
mdfivesum
expanded % for texlive 2019
XeTeXrevision
Uchar
Ucharcat




LuaTeX has the expandable primitives of etex plus (at least)



luatexbanner
luatexrevision
formatname
Uchar
directlua
luaescapestring
scantextokens
csstring
expanded
pdfextension
pdfvariable
pdffeedback




If any Japanese Tex user wants to add the list for (u)(e)ptex, feel free to edit this answer here....






share|improve this answer














Joseph has already answered, interpreting the "expandable` in your question as "fully expandable" (or what is perhaps better named as "safe in an expansion only context" see



Advantages and disadvantages of fully expandable macros



However to answer the question as actually asked, note that numexpr is neither a macro nor expandable.



All macros are by definition expandable, a macro works by expanding to its replacement text. There is no list of these as it is any command defined via def or its variants edef, gdef, xdef.



The TeXBook lists all the TeX primitivies, these are marked by a * in the index, although you need to check the description of each individually to see if they are expandable.





In classic TeX, the expandable primitives are (I think:-)



expandafter
csname
the
number
romannumeral
if
ifx
ifcat
ifcase
ifnum
ifodd
ifdim
ifeof
iftrue
iffalse
ifhbox
ifvbox
ifvoid
ifinner
ifvnode
ifhmode
ifmmode
else
or
fi
input % (@@input in LaTeX)
jobname
meaning
noexpand
string
topmark
firstmark
botmark




in etex the additional expandable primitives are



topmarks
firstmarks
botmarks
ifdefined
ifcsname
iffontchar
unless
eTeXrevision
unexpanded
detokenize
scantokens




in addition to all the above pdftex adds the following expandable primitives



pdfescapestring
pdfescapename
pdfescapehex
pdfstrcmp
pdfmatch
ifpdfabsnum
ifpdfabsdim
pdfuniformdeviate
pdfnormaldeviate
pdffilemoddate
pdffilesize
pdfmdffivesum
pdffiledump
pdfcolorstackinit
ifincsname
ifpdfprimitive
pdfcreationdate
pdfinsertht
pdftexbanner
pdftexrevision
expanded % (in development versions for texlive 2019)




XeTeX has the primitives of etex, and adds the following expandable primitives



ifincsname
ifprimitive
normaldeviate
uniformdeviate
filedump
filemoddate
filesize
mdfivesum
expanded % for texlive 2019
XeTeXrevision
Uchar
Ucharcat




LuaTeX has the expandable primitives of etex plus (at least)



luatexbanner
luatexrevision
formatname
Uchar
directlua
luaescapestring
scantextokens
csstring
expanded
pdfextension
pdfvariable
pdffeedback




If any Japanese Tex user wants to add the list for (u)(e)ptex, feel free to edit this answer here....







share|improve this answer














share|improve this answer



share|improve this answer








edited 31 secs ago

























answered 8 hours ago









David Carlisle

482k3811131850




482k3811131850








  • 2




    @AndréC yes sorry, my tex is rather better than my typing:-)
    – David Carlisle
    7 hours ago










  • If numexpr is not a macro, what is it? A e-TeX primitive ?
    – AndréC
    7 hours ago








  • 1




    @AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
    – David Carlisle
    7 hours ago








  • 1




    @Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
    – David Carlisle
    6 hours ago






  • 1




    @DavidCarlisle I believe csname should also be on the list
    – Anton
    3 hours ago














  • 2




    @AndréC yes sorry, my tex is rather better than my typing:-)
    – David Carlisle
    7 hours ago










  • If numexpr is not a macro, what is it? A e-TeX primitive ?
    – AndréC
    7 hours ago








  • 1




    @AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
    – David Carlisle
    7 hours ago








  • 1




    @Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
    – David Carlisle
    6 hours ago






  • 1




    @DavidCarlisle I believe csname should also be on the list
    – Anton
    3 hours ago








2




2




@AndréC yes sorry, my tex is rather better than my typing:-)
– David Carlisle
7 hours ago




@AndréC yes sorry, my tex is rather better than my typing:-)
– David Carlisle
7 hours ago












If numexpr is not a macro, what is it? A e-TeX primitive ?
– AndréC
7 hours ago






If numexpr is not a macro, what is it? A e-TeX primitive ?
– AndréC
7 hours ago






1




1




@AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
– David Carlisle
7 hours ago






@AndréC yes, macros are all user defined commands, although some expandable primitives act very much like pre-defined macros. (but numexpr isn't expandable either)
– David Carlisle
7 hours ago






1




1




@Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
– David Carlisle
6 hours ago




@Dr.ManuelKuehner classic tex mostly, the others I scanned over the manual, I may have missed a few but I'll edit if anyone spots any errors
– David Carlisle
6 hours ago




1




1




@DavidCarlisle I believe csname should also be on the list
– Anton
3 hours ago




@DavidCarlisle I believe csname should also be on the list
– Anton
3 hours ago











7














A list of all expandable macros is entirely impossible to provide: there are an open-ended number of cases. What one can do is provide a list of primitives which work by expansion, and general rules for macros.



Essentially, any primitives which carry out assignment or typesetting are not expandable, whilst other primitives are. Thus for example def, let, etc. are all non-expandable, as are hbox, raise, setbox, whereas expandafter, the and ifx are all expandable. Note that some primitives will be expandable in the right context: numexpr is not expandable in itself, but is a valid token coming after the or number:



edeftesta{numexpr 1+2relax}showtesta
edeftestb{numbernumexpr 1+2relax}showtestb


In terms of macros, we have to be clear what we mean by 'expandable'. TeX is a macro expansion language, so if we have for example



defbaz{}
deffoo{defbaz{bar}}


then we can do



edeftest{foo}showtest


although the result is not what is likely wanted/useful. As such, when we talk about expandable macros we normally mean macros which contain only expandable primitives and which thus can be used 'safely' inside an edef or similar. With e-TeX, it' possible to ensure that macros which don't meet this criterion don't 'blow up':



defbaz{}
protecteddeffoo{defbaz{bar}}
edeftest{foo}showtest


Where does that take us? Any macro which contains:




  • Any assignment primitive

  • Any typesetting primitive

  • Any protected macro

  • Any macro which itself meets one of the three criteria above


is not expandable. That is the majority of 'useful' macros, so as mentioned in comments, if you are not sure, assume non-expandable.





Note that the list of non-expandable primitives is quite long, and we do have to remember about the context. For example, something like tracingcommands acts like a count register, so is non-expandable unless if follows the. Thus unless we implement a token-by-token processor, just seeing tracingcommands doesn't tell us that a macro containing this token is not expandable.



deffoo{tracingcommands=1 }% Not expandable
defbaz{thetracingcommands}% Expandable




In LaTeX3/expl3, all macros are either fully expandable or are protected. Moreover, the expandable ones are all marked as such (with a star) in the documentation. The reason is that it requires some knowledge to see if something is expandable, in particular checking all macro 'dependencies'. As such, one has to work carefully to track expandable macros.






share|improve this answer



















  • 2




    There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
    – Joseph Wright
    8 hours ago






  • 1




    oops I just noticed this comment, which accurately predicts my answer:-)
    – David Carlisle
    7 hours ago
















7














A list of all expandable macros is entirely impossible to provide: there are an open-ended number of cases. What one can do is provide a list of primitives which work by expansion, and general rules for macros.



Essentially, any primitives which carry out assignment or typesetting are not expandable, whilst other primitives are. Thus for example def, let, etc. are all non-expandable, as are hbox, raise, setbox, whereas expandafter, the and ifx are all expandable. Note that some primitives will be expandable in the right context: numexpr is not expandable in itself, but is a valid token coming after the or number:



edeftesta{numexpr 1+2relax}showtesta
edeftestb{numbernumexpr 1+2relax}showtestb


In terms of macros, we have to be clear what we mean by 'expandable'. TeX is a macro expansion language, so if we have for example



defbaz{}
deffoo{defbaz{bar}}


then we can do



edeftest{foo}showtest


although the result is not what is likely wanted/useful. As such, when we talk about expandable macros we normally mean macros which contain only expandable primitives and which thus can be used 'safely' inside an edef or similar. With e-TeX, it' possible to ensure that macros which don't meet this criterion don't 'blow up':



defbaz{}
protecteddeffoo{defbaz{bar}}
edeftest{foo}showtest


Where does that take us? Any macro which contains:




  • Any assignment primitive

  • Any typesetting primitive

  • Any protected macro

  • Any macro which itself meets one of the three criteria above


is not expandable. That is the majority of 'useful' macros, so as mentioned in comments, if you are not sure, assume non-expandable.





Note that the list of non-expandable primitives is quite long, and we do have to remember about the context. For example, something like tracingcommands acts like a count register, so is non-expandable unless if follows the. Thus unless we implement a token-by-token processor, just seeing tracingcommands doesn't tell us that a macro containing this token is not expandable.



deffoo{tracingcommands=1 }% Not expandable
defbaz{thetracingcommands}% Expandable




In LaTeX3/expl3, all macros are either fully expandable or are protected. Moreover, the expandable ones are all marked as such (with a star) in the documentation. The reason is that it requires some knowledge to see if something is expandable, in particular checking all macro 'dependencies'. As such, one has to work carefully to track expandable macros.






share|improve this answer



















  • 2




    There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
    – Joseph Wright
    8 hours ago






  • 1




    oops I just noticed this comment, which accurately predicts my answer:-)
    – David Carlisle
    7 hours ago














7












7








7






A list of all expandable macros is entirely impossible to provide: there are an open-ended number of cases. What one can do is provide a list of primitives which work by expansion, and general rules for macros.



Essentially, any primitives which carry out assignment or typesetting are not expandable, whilst other primitives are. Thus for example def, let, etc. are all non-expandable, as are hbox, raise, setbox, whereas expandafter, the and ifx are all expandable. Note that some primitives will be expandable in the right context: numexpr is not expandable in itself, but is a valid token coming after the or number:



edeftesta{numexpr 1+2relax}showtesta
edeftestb{numbernumexpr 1+2relax}showtestb


In terms of macros, we have to be clear what we mean by 'expandable'. TeX is a macro expansion language, so if we have for example



defbaz{}
deffoo{defbaz{bar}}


then we can do



edeftest{foo}showtest


although the result is not what is likely wanted/useful. As such, when we talk about expandable macros we normally mean macros which contain only expandable primitives and which thus can be used 'safely' inside an edef or similar. With e-TeX, it' possible to ensure that macros which don't meet this criterion don't 'blow up':



defbaz{}
protecteddeffoo{defbaz{bar}}
edeftest{foo}showtest


Where does that take us? Any macro which contains:




  • Any assignment primitive

  • Any typesetting primitive

  • Any protected macro

  • Any macro which itself meets one of the three criteria above


is not expandable. That is the majority of 'useful' macros, so as mentioned in comments, if you are not sure, assume non-expandable.





Note that the list of non-expandable primitives is quite long, and we do have to remember about the context. For example, something like tracingcommands acts like a count register, so is non-expandable unless if follows the. Thus unless we implement a token-by-token processor, just seeing tracingcommands doesn't tell us that a macro containing this token is not expandable.



deffoo{tracingcommands=1 }% Not expandable
defbaz{thetracingcommands}% Expandable




In LaTeX3/expl3, all macros are either fully expandable or are protected. Moreover, the expandable ones are all marked as such (with a star) in the documentation. The reason is that it requires some knowledge to see if something is expandable, in particular checking all macro 'dependencies'. As such, one has to work carefully to track expandable macros.






share|improve this answer














A list of all expandable macros is entirely impossible to provide: there are an open-ended number of cases. What one can do is provide a list of primitives which work by expansion, and general rules for macros.



Essentially, any primitives which carry out assignment or typesetting are not expandable, whilst other primitives are. Thus for example def, let, etc. are all non-expandable, as are hbox, raise, setbox, whereas expandafter, the and ifx are all expandable. Note that some primitives will be expandable in the right context: numexpr is not expandable in itself, but is a valid token coming after the or number:



edeftesta{numexpr 1+2relax}showtesta
edeftestb{numbernumexpr 1+2relax}showtestb


In terms of macros, we have to be clear what we mean by 'expandable'. TeX is a macro expansion language, so if we have for example



defbaz{}
deffoo{defbaz{bar}}


then we can do



edeftest{foo}showtest


although the result is not what is likely wanted/useful. As such, when we talk about expandable macros we normally mean macros which contain only expandable primitives and which thus can be used 'safely' inside an edef or similar. With e-TeX, it' possible to ensure that macros which don't meet this criterion don't 'blow up':



defbaz{}
protecteddeffoo{defbaz{bar}}
edeftest{foo}showtest


Where does that take us? Any macro which contains:




  • Any assignment primitive

  • Any typesetting primitive

  • Any protected macro

  • Any macro which itself meets one of the three criteria above


is not expandable. That is the majority of 'useful' macros, so as mentioned in comments, if you are not sure, assume non-expandable.





Note that the list of non-expandable primitives is quite long, and we do have to remember about the context. For example, something like tracingcommands acts like a count register, so is non-expandable unless if follows the. Thus unless we implement a token-by-token processor, just seeing tracingcommands doesn't tell us that a macro containing this token is not expandable.



deffoo{tracingcommands=1 }% Not expandable
defbaz{thetracingcommands}% Expandable




In LaTeX3/expl3, all macros are either fully expandable or are protected. Moreover, the expandable ones are all marked as such (with a star) in the documentation. The reason is that it requires some knowledge to see if something is expandable, in particular checking all macro 'dependencies'. As such, one has to work carefully to track expandable macros.







share|improve this answer














share|improve this answer



share|improve this answer








edited 8 hours ago

























answered 8 hours ago









Joseph Wright

202k21554880




202k21554880








  • 2




    There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
    – Joseph Wright
    8 hours ago






  • 1




    oops I just noticed this comment, which accurately predicts my answer:-)
    – David Carlisle
    7 hours ago














  • 2




    There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
    – Joseph Wright
    8 hours ago






  • 1




    oops I just noticed this comment, which accurately predicts my answer:-)
    – David Carlisle
    7 hours ago








2




2




There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
– Joseph Wright
8 hours ago




There are around 300 TeX90 primitives, plus a lot more added by e-TeX, XeTeX, LuaTeX, ... A list of all non-expandable (or indeed expandable) ones is going to be long, and I'd say not all that useful.
– Joseph Wright
8 hours ago




1




1




oops I just noticed this comment, which accurately predicts my answer:-)
– David Carlisle
7 hours ago




oops I just noticed this comment, which accurately predicts my answer:-)
– David Carlisle
7 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467360%2fis-there-a-list-of-expandable-tex-primitives-latex-e-tex-others%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu