How to write a macro that is braces sensitive?Context-sensitive newline macroCreate my own NSDHow to write a parameter-driven macro?How can I create a better cryptogram environment?How to write a TeX macro that accepts a number or a count register as argument?Macro to close all open environments, groups and argument delimitersTexshop macro for bracesWrite an unpar macroInput length sensitive optional argument macrocontext-sensitive macro: look behind?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Prove that NP is closed under karp reduction?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

TGV timetables / schedules?

Modeling an IP Address

Unknown notation: What do three bars mean?

How does strength of boric acid solution increase in presence of salicylic acid?

How can bays and straits be determined in a procedurally generated map?

Voyeurism but not really

Why doesn't H₄O²⁺ exist?

can i play a electric guitar through a bass amp?

How to format long polynomial?

Is it possible to do 50 km distance without any previous training?

What would happen to a modern skyscraper if it rains micro blackholes?

How to add double frame in tcolorbox?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

How to find program name(s) of an installed package?

Did Shadowfax go to Valinor?

What are these boxed doors outside store fronts in New York?

What is the offset in a seaplane's hull?

Writing rule stating superpower from different root cause is bad writing

Characters won't fit in table

Do VLANs within a subnet need to have their own subnet for router on a stick?



How to write a macro that is braces sensitive?


Context-sensitive newline macroCreate my own NSDHow to write a parameter-driven macro?How can I create a better cryptogram environment?How to write a TeX macro that accepts a number or a count register as argument?Macro to close all open environments, groups and argument delimitersTexshop macro for bracesWrite an unpar macroInput length sensitive optional argument macrocontext-sensitive macro: look behind?













1















In the xparse package, there is the g type of argument which captures things inside a pair of TeX group tokens. This makes it possible to define commands foo that behaves differently for fooa and foo a. I am interested in whether such type of macro is possible in plain TeX (I guess yes) and if it is possible, how can it be implemented. I am new to plain TeX and I appreciate detailed explanation of the workflow of such a macro. I would also be happy to learn about other possibilities such as in e-TeX instead of plain TeX.










share|improve this question







New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

    – egreg
    18 mins ago












  • Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

    – Weijun Zhou
    14 mins ago







  • 1





    It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

    – egreg
    12 mins ago












  • Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

    – Weijun Zhou
    5 mins ago















1















In the xparse package, there is the g type of argument which captures things inside a pair of TeX group tokens. This makes it possible to define commands foo that behaves differently for fooa and foo a. I am interested in whether such type of macro is possible in plain TeX (I guess yes) and if it is possible, how can it be implemented. I am new to plain TeX and I appreciate detailed explanation of the workflow of such a macro. I would also be happy to learn about other possibilities such as in e-TeX instead of plain TeX.










share|improve this question







New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

    – egreg
    18 mins ago












  • Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

    – Weijun Zhou
    14 mins ago







  • 1





    It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

    – egreg
    12 mins ago












  • Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

    – Weijun Zhou
    5 mins ago













1












1








1








In the xparse package, there is the g type of argument which captures things inside a pair of TeX group tokens. This makes it possible to define commands foo that behaves differently for fooa and foo a. I am interested in whether such type of macro is possible in plain TeX (I guess yes) and if it is possible, how can it be implemented. I am new to plain TeX and I appreciate detailed explanation of the workflow of such a macro. I would also be happy to learn about other possibilities such as in e-TeX instead of plain TeX.










share|improve this question







New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












In the xparse package, there is the g type of argument which captures things inside a pair of TeX group tokens. This makes it possible to define commands foo that behaves differently for fooa and foo a. I am interested in whether such type of macro is possible in plain TeX (I guess yes) and if it is possible, how can it be implemented. I am new to plain TeX and I appreciate detailed explanation of the workflow of such a macro. I would also be happy to learn about other possibilities such as in e-TeX instead of plain TeX.







macros plain-tex braces






share|improve this question







New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 mins ago









Weijun ZhouWeijun Zhou

1084




1084




New contributor




Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Weijun Zhou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

    – egreg
    18 mins ago












  • Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

    – Weijun Zhou
    14 mins ago







  • 1





    It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

    – egreg
    12 mins ago












  • Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

    – Weijun Zhou
    5 mins ago

















  • It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

    – egreg
    18 mins ago












  • Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

    – Weijun Zhou
    14 mins ago







  • 1





    It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

    – egreg
    12 mins ago












  • Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

    – Weijun Zhou
    5 mins ago
















It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

– egreg
18 mins ago






It's possible, but it's bad syntax. Under normal TeX conventions, foo a and fooa should be considered equivalent (when the argument consists of a single token as in this case).

– egreg
18 mins ago














Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

– Weijun Zhou
14 mins ago






Thank you for your quick reply. I know it's bad syntax otherwise xparse would not declare it as obsolete, but it is (extensively) used in e.g. physics package. I am just not sure about whether it can be done in plain, or it requires some features of the engine.

– Weijun Zhou
14 mins ago





1




1





It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

– egreg
12 mins ago






It's indeed used in physics. My opinion about the package is that it has good ideas, but I can't recommend its usage. The weird syntax is just one among the several reasons for not recommending it.

– egreg
12 mins ago














Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

– Weijun Zhou
5 mins ago





Due to the weird syntax I end up adding relax here and there ... but I guess I will still use it.

– Weijun Zhou
5 mins ago










1 Answer
1






active

oldest

votes


















1














Fundamentally you just need to use futurelet as you do for any other look ahead



deffoofutureletfooauxfootoken
deffooaux%
ifxfootokenbgroup
% Brace group
else
% Something else
fi



The only reason this 'looks different' to other peek ahead situations is that you can't use an explicit {, but rather the implicit token bgroup.






share|improve this answer























  • That's clear enough and much simpler than I originally imagined.

    – Weijun Zhou
    9 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
);



);






Weijun Zhou is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483588%2fhow-to-write-a-macro-that-is-braces-sensitive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Fundamentally you just need to use futurelet as you do for any other look ahead



deffoofutureletfooauxfootoken
deffooaux%
ifxfootokenbgroup
% Brace group
else
% Something else
fi



The only reason this 'looks different' to other peek ahead situations is that you can't use an explicit {, but rather the implicit token bgroup.






share|improve this answer























  • That's clear enough and much simpler than I originally imagined.

    – Weijun Zhou
    9 mins ago















1














Fundamentally you just need to use futurelet as you do for any other look ahead



deffoofutureletfooauxfootoken
deffooaux%
ifxfootokenbgroup
% Brace group
else
% Something else
fi



The only reason this 'looks different' to other peek ahead situations is that you can't use an explicit {, but rather the implicit token bgroup.






share|improve this answer























  • That's clear enough and much simpler than I originally imagined.

    – Weijun Zhou
    9 mins ago













1












1








1







Fundamentally you just need to use futurelet as you do for any other look ahead



deffoofutureletfooauxfootoken
deffooaux%
ifxfootokenbgroup
% Brace group
else
% Something else
fi



The only reason this 'looks different' to other peek ahead situations is that you can't use an explicit {, but rather the implicit token bgroup.






share|improve this answer













Fundamentally you just need to use futurelet as you do for any other look ahead



deffoofutureletfooauxfootoken
deffooaux%
ifxfootokenbgroup
% Brace group
else
% Something else
fi



The only reason this 'looks different' to other peek ahead situations is that you can't use an explicit {, but rather the implicit token bgroup.







share|improve this answer












share|improve this answer



share|improve this answer










answered 14 mins ago









Joseph WrightJoseph Wright

205k23563891




205k23563891












  • That's clear enough and much simpler than I originally imagined.

    – Weijun Zhou
    9 mins ago

















  • That's clear enough and much simpler than I originally imagined.

    – Weijun Zhou
    9 mins ago
















That's clear enough and much simpler than I originally imagined.

– Weijun Zhou
9 mins ago





That's clear enough and much simpler than I originally imagined.

– Weijun Zhou
9 mins ago










Weijun Zhou is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Weijun Zhou is a new contributor. Be nice, and check out our Code of Conduct.












Weijun Zhou is a new contributor. Be nice, and check out our Code of Conduct.











Weijun Zhou is a new contributor. Be nice, and check out our Code of Conduct.














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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483588%2fhow-to-write-a-macro-that-is-braces-sensitive%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

acmart: Multiple authors: all with same affiliation, one author an additional affiliationHow to Write Names of Multiple Authors with Shared Affiliation in ACM 2017 Template?Multiple authors with different primary affiliation, but same additional affiliationSame affiliation for all authors without extra packagesIOS-Book-Article.cls: one author with multiple affiliationacmart: Shared Author AffiliationMultiple authors with different primary affiliation, but same additional affiliationAuthor affiliation with only 1 authorAdding Multiple Authors with Different Affiliation in LaTeX ArticleLaTeX: Multiple authors stays on same lineHow to Label Multiple Authors with Same DescriptionHow to make two authors use the same affiliationTwo authors with same affiliation on finished front page

How to write “ä” and other umlauts and accented letters in bibliography?Accents in BibTeXSorting references with special characters alphabeticallyUse ae ligature in bibliographyEastern European nameInverted circumflex in BibTexBibTex, non-ascii initials and nameptr fproblems with accent in LatexHow to add a Ø to my bibliography from Jabref?References without accentsTroubles when trying to cite St“omer-Verlet in ”title" field of a bib entryComprehensive list of accented charactersHow to type the letter “i” with two dots (diaeresis) in math mode?Problem with glossary text and accented lettersSpecial character in bibliographyAccented letters, Unicode and LaTeX accentsHow to stop natbib from modifying bibliography styleCitation of a paper with non-standard characters by BibtexWrite accented characters to file using writeHow to group the bibliography alphabetically, if some surnames start with “accented” characters?How can I automatically capitalize significant words in my bibliography?

Problem using RevTeX4-1 with “! Undefined control sequence. @bibitemShut”