Using a macro with parameters in everypar fails

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











up vote
4
down vote

favorite












Out of curiosity, I wonder why this fails:



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!

begindocument

begingroup
obeylines
everypar=bla
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument


with the error: Argument of bla has an extra }. I did look at par in the parameter text (as an argument delimiter) and vbox#1 in an everypar macro but these are not delimited arguments to a macro.



Later...



I discovered that xparse offers a solution of sorts, though I think this might be looked upon as abuse:



documentclassarticle

usepackagexparse

NewDocumentCommandblaOO#1.#2!

begindocument

begingroup
obeylines
everypar=bla
[C][Gin] skdjfs;ldjkf;sjkf
[ERT][ERTERT] djkfsjdfl;ksjdf;l
endgroup

enddocument


I assume that this works because the pesky improve this question
























  • Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
    – Joseph Wright♦
    Oct 4 at 12:11










  • No. It was part of an earlier experiment...
    – sgmoye
    Oct 4 at 12:15




























  • Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
    – Joseph Wright♦
    Oct 4 at 12:11










  • No. It was part of an earlier experiment...
    – sgmoye
    Oct 4 at 12:15




















Out of curiosity, I wonder why this fails:



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!

begindocument

begingroup
obeylines
everypar=bla
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument


with the error: Argument of bla has an extra . I did look at par in the parameter text (as an argument delimiter) and vbox#1 in an everypar macro but these are not delimited arguments to a macro.



Later...



I discovered that xparse offers a solution of sorts, though I think this might be looked upon as abuse:



documentclassarticle

usepackagexparse

NewDocumentCommandblaOO#1.#2!

begindocument

begingroup
obeylines
everypar=bla
[C][Gin] skdjfs;ldjkf;sjkf
[ERT][ERTERT] djkfsjdfl;ksjdf;l
endgroup

enddocument


I assume that this works because the pesky { is no longer in play. This is convenient in that I can avoid putting bla in front of each and every line (dozens of them).







tex-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 4 at 17:04

























asked Oct 4 at 12:05









sgmoye

3,64711225




3,64711225











  • Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
    – Joseph Wright♦
    Oct 4 at 12:11










  • No. It was part of an earlier experiment...
    – sgmoye
    Oct 4 at 12:15
















  • Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
    – Joseph Wright♦
    Oct 4 at 12:11










  • No. It was part of an earlier experiment...
    – sgmoye
    Oct 4 at 12:15















Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
– Joseph Wright♦
Oct 4 at 12:11




Is there a reason you want obeylines here? It makes the explanation longer ... though fundamentally the same
– Joseph Wright♦
Oct 4 at 12:11












No. It was part of an earlier experiment...
– sgmoye
Oct 4 at 12:15




No. It was part of an earlier experiment...
– sgmoye
Oct 4 at 12:15










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










TeX is in vertical mode when it reads your C start-of-paragraph text. The starts a group but does not change mode. That happens when TeX reads C, which must be in horizontal mode and so starts a paragraph. The everypar tokens are inserted, and your macro grabs C as #1 (you can see this if you use a macro with only one argument). In the current case, you then have a in the input stream. That can't be #2, so you get a TeX error.



Probably the easiest way to avoid this is to force TeX to leave vertical mode. The standard leavevmode won't work as it inserts some tokens that come after everypar. We can fix that with an e-TeX definition for leavevmode



protecteddefleavevmodeifvmodeexpandafterindentfi


which can then be inserted



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!
protecteddefleavevmodeifvmodeexpandafterindentfi

begindocument

begingroup
everypar=bla
leavevmode
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument





share|improve this answer
















  • 1




    What is e-tex specific here? The protected naturally, but it seems to work also without it.
    – Ulrike Fischer
    Oct 4 at 12:44










  • Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
    – sgmoye
    Oct 4 at 12:46










  • Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
    – sgmoye
    Oct 4 at 13:32










  • @sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
    – Joseph Wright♦
    Oct 4 at 14:52










  • @JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
    – sgmoye
    Oct 4 at 16:11










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%2f453789%2fusing-a-macro-with-parameters-in-everypar-fails%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
5
down vote



accepted










TeX is in vertical mode when it reads your C start-of-paragraph text. The starts a group but does not change mode. That happens when TeX reads C, which must be in horizontal mode and so starts a paragraph. The everypar tokens are inserted, and your macro grabs C as #1 (you can see this if you use a macro with only one argument). In the current case, you then have a in the input stream. That can't be #2, so you get a TeX error.



Probably the easiest way to avoid this is to force TeX to leave vertical mode. The standard leavevmode won't work as it inserts some tokens that come after everypar. We can fix that with an e-TeX definition for leavevmode



protecteddefleavevmodeifvmodeexpandafterindentfi


which can then be inserted



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!
protecteddefleavevmodeifvmodeexpandafterindentfi

begindocument

begingroup
everypar=bla
leavevmode
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument





share|improve this answer
















  • 1




    What is e-tex specific here? The protected naturally, but it seems to work also without it.
    – Ulrike Fischer
    Oct 4 at 12:44










  • Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
    – sgmoye
    Oct 4 at 12:46










  • Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
    – sgmoye
    Oct 4 at 13:32










  • @sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
    – Joseph Wright♦
    Oct 4 at 14:52










  • @JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
    – sgmoye
    Oct 4 at 16:11














up vote
5
down vote



accepted










TeX is in vertical mode when it reads your C start-of-paragraph text. The starts a group but does not change mode. That happens when TeX reads C, which must be in horizontal mode and so starts a paragraph. The everypar tokens are inserted, and your macro grabs C as #1 (you can see this if you use a macro with only one argument). In the current case, you then have a in the input stream. That can't be #2, so you get a TeX error.



Probably the easiest way to avoid this is to force TeX to leave vertical mode. The standard leavevmode won't work as it inserts some tokens that come after everypar. We can fix that with an e-TeX definition for leavevmode



protecteddefleavevmodeifvmodeexpandafterindentfi


which can then be inserted



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!
protecteddefleavevmodeifvmodeexpandafterindentfi

begindocument

begingroup
everypar=bla
leavevmode
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument





share|improve this answer
















  • 1




    What is e-tex specific here? The protected naturally, but it seems to work also without it.
    – Ulrike Fischer
    Oct 4 at 12:44










  • Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
    – sgmoye
    Oct 4 at 12:46










  • Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
    – sgmoye
    Oct 4 at 13:32










  • @sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
    – Joseph Wright♦
    Oct 4 at 14:52










  • @JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
    – sgmoye
    Oct 4 at 16:11












up vote
5
down vote



accepted







up vote
5
down vote



accepted






TeX is in vertical mode when it reads your C start-of-paragraph text. The starts a group but does not change mode. That happens when TeX reads C, which must be in horizontal mode and so starts a paragraph. The everypar tokens are inserted, and your macro grabs C as #1 (you can see this if you use a macro with only one argument). In the current case, you then have a in the input stream. That can't be #2, so you get a TeX error.



Probably the easiest way to avoid this is to force TeX to leave vertical mode. The standard leavevmode won't work as it inserts some tokens that come after everypar. We can fix that with an e-TeX definition for leavevmode



protecteddefleavevmodeifvmodeexpandafterindentfi


which can then be inserted



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!
protecteddefleavevmodeifvmodeexpandafterindentfi

begindocument

begingroup
everypar=bla
leavevmode
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument





share|improve this answer












TeX is in vertical mode when it reads your C start-of-paragraph text. The starts a group but does not change mode. That happens when TeX reads C, which must be in horizontal mode and so starts a paragraph. The everypar tokens are inserted, and your macro grabs C as #1 (you can see this if you use a macro with only one argument). In the current case, you then have a in the input stream. That can't be #2, so you get a TeX error.



Probably the easiest way to avoid this is to force TeX to leave vertical mode. The standard leavevmode won't work as it inserts some tokens that come after everypar. We can fix that with an e-TeX definition for leavevmode



protecteddefleavevmodeifvmodeexpandafterindentfi


which can then be inserted



documentclassarticle

usepackagexparse

NewDocumentCommandblamm#1.#2!
protecteddefleavevmodeifvmodeexpandafterindentfi

begindocument

begingroup
everypar=bla
leavevmode
CG skdjfs;ldjkf;sjkf
ERTERTERT djkfsjdfl;ksjdf;l
endgroup

enddocument






share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 4 at 12:33









Joseph Wright♦

198k21545864




198k21545864







  • 1




    What is e-tex specific here? The protected naturally, but it seems to work also without it.
    – Ulrike Fischer
    Oct 4 at 12:44










  • Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
    – sgmoye
    Oct 4 at 12:46










  • Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
    – sgmoye
    Oct 4 at 13:32










  • @sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
    – Joseph Wright♦
    Oct 4 at 14:52










  • @JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
    – sgmoye
    Oct 4 at 16:11












  • 1




    What is e-tex specific here? The protected naturally, but it seems to work also without it.
    – Ulrike Fischer
    Oct 4 at 12:44










  • Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
    – sgmoye
    Oct 4 at 12:46










  • Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
    – sgmoye
    Oct 4 at 13:32










  • @sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
    – Joseph Wright♦
    Oct 4 at 14:52










  • @JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
    – sgmoye
    Oct 4 at 16:11







1




1




What is e-tex specific here? The protected naturally, but it seems to work also without it.
– Ulrike Fischer
Oct 4 at 12:44




What is e-tex specific here? The protected naturally, but it seems to work also without it.
– Ulrike Fischer
Oct 4 at 12:44












Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
– sgmoye
Oct 4 at 12:46




Somewhere in the TeXBook there is a warning about beginning a paragraph with { -- can't find it now, but that should have made me think... This was a nice lesson.
– sgmoye
Oct 4 at 12:46












Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
– sgmoye
Oct 4 at 13:32




Actually, having TeXed the code, I find that does not work. The first line works correctly giving typeset C.G! skdjfs;ldjkf;sjkf but the second line gives typeset E.R!ERTERT djkfsjdfl;ksjdf;l. The code works if leavevmode is placed before each line.
– sgmoye
Oct 4 at 13:32












@sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
– Joseph Wright♦
Oct 4 at 14:52




@sgmoye I've dropped the obeylines as it makes life more tricky: perhaps you haven't?
– Joseph Wright♦
Oct 4 at 14:52












@JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
– sgmoye
Oct 4 at 16:11




@JosephWright I had absently put a return after the fist line. That led me to the discovery that leavevmode is required before each line, and the realization that there is no real labor-savings in using a macro with parameters inside everypar It would be nice if there were...
– sgmoye
Oct 4 at 16:11

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f453789%2fusing-a-macro-with-parameters-in-everypar-fails%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay