Passing an argument in a different way in a self-made environment












0















I want to pass an argument to a self-made tabular environment in the following format:



begin{customTabular}{|c|c|}{'@'}


...such that the second argument (here '@', WITHIN PARANTHESIS) is treated as a column separator symbol by the LaTeX document. How this can be done? Please suggest the changes/modifications in the code attached.



The code for customTabular environment is as follows (here, mytabular is similar to customTabular):



usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff









share|improve this question




















  • 1





    Is there any particular reason for wanting the quotes?

    – egreg
    Mar 25 at 22:21
















0















I want to pass an argument to a self-made tabular environment in the following format:



begin{customTabular}{|c|c|}{'@'}


...such that the second argument (here '@', WITHIN PARANTHESIS) is treated as a column separator symbol by the LaTeX document. How this can be done? Please suggest the changes/modifications in the code attached.



The code for customTabular environment is as follows (here, mytabular is similar to customTabular):



usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff









share|improve this question




















  • 1





    Is there any particular reason for wanting the quotes?

    – egreg
    Mar 25 at 22:21














0












0








0








I want to pass an argument to a self-made tabular environment in the following format:



begin{customTabular}{|c|c|}{'@'}


...such that the second argument (here '@', WITHIN PARANTHESIS) is treated as a column separator symbol by the LaTeX document. How this can be done? Please suggest the changes/modifications in the code attached.



The code for customTabular environment is as follows (here, mytabular is similar to customTabular):



usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff









share|improve this question
















I want to pass an argument to a self-made tabular environment in the following format:



begin{customTabular}{|c|c|}{'@'}


...such that the second argument (here '@', WITHIN PARANTHESIS) is treated as a column separator symbol by the LaTeX document. How this can be done? Please suggest the changes/modifications in the code attached.



The code for customTabular environment is as follows (here, mytabular is similar to customTabular):



usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}
}
{
end{tabular}
}
ExplSyntaxOff






tables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 11:35









JouleV

10.5k22559




10.5k22559










asked Mar 25 at 11:34









Naman Naman

62




62








  • 1





    Is there any particular reason for wanting the quotes?

    – egreg
    Mar 25 at 22:21














  • 1





    Is there any particular reason for wanting the quotes?

    – egreg
    Mar 25 at 22:21








1




1





Is there any particular reason for wanting the quotes?

– egreg
Mar 25 at 22:21





Is there any particular reason for wanting the quotes?

– egreg
Mar 25 at 22:21










2 Answers
2






active

oldest

votes


















2














You need to make the argument an optional group (or perhaps mandatory), and to arrange to strip any quote marks before using as a number:



documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{c} m G{','} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n { __mytab_test:n {#3} }
begin{tabular}[#1]{#2}
}
{
end{tabular}
}
cs_new:Npn __mytab_test:n #1 { __mytab_test:w #1 ' #1 '' q_stop }
cs_new:Npn __mytab_test:w #1 ' #2 ' #3 q_stop { `#2 }
ExplSyntaxOff

begin{document}
begin{mytabular}{cc}{'@'}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}{@}
a @ b\
c @ d
end{mytabular}
end{document}


The trick in removing ' tokens is that TeX is greedy in a match. So with



#1 ' #2 ' #3


any input containing a leading ' will have an empty #1, the 'argument' in #2 and rubbish left in #3. If there was no leading ', then #1 will be the same as #2 due to the set up macro, which supplies the input both with and without additional ' tokens.






share|improve this answer


























  • Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

    – Naman
    Mar 25 at 12:34





















0














If you don't require the quotes, your code works, provided you use square brackets for the argument. It's better style to also add the mandatory argument for the columns.



documentclass{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} m }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}{#2}
}
{
end{tabular}
}
ExplSyntaxOff

begin{document}

begin{mytabular}[@]{cc}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}
a , b\
c , d
end{mytabular}

end{document}


enter image description here



If you want a syntax such as begin{mytabular}{cc}[@], just exchange the arguments



NewDocumentEnvironment {mytabular} { m O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#2}
begin{tabular}{#1}
}
{
end{tabular}
}





share|improve this answer
























  • Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

    – Naman
    Mar 26 at 12:02











  • @Naman What are they for?

    – egreg
    Mar 26 at 12:06











  • Nothing much, rather, only a new way of trying the old stuff...

    – Naman
    Mar 26 at 16:38














Your Answer








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

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

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f481330%2fpassing-an-argument-in-a-different-way-in-a-self-made-environment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You need to make the argument an optional group (or perhaps mandatory), and to arrange to strip any quote marks before using as a number:



documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{c} m G{','} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n { __mytab_test:n {#3} }
begin{tabular}[#1]{#2}
}
{
end{tabular}
}
cs_new:Npn __mytab_test:n #1 { __mytab_test:w #1 ' #1 '' q_stop }
cs_new:Npn __mytab_test:w #1 ' #2 ' #3 q_stop { `#2 }
ExplSyntaxOff

begin{document}
begin{mytabular}{cc}{'@'}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}{@}
a @ b\
c @ d
end{mytabular}
end{document}


The trick in removing ' tokens is that TeX is greedy in a match. So with



#1 ' #2 ' #3


any input containing a leading ' will have an empty #1, the 'argument' in #2 and rubbish left in #3. If there was no leading ', then #1 will be the same as #2 due to the set up macro, which supplies the input both with and without additional ' tokens.






share|improve this answer


























  • Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

    – Naman
    Mar 25 at 12:34


















2














You need to make the argument an optional group (or perhaps mandatory), and to arrange to strip any quote marks before using as a number:



documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{c} m G{','} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n { __mytab_test:n {#3} }
begin{tabular}[#1]{#2}
}
{
end{tabular}
}
cs_new:Npn __mytab_test:n #1 { __mytab_test:w #1 ' #1 '' q_stop }
cs_new:Npn __mytab_test:w #1 ' #2 ' #3 q_stop { `#2 }
ExplSyntaxOff

begin{document}
begin{mytabular}{cc}{'@'}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}{@}
a @ b\
c @ d
end{mytabular}
end{document}


The trick in removing ' tokens is that TeX is greedy in a match. So with



#1 ' #2 ' #3


any input containing a leading ' will have an empty #1, the 'argument' in #2 and rubbish left in #3. If there was no leading ', then #1 will be the same as #2 due to the set up macro, which supplies the input both with and without additional ' tokens.






share|improve this answer


























  • Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

    – Naman
    Mar 25 at 12:34
















2












2








2







You need to make the argument an optional group (or perhaps mandatory), and to arrange to strip any quote marks before using as a number:



documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{c} m G{','} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n { __mytab_test:n {#3} }
begin{tabular}[#1]{#2}
}
{
end{tabular}
}
cs_new:Npn __mytab_test:n #1 { __mytab_test:w #1 ' #1 '' q_stop }
cs_new:Npn __mytab_test:w #1 ' #2 ' #3 q_stop { `#2 }
ExplSyntaxOff

begin{document}
begin{mytabular}{cc}{'@'}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}{@}
a @ b\
c @ d
end{mytabular}
end{document}


The trick in removing ' tokens is that TeX is greedy in a match. So with



#1 ' #2 ' #3


any input containing a leading ' will have an empty #1, the 'argument' in #2 and rubbish left in #3. If there was no leading ', then #1 will be the same as #2 due to the set up macro, which supplies the input both with and without additional ' tokens.






share|improve this answer















You need to make the argument an optional group (or perhaps mandatory), and to arrange to strip any quote marks before using as a number:



documentclass{article}
usepackage{xparse}
ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{c} m G{','} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n { __mytab_test:n {#3} }
begin{tabular}[#1]{#2}
}
{
end{tabular}
}
cs_new:Npn __mytab_test:n #1 { __mytab_test:w #1 ' #1 '' q_stop }
cs_new:Npn __mytab_test:w #1 ' #2 ' #3 q_stop { `#2 }
ExplSyntaxOff

begin{document}
begin{mytabular}{cc}{'@'}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}{@}
a @ b\
c @ d
end{mytabular}
end{document}


The trick in removing ' tokens is that TeX is greedy in a match. So with



#1 ' #2 ' #3


any input containing a leading ' will have an empty #1, the 'argument' in #2 and rubbish left in #3. If there was no leading ', then #1 will be the same as #2 due to the set up macro, which supplies the input both with and without additional ' tokens.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 22:23









egreg

731k8919303252




731k8919303252










answered Mar 25 at 12:19









Joseph WrightJoseph Wright

205k23563891




205k23563891













  • Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

    – Naman
    Mar 25 at 12:34





















  • Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

    – Naman
    Mar 25 at 12:34



















Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

– Naman
Mar 25 at 12:34







Thank You @Joseph. The answer really worked, but the syntax used is quite complicated and out of my current understanding of LaTeX. But, still the answer was helpful and it worked as the way I required. Please provide a simpler solution to the problem if possible.Thank You for solving my question :)

– Naman
Mar 25 at 12:34













0














If you don't require the quotes, your code works, provided you use square brackets for the argument. It's better style to also add the mandatory argument for the columns.



documentclass{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} m }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}{#2}
}
{
end{tabular}
}
ExplSyntaxOff

begin{document}

begin{mytabular}[@]{cc}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}
a , b\
c , d
end{mytabular}

end{document}


enter image description here



If you want a syntax such as begin{mytabular}{cc}[@], just exchange the arguments



NewDocumentEnvironment {mytabular} { m O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#2}
begin{tabular}{#1}
}
{
end{tabular}
}





share|improve this answer
























  • Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

    – Naman
    Mar 26 at 12:02











  • @Naman What are they for?

    – egreg
    Mar 26 at 12:06











  • Nothing much, rather, only a new way of trying the old stuff...

    – Naman
    Mar 26 at 16:38


















0














If you don't require the quotes, your code works, provided you use square brackets for the argument. It's better style to also add the mandatory argument for the columns.



documentclass{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} m }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}{#2}
}
{
end{tabular}
}
ExplSyntaxOff

begin{document}

begin{mytabular}[@]{cc}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}
a , b\
c , d
end{mytabular}

end{document}


enter image description here



If you want a syntax such as begin{mytabular}{cc}[@], just exchange the arguments



NewDocumentEnvironment {mytabular} { m O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#2}
begin{tabular}{#1}
}
{
end{tabular}
}





share|improve this answer
























  • Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

    – Naman
    Mar 26 at 12:02











  • @Naman What are they for?

    – egreg
    Mar 26 at 12:06











  • Nothing much, rather, only a new way of trying the old stuff...

    – Naman
    Mar 26 at 16:38
















0












0








0







If you don't require the quotes, your code works, provided you use square brackets for the argument. It's better style to also add the mandatory argument for the columns.



documentclass{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} m }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}{#2}
}
{
end{tabular}
}
ExplSyntaxOff

begin{document}

begin{mytabular}[@]{cc}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}
a , b\
c , d
end{mytabular}

end{document}


enter image description here



If you want a syntax such as begin{mytabular}{cc}[@], just exchange the arguments



NewDocumentEnvironment {mytabular} { m O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#2}
begin{tabular}{#1}
}
{
end{tabular}
}





share|improve this answer













If you don't require the quotes, your code works, provided you use square brackets for the argument. It's better style to also add the mandatory argument for the columns.



documentclass{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentEnvironment {mytabular} { O{,} m }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#1}
begin{tabular}{#2}
}
{
end{tabular}
}
ExplSyntaxOff

begin{document}

begin{mytabular}[@]{cc}
a @ b\
c @ d
end{mytabular}

begin{mytabular}{cc}
a , b\
c , d
end{mytabular}

end{document}


enter image description here



If you want a syntax such as begin{mytabular}{cc}[@], just exchange the arguments



NewDocumentEnvironment {mytabular} { m O{,} }
{
char_set_catcode_other:N &
char_set_catcode_alignment:n {`#2}
begin{tabular}{#1}
}
{
end{tabular}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 22:39









egregegreg

731k8919303252




731k8919303252













  • Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

    – Naman
    Mar 26 at 12:02











  • @Naman What are they for?

    – egreg
    Mar 26 at 12:06











  • Nothing much, rather, only a new way of trying the old stuff...

    – Naman
    Mar 26 at 16:38





















  • Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

    – Naman
    Mar 26 at 12:02











  • @Naman What are they for?

    – egreg
    Mar 26 at 12:06











  • Nothing much, rather, only a new way of trying the old stuff...

    – Naman
    Mar 26 at 16:38



















Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

– Naman
Mar 26 at 12:02





Thank You for your contribution but I do want the use of quotes in the argument passing method in the environment.

– Naman
Mar 26 at 12:02













@Naman What are they for?

– egreg
Mar 26 at 12:06





@Naman What are they for?

– egreg
Mar 26 at 12:06













Nothing much, rather, only a new way of trying the old stuff...

– Naman
Mar 26 at 16:38







Nothing much, rather, only a new way of trying the old stuff...

– Naman
Mar 26 at 16:38




















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f481330%2fpassing-an-argument-in-a-different-way-in-a-self-made-environment%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

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?