@@ -72,22 +72,32 @@ sub latex-pipeline(Str:D $func, Str:D $expr, *@args, *%args) {
7272 my $ is-latex = & is-latex-spec ($ expr );
7373 die ' Cannot parsr the given string as LaTeX code.' unless $ is-latex ;
7474
75- my $ expr2 = $ is-latex ?? parse-latex($ expr ) !! $ expr ;
75+ return do if $ is-latex {
76+ my $ expr2 = parse-latex($ expr );
7677
77- my $ res = ::( " & { $ func } " )( $ expr2 , | @ args , | % args ) ;
78+ my @ named-args = & to-latex . candidates» . signature » . params . map ({ $ _ . grep ( *. named)» . name }) . flat . unique ;
7879
79- return $ is-latex ?? to-latex($ res ) !! $ res ;
80+ my % args2 = % args . grep ({ $ _ ∉ @ named-args });
81+ my $ res = ::(" &{ $ func } " )($ expr2 , | @ args , | % args2 );
82+
83+ % args2 = % args . grep ({ $ _ ∈ @ named-args });
84+ to-latex($ res , | % args2 )
85+ } else {
86+ # Currently this won't be reached, but I want to
87+ # use this block of JSON strings that are valid MathJSON expressions.
88+ my $ res = ::(" &{ $ func } " )($ expr , | @ args , | % args );
89+ }
8090}
8191
8292# ==========================================================
8393# Free symbolic functions
8494# ==========================================================
8595
8696# | Simplify an expression, MathJSON or LaTeX.
87- our proto sub simplify ($ expr ) is export {* }
97+ our proto sub simplify ($ expr , | ) is export {* }
8898
89- multi sub simplify (Str : D $ expr ) {
90- latex-pipeline(' simplify' , $ expr )
99+ multi sub simplify (Str : D $ expr , * % args ) {
100+ latex-pipeline(' simplify' , $ expr , | % args )
91101}
92102
93103multi sub simplify ($ expr ) {
@@ -96,10 +106,10 @@ multi sub simplify($expr) {
96106}
97107
98108# | Assign to a symbol with name $id the the expression, $expr (MathJSON or LaTeX.)
99- our proto sub assign ($ id , $ expr ) is export {* }
109+ our proto sub assign ($ id , $ expr , | ) is export {* }
100110
101- multi sub assign ($ id , Str : D $ expr ) {
102- latex-pipeline(' assign' , $ expr , : $ id )
111+ multi sub assign ($ id , Str : D $ expr , * % args ) {
112+ latex-pipeline(' assign' , $ expr , : $ id , | % args )
103113}
104114
105115multi sub assign ($ id , $ expr ) {
@@ -113,10 +123,10 @@ multi sub assign($expr, :$id) {
113123}
114124
115125# | Evaluate an expression, MathJSON or LaTeX.
116- our proto sub evaluate ($ expr ) is export {* }
126+ our proto sub evaluate ($ expr , | ) is export {* }
117127
118- multi sub evaluate (Str : D $ expr ) {
119- latex-pipeline(' evaluate' , $ expr )
128+ multi sub evaluate (Str : D $ expr , * % args ) {
129+ latex-pipeline(' evaluate' , $ expr , | % args )
120130}
121131
122132multi sub evaluate ($ expr ) {
@@ -125,10 +135,10 @@ multi sub evaluate($expr) {
125135}
126136
127137# | Numerical value of an expression, MathJSON or LaTeX.
128- our proto sub N ($ expr ) is export {* }
138+ our proto sub N ($ expr , | ) is export {* }
129139
130- multi sub N ($ id , Str : D $ expr ) {
131- latex-pipeline(' N' , $ expr )
140+ multi sub N ($ id , Str : D $ expr , * % args ) {
141+ latex-pipeline(' N' , $ expr , | % args )
132142}
133143
134144multi sub N ($ expr ) {
@@ -137,10 +147,10 @@ multi sub N($expr) {
137147}
138148
139149# | Expand an expression, MathJSON or LaTeX.
140- our proto expand($ expr ) is export {* }
150+ our proto expand($ expr , | ) is export {* }
141151
142- multi sub expand (Str : D $ expr ) {
143- latex-pipeline(' expand' , $ expr )
152+ multi sub expand (Str : D $ expr , * % args ) {
153+ latex-pipeline(' expand' , $ expr , | % args )
144154}
145155
146156multi sub expand ($ expr ) {
@@ -149,10 +159,10 @@ multi sub expand($expr) {
149159}
150160
151161# | Expand an expression, MathJSON or LaTeX.
152- our proto sub expandAll ($ expr ) is export {* }
162+ our proto sub expandAll ($ expr , | ) is export {* }
153163
154- multi sub expandAll (Str : D $ expr ) {
155- latex-pipeline(' expandAll' , $ expr )
164+ multi sub expandAll (Str : D $ expr , * % args ) {
165+ latex-pipeline(' expandAll' , $ expr , | % args )
156166}
157167
158168multi sub expandAll ($ expr ) {
@@ -164,10 +174,10 @@ our &expand-all is export = &expandAll;
164174
165175
166176# | Factor an expression, MathJSON or LaTeX.
167- our proto sub factor ($ expr ) is export {* }
177+ our proto sub factor ($ expr , | ) is export {* }
168178
169- multi sub factor (Str : D $ expr ) {
170- latex-pipeline(' factor' , $ expr )
179+ multi sub factor (Str : D $ expr , * % args ) {
180+ latex-pipeline(' factor' , $ expr , | % args )
171181}
172182
173183multi sub factor ($ expr ) {
@@ -197,10 +207,10 @@ multi sub solve($expr) {
197207}
198208
199209# | Invoke a function over an expression, MathJSON or LaTeX.
200- our proto sub cortex-js-call ($ func , $ expr ) is export {* }
210+ our proto sub cortex-js-call ($ func , $ expr , | ) is export {* }
201211
202- multi sub cortex-js-call ($ func , Str : D $ expr ) {
203- latex-pipeline(' cortex-js-call' , $ expr , : $ func )
212+ multi sub cortex-js-call ($ func , Str : D $ expr , * % args ) {
213+ latex-pipeline(' cortex-js-call' , $ expr , : $ func , | % args )
204214}
205215
206216multi sub cortex-js-call ($ expr , : $ func ) {
0 commit comments