Sharmaans has uploaded a new change for review. https://gerrit.wikimedia.org/r/217866
Change subject: Translate LaTeX to Corresponding Mathematica ...................................................................... Translate LaTeX to Corresponding Mathematica A new SpecialPage where users can specifiy LaTeX input that is translated to the equivalent Mathematica expression. This mock up works only in selected cases. If an expression cannot be translated, the original LaTeX code is passed unmodified to the output. Change-Id: Ib16637649e97d7b008eec18ba49f7fe0a87520e8 --- M i18n/en.json M i18n/qqq.json M includes/special/LaTeXTranslator.php 3 files changed, 469 insertions(+), 432 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch refs/changes/66/217866/1 diff --git a/i18n/en.json b/i18n/en.json index a82101b..b1aea89 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -9,6 +9,7 @@ "mathdownload": "Download math search results", "mathindex": "Math index", "mathupload": "Submit math search results", + "latextranslator": "LaTeX to Mathematica Translator", "specialpages-group-mathsearch": "Math search", "mathsearch-desc": "Integrates the [http://search.mathweb.org/about.html MathWeb Search] engine", "getequationsbyquery": "Get equations by query", @@ -56,5 +57,5 @@ "math-search-type-0": "Keyword", "math-search-type-1": "TeX pattern", "math-search-type-2": "xQuery expression", - "math-search-expression-label": "Expression:" + "math-search-expression-label": "Expression:", } \ No newline at end of file diff --git a/i18n/qqq.json b/i18n/qqq.json index d80f7d6..026e9d5 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -18,6 +18,7 @@ "getequationsbyquery": "{{doc-special|GetEquationByQuery}}", "xquerygenerator": "{{doc-special|XQueryGenerator}}", "mathdebug": "{{doc-special|MathDebug}}", + "latextranslator": "{{doc-special|LaTeX to Mathematica Translator}}", "math-wmc-attach-results-help": "Form label help text", "math-wmc-attach-results-label": "Form label", "math-wmc-download-intro": "Introductory text for MathDownload special page.", diff --git a/includes/special/LaTeXTranslator.php b/includes/special/LaTeXTranslator.php index 0804743..ed91d2c 100644 --- a/includes/special/LaTeXTranslator.php +++ b/includes/special/LaTeXTranslator.php @@ -4,455 +4,491 @@ parent::__construct( 'LaTeXTranslator' ); } + /** + * Returns corresponding Mathematica translations of LaTeX functions + * @param $par + */ function execute( $par ) { $request = $this->getRequest(); $output = $this->getOutput(); - $this->setHeaders(); # Get request data from, e.g. $param = $request->getText( 'param' ); - error_reporting(0); - ini_set('display_errors', 0); - + /** + * Returns LaTeX arguments without curly brackets + * CURRENTLY NESTED as yields error unnested + * When brackR is placed within class, but outside of execute function + * Results in "call to undefined function brackR()" error + * When use $this->brackR(arg) to process function + * Doesn't return processed string parameter -- returns original argument + * @param $arg + * @return string + */ function brackR($arg){ $arg = trim($arg, " "); - if ($arg[0] == "{" && $arg[strlen($arg)-1] == "}"){ + if ($arg[0] == "{" && $arg[strlen($arg)-1] == "},,k"){ $arg = substr($arg,1,strlen($arg)-2); } return $arg; } - // EXTREMELY INEFFICIENT to remove captured curly braces-- - // need regex to not capture brackets - // Also, algorithm could be further condensed - // by classification of functions by argument type - // PHP FORM: http://stackoverflow.com/questions/5968280/how-to-run-a-php-function-from-an-html-form?rq=1 - //---------------------------------------------------------------------------------------------- // \divergence{x} + + /** + * @var string contains frequently occurring regex for recurisve extraction of nested parenthesis + */ $par = "(\{(?>[^{}]|(?-1))*\})"; - $arg = "(\\\\[?[A-z]*\]?|[0-9])"; - $data = ' -\Alpha = 0.5 -\Beta = 0.4 -\Gamma = 0.3 -\Delta = 0.2 -\Epsilon = 0.1 -\lambda = 6 -\mu = 5 -\nu = 4 -\rho = 3 -\sigma = 2 -\phi = 1 -\nu = 5 -\sin@@\sigma -\AiryAi@{\phi} -\AiryBi{\phi} -\AiryModulusM@{\nu} -\AGM@{\phi}{\sigma} -\AngerJ{\phi}@{\sigma} -\AppellFi@{\phi}{\sigma}{\rho}{\nu}{\mu}{\lambda} -\BarnesGamma@{\sigma} -\BesselJ{\Alpha}@{\Alpha} -\binom{\sigma}{\phi} -\CatalanNumber@{\Epsilon} -\ceiling{\sigma} -\ChebyT{\Alpha}@{\Alpha} -\conj{3 + 7 I} -\coshint@\phi -\Cylinder{\Epsilon}{\phi} -\DawsonsInt@{\phi I} -\DedekindModularEta@{\phi + I} -\deriv{\sigma x}{x} -\det{\phi} -\CompEllIntK@@{\Alpha} -\EllIntK@{\Delta\phi} -\EulerBeta{\phi}{\sigma} -\exp@{\Delta x} -\ExpInti@{\Epsilon} -\frac{\phi}\sigma -\FresnelSin@{\Alpha} -\floor{\phi*\sigma} -\GenHermiteH{\phi}@{\sigma} -\Gudermannian{\cos@\phi} -\HurwitzZeta@{\Gudermannian{\sin@\phi}}{\Alpha} -\HypergeoF@{\Alpha}{\Beta}{\Gamma}{\Delta} -\HyperpFq{\phi}{\sigma}@{\phi}{\phi,\sigma}{\rho} -\IncBeta{\rho}@{\phi}{\sigma} -\inverfc@\phi -\Jacobisd@{\nu}{\sigma} -\JacobiP{\phi}{\sigma}{\rho}@{\nu} -\JacobiZeta@{\Alpha}{\Alpha} -\Kelvinber{\nu}@{\Gamma} -\Kronecker{\Alpha}{\Alpha} -\LaguerreL[\Alpha]{\nu}@{x} -\LegendreP{\Alpha}@\phi -\LogInt@{\Alpha} -\LerchPhi@{\phi}{\sigma}{\rho} -\MittagLeffler{\phi}{\sigma}{\rho} -5\mod2 -\ModularJ{\phi} -\pochhammer{\phi}{\sigma} -\polygamma{\Alpha}@{\Beta} -\Polylogarithm{\Alpha}@{\Alpha} -\qFactorial{\lambda}{\mu}{\nu} -\qGamma{\Alpha}@{\Alpha} -\RamanujanTau@{\rho} -\realpart{\rho I+\nu} -\RiemannXi@{\Alpha} -\ScorerHi@{\Alpha} -\sign@{-\Alpha} -\SinInt@{\Alpha} -\SphBesselY{\Alpha}@{\phi} -\SphHankelHii{\Alpha}@{\Beta} -\SphericalHarmonicY{\Epsilon}{\Delta}@{\Gamma}{\Beta} -\SpheroidalEigenvalueLambda{\Epsilon}{\Delta}@{\Gamma} -\SpheroidalPs{\Epsilon}{\Delta}@{\Gamma}{\Beta} -\sqrt\sigma -\StruveL{\Epsilon}@{\Delta} -\WeberE{\Epsilon}{\Delta} -\WhitW{\Epsilon}{\Delta}@{\Gamma}'; - // regex cannot parse multiple nesting levels: '\log{\log{\cos{\sin{\Gudermannian1}}}}}' - //$data = '\AiryModulusM@{x}'; - $data = $_POST["input"]; + /** + * @var string contains frequently occurring regex for single argument of number or Greek letter + */ + $arg = "(\\\\[?[A-z]*\]?|[0-9]|[A-z]{1})"; + /** + * @var string contains data in Wiki html input form + */ + $data = $request->getText('input'); - $matcher = array(//"~(\{)~" , "~(\})~" , - # Trignometric & Trig Integrals: \acosh@{x} - "~\\\(a?(?>cos|sin|tan|csc|cot|sec)h?)(int)?@{0,2}(".$arg."|".$par.")~ie", - # Logarithm - "~\\\(?>log|ln)b?".$par."?@{0,2}(".$arg."|".$par.")~ie", - # Airy: \AiryAi@{z} - "~\\\\Airy([B|A]i)@{0,2}(".$arg."|".$par.")~ie", - # Airy Modulus M: \AiryModulusM@{z} - "~\\\\AiryModulusM@{0,2}(".$arg."|".$par.")~ie", - # Arithmetic Geometric Mean: \AGM@{a}{g} - "~\\\\AGM@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Anger: \AngerJ{\nu}@{z} - "~\\\\AngerJ".$par."@{0,2}(".$arg."|".$par.")~ie", - # Appell: \AppellFi@{\alpha}{\beta}{\beta'}{\gamma}{x}{y} - "~\\\\AppellF[i{1,3}v?]@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Barnes G: \BarnesGamma@{z} - "~\\\\BarnesGamma@{0,2}(".$arg."|".$par.")~ie", - # BesselJ: \BesselJ{n}@{z} - default?? for BesselJ{nu}/Cheby w/ no z??? - "~\\\Bessel([A-Z])".$par."@?(".$par.")?~ie", - # Binomial Coefficient: \binomial{m}{n} - "~\\\\binom(?>ial)?@{0,2}".$par.$par."~ie", - # Catalan Number: \CatalanNumber@{n} - "~\\\CatalanNumber@{0,2}(".$arg."|".$par.")~ie", - # Ceiling: \ceiling{x} - "~\\\ceiling@{0,2}(".$arg."|".$par.")~ie", - # Chebyshev: \ChebyT{x}@{n} - "~\\\Cheby([A-Z])".$par."@?(".$par.")?~ie", - # Complex Conjugate: \conj{z} - "~\\\conj@{0,2}".$par."~ie", - # Cylinder: \Cylinder{\nu}@{z} - "~\\\\Cylinder".$par."@{0,2}(".$arg."|".$par.")~ie", - # Dawson's Integral: \DawsonsInt@{z} - "~\\\DawsonsInt@{0,2}(".$arg."|".$par.")~ie", - # Dedekind's Eta: \DedekindModularEta@{\tau} - "~\\\DedekindModularEta@{0,2}(".$arg."|".$par.")~ie", - # Derivative: \deriv{f}{x} - "~\\\p?deriv@{0,2}".$par.$par."~ie", - # Determinant: \det - "~\\\det@{0,2}(".$arg."|".$par.")~ie", - # Divergence: \divergence - "~\\\divergence@{0,2}(".$arg."|".$par.")~ie", - # Elliptic Integral: \CompEllIntC@{a} - "~\\\\(?>Comp)?EllInt[C]?([A-Z]|Pi)@{0,3}(".$arg."|".$par.")(".$arg."|".$par.")?~ie", - # Error: \erf@{z} - "~\\\\erf[a-z]?@{0,2}(".$arg."|".$par.")~ie", - # Euler Beta & Gamma: \EulerBeta@{a}{b} - "~\\\\Euler(Beta|Gamma)@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")?~ie", - # Exponential: \exp@{x} - "~\\\\exp@{0,2}(".$arg."|".$par.")~ie", - # Exponential Integral: \ExpInti@{x} - "~\\\\ExpInt([a-z])?".$par."?@{0,2}(".$arg."|".$par.")~ie", - # Floor: \floor{x} - "~\\\\floor(".$arg."|".$par.")~ie", - # Fraction: \frac{a}{b} - "~\\\\frac(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Fresnel: \FresnelSin@{z} - "~\\\\Fresnel([a-z]*)@{0,2}(".$arg."|".$par.")~ie", - # Greek Letter: \Alpha - "~\\\(alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|vartheta| - gamma|kappa|lambda|mu|nu|xi|o[^mega]|pi|varpi|rho|varrho|sigma|varsigma - |tau|upsilon|phi|varphi|chi|psi|omega)~ie", - # Gamma: \GammaP@{a}{z} - "~\\\\Gamma(?>[PQ])@?(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Gudermannian: \Gudermannian@{x} - "~\\\\(arc)?Gudermannian@{0,2}(".$arg."|".$par.")~ie", - # Generalized Hermite: \GenHermiteH{n}@{x} - "~\\\\GenHermiteH".$par."@{0,2}(".$arg."|".$par.")~ie", - # HurwitzZeta: \HurwitzZeta@{s}{a} - "~\\\\HurwitzZeta@?(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Hypergeometric: \HypergeoF@{a}{b}{c}{d} - "~\\\\HypergeoF(@{0,3})".$par.$par.$par.$par."~ie", - # Hypergeometric (Generalized): \HyperpFq{p}{q}@{{\bf a}}{{\bf b}}{z} - "~\\\\HyperpFq(".$arg."|".$par.")(".$arg."|".$par.")@{0,3}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Incomplete Beta & Gamma: \IncBeta{x}@{a}{b}, \IncGamma@{a}{z} - "~\\\\Inc(Beta|Gamma)".$par."?@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Inverse Error (including complementary): \inverfc@{x} - "~\\\\inverf(c)?@{0,2}(".$arg."|".$par.")~ie", - # Imaginary Unit: \iunit - "~\\\\iunit~ie", - # Jacobi Elliptics: \Jacobisd@{z}{k} - "~\\\\(arc)?Jacobi([a-z]{2}|Zeta)@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Jacobi Polynomials: \JacobiP{\alpha}{\beta}{n}@{x} - "~\\\\JacobiP".$par.$par.$par."@{0,2}(".$arg."|".$par.")~ie", - # Kelvin: \Kelvinber{\nu}@{x} - "~\\\\Kelvin([bk]e[ri])(".$par.")@{0,2}(".$arg."|".$par.")?~ie", - # Klein Invariant: \ModularJ@{\tau} - "~\\\\ModularJ".$par."~ie", - # Kronecker: \Kronecker{j}{k} - "~\\\\Kronecker".$par.$par."~ie", - # LaguerreL[\a]{n}@{x} - "~\\\\LaguerreL(\[.*\])?".$par."@?(".$arg."|".$par.")~ie", - # Legendre: \LegendreP[\mu]{\nu}@{x} - "~\\\\Legendre(P|Q)(\[.*\])?(".$par.")@?(".$arg."|".$par.")?~ie", - # Associated Legendre: \AssLegendrePoly{n}@{x}{c} - "~\\\\AssLegendrePoly(".$par.")@?(".$arg."|".$par.")(".$arg."|".$par.")?~ie", - # LerchPhi: \LerchPhi@{z}{s}{a} - "~\\\\LerchPhi@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~ie", - # Log Integral: \LogInt@{x} - "~\\\\LogInt@{0,2}(".$arg."|".$par.")~ie", - # Mittag-Leffler: \MittagLeffler{a}{b}@{z} - "~\\\\MittagLeffler".$par.$par."@{0,2}(".$arg."|".$par.")~ie", - # Modulus: n \mod m - "~(".$arg."|".$par.")\\\\mod@{0,2}(".$arg."|".$par.")~ie", - # Permutations: \Permutations{n} - "~\\\\Permutations@{0,2}(".$arg."|".$par.")~ie", - # Pochhammer: \pochammer{a}{n} - "~\\\\pochhammer@{0,2}".$par.$par."~ie", - # PolyGamma: \polygamma{n}@{z} - "~\\\\Polygamma".$par."@{0,2}(".$arg."|".$par.")~ie", - # PolyLog: \Polylogarithms{x}@{z} - "~\\\\Polylogarithm".$par."@{0,2}(".$arg."|".$par.")~ie", - # Q Factorial: \qFactorial{a}{q}{n} - "~\\\\qFactorial@{0,2}".$par.$par.$par."~ie", - # Q Gamma: \qGamma{q}@{z} - "~\\\\qGamma".$par."@{0,2}(".$arg."|".$par.")~ie", - # Ramanujan Tau: \RamanujanTau@{k} - "~\\\\RamanujanTau@{0,2}(".$arg."|".$par.")~ie", - # Real Part: \realpart{z} - "~\\\\realpart@{0,2}".$par."~ie", - # Riemann: \RiemannXi@{s} - "~\\\\Riemann(Xi)@{0,2}(".$arg."|".$par.")~ie", - # Scorer: \ScorerHi@{z} - "~\\\\Scorer([G|H]i)@{0,2}(".$arg."|".$par.")~ie", - # Sign: \sign@{x} - "~\\\\sign@{0,2}(".$arg."|".$par.")~ie", - # Sin Integral: \SinInt@{x} - "~\\\\Sin(h?)Int@{0,2}(".$arg."|".$par.")~ie", - # Spherical BesselJ/Y | HankelH1/H2: \SphBesselJ{n}@{z} - "~\\\\Sph(Bessel|Hankel)(J|Y|Hii?)".$par."@{0,2}(".$arg."|".$par.")~ie", - # Spherical Harmonic: \SphericalHarmonicY{l}{m}@{\theta}{\phi} - "~\\\\SphericalHarmonicY".$par.$par."@?(".$arg."|".$par.")?(".$arg."|".$par.")?~ie", - # Spheroidal Eigenvalue: \SpheroidalEigenvalueLambda{m}{n}@{\gamma} - "~\\\\SpheroidalEigenvalueLambda".$par.$par."@?(".$arg."|".$par.")?~ie", - # Spheroidal Ps: \SpheroidalPs{m}{n}@{z}{\gamma^2} - "~\\\\Spheroidal(P|Q)s".$par.$par."@?(".$arg."|".$par.")?(".$arg."|".$par.")?~ie", - # Sqrt: \sqrt@{x} - "~\\\\sqrt@{0,2}(".$arg."|".$par.")~ie", - # StruveH: \StruveH{\nu}@{z} - "~\\\\Struve(H|L)".$par."@{0,2}(".$arg."|".$par.")~ie", - # WeberE: \WeberE{\nu}@{z} - "~\\\\WeberE".$par."@{0,2}(".$arg."|".$par.")~ie", - # Whittaker: \WhittakerM{\kappa}{\mu}@{z} - "~\\\\Whit(M|W)".$par.$par."@{0,2}(".$arg."|".$par.")~ie" + # reference: http://stackoverflow.com/a/28611214/4521584 + $replacements = array( + array( + # Trignometric & Trig Integrals: \acosh@{x} + 'search' => "~\\\(a?(?>cos|sin|tan|csc|cot|sec)h?)(int)?@{0,2}(".$arg."|".$par.")~i", + # Trignometric: ArcCosh[x] + 'replace' => function (array $m){ return ($m[1][0] == 'a'?'Arc'.ucfirst(strtolower(substr($m[1],1))):ucfirst(strtolower($m[1]))).(strlen($m[2])>0?'Integral':'').'['.brackR($m[3]).']';} + ), + array( + # Logarithm + 'search' => "~\\\(?>log|ln)b?".$par."?@{0,2}(".$arg."|".$par.")~i", + # Logarithm: Log[x] + 'replace' => function (array $m){ return 'Log['.(strlen($m[1])>0?$m[1].',':'').brackR($m[2]).']';} + ), + array( + # Airy: \AiryAi@{z} + 'search' => "~\\\\Airy([B|A]i)@{0,2}(".$arg."|".$par.")~i", + # Airy: AiryAi[z] + 'replace' => function (array $m){ return 'Airy'.$m[1].'['.brackR($m[2]).']';} + ), + array( + # Airy Modulus M: \AiryModulusM@{z} + 'search' => "~\\\\AiryModulusM@{0,2}(".$arg."|".$par.")~i", + # Airy Modulus M: Sqrt[AiryAi[x]^2+AiryBi[x]^2] + 'replace' => function (array $m){ return 'Sqrt[AiryAi['.brackR($m[1]).']^2+AiryBi['.brackR($m[1]).']^2]';} + ), + array( + # Arithmetic Geometric Mean: \AGM@{a}{g} + 'search' => "~\\\\AGM@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Arithmetic Geometric Mean: ArithmeticGeometricMean[a,b] + 'replace' => function (array $m){ return 'ArithmeticGeometricMean['.brackR($m[1]).','.brackR($m[4]).']';} + ), + array( + # Anger: \AngerJ{\nu}@{z} + 'search' => "~\\\\AngerJ".$par."@{0,2}(".$arg."|".$par.")~i", + # Anger: AngerJ[\nu,z] + 'replace' => function (array $m){ return 'AngerJ['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # Appell: \AppellFi@{\alpha}{\beta}{\beta'}{\gamma}{x}{y} + 'search' => "~\\\\AppellF[i{1,3}v?]@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Appell: AppellF1[\alpha,\beta,\beta',\gamma,x,y] + 'replace' => function (array $m){ return 'AppellF1['.brackR($m[1]).','.brackR($m[4]).','.brackR($m[7]).','.brackR($m[10]).','.brackR($m[13]).','.brackR('16').']';} + ), + array( + # Barnes G: \BarnesGamma@{z} + 'search' => "~\\\\BarnesGamma@{0,2}(".$arg."|".$par.")~i", + # Barnes G: BarnesG[z] + 'replace' => function (array $m){ return 'BarnesG['.brackR($m[1]).']';} + ), + array( + # BesselJ: \BesselJ{n}@{z} - default?? for BesselJ{nu}/Cheby w/ no z??? + 'search' => "~\\\Bessel([A-Z])".$par."@?(".$par.")?~i", + # BesselJ: BesselJ[n,z] + 'replace' => function (array $m){ return 'Bessel'.$m[1].'['.brackR($m[2]).(strlen($m[3])>0?','.brackR($m[3]):',0').']';} + ), + array( + # Binomial Coefficient: \binomial{m}{n} + 'search' => "~\\\\binom(?>ial)?@{0,2}".$par.$par."~i", + # Binomial Coefficient: Binomial[n,m] + 'replace' => function (array $m){ return 'Binomial['.brackR($m[2]).','.brackR($m[1]).']';} + ), + array( + # Catalan Number: \CatalanNumber@{n} + 'search' => "~\\\CatalanNumber@{0,2}(".$arg."|".$par.")~i", + # Catalan Number: CatalanNumber[n] + 'replace' => function (array $m){ return 'CatalanNumber['.brackR($m[1]).']';} + ), + array( + # Ceiling: \ceiling{x} + 'search' => "~\\\ceiling@{0,2}(".$arg."|".$par.")~i", + # Ceiling: Ceiling[x] + 'replace' => function (array $m){ return 'Ceiling['.brackR($m[1]).']';} + ), + array( + # Chebyshev: \ChebyT{x}@{n} + 'search' => "~\\\Cheby([A-Z])".$par."@?(".$par.")?~i", + # Chebyshev: ChebyshevT[n,x] + 'replace' => function (array $m){ return 'Chebyshev'.$m[1].'['.brackR($m[2]).(strlen($m[3])>0?','.brackR($m[3]):',0').']';} + ), + array( + # Complex Conjugate: \conj{z} + 'search' => "~\\\conj@{0,2}".$par."~i", + # Complex Conjugate: Conjugate[z] + 'replace' => function (array $m){ return 'Conjugate['.brackR($m[1]).']';} + ), + array( + # Cylinder: \Cylinder{\nu}@{z} + 'search' => "~\\\\Cylinder".$par."@{0,2}(".$arg."|".$par.")~i", + # Cylinder: ParabolicCylinderD[\nu,z] + 'replace' => function (array $m){ return 'ParabolicCylinderD['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # Dawson's Integral: \DawsonsInt@{z} + 'search' => "~\\\DawsonsInt@{0,2}(".$arg."|".$par.")~i", + # Dawsons Integral: DawsonF[z] + 'replace' => function (array $m){ return 'DawsonF['.brackR($m[1]).']';} + ), + array( + # Dedekind's Eta: \DedekindModularEta@{\tau} + 'search' => "~\\\DedekindModularEta@{0,2}(".$arg."|".$par.")~i", + # Dedekind's Eta: DedekindEta[\tau] + 'replace' => function (array $m){ return 'DedekindEta['.brackR($m[1]).']';} + ), + array( + # Derivative: \deriv{f}{x} + 'search' => "~\\\p?deriv@{0,2}".$par.$par."~i", + # Derivative: D[f,x] + 'replace' => function (array $m){ return 'D['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # Determinant: \det + 'search' => "~\\\det@{0,2}(".$arg."|".$par.")~i", + # Determinant: Det[a] + 'replace' => function (array $m){ return 'Det['.$m[1].']';} + ), + array( + # Divergence: \divergence + 'search' => "~\\\divergence@{0,2}(".$arg."|".$par.")~i", + # Divergence: divergence + 'replace' => function (array $m){ return 'Div['.$m[1].']';} + ), + array( + # Elliptic Integral: \CompEllIntC@{a} + 'search' => "~\\\\(?>Comp)?EllInt[C]?([A-Z]|Pi)@{0,3}(".$arg."|".$par.")(".$arg."|".$par.")?~i", + # Elliptic Integral: EllipticC[x, Sqrt[m]] + 'replace' => function (array $m){ return 'Elliptic'.$m[1].'['.(strlen($m[5])>0?brackR($m[2]).', Sqrt['.brackR($m[5]).']':'Sqrt['.brackR($m[2]).']').']';} + ), + array( + # Error: \erf@{z} + 'search' => "~\\\\erf[a-z]?@{0,2}(".$arg."|".$par.")~i", + # Error: Erf[z] + 'replace' => function (array $m){ return 'Erf['.brackR($m[1]).']';} + ), + array( + # Euler Beta & Gamma: \EulerBeta@{a}{b} + 'search' => "~\\\\Euler(Beta|Gamma)@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")?~i", + # Euler Beta & Gamma: Beta[a,b] + 'replace' => function (array $m){ return $m[1].'['.brackR($m[2]).(strlen($m[5])>0&&strtolower($m[1])=='beta'?','.brackR($m[5]):'').']';} + ), + array( + # Exponential: \exp@{x} + 'search' => "~\\\\exp@{0,2}(".$arg."|".$par.")~i", + # Exponential: Exp[x] + 'replace' => function (array $m){ return 'Exp['.brackR($m[1]).']';} + ), + array( + # Exponential Integral: \ExpInti@{x} + 'search' => "~\\\\ExpInt([a-z])?".$par."?@{0,2}(".$arg."|".$par.")~i", + # Exponential Integral: ExpIntegralEi[z] + 'replace' => function (array $m){ return 'ExpIntegralE'.($m[1]=='i'?'i':'').'['.(strlen($m[2])>0?brackR($m[2]).',':'').brackR($m[3]).']';} + ), + array( + # Floor: \floor{x} + 'search' => "~\\\\floor(".$arg."|".$par.")~i", + # Floor: Floor[x] + 'replace' => function (array $m){ return 'Floor['.brackR($m[1]).']';} + ), + array( + # Fraction: \frac{a}{b} + 'search' => "~\\\\frac(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Fraction: a/b + 'replace' => function (array $m){ return (strlen($m[3])>0?'('.brackR($m[1]).')':brackR($m[1])).'/'.(strlen($m[6])>0?'('.brackR($m[4]).')':brackR($m[4]));} + ), + array( + # Fresnel: \FresnelSin@{z} + 'search' => "~\\\\Fresnel([a-z]*)@{0,2}(".$arg."|".$par.")~i", + # Fresnel: FresnelS[z] + 'replace' => function (array $m){ return 'Fresnel'.ucfirst($m[1][0]).'['.brackR($m[2]).']';} + ), + array( + # Greek Letter: \Alpha + 'search' => "~\\\(alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|vartheta|gamma|kappa|lambda|mu|nu|xi|o[^mega]|pi|varpi|rho|varrho|sigma|varsigma|tau|upsilon|phi|varphi|chi|psi|omega)~i", + # Greek Letter: \[CapitalAlpha] + 'replace' => function (array $m){ return '\\\['.(strtolower($m[1]) != $m[1]?'Capital':'').ucfirst($m[1]).']';} + ), + array( + # Gamma: \GammaP@{a}{z} + 'search' => "~\\\\Gamma(?>[PQ])@?(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Gamma (Incomplete): + 'replace' => function (array $m){ return 'Gamma['.brackR($m[1]).','.brackR($m[4]).']';} + ), + array( + # Gudermannian: \Gudermannian@{x} + 'search' => "~\\\\(arc)?Gudermannian@{0,2}(".$arg."|".$par.")~i", + # Gudermannian: Gudermannian[z] + 'replace' => function (array $m){ return (strlen($m[1])>0?'Inverse':'').'Gudermannian['.brackR($m[2]).']';} + ), + array( + # Generalized Hermite: \GenHermiteH{n}@{x} + 'search' => "~\\\\GenHermiteH".$par."@{0,2}(".$arg."|".$par.")~i", + # Hermite: HermiteH[n,x] + 'replace' => function (array $m){ return 'HermiteH['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # HurwitzZeta: \HurwitzZeta@{s}{a} + 'search' => "~\\\\HurwitzZeta@?(".$arg."|".$par.")(".$arg."|".$par.")~i", + # HurwitzZeta: HurwitzZeta[s,a] + 'replace' => function (array $m){ return 'HurwitzZeta['.brackR($m[1]).','.brackR($m[4]).']';} + ), + array( + # Hypergeometric: \HypergeoF@{a}{b}{c}{d} + 'search' => "~\\\\HypergeoF(@{0,3})".$par.$par.$par.$par."~i", + # Hypergeometric: Hypergeometric2F1[a,b,c,d] + 'replace' => function (array $m){ return 'Hypergeometric2F1['.$m[2].','.$m[3].','.$m[4].','.$m[5].']';} + ), + array( + # Hypergeometric (Generalized): \HyperpFq{p}{q}@{{\bf a}}{{\bf b}}{z} + 'search' => "~\\\\HyperpFq(".$arg."|".$par.")(".$arg."|".$par.")@{0,3}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Hypergeometric (Generalized): HypergeometricPFQ[a,b,c] + 'replace' => function (array $m){ return 'HypergeometricPFQ['.$m[7].','.$m[10].','.brackR($m[13]).']';} + ), + array( + # Incomplete Beta & Gamma: \IncBeta{x}@{a}{b}, \IncGamma@{a}{z} + 'search' => "~\\\\Inc(Beta|Gamma)".$par."?@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Incomplete Beta & Gamma: Beta[z,a,b], Gamma[a,z] + 'replace' => function (array $m){ return $m[1].(strlen($m[2])>0?brackR($m[2]).',':'').brackR($m[3]).','.brackR($m[6]).']';} + ), + array( + # Inverse Error (including complementary): \inverfc@{x} + 'search' => "~\\\\inverf(c)?@{0,2}(".$arg."|".$par.")~i", + # Inverse Error (including complementary): InverseErfc[x] + 'replace' => function (array $m){ return 'InverseErf'.$m[1].'['.brackR($m[2]).']';} + ), + array( + # Imaginary Unit: \iunit + 'search' => "~\\\\iunit~i", + # Imaginary Unit: I return 'I';} + ), + array( + # Jacobi Elliptics: \Jacobisd@{z}{k} + 'search' => "~\\\\(arc)?Jacobi([a-z]{2}|Zeta)@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")~i", + # Jacobi Elliptics: JacobiSD[u,m] + 'replace' => function (array $m) {(strlen($m[1])>0?'Inverse':'').'Jacobi'.(strlen($m[2]) == 2 ? strtoupper($m[2]) : 'Zeta').'['.brackR($m[3]).', Sqrt['.brackR($m[6]).']]';} + ), + array( + # Jacobi Polynomials: \JacobiP{\alpha}{\beta}{n}@{x} + 'search' => "~\\\\JacobiP".$par.$par.$par."@{0,2}(".$arg."|".$par.")~i", + # Jacobi Polynomial: JacobiP[n,a,b,x] + 'replace' => function (array $m){ return 'JacobiP['.brackR($m[2]).','.brackR($m[1]).','.brackR($m[3]).','.brackR($m[4]).']';} + ), + array( + # Kelvin: \Kelvinber{\nu}@{x} + 'search' => "~\\\\Kelvin([bk]e[ri])(".$par.")@{0,2}(".$arg."|".$par.")?~i", + # Kelvin: KelvinBer[n,z] + 'replace' => function (array $m){ return 'Kelvin'.ucfirst($m[1]).'['.brackR($m[2]).(strlen(brackR($m[4]))>0?','.brackR($m[4]):'').']';} + ), + array( + # Klein Invariant: \ModularJ@{\tau} + 'search' => "~\\\\ModularJ".$par."~i", + # Klein Invariant: KleinInvariantJ[\tau] + 'replace' => function (array $m){ return 'KleinInvariantJ['.brackR($m[1]).']';} + ), + array( + # Kronecker: \Kronecker{j}{k} + 'search' => "~\\\\Kronecker".$par.$par."~i", + # Kronecker: Kronecker[j,k] + 'replace' => function (array $m){ return 'KroneckerDelta['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # LaguerreL[\a]{n}@{x} + 'search' => "~\\\\LaguerreL(\[.*\])?".$par."@?(".$arg."|".$par.")~i", + # LaguerreL: LaguerreL[n,a,x] + 'replace' => function (array $m){ return 'LaguerreL['.brackR($m[2]).','.(strlen(brackR($m[1]))>0?brackR($m[1]).',':'').brackR($m[3]).']';} + ), + array( + # Legendre/Ferrers: \LegendreP[\mu]{\nu}@{x} | \FerrersP[\mu]{\nu}@{x} + 'search' => "~\\\\(?>Legendre|Ferrers)([PQ]|Poly)(\[(?>[^{}]|(?-1))*\])?".$par."@?(".$arg."|".$par.")?~i", + # Legendre/Ferrers: LegendreP[\nu,x] | LegendreP[\nu,\mu,x] + 'replace' => function (array $m){ return 'Legendre'.$m[1].'['.brackR($m[3]).','.(strlen(brackR($m[2]))>0?brackR($m[2]).',':'').brackR($m[6]).']';} + ), + array( + # LerchPhi: \LerchPhi@{z}{s}{a} + 'search' => "~\\\\LerchPhi@{0,2}(".$arg."|".$par.")(".$arg."|".$par.")(".$arg."|".$par.")~i", + # LerchPhi: LerchPhi[z,s,a] + 'replace' => function (array $m){ return 'LerchPhi['.brackR($m[1]).','.brackR($m[4]).','.brackR($m[7]).']';} + ), + array( + # Log Integral: \LogInt@{x} + 'search' => "~\\\\LogInt@{0,2}(".$arg."|".$par.")~i", + # Log Integral: LogIntegral[x] + 'replace' => function (array $m){ return 'LogIntegral['.brackR($m[1]).']';} + ), + array( + # Mittag-Leffler: \MittagLeffler{a}{b}@{z} + 'search' => "~\\\\MittagLeffler".$par.$par."@{0,2}(".$arg."|".$par.")~i", + # Mittag-Leffler: MittagLefflerE[\alpha,\beta,z] + 'replace' => function (array $m){ return 'MittagLefflerE['.brackR($m[1]).','.brackR($m[2]).','.brackR($m[3]).']';} + ), + array( + # Modulus: n \mod m + 'search' => "~(".$arg."|".$par.")\\\\mod@{0,2}(".$arg."|".$par.")~i", + # Modulus: Mod[m,n] + 'replace' => function (array $m){ return 'Mod['.brackR($m[1]).','.brackR($m[4]).']';} + ), + array( + # Permutations: \Permutations{n} + 'search' => "~\\\\Permutations@{0,2}(".$arg."|".$par.")~i", + # Permutations: Permutations[n] + 'replace' => function (array $m){ return 'Permutations['.brackR($m[1]).']';} + ), + array( + # Pochhammer: \pochammer{a}{n} + 'search' => "~\\\\pochhammer@{0,2}".$par.$par."~i", + # Pochhammer: Pochhammer[a,n] + 'replace' => function (array $m){ return 'Pochhammer['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # PolyGamma: \polygamma{n}@{z} + 'search' => "~\\\\Polygamma".$par."@{0,2}(".$arg."|".$par.")~i", + # PolyGamma: PolyGamma[n,z] + 'replace' => function (array $m){ return 'PolyLog['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # PolyLog: \Polylogarithms{x}@{z} + 'search' => "~\\\\Polylogarithm".$par."@{0,2}(".$arg."|".$par.")~i", + # PolyLog: PolyLog[x,z] + 'replace' => function (array $m){ return 'PolyLog['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # Q Factorial: \qFactorial{a}{q}{n} + 'search' => "~\\\\qFactorial@{0,2}".$par.$par.$par."~i", + # Q Factorial: QFactorial[a,q,n] + 'replace' => function (array $m){ return 'QFactorial['.brackR($m[2]).','.brackR($m[3]).']';} + ), + array( + # Q Gamma: \qGamma{q}@{z} + 'search' => "~\\\\qGamma".$par."@{0,2}(".$arg."|".$par.")~i", + # Q Gamma: QGamma[z,q] + 'replace' => function (array $m){ return 'QGamma['.brackR($m[2]).','.brackR($m[1]).']';} + ), + array( + # Ramanujan Tau: \RamanujanTau@{k} + 'search' => "~\\\\RamanujanTau@{0,2}(".$arg."|".$par.")~i", + # Ramanujan Tau: RamanujanTau[k] + 'replace' => function (array $m){ return 'RamanujanTau['.brackR($m[1]).']';} + ), + array( + # Real Part: \realpart{z} + 'search' => "~\\\\realpart@{0,2}".$par."~i", + # Real Part: Re[z] + 'replace' => function (array $m){ return 'Re['.brackR($m[1]).']';} + ), + array( + # Riemann: \RiemannXi@{s} + 'search' => "~\\\\Riemann(Xi)@{0,2}(".$arg."|".$par.")~i", + # Riemann: RiemannXi[s] + 'replace' => function (array $m){ return 'Riemann'.$m[1].'['.brackR($m[2]).']';} + ), + array( + # Scorer: \ScorerHi@{z} + 'search' => "~\\\\Scorer([G|H]i)@{0,2}(".$arg."|".$par.")~i", + # Scorer: ScorerHi[z] + 'replace' => function (array $m){ return 'Scorer'.$m[1].'['.brackR($m[2]).']';} + ), + array( + # Sign: \sign@{x} + 'search' => "~\\\\sign@{0,2}(".$arg."|".$par.")~i", + # Sign: Sign[z] + 'replace' => function (array $m){ return 'Sign['.brackR($m[1]).']';} + ), + array( + # Sin Integral: \SinInt@{x} + 'search' => "~\\\\Sin(h?)Int@{0,2}(".$arg."|".$par.")~i", + # Sin Integral: SinInt[z] + 'replace' => function (array $m){ return 'Sin'.$m[1].'Integral['.brackR($m[2]).']';} + ), + array( + # Spherical BesselJ/Y | HankelH1/H2: \SphBesselJ{n}@{z} + 'search' => "~\\\\Sph(Bessel|Hankel)(J|Y|Hii?)".$par."@{0,2}(".$arg."|".$par.")~i", + # Spherical BesselJ/Y | HankelH1/H2: SphericalBesselJ[n,z] + 'replace' => function (array $m){ return 'Spherical'.$m[1].''.(substr($m[2],0,2) !== 'Hi'?$m[2]:'H'.(strlen($m[2])-1)).'['.brackR($m[3]).','.brackR($m[4]).']';} + ), + array( + # Spherical Harmonic: \SphericalHarmonicY{l}{m}@{\theta}{\phi} + 'search' => "~\\\\SphericalHarmonicY".$par.$par."@?(".$arg."|".$par.")?(".$arg."|".$par.")?~i", + # Spherical Harmonic: SphericalHarmonicY[l,m,\theta,\phi] + 'replace' => function (array $m){ return 'SphericalHarmonicY['.brackR($m[1]).','.brackR($m[2]).','.brackR($m[3]).','.brackR($m[6]).']';} + ), + array( + # Spheroidal Eigenvalue: \SpheroidalEigenvalueLambda{m}{n}@{\gamma} + 'search' => "~\\\\SpheroidalEigenvalueLambda".$par.$par."@?(".$arg."|".$par.")?~i", + # Spheroidal Eigenvalue: SpheroidalEigenvalue[n,m,\gamma] + 'replace' => function (array $m){ return 'SpheroidalEigenvalue['.brackR($m[1]).','.brackR($m[2]).','.brackR($m[3]).']';} + ), + array( + # Spheroidal Ps: \SpheroidalPs{m}{n}@{z}{\gamma^2} + 'search' => "~\\\\Spheroidal(P|Q)s".$par.$par."@?(".$arg."|".$par.")?(".$arg."|".$par.")?~i", + # Spheroidal Ps: SpheroidalPs[n,m,\gamma,z] + 'replace' => function (array $m){ return 'Spheroidal'.$m[1].'S['.brackR($m[2]).','.brackR($m[3]).',Sqrt['.brackR($m[7]).'],'.brackR($m[4]).']';} + ), + array( + # Sqrt: \sqrt@{x} + 'search' => "~\\\\sqrt@{0,2}(".$arg."|".$par.")~i", + # Sqrt: Sqrt[x] + 'replace' => function (array $m){ return 'Sqrt['.brackR($m[1]).']';} + ), + array( + # StruveH: \StruveH{\nu}@{z} + 'search' => "~\\\\Struve(H|L)".$par."@{0,2}(".$arg."|".$par.")~i", + # StruveH: StruveH[n,z] + 'replace' => function (array $m){ return 'Struve'.$m[1].'['.brackR($m[2]).','.brackR($m[3]).']';} + ), + array( + # WeberE: \WeberE{\nu}@{z} + 'search' => "~\\\\WeberE".$par."@{0,2}(".$arg."|".$par.")~i", + # WeberE: WeberE[\nu,z] + 'replace' => function (array $m){ return 'WeberE['.brackR($m[1]).','.brackR($m[2]).']';} + ), + array( + # Whittaker: \WhittakerM{\kappa}{\mu}@{z} + 'search' => "~\\\\Whit(M|W)".$par.$par."@{0,2}(".$arg."|".$par.")~i", + # Whittaker: WhittakerW[k,m,z] + 'replace' => function (array $m){ return 'Whittaker'.$m[1].'['.brackR($m[2]).','.brackR($m[3]).','.brackR($m[4]).']';} + ) ); - $replace = array(//'[', ']' , - # Trignometric: ArcCosh[x] - "('$1'[0] == 'a'?'Arc'.ucfirst(strtolower(substr($1,1))):ucfirst(strtolower('$1'))).(strlen('$2')>0?'Integral':'').'['.brackR('$3').']'", - # Logarithm: Log[x] - "'Log['.(strlen('$1')>0?'$1,':'').brackR('$2').']'", - # Airy: AiryAi[z] - "'Airy$1['.brackR('$2').']'", - # Airy Modulus M: Sqrt[AiryAi[x]^2+AiryBi[x]^2] - "'Sqrt[AiryAi['.brackR('$1').']^2+AiryBi['.brackR('$1').']^2]'", - # Arithmetic Geometric Mean: ArithmeticGeometricMean[a,b] - "'ArithmeticGeometricMean['.brackR('$1').','.brackR('$4').']'", - # Anger: AngerJ[\nu,z] - "'AngerJ['.brackR('$1').','.brackR('$2').']'", - # Appell: AppellF1[\alpha,\beta,\beta',\gamma,x,y] - "'AppellF1['.brackR('$1').','.brackR('$4').','.brackR('$7').','.brackR('$10').','.brackR('$13').','.brackR('$16').']'", - # Barnes G: BarnesG[z] - "'BarnesG['.brackR('$1').']'", - # BesselJ: BesselJ[n,z] - "'Bessel$1['.brackR('$2').(strlen('$3')>0?','.brackR('$3'):',0').']'", - # Binomial Coefficient: Binomial[n,m] - "'Binomial['.brackR('$2').','.brackR('$1').']'", - # Catalan Number: CatalanNumber[n] - "'CatalanNumber['.brackR('$1').']'", - # Ceiling: Ceiling[x] - "'Ceiling['.brackR('$1').']'", - # Chebyshev: ChebyshevT[n,x] - "'Chebyshev$1['.brackR('$2').(strlen('$3')>0?','.brackR('$3'):',0').']'", - # Complex Conjugate: Conjugate[z] - "'Conjugate['.brackR('$1').']'", - # Cylinder: ParabolicCylinderD[\nu,z] - "'ParabolicCylinderD['.brackR('$1').','.brackR('$2').']'", - # Dawsons Integral: DawsonF[z] - "'DawsonF['.brackR('$1').']'", - # Dedekind's Eta: DedekindEta[\tau] - "'DedekindEta['.brackR('$1').']'", - # Derivative: D[f,x] - "'D['.brackR('$1').','.brackR('$2').']'", - # Determinant: Det[a] - "'Det[$1]'", - # Divergence: divergence - "'Div[$1]'", - # Elliptic Integral: EllipticC[x, Sqrt[m]] - "'Elliptic$1['.(strlen('$5')>0?brackR('$2').', Sqrt['.brackR('$5').']':'Sqrt['.brackR('$2').']').']'", - # Error: Erf[z] - "'Erf['.brackR('$1').']'", - # Euler Beta & Gamma: Beta[a,b] - "'$1['.brackR('$2').(strlen('$5')>0&&strtolower('$1')=='beta'?','.brackR('$5'):'').']'", - # Exponential: Exp[x] - "'Exp['.brackR('$1').']'", - # Exponential Integral: ExpIntegralEi[z] - "'ExpIntegralE'.($1=='i'?'i':'').'['.(strlen('$2')>0?brackR('$2').',':'').brackR('$3').']'", - # Floor: Floor[x] - "'Floor['.brackR('$1').']'", - # Fraction: a/b - "(strlen('$3')>0?'('.brackR('$1').')':brackR('$1')).'/'.(strlen('$6')>0?'('.brackR('$4').')':brackR('$4'))", - # Fresnel: FresnelS[z] - "'Fresnel'.ucfirst('$1'[0]).'['.brackR('$2').']'", - # Greek Letter: \[CapitalAlpha] - "'\\\['.(strtolower('$1') != '$1'?'Capital':'').ucfirst('$1').']'", - # Gamma (Incomplete): - "'Gamma['.brackR('$1').','.brackR('$4').']'", - # Gudermannian: Gudermannian[z] - "(strlen('$1')>0?'Inverse':'').'Gudermannian['.brackR('$2').']'", - # Hermite: HermiteH[n,x] - "'HermiteH['.brackR('$1').','.brackR('$2').']'", - # HurwitzZeta: HurwitzZeta[s,a] - "'HurwitzZeta['.brackR('$1').','.brackR('$4').']'", - # Hypergeometric: Hypergeometric2F1[a,b,c,d] - "'Hypergeometric2F1[$2,$3,$4,$5]'", - # Hypergeometric (Generalized): HypergeometricPFQ[a,b,c] - "'HypergeometricPFQ[$7,$10'.','.brackR('$13').']'", - # Incomplete Beta & Gamma: Beta[z,a,b], Gamma[a,z] - "'$1['.(strlen('$2')>0?brackR('$2').',':'').brackR('$3').','.brackR('$6').']'", - # Inverse Error (including complementary): InverseErfc[x] - "'InverseErf$1['.brackR('$2').']'", - # Jacobi Elliptics: JacobiSD[u,m] - "(strlen('$1')>0?'Inverse':'').'Jacobi'.(strlen($2) == 2 ? strtoupper('$2') : 'Zeta').'['.brackR('$3').', Sqrt['.brackR('$6').']]'", - # Jacobi Polynomial: JacobiP[n,a,b,x] - "'JacobiP['.brackR('$2').','.brackR('$1').','.brackR('$3').','.brackR('$4').']'", - # Kelvin: KelvinBer[n,z] - "'Kelvin'.ucfirst('$1').'['.brackR('$2').(strlen(brackR('$4'))>0?','.brackR('$4'):'').']'", - # Klein Invariant: KleinInvariantJ[\tau] - "'KleinInvariantJ['.brackR('$1').']'", - # Kronecker: Kronecker[j,k] - "'KroneckerDelta['.brackR('$1').','.brackR('$2').']'", - # LaguerreL: LaguerreL[n,a,x] - "'LaguerreL['.brackR('$2').','.(strlen(brackR('$1'))>0?brackR('$1').',':'').brackR('$3').']'", - # LegendreP/Q: LegendreP[n,x] - "'Legendre$1['.brackR('$3').','.(strlen(brackR('$2'))>0?brackR('$2').',':'').brackR('$5').']'", - # Associated Legendre: LegendreP[n,m,x] - "'Legendre$1['.brackR('$3').','.brackR('$2').','.brackR('$5').']'", - # LerchPhi: LerchPhi[z,s,a] - "'LerchPhi['.brackR('$1').','.brackR('$4').','.brackR('$7').']'", - # Log Integral: LogIntegral[x] - "'LogIntegral['.brackR('$1').']'", - # Mittag-Leffler: MittagLefflerE[\alpha,\beta,z] - "'MittagLefflerE['.brackR('$1').','.brackR('$2').','.brackR('$3').']'", - # Modulus: Mod[m,n] - "'Mod['.brackR('$1').','.brackR('$4').']'", - # Permutations: Permutations[n] - "'Permutations['.brackR('$1').']'", - # Pochhammer: Pochhammer[a,n] - "'Pochhammer['.brackR('$1').','.brackR('$2').']'", - # PolyGamma: PolyGamma[n,z] - "'PolyLog['.brackR('$1').','.brackR('$2').']'", - # PolyLog: PolyLog[x,z] - "'PolyLog['.brackR('$1').','.brackR('$2').']'", - # Q Factorial: QFactorial[a,q,n] - "'QFactorial['.brackR('$2').','.brackR('$3').']'", - # Q Gamma: QGamma[z,q] - "'QGamma['.brackR('$2').','.brackR('$1').']'", - # Ramanujan Tau: RamanujanTau[k] - "'RamanujanTau['.brackR('$1').']'", - # Real Part: Re[z] - "'Re['.brackR('$1').']'", - # Riemann: RiemannXi[s] - "'Riemann$1['.brackR('$2').']'", - # Scorer: ScorerHi[z] - "'Scorer$1['.brackR('$2').']'", - # Sign: Sign[z] - "'Sign['.brackR('$1').']'", - # Sin Integral: SinInt[z] - "'Sin$1Integral['.brackR('$2').']'", - # Spherical BesselJ/Y | HankelH1/H2: SphericalBesselJ[n,z] - "'Spherical$1'.(substr('$2',0,2) !== 'Hi'?'$2':'H'.(strlen('$2')-1)).'['.brackR('$3').','.brackR('$4').']'", - # Spherical Harmonic: SphericalHarmonicY[l,m,\theta,\phi] - "'SphericalHarmonicY['.brackR('$1').','.brackR('$2').','.brackR('$3').','.brackR('$6').']'", - # Spheroidal Eigenvalue: SpheroidalEigenvalue[n,m,\gamma] - "'SpheroidalEigenvalue['.brackR('$1').','.brackR('$2').','.brackR('$3').']'", - # Spheroidal Ps: SpheroidalPs[n,m,\gamma,z] - "'Spheroidal$1S['.brackR('$2').','.brackR('$3').',Sqrt['.brackR('$7').'],'.brackR('$4').']'", - # Sqrt: Sqrt[x] - "'Sqrt['.brackR('$1').']'", - # StruveH: StruveH[n,z] - "'Struve$1['.brackR('$2').','.brackR('$3').']'", - # WeberE: WeberE[\nu,z] - "'WeberE['.brackR('$1').','.brackR('$2').']'", - # Whittaker: WhittakerW[k,m,z] - "'Whittaker$1['.brackR('$2').','.brackR('$3').','.brackR('$4').']'" - ); - if (isset($_POST["input"])) { - $translated = preg_replace($matcher, $replace, $data); - $translated = preg_replace($matcher, $replace, $translated); - //$translated = preg_replace_callback($matcher, function($matches) use (&$replace) {return array_shift($replace);}, $data); - //$translated = preg_replace_callback($matcher, function($matches) use (&$replace) {return array_shift($replace);}, $translated); - //echo "\n" . $translated; + if (isset($data)){ + foreach ($replacements as $set) { + $translated = preg_replace_callback( + $set['search'], + // select the correct replacement callback depending on $allowimgcode + $set['replace'], + $data + ); + } + foreach ($replacements as $set) { + $translated = preg_replace_callback( + $set['search'], + // select the correct replacement callback depending on $allowimgcode + $set['replace'], + $data + ); + } } - $wikitext = '<b>hellow</b>!'; - //$output-> - echo "<style> - html {height:100vh} - body{ - //background-color:#70DBFF; - text-align:center; - font-family:consolas; //lucida console; - height: 100vh; - } - - #container { - opacity:0.93; - filter:alpha(opacity=40); - width:900px; - margin:0 auto; - margin-top:0px; - margin-bottom:-50px; - border-width:20px; - border-style:solid; - border-color:#FFF #145266 #FFF #145266; - background-color:#FCFEFF; - } - - #pageheader { - text-align:center; - color:#303; - //background-color:#FFC; - margin:25px 25px -18px 25px; - } - - h1 { - font-size:35pt; - color:#367588; - margin:5px 0px -10px 0px; - } - - #form { - //height:35vh; - } - - #footer { - font-size:8pt; - margin:0px 60px 5px 60px; - } - </style> + $output -> addWikiText("LaTeX to Mathematica Translator + The application converts LaTeX functions which directly translate + to Mathematica counterparts. Functions without explicit Mathematica + support are available for translation via a DRMF package (under development)."); + /*addHtml does not work: + $output -> addHtml("<p>Hello World</p>");*/ + echo " <body> <div id='container'> <script type='text/javascript'> @@ -469,7 +505,6 @@ <textarea name='input' rows='17' cols='100' placeholder='Enter LaTeX for translation'>"; if (isset($data)){echo $data;} echo "</textarea><br><input type='submit' value='Translate'> - <!--action='TranslateFunction.php'<input type='text' name='latexinput' size='40' value='Enter LaTeX'>--> <br><br>Translated Mathematica:<br> <textarea name='output' id='output' rows='17' cols='100' placeholder='Translated Mathematica' onClick='SelectAll('output');' readonly='readonly'>"; if (isset($translated)){echo $translated;} echo "</textarea> -- To view, visit https://gerrit.wikimedia.org/r/217866 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib16637649e97d7b008eec18ba49f7fe0a87520e8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MathSearch Gerrit-Branch: master Gerrit-Owner: Sharmaans <sharma.ankit...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits