What is the difference between 'macro' and 'command'?












15














Some people use the word 'macro' and 'command' interchangeably to refer to the instructions given to LaTeX. Is there a real difference between the two terms? If there is, can we see some examples on what the differences are?










share|improve this question




















  • 1




    We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
    – Christian Hupfer
    yesterday








  • 1




    I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
    – Circumscribe
    yesterday












  • @Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
    – TeXnician
    yesterday












  • @TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
    – Circumscribe
    yesterday












  • Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
    – Circumscribe
    yesterday
















15














Some people use the word 'macro' and 'command' interchangeably to refer to the instructions given to LaTeX. Is there a real difference between the two terms? If there is, can we see some examples on what the differences are?










share|improve this question




















  • 1




    We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
    – Christian Hupfer
    yesterday








  • 1




    I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
    – Circumscribe
    yesterday












  • @Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
    – TeXnician
    yesterday












  • @TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
    – Circumscribe
    yesterday












  • Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
    – Circumscribe
    yesterday














15












15








15


1





Some people use the word 'macro' and 'command' interchangeably to refer to the instructions given to LaTeX. Is there a real difference between the two terms? If there is, can we see some examples on what the differences are?










share|improve this question















Some people use the word 'macro' and 'command' interchangeably to refer to the instructions given to LaTeX. Is there a real difference between the two terms? If there is, can we see some examples on what the differences are?







macros






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Werner

438k649611653




438k649611653










asked yesterday









Al-Motasem Aldaoudeyeh

1,495312




1,495312








  • 1




    We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
    – Christian Hupfer
    yesterday








  • 1




    I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
    – Circumscribe
    yesterday












  • @Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
    – TeXnician
    yesterday












  • @TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
    – Circumscribe
    yesterday












  • Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
    – Circumscribe
    yesterday














  • 1




    We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
    – Christian Hupfer
    yesterday








  • 1




    I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
    – Circumscribe
    yesterday












  • @Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
    – TeXnician
    yesterday












  • @TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
    – Circumscribe
    yesterday












  • Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
    – Circumscribe
    yesterday








1




1




We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
– Christian Hupfer
yesterday






We write macro or command or control sequence because we don't want to use the same name all the time. We're not lazy ;-)
– Christian Hupfer
yesterday






1




1




I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
– Circumscribe
yesterday






I personally do use these three words slightly differently, and I'm now wondering if this is correct. For me a "macro" is a command defined in terms of other commands (it can be expanded, so I exclude primitives and lengths), a "command" is an instruction that does something (which is admittedly vague, but this would include macros, but not lengths) and a "control" sequence" is a single token that consists of a backslash followed by a sequence of characters (irrespective of whether it is defined at all, but I'm not including active characters). Most commands are all three of these things.
– Circumscribe
yesterday














@Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
– TeXnician
yesterday






@Circumscribe There are expandable primitives that are sometimes expanding to a value, e.g. eTeXrevision. Is this a macro as per your definition?
– TeXnician
yesterday














@TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
– Circumscribe
yesterday






@TeXnician: Good point, I realised that only just before you posted your comment [for those reading along: the first version of my comment said that a macro is something that expands to something else]. I would say it is not (nor are e.g. the, ifx and csname), but I don't know how (or if) these terms are officially defined and I'm actually curious about what users think.
– Circumscribe
yesterday














Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
– Circumscribe
yesterday




Clarification: for my definition a "macro" would be anything for which the show<macro> output starts with "macro:" (and which is thus ultimately defined using a version of def?) and a command would be anything that is either a macro or a primitive (something for which show<primitive> outputs <primitive>), but is not a register (or a character). That last part is probably terrible as a definition though. I also tend to say "command" rather than "macro" when the instruction performs an assignment rather than producing output, but that's probably just me.
– Circumscribe
yesterday










3 Answers
3






active

oldest

votes


















17














macro programming is a programming style (as distinct from compiled programs) where the operation works by each token being replaced inline by its replacement text. Popular macro programming languages other than TeX include the C language pre-processor and the m4 system.



What macro means in LaTeX?



TeX's main mode of user customisation is via its macro processing language, but of course it requires some built in commands (primitives) that you may use to build up macros.



So commands such as def, halign, count are not macros.



Tex also has some primitives that are classed as expandable and so act pretty much the same as pre-defined macros although technically they are not classed as macros in TeX, a list of these expandable primitives is here:



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



A control sequence is a string of characters such as foobar that references a command (or token, or is undefined) as opposed to a character such as x that just references itself, it may reference tex primitives or macros, depending on the context. Note that being a macro is a property of the meaning of the token, but being a control sequence is a property of its syntax. So by default ~ is a macro but it is an active character token not a control sequence.



In TeX macros are always defined by def and its variants such as edef. LaTeX definition commands such as newcommand are themselves macros that ultimately result in an application of def to define a macro.






share|improve this answer































    6














    They're used interchangeably because they mean the same thing.





    • A macro is defined as




      a single computer instruction that stands for a sequence of operations




    • The use of command probably stems from the way it's defined in LaTeX via newcommand and renewcommand and LaTeX3's xparse via NewDocumentCommand and RenewDocumentCommand.


    • There's also control sequence used by DEK in his TeX Book. They all point to the same thing.







    share|improve this answer

















    • 6




      I would not say they mean the same thing, tex primitives are not macros.
      – David Carlisle
      yesterday










    • I'm confident the majority of people using (La)TeX use the terminology interchangeably.
      – Werner
      yesterday






    • 2




      Certainly some do but that I think leads to confusion (as witnessed by this question)
      – David Carlisle
      yesterday



















    4














    I seldom use the term "command" when it is about (La)TeX.



    In the TeXbook the term "command" does also appear in contexts where not single tokens but the coming into being of sequences of control word tokens plays a rôle.



    E.g., chapter 15 of the TeXbook includes a double dangerous bend paragraph where you can read:




    [...] Therefore plain TeX provides an allocation function for registers; Appendix B includes the command
    newinsertfootins

    which defines footins as the number for footnote insertions. [...]




    So, e.g., newinsertfootins is a "command".



    (By the way: The mentioned appendix B does actually not exhibit tokens. It exhibits TeX code, i.e., TeX-input which the programmer of the plain TeX format did produce. That TeX-input itself is not tokens. TeX will create tokens when processing that code.)



    In the TeXbook you also find the phrase "primitive command". It is used in contexts where very short and easily to grasp sequences of TeX-input play a rôle. (Sequences that, when being read and tokenized, yield primitives...)



    I suppose, a "command" according to the diction of the TeXbook is a sequence of characters which forms some portion of TeX-input. A portion of TeX-input which, when TeX reads and tokenizes that sequence of characters, yields a set of whatsoever tokens and/or (e.g., in case the command in question contains "invalid characters"/characters of category code 15) some error-messages. In case of yielding a set of tokens, that set of tokens is intended to form a syntactical entity which TeX's token-processing-apparatus can attempt to carry out/to process in whatsoever way. Such an attempt in turn may also yield error-messages and/or erroneous behavior.



    Thus the term "command" in the diction of the TeXbook itself seems to actually not focus on things as results of TeX's "digestive processes". One of the earlier results of TeX's digestive processes are tokens. Tokens are produced in TeX's mouth. Thus the term "command" itself seems to actually not refer to tokens. It seems to refer to subsets of the things which TeX gets to "eat"—it refers to portions of the TeX-input, i.e., to the things which in interactive mode the user/programmer can type, or which TeX can read from .tex-input-files or read-handles for tokenization and further processing.



    In the LaTeX 2e-kernel you have things like newcommand and renewcommand.



    These things during LaTeX's digestive processes cause LaTeX to perform assignments. But the point of view seems not to be the view of the LaTeX-program which "eats" LaTeX-input and while "digesting" produces "tokens" etc. The point of view seems to be the view of the programmer. The programmer does not produce tokens. She/he produces LaTeX-input. That LaTeX-input is not tokens yet. It is a sequence of input-characters.



    After writing newcommand..., the programmer in her/his code can take the thing introduced via newcommand for a small portion of LaTeX-input which when tokenized by LaTeX yields a token which itself is considered a syntactical entity which, when used as intended, can be carried out via LaTeX's token-processing-apparatus without yielding erroneous behavior.



    I could not find the phrase "command token" in texbook.tex.



    This can also be taken for an indication that "command" and "token" in the diction of the TeXbook do in the upshot not refer to the same stage of work.



    It seems, in the TeXbook the term "command" is used when the focus is on that stage where the programmer produces/delivers/types whatsoever .tex-input.



    It seems, in the TeXbook the terms "token" and "macro" are used when the focus is on that stage where the TeX-program does process the .tex-input.





    The term "macro" seems to refer to the concept of TeX's tokens while tokens and thus macro-tokens do not come into being while writing/producing/delivering TeX-input but while having the TeX-program read and tokenize TeX-input and from the resulting tokens expand the expandable ones.



    As far as I know, macro-tokens are &langle;control sequences&rangle; that both are expandable and do not have the meaning of one of those about 300 low-level atomic operations that are called "primitives".



    What kinds of tokens can form such &langle;control sequences&rangle;?



    &langle;control sequences&rangle; come in two flavors:





    1. &langle;control sequence tokens&rangle;

      These divide into &langle;control symbol tokens&rangle; and &langle;control word tokens&rangle;


    2. &langle;active character tokens&rangle;


    With this remark we reach the question of how to divide up &langle;control sequences&rangle;.





    As just seen, one way of dividing up &langle;control sequences&rangle; is by looking at the question what kinds of tokens can form &langle;control sequences&rangle;:



    &langle;control sequence tokens&rangle; are those lovely "thingies" that in TeX input need to be preceded by a character whose category code is 0 (escape).

    Usually the backslash-character is the only character whose category code is 0.



    &langle;control sequence tokens&rangle; come in two flavors:



    &langle;control symbol tokens&rangle; have names which consist of a single character which does not have category code 11 (letter).



    E.g., usually . and \ are &langle;control symbol tokens&rangle; as usually the characters . and do not have category code 11 (letter). a usually is not a &langle;control symbol token&rangle; as usually the character a does have the category code 11 (letter).



    &langle;control word tokens&rangle; have names which consist either of several characters which do not need to have the same category code, or of a single character which does have the category code 11 (letter).



    Any &langle;control sequence&rangle; (i.e., both &langle;control sequence tokens&rangle; and &langle;active character tokens&rangle;, see below) can come into being




    • when (La)TeX reads and tokenizes input.

    • when (La)TeX inserts it during expansion; e.g., as part of the &langle;replacement text&rangle; of a macro; e.g., as part of the the-expansion of a token-register.


    A &langle;control sequence token&rangle; can come into being also




    • as the result of expanding some csname..endcsname-expression.


    Any character whose current category code is not 11 (letter), even a character of category code 15 (invalid), can form the name of a &langle;control symbol token&rangle; that came into being as a result of reading and tokenizing TeX-input.

    (I say "current" because as soon as the character that forms the name of the &langle;control sequence token&rangle; in question is switched to 11 (letter), the &langle;control sequence token&rangle; in question will not be treated as a &langle;control symbol token&rangle; (any more) but as a &langle;control word token&rangle;.)



    Otherwise you could, e.g., not use &langle;control symbol tokens&rangle; for changing the category codes of characters that currently have category code 15 (invalid).



    But you can do, e.g.,:



    catcode`A=15 % Now uppercase-a is invalid.
    % Typing an "A" both outside a comment and not behind a character
    % of category code 5 (end of line) which is not
    % intended to form the name of a control-symbol-token would yield
    % an error-message now.
    % But you can do:
    catcode`A=11 % Now uppercase-a is a letter again.


    After elaborating on the names of &langle;control symbol tokens&rangle;, let's elaborate on the names of &langle;control word tokens&rangle;:



    On the one hand, TeX's reading- and tokenizing-apparatus will only take sequences of characters of category code 11 (letter) as names of &langle;control word tokens&rangle;.

    Thus names of &langle;control word tokens&rangle; created via having TeX read and tokenize them directly from TeX-input consist only of characters that had category code 11 (letter) at the time of reading and tokenizeng them.

    On the other hand names of &langle;control word tokens&rangle; created via evaluating csname..endcsname-expressions can consist either of more than one character of whatsoever category code differing from 5, 9, 14 and 15 at the time of reading and tokenizing the csname..endcsname-expression , or of a single character of category code 11 (letter).



    A character of category code 10 (space)—usually the space character (ASCII 32) is the only character with that category code — that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control symbol token&rangle; will not be ignored but will be tokenized as an explicit space token.

    The only exception to that rule is with such characters that follow the control-space, , i.e., that &langle;control symbol token&rangle; whose name is formed by the space character. These will be ignored, too.



    A character of category code 10 (space) that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control word token&rangle; will be ignored/will not yield any token.



    When (La)TeX does unexpanded-write a &langle;control word token&rangle; (be it writing to file, be it writing to the screen), it automatically inserts a space character at the end of the character sequence that represents the &langle;control word token&rangle; in question.



    When (La)TeX does unexpanded-write a &langle;control symbol token&rangle; it will not automatically insert such a trailing space character.



    When applying string for transforming the following token into a sequence of &langle;character tokens&rangle; (either character tokens of category code 12 (other) and/or character tokens of category code 10 (space) and character code 32—32 encodes the space-character in ASCII—so called explicit space tokens—(La)TeX will not attach an additional trailing space token.



    You can change the way in which TeX does unexpanded-write a &langle;control sequence token&rangle; whose name consists of a single character by before writing changing the category code of that character either to 11 (letter)—in this case it will be written as a &langle;control word token&rangle; with trailing space— or to a value differing from 11—in this case it will be written as a &langle;control symbol token&rangle; without trailing space.



    Thus you can have fun with TeX's automatic insertion of spaces when doing delayed writes with unexpanded &langle;control sequence tokens&rangle; whose names consist of a single character—the code



    documentclass{article}
    begin{document}
    newwritemywrite
    immediateopenoutmywrite test.txtrelax

    catcode`A=12

    writemywrite{bnoexpandAb}
    immediatewritemywrite{bnoexpandAb}

    catcode`A=11

    Hello

    end{document}


    besides the .dvi- or .pdf-file yields a file test.txt with the following content:



    bAb
    bA b


    As both write-commands were issued while A was of category code 12 (other), you might have expected each A to be unexpanded-written as &langle;control symbol token&rangle; without a trailing space, and thus you might have expected the output



    bAb
    bAb


    . But the first write was not immediate and thus it got carried out not immediately but at the time of shipping out the page. At that time, the second write, which was immediate, was already done and A had category code 11 (letter) again and thus the A in the first write was written within the second line as a &langle;control word token&rangle;, with LaTeX attaching a trailing space character.



    The nameless &langle;control sequence token&rangle;—methods for forming it are: 1) expanding csnameendcsname; 2) placing a backslash (a character of category code 0 (escape)) at the end of a line while the parameter endlinechar has a non-positive value or a value outside the range of code-points of the TeX-engine's input-encoding—deserves special attention:

    Applying string to it always yields the catcode 12(other) character token sequence csnameendcsname. There is no space token between csname and endcsname. There also is no trailing space token.

    Unexpanded-writing it yields the character sequence csnameendcsname␣—there is a trailing space character.



    Besides the &langle;control sequence tokens&rangle; there is another kind of &langle;control sequences&rangle;: &langle;active character tokens&rangle;.



    An &langle;active character token&rangle; is a &langle;character token&rangle; whose category code is 13 (active).

    An &langle;active character token&rangle; can be used like a &langle;control sequence token&rangle;.

    E.g., after catcode`b=13 you can do def b{The active character string b is a macro now.}





    Another way of dividing up &langle;control sequences&rangle; is by looking at their "decomposability":



    The TeXBook says:




    About 300 of TeX's control sequences are called primitive; these are
    the low-level atomic operations that are not decomposable into simpler
    functions. All other control sequences are defined, ultimately, in
    terms of the primitive ones. For example, input is a primitive
    operation, but ’ and " are not; the latter are defined in terms of
    an accent primitive.




    (It should not be overlooked that when defining &langle;control sequences&rangle; that are macros, &langle;non-active character tokens&rangle; can play a rôle also.)





    Yet an another way of dividing up &langle;control sequences&rangle; is by looking at the actions triggered by them and at the point in time when these actions are triggered:



    There is the analogy between TeX's input-processing and digestive processes:




    • TeX input is divided up into so-called tokens (&langle;control sequence tokens&rangle; and &langle;character tokens&rangle;) in TeX's mouth.

    • Expansion of expandable &langle;control sequences&rangle; takes place in the gullet.


    • Unexpandable &langle;control sequences&rangle; will be handled in the stomach.


    So you distinguish expandable &langle;control sequences&rangle; and unexpandable &langle;control sequences&rangle;.



    Expandable &langle;control sequences&rangle; (and their arguments) will in the gullet be replaced by other constellations of tokens. Replacement of expandable &langle;control sequences&rangle; takes place in the gullet until there are no more expandable &langle;control sequences&rangle; left.



    Unexpandable &langle;control sequences&rangle; (which came into being either during tokenization in TeX's mouth or via replacement of expandable tokens during expansion) pass the gullet and reach the stomach where boxes will be built, assignment-primitives will be carried out, etc.



    There are primitive &langle;control sequences&rangle; that are expandable:



    E.g., the string-primitive is an expandable primitive. Together with the following token it vanishes in TeX's gullet and as replacement you get a set of &langle;character tokens&rangle; of category code 12 (other) or 10 (space) that represents the name of the &langle;control sequence token&rangle; in question/is the catcode-12-pendant of the &langle;character token&rangle; in question. (When an explicit space token trails string, string will deliver an explicit space token.)



    E.g., the csname-primitive is an expandable primitive. It triggers the processing of a csname..endcsname-expression in TeX's gullet and it vanishes in TeX's gullet and as replacement you get the corresponding &langle;control symbol token&rangle; or &langle;control word token&rangle;. In case that token is undefined, it will get the meaning of the relax-primitive within the current scope.



    E.g., the romannumeral-primitive is an expandable primitive. It and a following &langle;number&rangle; vanish in TeX's gullet and in case the &langle;number&rangle; is positive as replacement you get a sequence of &langle;character tokens&rangle; of category code 12 (other) that represent the corresponding &langle;number&rangle; in lowercase-roman notation.



    There are primitive &langle;control sequences&rangle; that are not expandable:



    E.g., the relax-primitive is not expandable. It does pass the gullet and reach the stomach.



    E.g., the assignment-primitives def, edef, gdef, xdef, countdef etc are not expandable. They do not trigger their replacement in TeX's gullet but will reach the stomach.



    There are non-primitive &langle;control sequences&rangle; that are expandable:



    Macros are non-primitive &langle;control sequences&rangle; that are expandable. They and their arguments get replaced with their &langle;replacement text&rangle; in TeX's gullet. Macros are defined in TeX's stomach in terms of the primitives def, edef, gdef and xdef. Be aware that LaTeX's newcommand also is just a macro which "decomposes" in LaTeX's gullet to some set of tokens containing the def-primitive.



    There are non-primitive &langle;control sequences&rangle; that are not expandable:



    You can, e.g., do things like letbgroup={.



    bgroup is a &langle;control sequence&rangle;. More specific: It is a &langle;control sequence token&rangle;. It is a &langle;control word token&rangle;. It is not expandable but it also does not have the meaning of one of the about 300 non-decomposable functions of TeX that are called primitives. bgroup is an implicit character  token. ;-)



    Other kinds of non-primitive &langle;control sequences&rangle; that are not expandable are, e.g., chardef-tokens, countdef-tokens, toksdef-tokens, ...





    In order to get used to the terminology, let's unravel some cases:



    After carrying out the assignments



    catcode`W=13 %
    catcode`X=13 %
    catcode`Y=13 %
    catcode`Z=13 %
    newcommand W{The active character stringW is a macro.}
    newcommandsomething{This is a macro.}
    newcommand+{This is a macro, too.}
    let X=a
    let Y=relax
    let Z=romannumeral


    ,





    • W is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. It is a macro and thus both expandable and not a primitive.


    • X is a &langle;control sequence&rangle;: It is an
      &langle;active character token&rangle;. It is not expandable. Thus it cannot be a macro. It also is not an unexpandable primitive. It has the same meaning as the catcode 11(letter) &langle;character token&rangle; a. It is an implicit character token.


    • Y is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the unexpandable relax-primitive. Thus it is an unexpandable primitive.


    • Z is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the expandable romannumeral-primitive. Thus it is an expandable primitive.


    • something is a &langle;control sequence&rangle;: It is a &langle;control word token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


    • + is a &langle;control sequence&rangle;: It is a &langle;control symbol token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


    The term "macro" does always denote a non-primitive expandable &langle;control sequence&rangle;.

    Thus when you know that a token is a macro, you can conclude that it cannot be a
    &langle;non-active character token&rangle; because &langle;non-active character tokens&rangle; cannot be &langle;control sequences&rangle;.

    You can conclude that it is a &langle;control sequence&rangle;.

    But you cannot conclude whether the &langle;control sequence&rangle; is a &langle;control word token&rangle; or a &langle;control symbol token&rangle; or an
    &langle;active character token&rangle;.



    Not all expandable &langle;control sequences&rangle; are macros.



    There are expandable &langle;primitives&rangle; as well.



    Not all non-expandable &langle;control sequences&rangle; are &langle;primitives&rangle;.



    There are non-expandable non-primitives as well:



    E.g., implicit character tokens, chardef-tokens, countdef-tokens, toksdef-tokens, ...






    share|improve this answer























    • Sorry for asking, but just curiosity: are you writing everything from your mind?
      – Sigur
      17 hours ago










    • I just observed you were editing a lot.
      – Sigur
      16 hours ago










    • I mean: you just think about it and type or are you copying/pasting from some where?
      – Sigur
      16 hours ago










    • @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
      – Ulrich Diez
      16 hours ago






    • 2




      Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
      – Alan Munn
      39 mins 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%2f468508%2fwhat-is-the-difference-between-macro-and-command%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    17














    macro programming is a programming style (as distinct from compiled programs) where the operation works by each token being replaced inline by its replacement text. Popular macro programming languages other than TeX include the C language pre-processor and the m4 system.



    What macro means in LaTeX?



    TeX's main mode of user customisation is via its macro processing language, but of course it requires some built in commands (primitives) that you may use to build up macros.



    So commands such as def, halign, count are not macros.



    Tex also has some primitives that are classed as expandable and so act pretty much the same as pre-defined macros although technically they are not classed as macros in TeX, a list of these expandable primitives is here:



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



    A control sequence is a string of characters such as foobar that references a command (or token, or is undefined) as opposed to a character such as x that just references itself, it may reference tex primitives or macros, depending on the context. Note that being a macro is a property of the meaning of the token, but being a control sequence is a property of its syntax. So by default ~ is a macro but it is an active character token not a control sequence.



    In TeX macros are always defined by def and its variants such as edef. LaTeX definition commands such as newcommand are themselves macros that ultimately result in an application of def to define a macro.






    share|improve this answer




























      17














      macro programming is a programming style (as distinct from compiled programs) where the operation works by each token being replaced inline by its replacement text. Popular macro programming languages other than TeX include the C language pre-processor and the m4 system.



      What macro means in LaTeX?



      TeX's main mode of user customisation is via its macro processing language, but of course it requires some built in commands (primitives) that you may use to build up macros.



      So commands such as def, halign, count are not macros.



      Tex also has some primitives that are classed as expandable and so act pretty much the same as pre-defined macros although technically they are not classed as macros in TeX, a list of these expandable primitives is here:



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



      A control sequence is a string of characters such as foobar that references a command (or token, or is undefined) as opposed to a character such as x that just references itself, it may reference tex primitives or macros, depending on the context. Note that being a macro is a property of the meaning of the token, but being a control sequence is a property of its syntax. So by default ~ is a macro but it is an active character token not a control sequence.



      In TeX macros are always defined by def and its variants such as edef. LaTeX definition commands such as newcommand are themselves macros that ultimately result in an application of def to define a macro.






      share|improve this answer


























        17












        17








        17






        macro programming is a programming style (as distinct from compiled programs) where the operation works by each token being replaced inline by its replacement text. Popular macro programming languages other than TeX include the C language pre-processor and the m4 system.



        What macro means in LaTeX?



        TeX's main mode of user customisation is via its macro processing language, but of course it requires some built in commands (primitives) that you may use to build up macros.



        So commands such as def, halign, count are not macros.



        Tex also has some primitives that are classed as expandable and so act pretty much the same as pre-defined macros although technically they are not classed as macros in TeX, a list of these expandable primitives is here:



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



        A control sequence is a string of characters such as foobar that references a command (or token, or is undefined) as opposed to a character such as x that just references itself, it may reference tex primitives or macros, depending on the context. Note that being a macro is a property of the meaning of the token, but being a control sequence is a property of its syntax. So by default ~ is a macro but it is an active character token not a control sequence.



        In TeX macros are always defined by def and its variants such as edef. LaTeX definition commands such as newcommand are themselves macros that ultimately result in an application of def to define a macro.






        share|improve this answer














        macro programming is a programming style (as distinct from compiled programs) where the operation works by each token being replaced inline by its replacement text. Popular macro programming languages other than TeX include the C language pre-processor and the m4 system.



        What macro means in LaTeX?



        TeX's main mode of user customisation is via its macro processing language, but of course it requires some built in commands (primitives) that you may use to build up macros.



        So commands such as def, halign, count are not macros.



        Tex also has some primitives that are classed as expandable and so act pretty much the same as pre-defined macros although technically they are not classed as macros in TeX, a list of these expandable primitives is here:



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



        A control sequence is a string of characters such as foobar that references a command (or token, or is undefined) as opposed to a character such as x that just references itself, it may reference tex primitives or macros, depending on the context. Note that being a macro is a property of the meaning of the token, but being a control sequence is a property of its syntax. So by default ~ is a macro but it is an active character token not a control sequence.



        In TeX macros are always defined by def and its variants such as edef. LaTeX definition commands such as newcommand are themselves macros that ultimately result in an application of def to define a macro.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        David Carlisle

        483k4011161857




        483k4011161857























            6














            They're used interchangeably because they mean the same thing.





            • A macro is defined as




              a single computer instruction that stands for a sequence of operations




            • The use of command probably stems from the way it's defined in LaTeX via newcommand and renewcommand and LaTeX3's xparse via NewDocumentCommand and RenewDocumentCommand.


            • There's also control sequence used by DEK in his TeX Book. They all point to the same thing.







            share|improve this answer

















            • 6




              I would not say they mean the same thing, tex primitives are not macros.
              – David Carlisle
              yesterday










            • I'm confident the majority of people using (La)TeX use the terminology interchangeably.
              – Werner
              yesterday






            • 2




              Certainly some do but that I think leads to confusion (as witnessed by this question)
              – David Carlisle
              yesterday
















            6














            They're used interchangeably because they mean the same thing.





            • A macro is defined as




              a single computer instruction that stands for a sequence of operations




            • The use of command probably stems from the way it's defined in LaTeX via newcommand and renewcommand and LaTeX3's xparse via NewDocumentCommand and RenewDocumentCommand.


            • There's also control sequence used by DEK in his TeX Book. They all point to the same thing.







            share|improve this answer

















            • 6




              I would not say they mean the same thing, tex primitives are not macros.
              – David Carlisle
              yesterday










            • I'm confident the majority of people using (La)TeX use the terminology interchangeably.
              – Werner
              yesterday






            • 2




              Certainly some do but that I think leads to confusion (as witnessed by this question)
              – David Carlisle
              yesterday














            6












            6








            6






            They're used interchangeably because they mean the same thing.





            • A macro is defined as




              a single computer instruction that stands for a sequence of operations




            • The use of command probably stems from the way it's defined in LaTeX via newcommand and renewcommand and LaTeX3's xparse via NewDocumentCommand and RenewDocumentCommand.


            • There's also control sequence used by DEK in his TeX Book. They all point to the same thing.







            share|improve this answer












            They're used interchangeably because they mean the same thing.





            • A macro is defined as




              a single computer instruction that stands for a sequence of operations




            • The use of command probably stems from the way it's defined in LaTeX via newcommand and renewcommand and LaTeX3's xparse via NewDocumentCommand and RenewDocumentCommand.


            • There's also control sequence used by DEK in his TeX Book. They all point to the same thing.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            Werner

            438k649611653




            438k649611653








            • 6




              I would not say they mean the same thing, tex primitives are not macros.
              – David Carlisle
              yesterday










            • I'm confident the majority of people using (La)TeX use the terminology interchangeably.
              – Werner
              yesterday






            • 2




              Certainly some do but that I think leads to confusion (as witnessed by this question)
              – David Carlisle
              yesterday














            • 6




              I would not say they mean the same thing, tex primitives are not macros.
              – David Carlisle
              yesterday










            • I'm confident the majority of people using (La)TeX use the terminology interchangeably.
              – Werner
              yesterday






            • 2




              Certainly some do but that I think leads to confusion (as witnessed by this question)
              – David Carlisle
              yesterday








            6




            6




            I would not say they mean the same thing, tex primitives are not macros.
            – David Carlisle
            yesterday




            I would not say they mean the same thing, tex primitives are not macros.
            – David Carlisle
            yesterday












            I'm confident the majority of people using (La)TeX use the terminology interchangeably.
            – Werner
            yesterday




            I'm confident the majority of people using (La)TeX use the terminology interchangeably.
            – Werner
            yesterday




            2




            2




            Certainly some do but that I think leads to confusion (as witnessed by this question)
            – David Carlisle
            yesterday




            Certainly some do but that I think leads to confusion (as witnessed by this question)
            – David Carlisle
            yesterday











            4














            I seldom use the term "command" when it is about (La)TeX.



            In the TeXbook the term "command" does also appear in contexts where not single tokens but the coming into being of sequences of control word tokens plays a rôle.



            E.g., chapter 15 of the TeXbook includes a double dangerous bend paragraph where you can read:




            [...] Therefore plain TeX provides an allocation function for registers; Appendix B includes the command
            newinsertfootins

            which defines footins as the number for footnote insertions. [...]




            So, e.g., newinsertfootins is a "command".



            (By the way: The mentioned appendix B does actually not exhibit tokens. It exhibits TeX code, i.e., TeX-input which the programmer of the plain TeX format did produce. That TeX-input itself is not tokens. TeX will create tokens when processing that code.)



            In the TeXbook you also find the phrase "primitive command". It is used in contexts where very short and easily to grasp sequences of TeX-input play a rôle. (Sequences that, when being read and tokenized, yield primitives...)



            I suppose, a "command" according to the diction of the TeXbook is a sequence of characters which forms some portion of TeX-input. A portion of TeX-input which, when TeX reads and tokenizes that sequence of characters, yields a set of whatsoever tokens and/or (e.g., in case the command in question contains "invalid characters"/characters of category code 15) some error-messages. In case of yielding a set of tokens, that set of tokens is intended to form a syntactical entity which TeX's token-processing-apparatus can attempt to carry out/to process in whatsoever way. Such an attempt in turn may also yield error-messages and/or erroneous behavior.



            Thus the term "command" in the diction of the TeXbook itself seems to actually not focus on things as results of TeX's "digestive processes". One of the earlier results of TeX's digestive processes are tokens. Tokens are produced in TeX's mouth. Thus the term "command" itself seems to actually not refer to tokens. It seems to refer to subsets of the things which TeX gets to "eat"—it refers to portions of the TeX-input, i.e., to the things which in interactive mode the user/programmer can type, or which TeX can read from .tex-input-files or read-handles for tokenization and further processing.



            In the LaTeX 2e-kernel you have things like newcommand and renewcommand.



            These things during LaTeX's digestive processes cause LaTeX to perform assignments. But the point of view seems not to be the view of the LaTeX-program which "eats" LaTeX-input and while "digesting" produces "tokens" etc. The point of view seems to be the view of the programmer. The programmer does not produce tokens. She/he produces LaTeX-input. That LaTeX-input is not tokens yet. It is a sequence of input-characters.



            After writing newcommand..., the programmer in her/his code can take the thing introduced via newcommand for a small portion of LaTeX-input which when tokenized by LaTeX yields a token which itself is considered a syntactical entity which, when used as intended, can be carried out via LaTeX's token-processing-apparatus without yielding erroneous behavior.



            I could not find the phrase "command token" in texbook.tex.



            This can also be taken for an indication that "command" and "token" in the diction of the TeXbook do in the upshot not refer to the same stage of work.



            It seems, in the TeXbook the term "command" is used when the focus is on that stage where the programmer produces/delivers/types whatsoever .tex-input.



            It seems, in the TeXbook the terms "token" and "macro" are used when the focus is on that stage where the TeX-program does process the .tex-input.





            The term "macro" seems to refer to the concept of TeX's tokens while tokens and thus macro-tokens do not come into being while writing/producing/delivering TeX-input but while having the TeX-program read and tokenize TeX-input and from the resulting tokens expand the expandable ones.



            As far as I know, macro-tokens are &langle;control sequences&rangle; that both are expandable and do not have the meaning of one of those about 300 low-level atomic operations that are called "primitives".



            What kinds of tokens can form such &langle;control sequences&rangle;?



            &langle;control sequences&rangle; come in two flavors:





            1. &langle;control sequence tokens&rangle;

              These divide into &langle;control symbol tokens&rangle; and &langle;control word tokens&rangle;


            2. &langle;active character tokens&rangle;


            With this remark we reach the question of how to divide up &langle;control sequences&rangle;.





            As just seen, one way of dividing up &langle;control sequences&rangle; is by looking at the question what kinds of tokens can form &langle;control sequences&rangle;:



            &langle;control sequence tokens&rangle; are those lovely "thingies" that in TeX input need to be preceded by a character whose category code is 0 (escape).

            Usually the backslash-character is the only character whose category code is 0.



            &langle;control sequence tokens&rangle; come in two flavors:



            &langle;control symbol tokens&rangle; have names which consist of a single character which does not have category code 11 (letter).



            E.g., usually . and \ are &langle;control symbol tokens&rangle; as usually the characters . and do not have category code 11 (letter). a usually is not a &langle;control symbol token&rangle; as usually the character a does have the category code 11 (letter).



            &langle;control word tokens&rangle; have names which consist either of several characters which do not need to have the same category code, or of a single character which does have the category code 11 (letter).



            Any &langle;control sequence&rangle; (i.e., both &langle;control sequence tokens&rangle; and &langle;active character tokens&rangle;, see below) can come into being




            • when (La)TeX reads and tokenizes input.

            • when (La)TeX inserts it during expansion; e.g., as part of the &langle;replacement text&rangle; of a macro; e.g., as part of the the-expansion of a token-register.


            A &langle;control sequence token&rangle; can come into being also




            • as the result of expanding some csname..endcsname-expression.


            Any character whose current category code is not 11 (letter), even a character of category code 15 (invalid), can form the name of a &langle;control symbol token&rangle; that came into being as a result of reading and tokenizing TeX-input.

            (I say "current" because as soon as the character that forms the name of the &langle;control sequence token&rangle; in question is switched to 11 (letter), the &langle;control sequence token&rangle; in question will not be treated as a &langle;control symbol token&rangle; (any more) but as a &langle;control word token&rangle;.)



            Otherwise you could, e.g., not use &langle;control symbol tokens&rangle; for changing the category codes of characters that currently have category code 15 (invalid).



            But you can do, e.g.,:



            catcode`A=15 % Now uppercase-a is invalid.
            % Typing an "A" both outside a comment and not behind a character
            % of category code 5 (end of line) which is not
            % intended to form the name of a control-symbol-token would yield
            % an error-message now.
            % But you can do:
            catcode`A=11 % Now uppercase-a is a letter again.


            After elaborating on the names of &langle;control symbol tokens&rangle;, let's elaborate on the names of &langle;control word tokens&rangle;:



            On the one hand, TeX's reading- and tokenizing-apparatus will only take sequences of characters of category code 11 (letter) as names of &langle;control word tokens&rangle;.

            Thus names of &langle;control word tokens&rangle; created via having TeX read and tokenize them directly from TeX-input consist only of characters that had category code 11 (letter) at the time of reading and tokenizeng them.

            On the other hand names of &langle;control word tokens&rangle; created via evaluating csname..endcsname-expressions can consist either of more than one character of whatsoever category code differing from 5, 9, 14 and 15 at the time of reading and tokenizing the csname..endcsname-expression , or of a single character of category code 11 (letter).



            A character of category code 10 (space)—usually the space character (ASCII 32) is the only character with that category code — that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control symbol token&rangle; will not be ignored but will be tokenized as an explicit space token.

            The only exception to that rule is with such characters that follow the control-space, , i.e., that &langle;control symbol token&rangle; whose name is formed by the space character. These will be ignored, too.



            A character of category code 10 (space) that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control word token&rangle; will be ignored/will not yield any token.



            When (La)TeX does unexpanded-write a &langle;control word token&rangle; (be it writing to file, be it writing to the screen), it automatically inserts a space character at the end of the character sequence that represents the &langle;control word token&rangle; in question.



            When (La)TeX does unexpanded-write a &langle;control symbol token&rangle; it will not automatically insert such a trailing space character.



            When applying string for transforming the following token into a sequence of &langle;character tokens&rangle; (either character tokens of category code 12 (other) and/or character tokens of category code 10 (space) and character code 32—32 encodes the space-character in ASCII—so called explicit space tokens—(La)TeX will not attach an additional trailing space token.



            You can change the way in which TeX does unexpanded-write a &langle;control sequence token&rangle; whose name consists of a single character by before writing changing the category code of that character either to 11 (letter)—in this case it will be written as a &langle;control word token&rangle; with trailing space— or to a value differing from 11—in this case it will be written as a &langle;control symbol token&rangle; without trailing space.



            Thus you can have fun with TeX's automatic insertion of spaces when doing delayed writes with unexpanded &langle;control sequence tokens&rangle; whose names consist of a single character—the code



            documentclass{article}
            begin{document}
            newwritemywrite
            immediateopenoutmywrite test.txtrelax

            catcode`A=12

            writemywrite{bnoexpandAb}
            immediatewritemywrite{bnoexpandAb}

            catcode`A=11

            Hello

            end{document}


            besides the .dvi- or .pdf-file yields a file test.txt with the following content:



            bAb
            bA b


            As both write-commands were issued while A was of category code 12 (other), you might have expected each A to be unexpanded-written as &langle;control symbol token&rangle; without a trailing space, and thus you might have expected the output



            bAb
            bAb


            . But the first write was not immediate and thus it got carried out not immediately but at the time of shipping out the page. At that time, the second write, which was immediate, was already done and A had category code 11 (letter) again and thus the A in the first write was written within the second line as a &langle;control word token&rangle;, with LaTeX attaching a trailing space character.



            The nameless &langle;control sequence token&rangle;—methods for forming it are: 1) expanding csnameendcsname; 2) placing a backslash (a character of category code 0 (escape)) at the end of a line while the parameter endlinechar has a non-positive value or a value outside the range of code-points of the TeX-engine's input-encoding—deserves special attention:

            Applying string to it always yields the catcode 12(other) character token sequence csnameendcsname. There is no space token between csname and endcsname. There also is no trailing space token.

            Unexpanded-writing it yields the character sequence csnameendcsname␣—there is a trailing space character.



            Besides the &langle;control sequence tokens&rangle; there is another kind of &langle;control sequences&rangle;: &langle;active character tokens&rangle;.



            An &langle;active character token&rangle; is a &langle;character token&rangle; whose category code is 13 (active).

            An &langle;active character token&rangle; can be used like a &langle;control sequence token&rangle;.

            E.g., after catcode`b=13 you can do def b{The active character string b is a macro now.}





            Another way of dividing up &langle;control sequences&rangle; is by looking at their "decomposability":



            The TeXBook says:




            About 300 of TeX's control sequences are called primitive; these are
            the low-level atomic operations that are not decomposable into simpler
            functions. All other control sequences are defined, ultimately, in
            terms of the primitive ones. For example, input is a primitive
            operation, but ’ and " are not; the latter are defined in terms of
            an accent primitive.




            (It should not be overlooked that when defining &langle;control sequences&rangle; that are macros, &langle;non-active character tokens&rangle; can play a rôle also.)





            Yet an another way of dividing up &langle;control sequences&rangle; is by looking at the actions triggered by them and at the point in time when these actions are triggered:



            There is the analogy between TeX's input-processing and digestive processes:




            • TeX input is divided up into so-called tokens (&langle;control sequence tokens&rangle; and &langle;character tokens&rangle;) in TeX's mouth.

            • Expansion of expandable &langle;control sequences&rangle; takes place in the gullet.


            • Unexpandable &langle;control sequences&rangle; will be handled in the stomach.


            So you distinguish expandable &langle;control sequences&rangle; and unexpandable &langle;control sequences&rangle;.



            Expandable &langle;control sequences&rangle; (and their arguments) will in the gullet be replaced by other constellations of tokens. Replacement of expandable &langle;control sequences&rangle; takes place in the gullet until there are no more expandable &langle;control sequences&rangle; left.



            Unexpandable &langle;control sequences&rangle; (which came into being either during tokenization in TeX's mouth or via replacement of expandable tokens during expansion) pass the gullet and reach the stomach where boxes will be built, assignment-primitives will be carried out, etc.



            There are primitive &langle;control sequences&rangle; that are expandable:



            E.g., the string-primitive is an expandable primitive. Together with the following token it vanishes in TeX's gullet and as replacement you get a set of &langle;character tokens&rangle; of category code 12 (other) or 10 (space) that represents the name of the &langle;control sequence token&rangle; in question/is the catcode-12-pendant of the &langle;character token&rangle; in question. (When an explicit space token trails string, string will deliver an explicit space token.)



            E.g., the csname-primitive is an expandable primitive. It triggers the processing of a csname..endcsname-expression in TeX's gullet and it vanishes in TeX's gullet and as replacement you get the corresponding &langle;control symbol token&rangle; or &langle;control word token&rangle;. In case that token is undefined, it will get the meaning of the relax-primitive within the current scope.



            E.g., the romannumeral-primitive is an expandable primitive. It and a following &langle;number&rangle; vanish in TeX's gullet and in case the &langle;number&rangle; is positive as replacement you get a sequence of &langle;character tokens&rangle; of category code 12 (other) that represent the corresponding &langle;number&rangle; in lowercase-roman notation.



            There are primitive &langle;control sequences&rangle; that are not expandable:



            E.g., the relax-primitive is not expandable. It does pass the gullet and reach the stomach.



            E.g., the assignment-primitives def, edef, gdef, xdef, countdef etc are not expandable. They do not trigger their replacement in TeX's gullet but will reach the stomach.



            There are non-primitive &langle;control sequences&rangle; that are expandable:



            Macros are non-primitive &langle;control sequences&rangle; that are expandable. They and their arguments get replaced with their &langle;replacement text&rangle; in TeX's gullet. Macros are defined in TeX's stomach in terms of the primitives def, edef, gdef and xdef. Be aware that LaTeX's newcommand also is just a macro which "decomposes" in LaTeX's gullet to some set of tokens containing the def-primitive.



            There are non-primitive &langle;control sequences&rangle; that are not expandable:



            You can, e.g., do things like letbgroup={.



            bgroup is a &langle;control sequence&rangle;. More specific: It is a &langle;control sequence token&rangle;. It is a &langle;control word token&rangle;. It is not expandable but it also does not have the meaning of one of the about 300 non-decomposable functions of TeX that are called primitives. bgroup is an implicit character  token. ;-)



            Other kinds of non-primitive &langle;control sequences&rangle; that are not expandable are, e.g., chardef-tokens, countdef-tokens, toksdef-tokens, ...





            In order to get used to the terminology, let's unravel some cases:



            After carrying out the assignments



            catcode`W=13 %
            catcode`X=13 %
            catcode`Y=13 %
            catcode`Z=13 %
            newcommand W{The active character stringW is a macro.}
            newcommandsomething{This is a macro.}
            newcommand+{This is a macro, too.}
            let X=a
            let Y=relax
            let Z=romannumeral


            ,





            • W is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. It is a macro and thus both expandable and not a primitive.


            • X is a &langle;control sequence&rangle;: It is an
              &langle;active character token&rangle;. It is not expandable. Thus it cannot be a macro. It also is not an unexpandable primitive. It has the same meaning as the catcode 11(letter) &langle;character token&rangle; a. It is an implicit character token.


            • Y is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the unexpandable relax-primitive. Thus it is an unexpandable primitive.


            • Z is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the expandable romannumeral-primitive. Thus it is an expandable primitive.


            • something is a &langle;control sequence&rangle;: It is a &langle;control word token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            • + is a &langle;control sequence&rangle;: It is a &langle;control symbol token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            The term "macro" does always denote a non-primitive expandable &langle;control sequence&rangle;.

            Thus when you know that a token is a macro, you can conclude that it cannot be a
            &langle;non-active character token&rangle; because &langle;non-active character tokens&rangle; cannot be &langle;control sequences&rangle;.

            You can conclude that it is a &langle;control sequence&rangle;.

            But you cannot conclude whether the &langle;control sequence&rangle; is a &langle;control word token&rangle; or a &langle;control symbol token&rangle; or an
            &langle;active character token&rangle;.



            Not all expandable &langle;control sequences&rangle; are macros.



            There are expandable &langle;primitives&rangle; as well.



            Not all non-expandable &langle;control sequences&rangle; are &langle;primitives&rangle;.



            There are non-expandable non-primitives as well:



            E.g., implicit character tokens, chardef-tokens, countdef-tokens, toksdef-tokens, ...






            share|improve this answer























            • Sorry for asking, but just curiosity: are you writing everything from your mind?
              – Sigur
              17 hours ago










            • I just observed you were editing a lot.
              – Sigur
              16 hours ago










            • I mean: you just think about it and type or are you copying/pasting from some where?
              – Sigur
              16 hours ago










            • @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
              – Ulrich Diez
              16 hours ago






            • 2




              Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
              – Alan Munn
              39 mins ago


















            4














            I seldom use the term "command" when it is about (La)TeX.



            In the TeXbook the term "command" does also appear in contexts where not single tokens but the coming into being of sequences of control word tokens plays a rôle.



            E.g., chapter 15 of the TeXbook includes a double dangerous bend paragraph where you can read:




            [...] Therefore plain TeX provides an allocation function for registers; Appendix B includes the command
            newinsertfootins

            which defines footins as the number for footnote insertions. [...]




            So, e.g., newinsertfootins is a "command".



            (By the way: The mentioned appendix B does actually not exhibit tokens. It exhibits TeX code, i.e., TeX-input which the programmer of the plain TeX format did produce. That TeX-input itself is not tokens. TeX will create tokens when processing that code.)



            In the TeXbook you also find the phrase "primitive command". It is used in contexts where very short and easily to grasp sequences of TeX-input play a rôle. (Sequences that, when being read and tokenized, yield primitives...)



            I suppose, a "command" according to the diction of the TeXbook is a sequence of characters which forms some portion of TeX-input. A portion of TeX-input which, when TeX reads and tokenizes that sequence of characters, yields a set of whatsoever tokens and/or (e.g., in case the command in question contains "invalid characters"/characters of category code 15) some error-messages. In case of yielding a set of tokens, that set of tokens is intended to form a syntactical entity which TeX's token-processing-apparatus can attempt to carry out/to process in whatsoever way. Such an attempt in turn may also yield error-messages and/or erroneous behavior.



            Thus the term "command" in the diction of the TeXbook itself seems to actually not focus on things as results of TeX's "digestive processes". One of the earlier results of TeX's digestive processes are tokens. Tokens are produced in TeX's mouth. Thus the term "command" itself seems to actually not refer to tokens. It seems to refer to subsets of the things which TeX gets to "eat"—it refers to portions of the TeX-input, i.e., to the things which in interactive mode the user/programmer can type, or which TeX can read from .tex-input-files or read-handles for tokenization and further processing.



            In the LaTeX 2e-kernel you have things like newcommand and renewcommand.



            These things during LaTeX's digestive processes cause LaTeX to perform assignments. But the point of view seems not to be the view of the LaTeX-program which "eats" LaTeX-input and while "digesting" produces "tokens" etc. The point of view seems to be the view of the programmer. The programmer does not produce tokens. She/he produces LaTeX-input. That LaTeX-input is not tokens yet. It is a sequence of input-characters.



            After writing newcommand..., the programmer in her/his code can take the thing introduced via newcommand for a small portion of LaTeX-input which when tokenized by LaTeX yields a token which itself is considered a syntactical entity which, when used as intended, can be carried out via LaTeX's token-processing-apparatus without yielding erroneous behavior.



            I could not find the phrase "command token" in texbook.tex.



            This can also be taken for an indication that "command" and "token" in the diction of the TeXbook do in the upshot not refer to the same stage of work.



            It seems, in the TeXbook the term "command" is used when the focus is on that stage where the programmer produces/delivers/types whatsoever .tex-input.



            It seems, in the TeXbook the terms "token" and "macro" are used when the focus is on that stage where the TeX-program does process the .tex-input.





            The term "macro" seems to refer to the concept of TeX's tokens while tokens and thus macro-tokens do not come into being while writing/producing/delivering TeX-input but while having the TeX-program read and tokenize TeX-input and from the resulting tokens expand the expandable ones.



            As far as I know, macro-tokens are &langle;control sequences&rangle; that both are expandable and do not have the meaning of one of those about 300 low-level atomic operations that are called "primitives".



            What kinds of tokens can form such &langle;control sequences&rangle;?



            &langle;control sequences&rangle; come in two flavors:





            1. &langle;control sequence tokens&rangle;

              These divide into &langle;control symbol tokens&rangle; and &langle;control word tokens&rangle;


            2. &langle;active character tokens&rangle;


            With this remark we reach the question of how to divide up &langle;control sequences&rangle;.





            As just seen, one way of dividing up &langle;control sequences&rangle; is by looking at the question what kinds of tokens can form &langle;control sequences&rangle;:



            &langle;control sequence tokens&rangle; are those lovely "thingies" that in TeX input need to be preceded by a character whose category code is 0 (escape).

            Usually the backslash-character is the only character whose category code is 0.



            &langle;control sequence tokens&rangle; come in two flavors:



            &langle;control symbol tokens&rangle; have names which consist of a single character which does not have category code 11 (letter).



            E.g., usually . and \ are &langle;control symbol tokens&rangle; as usually the characters . and do not have category code 11 (letter). a usually is not a &langle;control symbol token&rangle; as usually the character a does have the category code 11 (letter).



            &langle;control word tokens&rangle; have names which consist either of several characters which do not need to have the same category code, or of a single character which does have the category code 11 (letter).



            Any &langle;control sequence&rangle; (i.e., both &langle;control sequence tokens&rangle; and &langle;active character tokens&rangle;, see below) can come into being




            • when (La)TeX reads and tokenizes input.

            • when (La)TeX inserts it during expansion; e.g., as part of the &langle;replacement text&rangle; of a macro; e.g., as part of the the-expansion of a token-register.


            A &langle;control sequence token&rangle; can come into being also




            • as the result of expanding some csname..endcsname-expression.


            Any character whose current category code is not 11 (letter), even a character of category code 15 (invalid), can form the name of a &langle;control symbol token&rangle; that came into being as a result of reading and tokenizing TeX-input.

            (I say "current" because as soon as the character that forms the name of the &langle;control sequence token&rangle; in question is switched to 11 (letter), the &langle;control sequence token&rangle; in question will not be treated as a &langle;control symbol token&rangle; (any more) but as a &langle;control word token&rangle;.)



            Otherwise you could, e.g., not use &langle;control symbol tokens&rangle; for changing the category codes of characters that currently have category code 15 (invalid).



            But you can do, e.g.,:



            catcode`A=15 % Now uppercase-a is invalid.
            % Typing an "A" both outside a comment and not behind a character
            % of category code 5 (end of line) which is not
            % intended to form the name of a control-symbol-token would yield
            % an error-message now.
            % But you can do:
            catcode`A=11 % Now uppercase-a is a letter again.


            After elaborating on the names of &langle;control symbol tokens&rangle;, let's elaborate on the names of &langle;control word tokens&rangle;:



            On the one hand, TeX's reading- and tokenizing-apparatus will only take sequences of characters of category code 11 (letter) as names of &langle;control word tokens&rangle;.

            Thus names of &langle;control word tokens&rangle; created via having TeX read and tokenize them directly from TeX-input consist only of characters that had category code 11 (letter) at the time of reading and tokenizeng them.

            On the other hand names of &langle;control word tokens&rangle; created via evaluating csname..endcsname-expressions can consist either of more than one character of whatsoever category code differing from 5, 9, 14 and 15 at the time of reading and tokenizing the csname..endcsname-expression , or of a single character of category code 11 (letter).



            A character of category code 10 (space)—usually the space character (ASCII 32) is the only character with that category code — that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control symbol token&rangle; will not be ignored but will be tokenized as an explicit space token.

            The only exception to that rule is with such characters that follow the control-space, , i.e., that &langle;control symbol token&rangle; whose name is formed by the space character. These will be ignored, too.



            A character of category code 10 (space) that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control word token&rangle; will be ignored/will not yield any token.



            When (La)TeX does unexpanded-write a &langle;control word token&rangle; (be it writing to file, be it writing to the screen), it automatically inserts a space character at the end of the character sequence that represents the &langle;control word token&rangle; in question.



            When (La)TeX does unexpanded-write a &langle;control symbol token&rangle; it will not automatically insert such a trailing space character.



            When applying string for transforming the following token into a sequence of &langle;character tokens&rangle; (either character tokens of category code 12 (other) and/or character tokens of category code 10 (space) and character code 32—32 encodes the space-character in ASCII—so called explicit space tokens—(La)TeX will not attach an additional trailing space token.



            You can change the way in which TeX does unexpanded-write a &langle;control sequence token&rangle; whose name consists of a single character by before writing changing the category code of that character either to 11 (letter)—in this case it will be written as a &langle;control word token&rangle; with trailing space— or to a value differing from 11—in this case it will be written as a &langle;control symbol token&rangle; without trailing space.



            Thus you can have fun with TeX's automatic insertion of spaces when doing delayed writes with unexpanded &langle;control sequence tokens&rangle; whose names consist of a single character—the code



            documentclass{article}
            begin{document}
            newwritemywrite
            immediateopenoutmywrite test.txtrelax

            catcode`A=12

            writemywrite{bnoexpandAb}
            immediatewritemywrite{bnoexpandAb}

            catcode`A=11

            Hello

            end{document}


            besides the .dvi- or .pdf-file yields a file test.txt with the following content:



            bAb
            bA b


            As both write-commands were issued while A was of category code 12 (other), you might have expected each A to be unexpanded-written as &langle;control symbol token&rangle; without a trailing space, and thus you might have expected the output



            bAb
            bAb


            . But the first write was not immediate and thus it got carried out not immediately but at the time of shipping out the page. At that time, the second write, which was immediate, was already done and A had category code 11 (letter) again and thus the A in the first write was written within the second line as a &langle;control word token&rangle;, with LaTeX attaching a trailing space character.



            The nameless &langle;control sequence token&rangle;—methods for forming it are: 1) expanding csnameendcsname; 2) placing a backslash (a character of category code 0 (escape)) at the end of a line while the parameter endlinechar has a non-positive value or a value outside the range of code-points of the TeX-engine's input-encoding—deserves special attention:

            Applying string to it always yields the catcode 12(other) character token sequence csnameendcsname. There is no space token between csname and endcsname. There also is no trailing space token.

            Unexpanded-writing it yields the character sequence csnameendcsname␣—there is a trailing space character.



            Besides the &langle;control sequence tokens&rangle; there is another kind of &langle;control sequences&rangle;: &langle;active character tokens&rangle;.



            An &langle;active character token&rangle; is a &langle;character token&rangle; whose category code is 13 (active).

            An &langle;active character token&rangle; can be used like a &langle;control sequence token&rangle;.

            E.g., after catcode`b=13 you can do def b{The active character string b is a macro now.}





            Another way of dividing up &langle;control sequences&rangle; is by looking at their "decomposability":



            The TeXBook says:




            About 300 of TeX's control sequences are called primitive; these are
            the low-level atomic operations that are not decomposable into simpler
            functions. All other control sequences are defined, ultimately, in
            terms of the primitive ones. For example, input is a primitive
            operation, but ’ and " are not; the latter are defined in terms of
            an accent primitive.




            (It should not be overlooked that when defining &langle;control sequences&rangle; that are macros, &langle;non-active character tokens&rangle; can play a rôle also.)





            Yet an another way of dividing up &langle;control sequences&rangle; is by looking at the actions triggered by them and at the point in time when these actions are triggered:



            There is the analogy between TeX's input-processing and digestive processes:




            • TeX input is divided up into so-called tokens (&langle;control sequence tokens&rangle; and &langle;character tokens&rangle;) in TeX's mouth.

            • Expansion of expandable &langle;control sequences&rangle; takes place in the gullet.


            • Unexpandable &langle;control sequences&rangle; will be handled in the stomach.


            So you distinguish expandable &langle;control sequences&rangle; and unexpandable &langle;control sequences&rangle;.



            Expandable &langle;control sequences&rangle; (and their arguments) will in the gullet be replaced by other constellations of tokens. Replacement of expandable &langle;control sequences&rangle; takes place in the gullet until there are no more expandable &langle;control sequences&rangle; left.



            Unexpandable &langle;control sequences&rangle; (which came into being either during tokenization in TeX's mouth or via replacement of expandable tokens during expansion) pass the gullet and reach the stomach where boxes will be built, assignment-primitives will be carried out, etc.



            There are primitive &langle;control sequences&rangle; that are expandable:



            E.g., the string-primitive is an expandable primitive. Together with the following token it vanishes in TeX's gullet and as replacement you get a set of &langle;character tokens&rangle; of category code 12 (other) or 10 (space) that represents the name of the &langle;control sequence token&rangle; in question/is the catcode-12-pendant of the &langle;character token&rangle; in question. (When an explicit space token trails string, string will deliver an explicit space token.)



            E.g., the csname-primitive is an expandable primitive. It triggers the processing of a csname..endcsname-expression in TeX's gullet and it vanishes in TeX's gullet and as replacement you get the corresponding &langle;control symbol token&rangle; or &langle;control word token&rangle;. In case that token is undefined, it will get the meaning of the relax-primitive within the current scope.



            E.g., the romannumeral-primitive is an expandable primitive. It and a following &langle;number&rangle; vanish in TeX's gullet and in case the &langle;number&rangle; is positive as replacement you get a sequence of &langle;character tokens&rangle; of category code 12 (other) that represent the corresponding &langle;number&rangle; in lowercase-roman notation.



            There are primitive &langle;control sequences&rangle; that are not expandable:



            E.g., the relax-primitive is not expandable. It does pass the gullet and reach the stomach.



            E.g., the assignment-primitives def, edef, gdef, xdef, countdef etc are not expandable. They do not trigger their replacement in TeX's gullet but will reach the stomach.



            There are non-primitive &langle;control sequences&rangle; that are expandable:



            Macros are non-primitive &langle;control sequences&rangle; that are expandable. They and their arguments get replaced with their &langle;replacement text&rangle; in TeX's gullet. Macros are defined in TeX's stomach in terms of the primitives def, edef, gdef and xdef. Be aware that LaTeX's newcommand also is just a macro which "decomposes" in LaTeX's gullet to some set of tokens containing the def-primitive.



            There are non-primitive &langle;control sequences&rangle; that are not expandable:



            You can, e.g., do things like letbgroup={.



            bgroup is a &langle;control sequence&rangle;. More specific: It is a &langle;control sequence token&rangle;. It is a &langle;control word token&rangle;. It is not expandable but it also does not have the meaning of one of the about 300 non-decomposable functions of TeX that are called primitives. bgroup is an implicit character  token. ;-)



            Other kinds of non-primitive &langle;control sequences&rangle; that are not expandable are, e.g., chardef-tokens, countdef-tokens, toksdef-tokens, ...





            In order to get used to the terminology, let's unravel some cases:



            After carrying out the assignments



            catcode`W=13 %
            catcode`X=13 %
            catcode`Y=13 %
            catcode`Z=13 %
            newcommand W{The active character stringW is a macro.}
            newcommandsomething{This is a macro.}
            newcommand+{This is a macro, too.}
            let X=a
            let Y=relax
            let Z=romannumeral


            ,





            • W is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. It is a macro and thus both expandable and not a primitive.


            • X is a &langle;control sequence&rangle;: It is an
              &langle;active character token&rangle;. It is not expandable. Thus it cannot be a macro. It also is not an unexpandable primitive. It has the same meaning as the catcode 11(letter) &langle;character token&rangle; a. It is an implicit character token.


            • Y is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the unexpandable relax-primitive. Thus it is an unexpandable primitive.


            • Z is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the expandable romannumeral-primitive. Thus it is an expandable primitive.


            • something is a &langle;control sequence&rangle;: It is a &langle;control word token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            • + is a &langle;control sequence&rangle;: It is a &langle;control symbol token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            The term "macro" does always denote a non-primitive expandable &langle;control sequence&rangle;.

            Thus when you know that a token is a macro, you can conclude that it cannot be a
            &langle;non-active character token&rangle; because &langle;non-active character tokens&rangle; cannot be &langle;control sequences&rangle;.

            You can conclude that it is a &langle;control sequence&rangle;.

            But you cannot conclude whether the &langle;control sequence&rangle; is a &langle;control word token&rangle; or a &langle;control symbol token&rangle; or an
            &langle;active character token&rangle;.



            Not all expandable &langle;control sequences&rangle; are macros.



            There are expandable &langle;primitives&rangle; as well.



            Not all non-expandable &langle;control sequences&rangle; are &langle;primitives&rangle;.



            There are non-expandable non-primitives as well:



            E.g., implicit character tokens, chardef-tokens, countdef-tokens, toksdef-tokens, ...






            share|improve this answer























            • Sorry for asking, but just curiosity: are you writing everything from your mind?
              – Sigur
              17 hours ago










            • I just observed you were editing a lot.
              – Sigur
              16 hours ago










            • I mean: you just think about it and type or are you copying/pasting from some where?
              – Sigur
              16 hours ago










            • @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
              – Ulrich Diez
              16 hours ago






            • 2




              Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
              – Alan Munn
              39 mins ago
















            4












            4








            4






            I seldom use the term "command" when it is about (La)TeX.



            In the TeXbook the term "command" does also appear in contexts where not single tokens but the coming into being of sequences of control word tokens plays a rôle.



            E.g., chapter 15 of the TeXbook includes a double dangerous bend paragraph where you can read:




            [...] Therefore plain TeX provides an allocation function for registers; Appendix B includes the command
            newinsertfootins

            which defines footins as the number for footnote insertions. [...]




            So, e.g., newinsertfootins is a "command".



            (By the way: The mentioned appendix B does actually not exhibit tokens. It exhibits TeX code, i.e., TeX-input which the programmer of the plain TeX format did produce. That TeX-input itself is not tokens. TeX will create tokens when processing that code.)



            In the TeXbook you also find the phrase "primitive command". It is used in contexts where very short and easily to grasp sequences of TeX-input play a rôle. (Sequences that, when being read and tokenized, yield primitives...)



            I suppose, a "command" according to the diction of the TeXbook is a sequence of characters which forms some portion of TeX-input. A portion of TeX-input which, when TeX reads and tokenizes that sequence of characters, yields a set of whatsoever tokens and/or (e.g., in case the command in question contains "invalid characters"/characters of category code 15) some error-messages. In case of yielding a set of tokens, that set of tokens is intended to form a syntactical entity which TeX's token-processing-apparatus can attempt to carry out/to process in whatsoever way. Such an attempt in turn may also yield error-messages and/or erroneous behavior.



            Thus the term "command" in the diction of the TeXbook itself seems to actually not focus on things as results of TeX's "digestive processes". One of the earlier results of TeX's digestive processes are tokens. Tokens are produced in TeX's mouth. Thus the term "command" itself seems to actually not refer to tokens. It seems to refer to subsets of the things which TeX gets to "eat"—it refers to portions of the TeX-input, i.e., to the things which in interactive mode the user/programmer can type, or which TeX can read from .tex-input-files or read-handles for tokenization and further processing.



            In the LaTeX 2e-kernel you have things like newcommand and renewcommand.



            These things during LaTeX's digestive processes cause LaTeX to perform assignments. But the point of view seems not to be the view of the LaTeX-program which "eats" LaTeX-input and while "digesting" produces "tokens" etc. The point of view seems to be the view of the programmer. The programmer does not produce tokens. She/he produces LaTeX-input. That LaTeX-input is not tokens yet. It is a sequence of input-characters.



            After writing newcommand..., the programmer in her/his code can take the thing introduced via newcommand for a small portion of LaTeX-input which when tokenized by LaTeX yields a token which itself is considered a syntactical entity which, when used as intended, can be carried out via LaTeX's token-processing-apparatus without yielding erroneous behavior.



            I could not find the phrase "command token" in texbook.tex.



            This can also be taken for an indication that "command" and "token" in the diction of the TeXbook do in the upshot not refer to the same stage of work.



            It seems, in the TeXbook the term "command" is used when the focus is on that stage where the programmer produces/delivers/types whatsoever .tex-input.



            It seems, in the TeXbook the terms "token" and "macro" are used when the focus is on that stage where the TeX-program does process the .tex-input.





            The term "macro" seems to refer to the concept of TeX's tokens while tokens and thus macro-tokens do not come into being while writing/producing/delivering TeX-input but while having the TeX-program read and tokenize TeX-input and from the resulting tokens expand the expandable ones.



            As far as I know, macro-tokens are &langle;control sequences&rangle; that both are expandable and do not have the meaning of one of those about 300 low-level atomic operations that are called "primitives".



            What kinds of tokens can form such &langle;control sequences&rangle;?



            &langle;control sequences&rangle; come in two flavors:





            1. &langle;control sequence tokens&rangle;

              These divide into &langle;control symbol tokens&rangle; and &langle;control word tokens&rangle;


            2. &langle;active character tokens&rangle;


            With this remark we reach the question of how to divide up &langle;control sequences&rangle;.





            As just seen, one way of dividing up &langle;control sequences&rangle; is by looking at the question what kinds of tokens can form &langle;control sequences&rangle;:



            &langle;control sequence tokens&rangle; are those lovely "thingies" that in TeX input need to be preceded by a character whose category code is 0 (escape).

            Usually the backslash-character is the only character whose category code is 0.



            &langle;control sequence tokens&rangle; come in two flavors:



            &langle;control symbol tokens&rangle; have names which consist of a single character which does not have category code 11 (letter).



            E.g., usually . and \ are &langle;control symbol tokens&rangle; as usually the characters . and do not have category code 11 (letter). a usually is not a &langle;control symbol token&rangle; as usually the character a does have the category code 11 (letter).



            &langle;control word tokens&rangle; have names which consist either of several characters which do not need to have the same category code, or of a single character which does have the category code 11 (letter).



            Any &langle;control sequence&rangle; (i.e., both &langle;control sequence tokens&rangle; and &langle;active character tokens&rangle;, see below) can come into being




            • when (La)TeX reads and tokenizes input.

            • when (La)TeX inserts it during expansion; e.g., as part of the &langle;replacement text&rangle; of a macro; e.g., as part of the the-expansion of a token-register.


            A &langle;control sequence token&rangle; can come into being also




            • as the result of expanding some csname..endcsname-expression.


            Any character whose current category code is not 11 (letter), even a character of category code 15 (invalid), can form the name of a &langle;control symbol token&rangle; that came into being as a result of reading and tokenizing TeX-input.

            (I say "current" because as soon as the character that forms the name of the &langle;control sequence token&rangle; in question is switched to 11 (letter), the &langle;control sequence token&rangle; in question will not be treated as a &langle;control symbol token&rangle; (any more) but as a &langle;control word token&rangle;.)



            Otherwise you could, e.g., not use &langle;control symbol tokens&rangle; for changing the category codes of characters that currently have category code 15 (invalid).



            But you can do, e.g.,:



            catcode`A=15 % Now uppercase-a is invalid.
            % Typing an "A" both outside a comment and not behind a character
            % of category code 5 (end of line) which is not
            % intended to form the name of a control-symbol-token would yield
            % an error-message now.
            % But you can do:
            catcode`A=11 % Now uppercase-a is a letter again.


            After elaborating on the names of &langle;control symbol tokens&rangle;, let's elaborate on the names of &langle;control word tokens&rangle;:



            On the one hand, TeX's reading- and tokenizing-apparatus will only take sequences of characters of category code 11 (letter) as names of &langle;control word tokens&rangle;.

            Thus names of &langle;control word tokens&rangle; created via having TeX read and tokenize them directly from TeX-input consist only of characters that had category code 11 (letter) at the time of reading and tokenizeng them.

            On the other hand names of &langle;control word tokens&rangle; created via evaluating csname..endcsname-expressions can consist either of more than one character of whatsoever category code differing from 5, 9, 14 and 15 at the time of reading and tokenizing the csname..endcsname-expression , or of a single character of category code 11 (letter).



            A character of category code 10 (space)—usually the space character (ASCII 32) is the only character with that category code — that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control symbol token&rangle; will not be ignored but will be tokenized as an explicit space token.

            The only exception to that rule is with such characters that follow the control-space, , i.e., that &langle;control symbol token&rangle; whose name is formed by the space character. These will be ignored, too.



            A character of category code 10 (space) that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control word token&rangle; will be ignored/will not yield any token.



            When (La)TeX does unexpanded-write a &langle;control word token&rangle; (be it writing to file, be it writing to the screen), it automatically inserts a space character at the end of the character sequence that represents the &langle;control word token&rangle; in question.



            When (La)TeX does unexpanded-write a &langle;control symbol token&rangle; it will not automatically insert such a trailing space character.



            When applying string for transforming the following token into a sequence of &langle;character tokens&rangle; (either character tokens of category code 12 (other) and/or character tokens of category code 10 (space) and character code 32—32 encodes the space-character in ASCII—so called explicit space tokens—(La)TeX will not attach an additional trailing space token.



            You can change the way in which TeX does unexpanded-write a &langle;control sequence token&rangle; whose name consists of a single character by before writing changing the category code of that character either to 11 (letter)—in this case it will be written as a &langle;control word token&rangle; with trailing space— or to a value differing from 11—in this case it will be written as a &langle;control symbol token&rangle; without trailing space.



            Thus you can have fun with TeX's automatic insertion of spaces when doing delayed writes with unexpanded &langle;control sequence tokens&rangle; whose names consist of a single character—the code



            documentclass{article}
            begin{document}
            newwritemywrite
            immediateopenoutmywrite test.txtrelax

            catcode`A=12

            writemywrite{bnoexpandAb}
            immediatewritemywrite{bnoexpandAb}

            catcode`A=11

            Hello

            end{document}


            besides the .dvi- or .pdf-file yields a file test.txt with the following content:



            bAb
            bA b


            As both write-commands were issued while A was of category code 12 (other), you might have expected each A to be unexpanded-written as &langle;control symbol token&rangle; without a trailing space, and thus you might have expected the output



            bAb
            bAb


            . But the first write was not immediate and thus it got carried out not immediately but at the time of shipping out the page. At that time, the second write, which was immediate, was already done and A had category code 11 (letter) again and thus the A in the first write was written within the second line as a &langle;control word token&rangle;, with LaTeX attaching a trailing space character.



            The nameless &langle;control sequence token&rangle;—methods for forming it are: 1) expanding csnameendcsname; 2) placing a backslash (a character of category code 0 (escape)) at the end of a line while the parameter endlinechar has a non-positive value or a value outside the range of code-points of the TeX-engine's input-encoding—deserves special attention:

            Applying string to it always yields the catcode 12(other) character token sequence csnameendcsname. There is no space token between csname and endcsname. There also is no trailing space token.

            Unexpanded-writing it yields the character sequence csnameendcsname␣—there is a trailing space character.



            Besides the &langle;control sequence tokens&rangle; there is another kind of &langle;control sequences&rangle;: &langle;active character tokens&rangle;.



            An &langle;active character token&rangle; is a &langle;character token&rangle; whose category code is 13 (active).

            An &langle;active character token&rangle; can be used like a &langle;control sequence token&rangle;.

            E.g., after catcode`b=13 you can do def b{The active character string b is a macro now.}





            Another way of dividing up &langle;control sequences&rangle; is by looking at their "decomposability":



            The TeXBook says:




            About 300 of TeX's control sequences are called primitive; these are
            the low-level atomic operations that are not decomposable into simpler
            functions. All other control sequences are defined, ultimately, in
            terms of the primitive ones. For example, input is a primitive
            operation, but ’ and " are not; the latter are defined in terms of
            an accent primitive.




            (It should not be overlooked that when defining &langle;control sequences&rangle; that are macros, &langle;non-active character tokens&rangle; can play a rôle also.)





            Yet an another way of dividing up &langle;control sequences&rangle; is by looking at the actions triggered by them and at the point in time when these actions are triggered:



            There is the analogy between TeX's input-processing and digestive processes:




            • TeX input is divided up into so-called tokens (&langle;control sequence tokens&rangle; and &langle;character tokens&rangle;) in TeX's mouth.

            • Expansion of expandable &langle;control sequences&rangle; takes place in the gullet.


            • Unexpandable &langle;control sequences&rangle; will be handled in the stomach.


            So you distinguish expandable &langle;control sequences&rangle; and unexpandable &langle;control sequences&rangle;.



            Expandable &langle;control sequences&rangle; (and their arguments) will in the gullet be replaced by other constellations of tokens. Replacement of expandable &langle;control sequences&rangle; takes place in the gullet until there are no more expandable &langle;control sequences&rangle; left.



            Unexpandable &langle;control sequences&rangle; (which came into being either during tokenization in TeX's mouth or via replacement of expandable tokens during expansion) pass the gullet and reach the stomach where boxes will be built, assignment-primitives will be carried out, etc.



            There are primitive &langle;control sequences&rangle; that are expandable:



            E.g., the string-primitive is an expandable primitive. Together with the following token it vanishes in TeX's gullet and as replacement you get a set of &langle;character tokens&rangle; of category code 12 (other) or 10 (space) that represents the name of the &langle;control sequence token&rangle; in question/is the catcode-12-pendant of the &langle;character token&rangle; in question. (When an explicit space token trails string, string will deliver an explicit space token.)



            E.g., the csname-primitive is an expandable primitive. It triggers the processing of a csname..endcsname-expression in TeX's gullet and it vanishes in TeX's gullet and as replacement you get the corresponding &langle;control symbol token&rangle; or &langle;control word token&rangle;. In case that token is undefined, it will get the meaning of the relax-primitive within the current scope.



            E.g., the romannumeral-primitive is an expandable primitive. It and a following &langle;number&rangle; vanish in TeX's gullet and in case the &langle;number&rangle; is positive as replacement you get a sequence of &langle;character tokens&rangle; of category code 12 (other) that represent the corresponding &langle;number&rangle; in lowercase-roman notation.



            There are primitive &langle;control sequences&rangle; that are not expandable:



            E.g., the relax-primitive is not expandable. It does pass the gullet and reach the stomach.



            E.g., the assignment-primitives def, edef, gdef, xdef, countdef etc are not expandable. They do not trigger their replacement in TeX's gullet but will reach the stomach.



            There are non-primitive &langle;control sequences&rangle; that are expandable:



            Macros are non-primitive &langle;control sequences&rangle; that are expandable. They and their arguments get replaced with their &langle;replacement text&rangle; in TeX's gullet. Macros are defined in TeX's stomach in terms of the primitives def, edef, gdef and xdef. Be aware that LaTeX's newcommand also is just a macro which "decomposes" in LaTeX's gullet to some set of tokens containing the def-primitive.



            There are non-primitive &langle;control sequences&rangle; that are not expandable:



            You can, e.g., do things like letbgroup={.



            bgroup is a &langle;control sequence&rangle;. More specific: It is a &langle;control sequence token&rangle;. It is a &langle;control word token&rangle;. It is not expandable but it also does not have the meaning of one of the about 300 non-decomposable functions of TeX that are called primitives. bgroup is an implicit character  token. ;-)



            Other kinds of non-primitive &langle;control sequences&rangle; that are not expandable are, e.g., chardef-tokens, countdef-tokens, toksdef-tokens, ...





            In order to get used to the terminology, let's unravel some cases:



            After carrying out the assignments



            catcode`W=13 %
            catcode`X=13 %
            catcode`Y=13 %
            catcode`Z=13 %
            newcommand W{The active character stringW is a macro.}
            newcommandsomething{This is a macro.}
            newcommand+{This is a macro, too.}
            let X=a
            let Y=relax
            let Z=romannumeral


            ,





            • W is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. It is a macro and thus both expandable and not a primitive.


            • X is a &langle;control sequence&rangle;: It is an
              &langle;active character token&rangle;. It is not expandable. Thus it cannot be a macro. It also is not an unexpandable primitive. It has the same meaning as the catcode 11(letter) &langle;character token&rangle; a. It is an implicit character token.


            • Y is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the unexpandable relax-primitive. Thus it is an unexpandable primitive.


            • Z is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the expandable romannumeral-primitive. Thus it is an expandable primitive.


            • something is a &langle;control sequence&rangle;: It is a &langle;control word token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            • + is a &langle;control sequence&rangle;: It is a &langle;control symbol token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            The term "macro" does always denote a non-primitive expandable &langle;control sequence&rangle;.

            Thus when you know that a token is a macro, you can conclude that it cannot be a
            &langle;non-active character token&rangle; because &langle;non-active character tokens&rangle; cannot be &langle;control sequences&rangle;.

            You can conclude that it is a &langle;control sequence&rangle;.

            But you cannot conclude whether the &langle;control sequence&rangle; is a &langle;control word token&rangle; or a &langle;control symbol token&rangle; or an
            &langle;active character token&rangle;.



            Not all expandable &langle;control sequences&rangle; are macros.



            There are expandable &langle;primitives&rangle; as well.



            Not all non-expandable &langle;control sequences&rangle; are &langle;primitives&rangle;.



            There are non-expandable non-primitives as well:



            E.g., implicit character tokens, chardef-tokens, countdef-tokens, toksdef-tokens, ...






            share|improve this answer














            I seldom use the term "command" when it is about (La)TeX.



            In the TeXbook the term "command" does also appear in contexts where not single tokens but the coming into being of sequences of control word tokens plays a rôle.



            E.g., chapter 15 of the TeXbook includes a double dangerous bend paragraph where you can read:




            [...] Therefore plain TeX provides an allocation function for registers; Appendix B includes the command
            newinsertfootins

            which defines footins as the number for footnote insertions. [...]




            So, e.g., newinsertfootins is a "command".



            (By the way: The mentioned appendix B does actually not exhibit tokens. It exhibits TeX code, i.e., TeX-input which the programmer of the plain TeX format did produce. That TeX-input itself is not tokens. TeX will create tokens when processing that code.)



            In the TeXbook you also find the phrase "primitive command". It is used in contexts where very short and easily to grasp sequences of TeX-input play a rôle. (Sequences that, when being read and tokenized, yield primitives...)



            I suppose, a "command" according to the diction of the TeXbook is a sequence of characters which forms some portion of TeX-input. A portion of TeX-input which, when TeX reads and tokenizes that sequence of characters, yields a set of whatsoever tokens and/or (e.g., in case the command in question contains "invalid characters"/characters of category code 15) some error-messages. In case of yielding a set of tokens, that set of tokens is intended to form a syntactical entity which TeX's token-processing-apparatus can attempt to carry out/to process in whatsoever way. Such an attempt in turn may also yield error-messages and/or erroneous behavior.



            Thus the term "command" in the diction of the TeXbook itself seems to actually not focus on things as results of TeX's "digestive processes". One of the earlier results of TeX's digestive processes are tokens. Tokens are produced in TeX's mouth. Thus the term "command" itself seems to actually not refer to tokens. It seems to refer to subsets of the things which TeX gets to "eat"—it refers to portions of the TeX-input, i.e., to the things which in interactive mode the user/programmer can type, or which TeX can read from .tex-input-files or read-handles for tokenization and further processing.



            In the LaTeX 2e-kernel you have things like newcommand and renewcommand.



            These things during LaTeX's digestive processes cause LaTeX to perform assignments. But the point of view seems not to be the view of the LaTeX-program which "eats" LaTeX-input and while "digesting" produces "tokens" etc. The point of view seems to be the view of the programmer. The programmer does not produce tokens. She/he produces LaTeX-input. That LaTeX-input is not tokens yet. It is a sequence of input-characters.



            After writing newcommand..., the programmer in her/his code can take the thing introduced via newcommand for a small portion of LaTeX-input which when tokenized by LaTeX yields a token which itself is considered a syntactical entity which, when used as intended, can be carried out via LaTeX's token-processing-apparatus without yielding erroneous behavior.



            I could not find the phrase "command token" in texbook.tex.



            This can also be taken for an indication that "command" and "token" in the diction of the TeXbook do in the upshot not refer to the same stage of work.



            It seems, in the TeXbook the term "command" is used when the focus is on that stage where the programmer produces/delivers/types whatsoever .tex-input.



            It seems, in the TeXbook the terms "token" and "macro" are used when the focus is on that stage where the TeX-program does process the .tex-input.





            The term "macro" seems to refer to the concept of TeX's tokens while tokens and thus macro-tokens do not come into being while writing/producing/delivering TeX-input but while having the TeX-program read and tokenize TeX-input and from the resulting tokens expand the expandable ones.



            As far as I know, macro-tokens are &langle;control sequences&rangle; that both are expandable and do not have the meaning of one of those about 300 low-level atomic operations that are called "primitives".



            What kinds of tokens can form such &langle;control sequences&rangle;?



            &langle;control sequences&rangle; come in two flavors:





            1. &langle;control sequence tokens&rangle;

              These divide into &langle;control symbol tokens&rangle; and &langle;control word tokens&rangle;


            2. &langle;active character tokens&rangle;


            With this remark we reach the question of how to divide up &langle;control sequences&rangle;.





            As just seen, one way of dividing up &langle;control sequences&rangle; is by looking at the question what kinds of tokens can form &langle;control sequences&rangle;:



            &langle;control sequence tokens&rangle; are those lovely "thingies" that in TeX input need to be preceded by a character whose category code is 0 (escape).

            Usually the backslash-character is the only character whose category code is 0.



            &langle;control sequence tokens&rangle; come in two flavors:



            &langle;control symbol tokens&rangle; have names which consist of a single character which does not have category code 11 (letter).



            E.g., usually . and \ are &langle;control symbol tokens&rangle; as usually the characters . and do not have category code 11 (letter). a usually is not a &langle;control symbol token&rangle; as usually the character a does have the category code 11 (letter).



            &langle;control word tokens&rangle; have names which consist either of several characters which do not need to have the same category code, or of a single character which does have the category code 11 (letter).



            Any &langle;control sequence&rangle; (i.e., both &langle;control sequence tokens&rangle; and &langle;active character tokens&rangle;, see below) can come into being




            • when (La)TeX reads and tokenizes input.

            • when (La)TeX inserts it during expansion; e.g., as part of the &langle;replacement text&rangle; of a macro; e.g., as part of the the-expansion of a token-register.


            A &langle;control sequence token&rangle; can come into being also




            • as the result of expanding some csname..endcsname-expression.


            Any character whose current category code is not 11 (letter), even a character of category code 15 (invalid), can form the name of a &langle;control symbol token&rangle; that came into being as a result of reading and tokenizing TeX-input.

            (I say "current" because as soon as the character that forms the name of the &langle;control sequence token&rangle; in question is switched to 11 (letter), the &langle;control sequence token&rangle; in question will not be treated as a &langle;control symbol token&rangle; (any more) but as a &langle;control word token&rangle;.)



            Otherwise you could, e.g., not use &langle;control symbol tokens&rangle; for changing the category codes of characters that currently have category code 15 (invalid).



            But you can do, e.g.,:



            catcode`A=15 % Now uppercase-a is invalid.
            % Typing an "A" both outside a comment and not behind a character
            % of category code 5 (end of line) which is not
            % intended to form the name of a control-symbol-token would yield
            % an error-message now.
            % But you can do:
            catcode`A=11 % Now uppercase-a is a letter again.


            After elaborating on the names of &langle;control symbol tokens&rangle;, let's elaborate on the names of &langle;control word tokens&rangle;:



            On the one hand, TeX's reading- and tokenizing-apparatus will only take sequences of characters of category code 11 (letter) as names of &langle;control word tokens&rangle;.

            Thus names of &langle;control word tokens&rangle; created via having TeX read and tokenize them directly from TeX-input consist only of characters that had category code 11 (letter) at the time of reading and tokenizeng them.

            On the other hand names of &langle;control word tokens&rangle; created via evaluating csname..endcsname-expressions can consist either of more than one character of whatsoever category code differing from 5, 9, 14 and 15 at the time of reading and tokenizing the csname..endcsname-expression , or of a single character of category code 11 (letter).



            A character of category code 10 (space)—usually the space character (ASCII 32) is the only character with that category code — that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control symbol token&rangle; will not be ignored but will be tokenized as an explicit space token.

            The only exception to that rule is with such characters that follow the control-space, , i.e., that &langle;control symbol token&rangle; whose name is formed by the space character. These will be ignored, too.



            A character of category code 10 (space) that in the TeX-input occurs behind a character-sequence that got tokenized as &langle;control word token&rangle; will be ignored/will not yield any token.



            When (La)TeX does unexpanded-write a &langle;control word token&rangle; (be it writing to file, be it writing to the screen), it automatically inserts a space character at the end of the character sequence that represents the &langle;control word token&rangle; in question.



            When (La)TeX does unexpanded-write a &langle;control symbol token&rangle; it will not automatically insert such a trailing space character.



            When applying string for transforming the following token into a sequence of &langle;character tokens&rangle; (either character tokens of category code 12 (other) and/or character tokens of category code 10 (space) and character code 32—32 encodes the space-character in ASCII—so called explicit space tokens—(La)TeX will not attach an additional trailing space token.



            You can change the way in which TeX does unexpanded-write a &langle;control sequence token&rangle; whose name consists of a single character by before writing changing the category code of that character either to 11 (letter)—in this case it will be written as a &langle;control word token&rangle; with trailing space— or to a value differing from 11—in this case it will be written as a &langle;control symbol token&rangle; without trailing space.



            Thus you can have fun with TeX's automatic insertion of spaces when doing delayed writes with unexpanded &langle;control sequence tokens&rangle; whose names consist of a single character—the code



            documentclass{article}
            begin{document}
            newwritemywrite
            immediateopenoutmywrite test.txtrelax

            catcode`A=12

            writemywrite{bnoexpandAb}
            immediatewritemywrite{bnoexpandAb}

            catcode`A=11

            Hello

            end{document}


            besides the .dvi- or .pdf-file yields a file test.txt with the following content:



            bAb
            bA b


            As both write-commands were issued while A was of category code 12 (other), you might have expected each A to be unexpanded-written as &langle;control symbol token&rangle; without a trailing space, and thus you might have expected the output



            bAb
            bAb


            . But the first write was not immediate and thus it got carried out not immediately but at the time of shipping out the page. At that time, the second write, which was immediate, was already done and A had category code 11 (letter) again and thus the A in the first write was written within the second line as a &langle;control word token&rangle;, with LaTeX attaching a trailing space character.



            The nameless &langle;control sequence token&rangle;—methods for forming it are: 1) expanding csnameendcsname; 2) placing a backslash (a character of category code 0 (escape)) at the end of a line while the parameter endlinechar has a non-positive value or a value outside the range of code-points of the TeX-engine's input-encoding—deserves special attention:

            Applying string to it always yields the catcode 12(other) character token sequence csnameendcsname. There is no space token between csname and endcsname. There also is no trailing space token.

            Unexpanded-writing it yields the character sequence csnameendcsname␣—there is a trailing space character.



            Besides the &langle;control sequence tokens&rangle; there is another kind of &langle;control sequences&rangle;: &langle;active character tokens&rangle;.



            An &langle;active character token&rangle; is a &langle;character token&rangle; whose category code is 13 (active).

            An &langle;active character token&rangle; can be used like a &langle;control sequence token&rangle;.

            E.g., after catcode`b=13 you can do def b{The active character string b is a macro now.}





            Another way of dividing up &langle;control sequences&rangle; is by looking at their "decomposability":



            The TeXBook says:




            About 300 of TeX's control sequences are called primitive; these are
            the low-level atomic operations that are not decomposable into simpler
            functions. All other control sequences are defined, ultimately, in
            terms of the primitive ones. For example, input is a primitive
            operation, but ’ and " are not; the latter are defined in terms of
            an accent primitive.




            (It should not be overlooked that when defining &langle;control sequences&rangle; that are macros, &langle;non-active character tokens&rangle; can play a rôle also.)





            Yet an another way of dividing up &langle;control sequences&rangle; is by looking at the actions triggered by them and at the point in time when these actions are triggered:



            There is the analogy between TeX's input-processing and digestive processes:




            • TeX input is divided up into so-called tokens (&langle;control sequence tokens&rangle; and &langle;character tokens&rangle;) in TeX's mouth.

            • Expansion of expandable &langle;control sequences&rangle; takes place in the gullet.


            • Unexpandable &langle;control sequences&rangle; will be handled in the stomach.


            So you distinguish expandable &langle;control sequences&rangle; and unexpandable &langle;control sequences&rangle;.



            Expandable &langle;control sequences&rangle; (and their arguments) will in the gullet be replaced by other constellations of tokens. Replacement of expandable &langle;control sequences&rangle; takes place in the gullet until there are no more expandable &langle;control sequences&rangle; left.



            Unexpandable &langle;control sequences&rangle; (which came into being either during tokenization in TeX's mouth or via replacement of expandable tokens during expansion) pass the gullet and reach the stomach where boxes will be built, assignment-primitives will be carried out, etc.



            There are primitive &langle;control sequences&rangle; that are expandable:



            E.g., the string-primitive is an expandable primitive. Together with the following token it vanishes in TeX's gullet and as replacement you get a set of &langle;character tokens&rangle; of category code 12 (other) or 10 (space) that represents the name of the &langle;control sequence token&rangle; in question/is the catcode-12-pendant of the &langle;character token&rangle; in question. (When an explicit space token trails string, string will deliver an explicit space token.)



            E.g., the csname-primitive is an expandable primitive. It triggers the processing of a csname..endcsname-expression in TeX's gullet and it vanishes in TeX's gullet and as replacement you get the corresponding &langle;control symbol token&rangle; or &langle;control word token&rangle;. In case that token is undefined, it will get the meaning of the relax-primitive within the current scope.



            E.g., the romannumeral-primitive is an expandable primitive. It and a following &langle;number&rangle; vanish in TeX's gullet and in case the &langle;number&rangle; is positive as replacement you get a sequence of &langle;character tokens&rangle; of category code 12 (other) that represent the corresponding &langle;number&rangle; in lowercase-roman notation.



            There are primitive &langle;control sequences&rangle; that are not expandable:



            E.g., the relax-primitive is not expandable. It does pass the gullet and reach the stomach.



            E.g., the assignment-primitives def, edef, gdef, xdef, countdef etc are not expandable. They do not trigger their replacement in TeX's gullet but will reach the stomach.



            There are non-primitive &langle;control sequences&rangle; that are expandable:



            Macros are non-primitive &langle;control sequences&rangle; that are expandable. They and their arguments get replaced with their &langle;replacement text&rangle; in TeX's gullet. Macros are defined in TeX's stomach in terms of the primitives def, edef, gdef and xdef. Be aware that LaTeX's newcommand also is just a macro which "decomposes" in LaTeX's gullet to some set of tokens containing the def-primitive.



            There are non-primitive &langle;control sequences&rangle; that are not expandable:



            You can, e.g., do things like letbgroup={.



            bgroup is a &langle;control sequence&rangle;. More specific: It is a &langle;control sequence token&rangle;. It is a &langle;control word token&rangle;. It is not expandable but it also does not have the meaning of one of the about 300 non-decomposable functions of TeX that are called primitives. bgroup is an implicit character  token. ;-)



            Other kinds of non-primitive &langle;control sequences&rangle; that are not expandable are, e.g., chardef-tokens, countdef-tokens, toksdef-tokens, ...





            In order to get used to the terminology, let's unravel some cases:



            After carrying out the assignments



            catcode`W=13 %
            catcode`X=13 %
            catcode`Y=13 %
            catcode`Z=13 %
            newcommand W{The active character stringW is a macro.}
            newcommandsomething{This is a macro.}
            newcommand+{This is a macro, too.}
            let X=a
            let Y=relax
            let Z=romannumeral


            ,





            • W is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. It is a macro and thus both expandable and not a primitive.


            • X is a &langle;control sequence&rangle;: It is an
              &langle;active character token&rangle;. It is not expandable. Thus it cannot be a macro. It also is not an unexpandable primitive. It has the same meaning as the catcode 11(letter) &langle;character token&rangle; a. It is an implicit character token.


            • Y is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the unexpandable relax-primitive. Thus it is an unexpandable primitive.


            • Z is a &langle;control sequence&rangle;: It is an &langle;active character token&rangle;. Its meaning equals the meaning of the expandable romannumeral-primitive. Thus it is an expandable primitive.


            • something is a &langle;control sequence&rangle;: It is a &langle;control word token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            • + is a &langle;control sequence&rangle;: It is a &langle;control symbol token&rangle;. It is expandable. Its meaning does not equal one of the about 300 non-decomposable functions of TeX that are called primitives. It is a macro.


            The term "macro" does always denote a non-primitive expandable &langle;control sequence&rangle;.

            Thus when you know that a token is a macro, you can conclude that it cannot be a
            &langle;non-active character token&rangle; because &langle;non-active character tokens&rangle; cannot be &langle;control sequences&rangle;.

            You can conclude that it is a &langle;control sequence&rangle;.

            But you cannot conclude whether the &langle;control sequence&rangle; is a &langle;control word token&rangle; or a &langle;control symbol token&rangle; or an
            &langle;active character token&rangle;.



            Not all expandable &langle;control sequences&rangle; are macros.



            There are expandable &langle;primitives&rangle; as well.



            Not all non-expandable &langle;control sequences&rangle; are &langle;primitives&rangle;.



            There are non-expandable non-primitives as well:



            E.g., implicit character tokens, chardef-tokens, countdef-tokens, toksdef-tokens, ...







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 26 mins ago

























            answered 18 hours ago









            Ulrich Diez

            4,200615




            4,200615












            • Sorry for asking, but just curiosity: are you writing everything from your mind?
              – Sigur
              17 hours ago










            • I just observed you were editing a lot.
              – Sigur
              16 hours ago










            • I mean: you just think about it and type or are you copying/pasting from some where?
              – Sigur
              16 hours ago










            • @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
              – Ulrich Diez
              16 hours ago






            • 2




              Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
              – Alan Munn
              39 mins ago




















            • Sorry for asking, but just curiosity: are you writing everything from your mind?
              – Sigur
              17 hours ago










            • I just observed you were editing a lot.
              – Sigur
              16 hours ago










            • I mean: you just think about it and type or are you copying/pasting from some where?
              – Sigur
              16 hours ago










            • @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
              – Ulrich Diez
              16 hours ago






            • 2




              Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
              – Alan Munn
              39 mins ago


















            Sorry for asking, but just curiosity: are you writing everything from your mind?
            – Sigur
            17 hours ago




            Sorry for asking, but just curiosity: are you writing everything from your mind?
            – Sigur
            17 hours ago












            I just observed you were editing a lot.
            – Sigur
            16 hours ago




            I just observed you were editing a lot.
            – Sigur
            16 hours ago












            I mean: you just think about it and type or are you copying/pasting from some where?
            – Sigur
            16 hours ago




            I mean: you just think about it and type or are you copying/pasting from some where?
            – Sigur
            16 hours ago












            @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
            – Ulrich Diez
            16 hours ago




            @Sigur I just thought about it, looked up the quotes and spontaneously typed into the input-field of the TeX-LaTeX-StackExchange-Website shown in my internet-browser. If I had really planned this answer systematically, I would have typed within my favorite editor-software, saved the text as a file and revised it a few times before pasting it from the editor-software to the input-field of the TeX-LaTeX-StackExchange-Website. But I didn't take it all too serious. I just wanted to have fun...;-)
            – Ulrich Diez
            16 hours ago




            2




            2




            Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
            – Alan Munn
            39 mins ago






            Ulrich, Since TeX doesn't end in an orthographic 's', it's possessive form should be "TeX's" not just "TeX'".
            – Alan Munn
            39 mins 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%2f468508%2fwhat-is-the-difference-between-macro-and-command%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

            1300-talet

            1300-talet

            Display a custom attribute below product name in the front-end Magento 1.9.3.8