Help:Comparison between ParserFunctions syntax and TeX syntax: Difference between revisions
Content deleted Content added
postfix function calls and nested template calls |
{{MovedToMediaWiki|Manual:Comparison between ParserFunctions syntax and TeX syntax}} Tag: Replaced |
||
Line 1: | Line 1: | ||
⚫ | |||
It would be convenient to be able to use the same wikitext in evaluating a numerical expression with [[mw:Help:Extension:ParserFunctions|ParserFunctions]] and as [[Help:Displaying a formula|TeX code for nicely displaying it]]. However, there are several issues. |
|||
==Same code is possible, but display could be better== |
|||
Example: |
|||
{{expression demo|1+2e11*3/(4+5^6)}} |
|||
In this example the same wikitext is suitable for ParserFunctions and for TeX. Advantages of using TeX for the display, over displaying the raw wikitext, include the nice display of a power with a one-character exponent. An advantage of the wikitext being suitable for TeX is also the possibility to incorporate the wikitext in a larger TeX string, with also parts which no not require automatic evaluation. However, preferable in displaying the expression might additionally be: |
|||
*normal power notation instead of e-notation |
|||
*× instead of * |
|||
*division with a horizontal division bar |
|||
==Same code is not directly possible== |
|||
In addition to incompatibility with postfix function calls as well as nested template calls, it is not directly possible to use the same expression for a power with a multi-character exponent, because TeX requires braces, while ParserFunctions does not allow them: |
|||
{{expression demo|2^10}} |
|||
{{expression demo|2^(10)}} |
|||
{{expression demo|2^{10} }} |
|||
==Remedy== |
|||
One can put the expression in a template like [[Template:Example expression for common use by ParserFunctions and TeX]], with a parameter that is given the value "c" for a calculation and "d" for display. Using [[Template:()]] the power in the example can now be written <nowiki>2^{{()|{{{1}}}|10}}</nowiki>: |
|||
---- |
|||
<nowiki>{{#expr:2^{{()|c|10}}}}</nowiki> gives {{#expr:2^{{()|c|10}}}} |
|||
<nowiki>{{#tag:math|2^{{()|d|10}}}}</nowiki> gives {{#tag:math|2^{{()|d|10}}}} |
|||
---- |
|||
Similarly we can use [[Template:Frac]] to produce either a division in ParserFunctions syntax, or a division with a horizontal bar in TeX syntax. Thus: |
|||
<nowiki>{{#expr:{{Example expression for common use by ParserFunctions and TeX|c}}}}</nowiki> gives {{#expr:{{Example expression for common use by ParserFunctions and TeX|c}}}} |
|||
<nowiki>{{#tag:math|{{Example expression for common use by ParserFunctions and TeX|d}}}}</nowiki> gives {{#tag:math|{{Example expression for common use by ParserFunctions and TeX|d}}}} |
|||
Using [[Template:Tex number]], which takes the output of #expr and converts it to a TeX string, we can create TeX output including the result of the computation: |
|||
<nowiki>{{#tag:math|g=\frac{GM}{R^2}={{Example expression for common use by ParserFunctions and TeX|d}}={{Tex number|{{Example expression for common use by ParserFunctions and TeX|c}}}} m/s^2}}</nowiki> gives: |
|||
{{#tag:math|g=\frac{GM}{R^2}={{Example expression for common use by ParserFunctions and TeX|d}}={{Tex number|{{Example expression for common use by ParserFunctions and TeX|c}}}} m/s^2}} |
|||
The numeric expression can be changed at one place, in its template, to produce new TeX output with automatically updated numeric result. |
|||
Another example is [[Template:Example expression for common use by ParserFunctions and TeX: escape velocity]]; this time parameter {{{1}}} can also be "f" for formula, for this value the template produces the TeX code for the formula without numbers substituted in it. Also, the template uses [[Template:Sqrt]]. Thus: |
|||
<nowiki>{{#tag:math|v_e = {{Example expression for common use by ParserFunctions and TeX: escape velocity|f}}={{Example expression for common use by ParserFunctions and TeX: escape velocity|d}}={{Tex number|{{Example expression for common use by ParserFunctions and TeX: escape velocity|c}}}} m/s}}</nowiki> gives: |
|||
{{#tag:math|v_e = {{Example expression for common use by ParserFunctions and TeX: escape velocity|f}}={{Example expression for common use by ParserFunctions and TeX: escape velocity|d}}={{Tex number|{{Example expression for common use by ParserFunctions and TeX: escape velocity|c}}}} m/s}} |
|||
Now the formula can be changed in its template, to produce new TeX output for both the formula and the computation, and automatically updated numeric result. |
|||
Note that since the formula is in a separate template, [[Help:Preview#Limitations, detecting preview mode|changes cannot be fully previewed]]; at most they can be previewed for one value of its parameter, by making that the default value. |
|||
{{h:f}} |
|||
⚫ |
Latest revision as of 17:37, 4 July 2024
![]() |
This page has been moved to Manual:Comparison between ParserFunctions syntax and TeX syntax on mediawiki.org.
Any modifications or additions to this page should be made on mediawiki.org instead. |