scantokens not playing nice with def or gdef etc

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











up vote
2
down vote

favorite












I working in a context where I'm changing catcodes and need to rescan the tokens before proceeding to process the text. But, I'm running into problems. Even with this bare minimum code, I still have issues.



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


Resulting in the error:



! Undefined control sequence.
aeinput ...ae@input ::#1::}endgroup ae@input


I get the same error if I write:



scantokensxdefae@input::#1::%%


Why is this not compiling?



Also, if I do something like



expandaftergdefexpandafterae@inputexpandafterscantokens::#1::%%


I get the following error:



! File ended while scanning definition of ae@input.


Even adding everyoefnoexpand doesn't help.



HOWEVER, the following does work (which makes me even more confused).



xdefae@inputscantokens::#1::%%


So, what's happening here?



Where does this question come from?



I thought I had a simple answer for inputing text within an environment for which I've already changed the catcode of . Basically, in that question I have an environment



beginspeech
inside here periods have a different catcode

endspeech


The OP for that question wanted to do something like



beginspeech
inputtext.tex
endspeech


Clearly, input is not going to work here because . has the wrong catcode. I thought I could easily remedy this (and allow the OP to continue writing inputtext.tex) by doing something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@inputinput#1%%
endgroup
ae@input
%%
makeatother


An alternative approach would have been to do something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@filehandle#1%%
endgroup
inputae@filehandle%%
%%
makeatother


That way, the input file would handle periods appropriately according to the speech environment.



Something like



newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensinput#1%%
endgroup



Only superficially looks like it could work, but the input file would have not have the correct catcode for the periods anymore.










share|improve this question























  • What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
    – Henri Menke
    1 hour ago











  • @HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
    – A.Ellett
    1 hour ago











  • @HenriMenke You changed your comment before I noticed.
    – A.Ellett
    1 hour ago










  • Have you had a look at tex.stackexchange.com/questions/117906/… ?
    – Henri Menke
    1 hour ago










  • @HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
    – A.Ellett
    1 hour ago














up vote
2
down vote

favorite












I working in a context where I'm changing catcodes and need to rescan the tokens before proceeding to process the text. But, I'm running into problems. Even with this bare minimum code, I still have issues.



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


Resulting in the error:



! Undefined control sequence.
aeinput ...ae@input ::#1::}endgroup ae@input


I get the same error if I write:



scantokensxdefae@input::#1::%%


Why is this not compiling?



Also, if I do something like



expandaftergdefexpandafterae@inputexpandafterscantokens::#1::%%


I get the following error:



! File ended while scanning definition of ae@input.


Even adding everyoefnoexpand doesn't help.



HOWEVER, the following does work (which makes me even more confused).



xdefae@inputscantokens::#1::%%


So, what's happening here?



Where does this question come from?



I thought I had a simple answer for inputing text within an environment for which I've already changed the catcode of . Basically, in that question I have an environment



beginspeech
inside here periods have a different catcode

endspeech


The OP for that question wanted to do something like



beginspeech
inputtext.tex
endspeech


Clearly, input is not going to work here because . has the wrong catcode. I thought I could easily remedy this (and allow the OP to continue writing inputtext.tex) by doing something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@inputinput#1%%
endgroup
ae@input
%%
makeatother


An alternative approach would have been to do something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@filehandle#1%%
endgroup
inputae@filehandle%%
%%
makeatother


That way, the input file would handle periods appropriately according to the speech environment.



Something like



newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensinput#1%%
endgroup



Only superficially looks like it could work, but the input file would have not have the correct catcode for the periods anymore.










share|improve this question























  • What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
    – Henri Menke
    1 hour ago











  • @HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
    – A.Ellett
    1 hour ago











  • @HenriMenke You changed your comment before I noticed.
    – A.Ellett
    1 hour ago










  • Have you had a look at tex.stackexchange.com/questions/117906/… ?
    – Henri Menke
    1 hour ago










  • @HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
    – A.Ellett
    1 hour ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I working in a context where I'm changing catcodes and need to rescan the tokens before proceeding to process the text. But, I'm running into problems. Even with this bare minimum code, I still have issues.



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


Resulting in the error:



! Undefined control sequence.
aeinput ...ae@input ::#1::}endgroup ae@input


I get the same error if I write:



scantokensxdefae@input::#1::%%


Why is this not compiling?



Also, if I do something like



expandaftergdefexpandafterae@inputexpandafterscantokens::#1::%%


I get the following error:



! File ended while scanning definition of ae@input.


Even adding everyoefnoexpand doesn't help.



HOWEVER, the following does work (which makes me even more confused).



xdefae@inputscantokens::#1::%%


So, what's happening here?



Where does this question come from?



I thought I had a simple answer for inputing text within an environment for which I've already changed the catcode of . Basically, in that question I have an environment



beginspeech
inside here periods have a different catcode

endspeech


The OP for that question wanted to do something like



beginspeech
inputtext.tex
endspeech


Clearly, input is not going to work here because . has the wrong catcode. I thought I could easily remedy this (and allow the OP to continue writing inputtext.tex) by doing something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@inputinput#1%%
endgroup
ae@input
%%
makeatother


An alternative approach would have been to do something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@filehandle#1%%
endgroup
inputae@filehandle%%
%%
makeatother


That way, the input file would handle periods appropriately according to the speech environment.



Something like



newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensinput#1%%
endgroup



Only superficially looks like it could work, but the input file would have not have the correct catcode for the periods anymore.










share|improve this question















I working in a context where I'm changing catcodes and need to rescan the tokens before proceeding to process the text. But, I'm running into problems. Even with this bare minimum code, I still have issues.



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


Resulting in the error:



! Undefined control sequence.
aeinput ...ae@input ::#1::}endgroup ae@input


I get the same error if I write:



scantokensxdefae@input::#1::%%


Why is this not compiling?



Also, if I do something like



expandaftergdefexpandafterae@inputexpandafterscantokens::#1::%%


I get the following error:



! File ended while scanning definition of ae@input.


Even adding everyoefnoexpand doesn't help.



HOWEVER, the following does work (which makes me even more confused).



xdefae@inputscantokens::#1::%%


So, what's happening here?



Where does this question come from?



I thought I had a simple answer for inputing text within an environment for which I've already changed the catcode of . Basically, in that question I have an environment



beginspeech
inside here periods have a different catcode

endspeech


The OP for that question wanted to do something like



beginspeech
inputtext.tex
endspeech


Clearly, input is not going to work here because . has the wrong catcode. I thought I could easily remedy this (and allow the OP to continue writing inputtext.tex) by doing something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@inputinput#1%%
endgroup
ae@input
%%
makeatother


An alternative approach would have been to do something like



makeatletter
newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensgdefae@filehandle#1%%
endgroup
inputae@filehandle%%
%%
makeatother


That way, the input file would handle periods appropriately according to the speech environment.



Something like



newcommandaeinput[1]%%
begingroup
catcode`.=periodcatcode
scantokensinput#1%%
endgroup



Only superficially looks like it could work, but the input file would have not have the correct catcode for the periods anymore.







input catcodes e-tex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago

























asked 1 hour ago









A.Ellett

34.8k1063162




34.8k1063162











  • What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
    – Henri Menke
    1 hour ago











  • @HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
    – A.Ellett
    1 hour ago











  • @HenriMenke You changed your comment before I noticed.
    – A.Ellett
    1 hour ago










  • Have you had a look at tex.stackexchange.com/questions/117906/… ?
    – Henri Menke
    1 hour ago










  • @HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
    – A.Ellett
    1 hour ago
















  • What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
    – Henri Menke
    1 hour ago











  • @HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
    – A.Ellett
    1 hour ago











  • @HenriMenke You changed your comment before I noticed.
    – A.Ellett
    1 hour ago










  • Have you had a look at tex.stackexchange.com/questions/117906/… ?
    – Henri Menke
    1 hour ago










  • @HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
    – A.Ellett
    1 hour ago















What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
– Henri Menke
1 hour ago





What is the purpose of xdef? This will also fully expand #1. Why not just newcommandaeinput[1]scantokens#1ignorespaces?
– Henri Menke
1 hour ago













@HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
– A.Ellett
1 hour ago





@HenriMenke According to the etex documentation scantokens is expandable. But, let's say it's not. Why in the world would xdefae@inputscantokens.... be the only instance for which my code compiled?
– A.Ellett
1 hour ago













@HenriMenke You changed your comment before I noticed.
– A.Ellett
1 hour ago




@HenriMenke You changed your comment before I noticed.
– A.Ellett
1 hour ago












Have you had a look at tex.stackexchange.com/questions/117906/… ?
– Henri Menke
1 hour ago




Have you had a look at tex.stackexchange.com/questions/117906/… ?
– Henri Menke
1 hour ago












@HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
– A.Ellett
1 hour ago




@HenriMenke Yes, I have and I can't seem to make things work. I've updated my answer to explain why your first suggestion is not tenable.
– A.Ellett
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Remember that scantokens applies the category codes in force when it's used. Thus in



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


the scantokens line is inserted in the doucment, where @ is not a letter. So
gdefae@input defines ae as a macro to be followed by @input with replacement text ::<#1>::. You need to change the category codes inside your group



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
makeatletter
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


As you observe, whilst scantokens is expandable, getting that right is a bit tricky as it has some oddities about the 'end of file' for the virtual file it uses. Those can be got around (see the tl_rescan:nn code and similar in expl3), but it's non-trivial.






share|improve this answer




















  • OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
    – A.Ellett
    25 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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f453568%2fscantokens-not-playing-nice-with-def-or-gdef-etc%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Remember that scantokens applies the category codes in force when it's used. Thus in



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


the scantokens line is inserted in the doucment, where @ is not a letter. So
gdefae@input defines ae as a macro to be followed by @input with replacement text ::<#1>::. You need to change the category codes inside your group



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
makeatletter
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


As you observe, whilst scantokens is expandable, getting that right is a bit tricky as it has some oddities about the 'end of file' for the virtual file it uses. Those can be got around (see the tl_rescan:nn code and similar in expl3), but it's non-trivial.






share|improve this answer




















  • OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
    – A.Ellett
    25 mins ago














up vote
3
down vote



accepted










Remember that scantokens applies the category codes in force when it's used. Thus in



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


the scantokens line is inserted in the doucment, where @ is not a letter. So
gdefae@input defines ae as a macro to be followed by @input with replacement text ::<#1>::. You need to change the category codes inside your group



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
makeatletter
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


As you observe, whilst scantokens is expandable, getting that right is a bit tricky as it has some oddities about the 'end of file' for the virtual file it uses. Those can be got around (see the tl_rescan:nn code and similar in expl3), but it's non-trivial.






share|improve this answer




















  • OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
    – A.Ellett
    25 mins ago












up vote
3
down vote



accepted







up vote
3
down vote



accepted






Remember that scantokens applies the category codes in force when it's used. Thus in



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


the scantokens line is inserted in the doucment, where @ is not a letter. So
gdefae@input defines ae as a macro to be followed by @input with replacement text ::<#1>::. You need to change the category codes inside your group



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
makeatletter
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


As you observe, whilst scantokens is expandable, getting that right is a bit tricky as it has some oddities about the 'end of file' for the virtual file it uses. Those can be got around (see the tl_rescan:nn code and similar in expl3), but it's non-trivial.






share|improve this answer












Remember that scantokens applies the category codes in force when it's used. Thus in



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


the scantokens line is inserted in the doucment, where @ is not a letter. So
gdefae@input defines ae as a macro to be followed by @input with replacement text ::<#1>::. You need to change the category codes inside your group



documentclassarticle

makeatletter
newcommandaeinput[1]%%
begingroup
makeatletter
scantokensgdefae@input::#1::%%
endgroup
ae@input
%%
makeatother

begindocument
aeinputHELLO
enddocument


As you observe, whilst scantokens is expandable, getting that right is a bit tricky as it has some oddities about the 'end of file' for the virtual file it uses. Those can be got around (see the tl_rescan:nn code and similar in expl3), but it's non-trivial.







share|improve this answer












share|improve this answer



share|improve this answer










answered 29 mins ago









Joseph Wright♦

197k21543863




197k21543863











  • OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
    – A.Ellett
    25 mins ago
















  • OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
    – A.Ellett
    25 mins ago















OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
– A.Ellett
25 mins ago




OMG. How did I not see that! Yikes. Subtle, but also kind of obvious---at least for the amount of monkeying around I do with this stuff. Thank you.
– A.Ellett
25 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f453568%2fscantokens-not-playing-nice-with-def-or-gdef-etc%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