Shortcut for a polynomial of the form $a_nx^n+ldots+a_1x+a_0$












6















I currently taking a course in Algebra, and I find myself typing the polynomial



$a_nx^n+ldots+a_1x+a_0$ 


over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.



I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.










share|improve this question









New contributor




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





















  • Welcome to TeX.SE!

    – Mico
    12 hours ago











  • Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

    – Mico
    12 hours ago






  • 2





    Exactly as you say! and thank you for the warm welcome :) @Mico

    – Kam
    12 hours ago













  • Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

    – John Kormylo
    8 hours ago
















6















I currently taking a course in Algebra, and I find myself typing the polynomial



$a_nx^n+ldots+a_1x+a_0$ 


over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.



I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.










share|improve this question









New contributor




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





















  • Welcome to TeX.SE!

    – Mico
    12 hours ago











  • Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

    – Mico
    12 hours ago






  • 2





    Exactly as you say! and thank you for the warm welcome :) @Mico

    – Kam
    12 hours ago













  • Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

    – John Kormylo
    8 hours ago














6












6








6








I currently taking a course in Algebra, and I find myself typing the polynomial



$a_nx^n+ldots+a_1x+a_0$ 


over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.



I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.










share|improve this question









New contributor




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












I currently taking a course in Algebra, and I find myself typing the polynomial



$a_nx^n+ldots+a_1x+a_0$ 


over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.



I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.







math-mode macros shortcut






share|improve this question









New contributor




Kam 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




Kam 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 29 mins ago









Riker

1033




1033






New contributor




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









asked 12 hours ago









KamKam

333




333




New contributor




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





New contributor





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






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













  • Welcome to TeX.SE!

    – Mico
    12 hours ago











  • Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

    – Mico
    12 hours ago






  • 2





    Exactly as you say! and thank you for the warm welcome :) @Mico

    – Kam
    12 hours ago













  • Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

    – John Kormylo
    8 hours ago



















  • Welcome to TeX.SE!

    – Mico
    12 hours ago











  • Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

    – Mico
    12 hours ago






  • 2





    Exactly as you say! and thank you for the warm welcome :) @Mico

    – Kam
    12 hours ago













  • Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

    – John Kormylo
    8 hours ago

















Welcome to TeX.SE!

– Mico
12 hours ago





Welcome to TeX.SE!

– Mico
12 hours ago













Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

– Mico
12 hours ago





Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always n (w/ n>1, right?) and is the lowest order always 0 , i.e., a constant?

– Mico
12 hours ago




2




2





Exactly as you say! and thank you for the warm welcome :) @Mico

– Kam
12 hours ago







Exactly as you say! and thank you for the warm welcome :) @Mico

– Kam
12 hours ago















Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

– John Kormylo
8 hours ago





Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)

– John Kormylo
8 hours ago










2 Answers
2






active

oldest

votes


















8














I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n and 0, respectively.) The macro called pn in the following example satisfies these criteria.



Incidentally, the typographic ellipsis used between binary operators (such as +) is usually of the form cdots, not ldots. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}

begin{document}
$pn{a}{x}$

$pn{lambda}{z}$

$pn{alpha}{xi}$
end{document}




Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n, but that it's true that most polynomials are, in fact, order n. In that case, it makes sense to modify the pn macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n by default.



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}

begin{document}
$pn{a}{x}$ % use default order (n) of polynomial

$pn[4]{lambda}{z}$

$pn[q]{alpha}{xi}$
end{document}





share|improve this answer





















  • 1





    Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

    – Kam
    12 hours ago













  • Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

    – Kam
    12 hours ago











  • @Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

    – Mico
    11 hours ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    11 hours ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    10 hours ago



















5














With a fairly simple syntax:



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}

keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}

cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff

begin{document}

$poly$

$poly[var=z]$

$poly[var=t,degree=m,coef=b]$

$poly[var=t,degree=m,coef=b,reverse]$

end{document}


The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are



var = x
degree = n
coef = a


You can also make shorthands with, say



newcommand{polybtn}{poly[var=t,coef=b,degree=n]}


enter image description here






share|improve this answer
























  • +1 for "fairly simple syntax". :-)

    – Mico
    3 hours ago








  • 1





    @Mico Fairly simple user syntax.

    – egreg
    3 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',
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
});


}
});






Kam 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%2f471846%2fshortcut-for-a-polynomial-of-the-form-a-nxn-ldotsa-1xa-0%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









8














I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n and 0, respectively.) The macro called pn in the following example satisfies these criteria.



Incidentally, the typographic ellipsis used between binary operators (such as +) is usually of the form cdots, not ldots. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}

begin{document}
$pn{a}{x}$

$pn{lambda}{z}$

$pn{alpha}{xi}$
end{document}




Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n, but that it's true that most polynomials are, in fact, order n. In that case, it makes sense to modify the pn macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n by default.



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}

begin{document}
$pn{a}{x}$ % use default order (n) of polynomial

$pn[4]{lambda}{z}$

$pn[q]{alpha}{xi}$
end{document}





share|improve this answer





















  • 1





    Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

    – Kam
    12 hours ago













  • Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

    – Kam
    12 hours ago











  • @Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

    – Mico
    11 hours ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    11 hours ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    10 hours ago
















8














I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n and 0, respectively.) The macro called pn in the following example satisfies these criteria.



Incidentally, the typographic ellipsis used between binary operators (such as +) is usually of the form cdots, not ldots. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}

begin{document}
$pn{a}{x}$

$pn{lambda}{z}$

$pn{alpha}{xi}$
end{document}




Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n, but that it's true that most polynomials are, in fact, order n. In that case, it makes sense to modify the pn macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n by default.



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}

begin{document}
$pn{a}{x}$ % use default order (n) of polynomial

$pn[4]{lambda}{z}$

$pn[q]{alpha}{xi}$
end{document}





share|improve this answer





















  • 1





    Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

    – Kam
    12 hours ago













  • Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

    – Kam
    12 hours ago











  • @Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

    – Mico
    11 hours ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    11 hours ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    10 hours ago














8












8








8







I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n and 0, respectively.) The macro called pn in the following example satisfies these criteria.



Incidentally, the typographic ellipsis used between binary operators (such as +) is usually of the form cdots, not ldots. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}

begin{document}
$pn{a}{x}$

$pn{lambda}{z}$

$pn{alpha}{xi}$
end{document}




Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n, but that it's true that most polynomials are, in fact, order n. In that case, it makes sense to modify the pn macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n by default.



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}

begin{document}
$pn{a}{x}$ % use default order (n) of polynomial

$pn[4]{lambda}{z}$

$pn[q]{alpha}{xi}$
end{document}





share|improve this answer















I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n and 0, respectively.) The macro called pn in the following example satisfies these criteria.



Incidentally, the typographic ellipsis used between binary operators (such as +) is usually of the form cdots, not ldots. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}

begin{document}
$pn{a}{x}$

$pn{lambda}{z}$

$pn{alpha}{xi}$
end{document}




Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n, but that it's true that most polynomials are, in fact, order n. In that case, it makes sense to modify the pn macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n by default.



enter image description here



documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}

begin{document}
$pn{a}{x}$ % use default order (n) of polynomial

$pn[4]{lambda}{z}$

$pn[q]{alpha}{xi}$
end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited 11 hours ago

























answered 12 hours ago









MicoMico

276k30374765




276k30374765








  • 1





    Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

    – Kam
    12 hours ago













  • Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

    – Kam
    12 hours ago











  • @Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

    – Mico
    11 hours ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    11 hours ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    10 hours ago














  • 1





    Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

    – Kam
    12 hours ago













  • Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

    – Kam
    12 hours ago











  • @Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

    – Mico
    11 hours ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    11 hours ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    10 hours ago








1




1





Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

– Kam
12 hours ago







Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!

– Kam
12 hours ago















Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

– Kam
12 hours ago





Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again

– Kam
12 hours ago













@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

– Mico
11 hours ago





@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the pn macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n.

– Mico
11 hours ago




2




2





Eternally Grateful! Thanks again :)

– Kam
11 hours ago





Eternally Grateful! Thanks again :)

– Kam
11 hours ago




1




1





+1 for generating enthusiasm :)

– jfbu
10 hours ago





+1 for generating enthusiasm :)

– jfbu
10 hours ago











5














With a fairly simple syntax:



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}

keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}

cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff

begin{document}

$poly$

$poly[var=z]$

$poly[var=t,degree=m,coef=b]$

$poly[var=t,degree=m,coef=b,reverse]$

end{document}


The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are



var = x
degree = n
coef = a


You can also make shorthands with, say



newcommand{polybtn}{poly[var=t,coef=b,degree=n]}


enter image description here






share|improve this answer
























  • +1 for "fairly simple syntax". :-)

    – Mico
    3 hours ago








  • 1





    @Mico Fairly simple user syntax.

    – egreg
    3 hours ago
















5














With a fairly simple syntax:



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}

keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}

cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff

begin{document}

$poly$

$poly[var=z]$

$poly[var=t,degree=m,coef=b]$

$poly[var=t,degree=m,coef=b,reverse]$

end{document}


The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are



var = x
degree = n
coef = a


You can also make shorthands with, say



newcommand{polybtn}{poly[var=t,coef=b,degree=n]}


enter image description here






share|improve this answer
























  • +1 for "fairly simple syntax". :-)

    – Mico
    3 hours ago








  • 1





    @Mico Fairly simple user syntax.

    – egreg
    3 hours ago














5












5








5







With a fairly simple syntax:



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}

keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}

cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff

begin{document}

$poly$

$poly[var=z]$

$poly[var=t,degree=m,coef=b]$

$poly[var=t,degree=m,coef=b,reverse]$

end{document}


The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are



var = x
degree = n
coef = a


You can also make shorthands with, say



newcommand{polybtn}{poly[var=t,coef=b,degree=n]}


enter image description here






share|improve this answer













With a fairly simple syntax:



documentclass{article}
usepackage{amsmath}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}

keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}

cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff

begin{document}

$poly$

$poly[var=z]$

$poly[var=t,degree=m,coef=b]$

$poly[var=t,degree=m,coef=b,reverse]$

end{document}


The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are



var = x
degree = n
coef = a


You can also make shorthands with, say



newcommand{polybtn}{poly[var=t,coef=b,degree=n]}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered 10 hours ago









egregegreg

715k8618983185




715k8618983185













  • +1 for "fairly simple syntax". :-)

    – Mico
    3 hours ago








  • 1





    @Mico Fairly simple user syntax.

    – egreg
    3 hours ago



















  • +1 for "fairly simple syntax". :-)

    – Mico
    3 hours ago








  • 1





    @Mico Fairly simple user syntax.

    – egreg
    3 hours ago

















+1 for "fairly simple syntax". :-)

– Mico
3 hours ago







+1 for "fairly simple syntax". :-)

– Mico
3 hours ago






1




1





@Mico Fairly simple user syntax.

– egreg
3 hours ago





@Mico Fairly simple user syntax.

– egreg
3 hours ago










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










draft saved

draft discarded


















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













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












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
















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


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

But avoid



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

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


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




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471846%2fshortcut-for-a-polynomial-of-the-form-a-nxn-ldotsa-1xa-0%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

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...