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












10















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
    2 days 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
    2 days ago






  • 2





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

    – Kam
    2 days 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
    2 days ago
















10















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
    2 days 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
    2 days ago






  • 2





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

    – Kam
    2 days 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
    2 days ago














10












10








10


1






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 2 days 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 2 days ago









KamKam

535




535




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
    2 days 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
    2 days ago






  • 2





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

    – Kam
    2 days 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
    2 days ago



















  • Welcome to TeX.SE!

    – Mico
    2 days 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
    2 days ago






  • 2





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

    – Kam
    2 days 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
    2 days ago

















Welcome to TeX.SE!

– Mico
2 days ago





Welcome to TeX.SE!

– Mico
2 days 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
2 days 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
2 days ago




2




2





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

– Kam
2 days ago







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

– Kam
2 days 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
2 days 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
2 days ago










3 Answers
3






active

oldest

votes


















12














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
    2 days ago













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

    – Kam
    2 days 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
    2 days ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    2 days ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    2 days ago



















11














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
    2 days ago








  • 2





    @Mico Fairly simple user syntax.

    – egreg
    2 days ago











  • Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

    – Kam
    2 days ago



















1














I would propose poly{ax^n}



newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}


You can use poly{ax} or poly{ax^n}.






share|improve this answer
























  • Thank you very much!

    – Kam
    16 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

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









12














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
    2 days ago













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

    – Kam
    2 days 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
    2 days ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    2 days ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    2 days ago
















12














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
    2 days ago













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

    – Kam
    2 days 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
    2 days ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    2 days ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    2 days ago














12












12








12







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 2 days ago

























answered 2 days ago









MicoMico

276k30377766




276k30377766








  • 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
    2 days ago













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

    – Kam
    2 days 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
    2 days ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    2 days ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    2 days 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
    2 days ago













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

    – Kam
    2 days 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
    2 days ago






  • 2





    Eternally Grateful! Thanks again :)

    – Kam
    2 days ago






  • 1





    +1 for generating enthusiasm :)

    – jfbu
    2 days 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
2 days 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
2 days ago















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

– Kam
2 days ago





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

– Kam
2 days 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
2 days 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
2 days ago




2




2





Eternally Grateful! Thanks again :)

– Kam
2 days ago





Eternally Grateful! Thanks again :)

– Kam
2 days ago




1




1





+1 for generating enthusiasm :)

– jfbu
2 days ago





+1 for generating enthusiasm :)

– jfbu
2 days ago











11














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
    2 days ago








  • 2





    @Mico Fairly simple user syntax.

    – egreg
    2 days ago











  • Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

    – Kam
    2 days ago
















11














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
    2 days ago








  • 2





    @Mico Fairly simple user syntax.

    – egreg
    2 days ago











  • Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

    – Kam
    2 days ago














11












11








11







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 2 days ago









egregegreg

715k8619003187




715k8619003187













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

    – Mico
    2 days ago








  • 2





    @Mico Fairly simple user syntax.

    – egreg
    2 days ago











  • Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

    – Kam
    2 days ago



















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

    – Mico
    2 days ago








  • 2





    @Mico Fairly simple user syntax.

    – egreg
    2 days ago











  • Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

    – Kam
    2 days ago

















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

– Mico
2 days ago







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

– Mico
2 days ago






2




2





@Mico Fairly simple user syntax.

– egreg
2 days ago





@Mico Fairly simple user syntax.

– egreg
2 days ago













Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

– Kam
2 days ago





Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!

– Kam
2 days ago











1














I would propose poly{ax^n}



newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}


You can use poly{ax} or poly{ax^n}.






share|improve this answer
























  • Thank you very much!

    – Kam
    16 hours ago
















1














I would propose poly{ax^n}



newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}


You can use poly{ax} or poly{ax^n}.






share|improve this answer
























  • Thank you very much!

    – Kam
    16 hours ago














1












1








1







I would propose poly{ax^n}



newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}


You can use poly{ax} or poly{ax^n}.






share|improve this answer













I would propose poly{ax^n}



newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}


You can use poly{ax} or poly{ax^n}.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









ManuelManuel

21.2k846106




21.2k846106













  • Thank you very much!

    – Kam
    16 hours ago



















  • Thank you very much!

    – Kam
    16 hours ago

















Thank you very much!

– Kam
16 hours ago





Thank you very much!

– Kam
16 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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy