LaTeX newcommand limitation

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I want to know the possibilities and the limitation of LaTeX's newcommand regarding the definition and the use/call of new macros. I know some of these examples are primitive but they can help to understand the limitations.
I am only interested in basic newcommands with ""char+ as name.



Invalid examples:



newcommandnewcentercenter 
beginnewcenter
endcenter

newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree

newcommandtiontion
sectionmysec


Valid examples:



newcommandoptarg[myoptarg] 
sectionoptargmysec

newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular

newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo

newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour









share|improve this question









New contributor




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



















  • I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
    – Henri Menke
    4 hours ago










  • These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
    – A.Ellett
    4 hours ago










  • these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
    – David Carlisle
    4 hours ago














up vote
1
down vote

favorite












I want to know the possibilities and the limitation of LaTeX's newcommand regarding the definition and the use/call of new macros. I know some of these examples are primitive but they can help to understand the limitations.
I am only interested in basic newcommands with ""char+ as name.



Invalid examples:



newcommandnewcentercenter 
beginnewcenter
endcenter

newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree

newcommandtiontion
sectionmysec


Valid examples:



newcommandoptarg[myoptarg] 
sectionoptargmysec

newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular

newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo

newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour









share|improve this question









New contributor




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



















  • I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
    – Henri Menke
    4 hours ago










  • These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
    – A.Ellett
    4 hours ago










  • these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
    – David Carlisle
    4 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to know the possibilities and the limitation of LaTeX's newcommand regarding the definition and the use/call of new macros. I know some of these examples are primitive but they can help to understand the limitations.
I am only interested in basic newcommands with ""char+ as name.



Invalid examples:



newcommandnewcentercenter 
beginnewcenter
endcenter

newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree

newcommandtiontion
sectionmysec


Valid examples:



newcommandoptarg[myoptarg] 
sectionoptargmysec

newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular

newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo

newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour









share|improve this question









New contributor




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











I want to know the possibilities and the limitation of LaTeX's newcommand regarding the definition and the use/call of new macros. I know some of these examples are primitive but they can help to understand the limitations.
I am only interested in basic newcommands with ""char+ as name.



Invalid examples:



newcommandnewcentercenter 
beginnewcenter
endcenter

newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree

newcommandtiontion
sectionmysec


Valid examples:



newcommandoptarg[myoptarg] 
sectionoptargmysec

newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular

newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo

newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour






macros latex-base






share|improve this question









New contributor




Bighted19 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




Bighted19 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








edited 24 mins ago









Phelype Oleinik

17k43769




17k43769






New contributor




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









asked 4 hours ago









Bighted19

62




62




New contributor




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





New contributor





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






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











  • I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
    – Henri Menke
    4 hours ago










  • These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
    – A.Ellett
    4 hours ago










  • these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
    – David Carlisle
    4 hours ago
















  • I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
    – Henri Menke
    4 hours ago










  • These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
    – A.Ellett
    4 hours ago










  • these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
    – David Carlisle
    4 hours ago















I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
– Henri Menke
4 hours ago




I don't really see what the use-case would be other than unreadable and unmaintainable document source code.
– Henri Menke
4 hours ago












These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
– A.Ellett
4 hours ago




These don't so much look like limitations of newcommand but an issue of understanding LaTeX (and TeX)'s command expansion rules.
– A.Ellett
4 hours ago












these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
– David Carlisle
4 hours ago




these are not really related to newcommand but to the use of the macros, you would get the same errors if the macros were defined by the primitive def
– David Carlisle
4 hours ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote













expandafter solves almost all your problems. You seem to be a LaTeX beginner, so these are not things you should usually have to do. Please also have a look at When to use edef, noexpand, and expandafter?



documentclassarticle
begindocument

newcommandnewcentercenter
expandafterbeginexpandafternewcenter
endcenter

newcommandtabularthreetabular
expandafterbegintabularthreeccc
cell& cell
expandafterendtabularthree

newcommandtiontion
csname sectionendcsnamemysec

enddocument





share|improve this answer




















  • You beat me to the punch. Your answer is almost verbatim my answer. lol.
    – A.Ellett
    4 hours ago

















up vote
2
down vote













Henri Menke told you how to work around the rules. This answer will show you why the syntax you used (doesn't) work.



The ones that don't work:



newcommandnewcentercenter
beginnewcenter
endcenter


This one fails because @currenvir expands to newcenter and when LaTeX calls the @checkend command, it compares the meaning of @currenvir and the argument to end, which is center. The comparison fails because it compares newcenter with center without further expasion, so they differ and an error is raised. The error message, on the other hand, fully expands @currenvir and the error message is misleading:



! LaTeX Error: begincenter on input line 29 ended by endcenter.



newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree


This one fails because LaTeX checks if the enfironment exists with ifcsname which will build a command with the argument to begin which, in this case, is tabularthree, which expands to tabular. The ifcsname then checks for a command named tabular, which doesn't exist and LaTeX tells you:



! LaTeX Error: Environment tabular undefined.



newcommandtiontion
sectionmysec


This one fails because it's invalid. The command sec is expanded, and it is the secant function, which is only allowed in math-mode, so TeX thinks you forgot a $:



! Missing $ inserted.
<inserted text>
$
l.46 sec


If sec wasn't a math-mode command, TeX would try to execute it. If it had an argument, the argument would be the command tion, which then expands to tion and then the sec command would do its thing (whatever it happened to be) with tion. If it didn't exist, TeX would complain that sec doesn't exist.




The one that works:



newcommandoptarg[myoptarg]
sectionoptargmysec


This one compiles, but it doesn't produce what you'd expect. The test for the optional argument fails, because the code for section doesn't see a [ character (and it doesn't expand optarg looking for it), so it takes optarg as the mandatory argument and the title of the section becomes [myoptarg] and mysec is written below.




The ones that do work:



newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular


This one works because when TeX expands mybegin it just finds begin. TeX then proceeds expanding begin and doing things normally. The cc thing works because tabular expands the tokens of the alignment preamble.




newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo


This one works by the same reason that the first case didn't. The check for the environment name is performed for tabulartwo and tabulartwo, which are the same thing. And the braces there don't make a difference because by TeX's argument grabbing rules, a normal argument is either a single token (tabulartwo is a single token) or, if a open brace ({) is found, then the argument is the <balanced text> within that pair of braces (tabulartwo and tabular are <balanced text> within a pair of braces).




newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour


Same as above.




But you really shouldn't be inventing syntax for commands, because even if it works, you will obfuscate your code and not even you will understand it in a few weeks.






share|improve this answer
















  • 1




    On the other hand, begintabularccc will not work if the array package is loaded.
    – egreg
    4 hours ago










Your Answer







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

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

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Bighted19 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%2f452660%2flatex-newcommand-limitation%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













expandafter solves almost all your problems. You seem to be a LaTeX beginner, so these are not things you should usually have to do. Please also have a look at When to use edef, noexpand, and expandafter?



documentclassarticle
begindocument

newcommandnewcentercenter
expandafterbeginexpandafternewcenter
endcenter

newcommandtabularthreetabular
expandafterbegintabularthreeccc
cell& cell
expandafterendtabularthree

newcommandtiontion
csname sectionendcsnamemysec

enddocument





share|improve this answer




















  • You beat me to the punch. Your answer is almost verbatim my answer. lol.
    – A.Ellett
    4 hours ago














up vote
3
down vote













expandafter solves almost all your problems. You seem to be a LaTeX beginner, so these are not things you should usually have to do. Please also have a look at When to use edef, noexpand, and expandafter?



documentclassarticle
begindocument

newcommandnewcentercenter
expandafterbeginexpandafternewcenter
endcenter

newcommandtabularthreetabular
expandafterbegintabularthreeccc
cell& cell
expandafterendtabularthree

newcommandtiontion
csname sectionendcsnamemysec

enddocument





share|improve this answer




















  • You beat me to the punch. Your answer is almost verbatim my answer. lol.
    – A.Ellett
    4 hours ago












up vote
3
down vote










up vote
3
down vote









expandafter solves almost all your problems. You seem to be a LaTeX beginner, so these are not things you should usually have to do. Please also have a look at When to use edef, noexpand, and expandafter?



documentclassarticle
begindocument

newcommandnewcentercenter
expandafterbeginexpandafternewcenter
endcenter

newcommandtabularthreetabular
expandafterbegintabularthreeccc
cell& cell
expandafterendtabularthree

newcommandtiontion
csname sectionendcsnamemysec

enddocument





share|improve this answer












expandafter solves almost all your problems. You seem to be a LaTeX beginner, so these are not things you should usually have to do. Please also have a look at When to use edef, noexpand, and expandafter?



documentclassarticle
begindocument

newcommandnewcentercenter
expandafterbeginexpandafternewcenter
endcenter

newcommandtabularthreetabular
expandafterbegintabularthreeccc
cell& cell
expandafterendtabularthree

newcommandtiontion
csname sectionendcsnamemysec

enddocument






share|improve this answer












share|improve this answer



share|improve this answer










answered 4 hours ago









Henri Menke

64.8k7144253




64.8k7144253











  • You beat me to the punch. Your answer is almost verbatim my answer. lol.
    – A.Ellett
    4 hours ago
















  • You beat me to the punch. Your answer is almost verbatim my answer. lol.
    – A.Ellett
    4 hours ago















You beat me to the punch. Your answer is almost verbatim my answer. lol.
– A.Ellett
4 hours ago




You beat me to the punch. Your answer is almost verbatim my answer. lol.
– A.Ellett
4 hours ago










up vote
2
down vote













Henri Menke told you how to work around the rules. This answer will show you why the syntax you used (doesn't) work.



The ones that don't work:



newcommandnewcentercenter
beginnewcenter
endcenter


This one fails because @currenvir expands to newcenter and when LaTeX calls the @checkend command, it compares the meaning of @currenvir and the argument to end, which is center. The comparison fails because it compares newcenter with center without further expasion, so they differ and an error is raised. The error message, on the other hand, fully expands @currenvir and the error message is misleading:



! LaTeX Error: begincenter on input line 29 ended by endcenter.



newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree


This one fails because LaTeX checks if the enfironment exists with ifcsname which will build a command with the argument to begin which, in this case, is tabularthree, which expands to tabular. The ifcsname then checks for a command named tabular, which doesn't exist and LaTeX tells you:



! LaTeX Error: Environment tabular undefined.



newcommandtiontion
sectionmysec


This one fails because it's invalid. The command sec is expanded, and it is the secant function, which is only allowed in math-mode, so TeX thinks you forgot a $:



! Missing $ inserted.
<inserted text>
$
l.46 sec


If sec wasn't a math-mode command, TeX would try to execute it. If it had an argument, the argument would be the command tion, which then expands to tion and then the sec command would do its thing (whatever it happened to be) with tion. If it didn't exist, TeX would complain that sec doesn't exist.




The one that works:



newcommandoptarg[myoptarg]
sectionoptargmysec


This one compiles, but it doesn't produce what you'd expect. The test for the optional argument fails, because the code for section doesn't see a [ character (and it doesn't expand optarg looking for it), so it takes optarg as the mandatory argument and the title of the section becomes [myoptarg] and mysec is written below.




The ones that do work:



newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular


This one works because when TeX expands mybegin it just finds begin. TeX then proceeds expanding begin and doing things normally. The cc thing works because tabular expands the tokens of the alignment preamble.




newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo


This one works by the same reason that the first case didn't. The check for the environment name is performed for tabulartwo and tabulartwo, which are the same thing. And the braces there don't make a difference because by TeX's argument grabbing rules, a normal argument is either a single token (tabulartwo is a single token) or, if a open brace ({) is found, then the argument is the <balanced text> within that pair of braces (tabulartwo and tabular are <balanced text> within a pair of braces).




newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour


Same as above.




But you really shouldn't be inventing syntax for commands, because even if it works, you will obfuscate your code and not even you will understand it in a few weeks.






share|improve this answer
















  • 1




    On the other hand, begintabularccc will not work if the array package is loaded.
    – egreg
    4 hours ago














up vote
2
down vote













Henri Menke told you how to work around the rules. This answer will show you why the syntax you used (doesn't) work.



The ones that don't work:



newcommandnewcentercenter
beginnewcenter
endcenter


This one fails because @currenvir expands to newcenter and when LaTeX calls the @checkend command, it compares the meaning of @currenvir and the argument to end, which is center. The comparison fails because it compares newcenter with center without further expasion, so they differ and an error is raised. The error message, on the other hand, fully expands @currenvir and the error message is misleading:



! LaTeX Error: begincenter on input line 29 ended by endcenter.



newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree


This one fails because LaTeX checks if the enfironment exists with ifcsname which will build a command with the argument to begin which, in this case, is tabularthree, which expands to tabular. The ifcsname then checks for a command named tabular, which doesn't exist and LaTeX tells you:



! LaTeX Error: Environment tabular undefined.



newcommandtiontion
sectionmysec


This one fails because it's invalid. The command sec is expanded, and it is the secant function, which is only allowed in math-mode, so TeX thinks you forgot a $:



! Missing $ inserted.
<inserted text>
$
l.46 sec


If sec wasn't a math-mode command, TeX would try to execute it. If it had an argument, the argument would be the command tion, which then expands to tion and then the sec command would do its thing (whatever it happened to be) with tion. If it didn't exist, TeX would complain that sec doesn't exist.




The one that works:



newcommandoptarg[myoptarg]
sectionoptargmysec


This one compiles, but it doesn't produce what you'd expect. The test for the optional argument fails, because the code for section doesn't see a [ character (and it doesn't expand optarg looking for it), so it takes optarg as the mandatory argument and the title of the section becomes [myoptarg] and mysec is written below.




The ones that do work:



newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular


This one works because when TeX expands mybegin it just finds begin. TeX then proceeds expanding begin and doing things normally. The cc thing works because tabular expands the tokens of the alignment preamble.




newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo


This one works by the same reason that the first case didn't. The check for the environment name is performed for tabulartwo and tabulartwo, which are the same thing. And the braces there don't make a difference because by TeX's argument grabbing rules, a normal argument is either a single token (tabulartwo is a single token) or, if a open brace ({) is found, then the argument is the <balanced text> within that pair of braces (tabulartwo and tabular are <balanced text> within a pair of braces).




newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour


Same as above.




But you really shouldn't be inventing syntax for commands, because even if it works, you will obfuscate your code and not even you will understand it in a few weeks.






share|improve this answer
















  • 1




    On the other hand, begintabularccc will not work if the array package is loaded.
    – egreg
    4 hours ago












up vote
2
down vote










up vote
2
down vote









Henri Menke told you how to work around the rules. This answer will show you why the syntax you used (doesn't) work.



The ones that don't work:



newcommandnewcentercenter
beginnewcenter
endcenter


This one fails because @currenvir expands to newcenter and when LaTeX calls the @checkend command, it compares the meaning of @currenvir and the argument to end, which is center. The comparison fails because it compares newcenter with center without further expasion, so they differ and an error is raised. The error message, on the other hand, fully expands @currenvir and the error message is misleading:



! LaTeX Error: begincenter on input line 29 ended by endcenter.



newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree


This one fails because LaTeX checks if the enfironment exists with ifcsname which will build a command with the argument to begin which, in this case, is tabularthree, which expands to tabular. The ifcsname then checks for a command named tabular, which doesn't exist and LaTeX tells you:



! LaTeX Error: Environment tabular undefined.



newcommandtiontion
sectionmysec


This one fails because it's invalid. The command sec is expanded, and it is the secant function, which is only allowed in math-mode, so TeX thinks you forgot a $:



! Missing $ inserted.
<inserted text>
$
l.46 sec


If sec wasn't a math-mode command, TeX would try to execute it. If it had an argument, the argument would be the command tion, which then expands to tion and then the sec command would do its thing (whatever it happened to be) with tion. If it didn't exist, TeX would complain that sec doesn't exist.




The one that works:



newcommandoptarg[myoptarg]
sectionoptargmysec


This one compiles, but it doesn't produce what you'd expect. The test for the optional argument fails, because the code for section doesn't see a [ character (and it doesn't expand optarg looking for it), so it takes optarg as the mandatory argument and the title of the section becomes [myoptarg] and mysec is written below.




The ones that do work:



newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular


This one works because when TeX expands mybegin it just finds begin. TeX then proceeds expanding begin and doing things normally. The cc thing works because tabular expands the tokens of the alignment preamble.




newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo


This one works by the same reason that the first case didn't. The check for the environment name is performed for tabulartwo and tabulartwo, which are the same thing. And the braces there don't make a difference because by TeX's argument grabbing rules, a normal argument is either a single token (tabulartwo is a single token) or, if a open brace ({) is found, then the argument is the <balanced text> within that pair of braces (tabulartwo and tabular are <balanced text> within a pair of braces).




newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour


Same as above.




But you really shouldn't be inventing syntax for commands, because even if it works, you will obfuscate your code and not even you will understand it in a few weeks.






share|improve this answer












Henri Menke told you how to work around the rules. This answer will show you why the syntax you used (doesn't) work.



The ones that don't work:



newcommandnewcentercenter
beginnewcenter
endcenter


This one fails because @currenvir expands to newcenter and when LaTeX calls the @checkend command, it compares the meaning of @currenvir and the argument to end, which is center. The comparison fails because it compares newcenter with center without further expasion, so they differ and an error is raised. The error message, on the other hand, fully expands @currenvir and the error message is misleading:



! LaTeX Error: begincenter on input line 29 ended by endcenter.



newcommandtabularthreetabular
begin tabularthree ccc
cell& cell
end tabularthree


This one fails because LaTeX checks if the enfironment exists with ifcsname which will build a command with the argument to begin which, in this case, is tabularthree, which expands to tabular. The ifcsname then checks for a command named tabular, which doesn't exist and LaTeX tells you:



! LaTeX Error: Environment tabular undefined.



newcommandtiontion
sectionmysec


This one fails because it's invalid. The command sec is expanded, and it is the secant function, which is only allowed in math-mode, so TeX thinks you forgot a $:



! Missing $ inserted.
<inserted text>
$
l.46 sec


If sec wasn't a math-mode command, TeX would try to execute it. If it had an argument, the argument would be the command tion, which then expands to tion and then the sec command would do its thing (whatever it happened to be) with tion. If it didn't exist, TeX would complain that sec doesn't exist.




The one that works:



newcommandoptarg[myoptarg]
sectionoptargmysec


This one compiles, but it doesn't produce what you'd expect. The test for the optional argument fails, because the code for section doesn't see a [ character (and it doesn't expand optarg looking for it), so it takes optarg as the mandatory argument and the title of the section becomes [myoptarg] and mysec is written below.




The ones that do work:



newcommandcccc
newcommandmybeginbegin
mybegintabularccc
cell& cell
endtabular


This one works because when TeX expands mybegin it just finds begin. TeX then proceeds expanding begin and doing things normally. The cc thing works because tabular expands the tokens of the alignment preamble.




newcommandtabulartwotabular
begintabulartwo ccc
cell& cell
end tabulartwo


This one works by the same reason that the first case didn't. The check for the environment name is performed for tabulartwo and tabulartwo, which are the same thing. And the braces there don't make a difference because by TeX's argument grabbing rules, a normal argument is either a single token (tabulartwo is a single token) or, if a open brace ({) is found, then the argument is the <balanced text> within that pair of braces (tabulartwo and tabular are <balanced text> within a pair of braces).




newcommandtabularfourtabular
begin tabularfourccc
cell& cell
end tabularfour


Same as above.




But you really shouldn't be inventing syntax for commands, because even if it works, you will obfuscate your code and not even you will understand it in a few weeks.







share|improve this answer












share|improve this answer



share|improve this answer










answered 4 hours ago









Phelype Oleinik

17k43769




17k43769







  • 1




    On the other hand, begintabularccc will not work if the array package is loaded.
    – egreg
    4 hours ago












  • 1




    On the other hand, begintabularccc will not work if the array package is loaded.
    – egreg
    4 hours ago







1




1




On the other hand, begintabularccc will not work if the array package is loaded.
– egreg
4 hours ago




On the other hand, begintabularccc will not work if the array package is loaded.
– egreg
4 hours ago










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









 

draft saved


draft discarded


















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












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











Bighted19 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%2f452660%2flatex-newcommand-limitation%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery