Community Wishlist Survey 2021/Editing/Add global LaTeX macros for math in math tags

Add global LaTeX macros for math in math tags

  • Problem: Certain math symbols, such as absolute value and expected value, are very tedious to type and make editing more cumbersome and error-prone.
  • Who would benefit: Anyone who types lots of math equations and uses proper symbols for spacing (ex. not just using pipe character for absolute value).
  • Proposed solution: A community-decided global list of macros enabled for anyone using math tags.
  • More comments: For example, if it is declared globally \DeclarePairedDelimiter\abs{\lvert}{\rvert}, then editors may type \abs{x} instead of \lvert x \rvert. Similarly for expected value, editors would avoid typing \operatorname{E} all the time. I proposed this last year at https://en.wikipedia.org/wiki/Wikipedia:Village_pump_(technical)/Archive_177#Equation_\operatorname_macros%3F where it got some interest and positive reception, though ultimately not implemented.
  • Phabricator tickets:
  • Proposer: Wqwt (talk) 01:22, 18 November 2020 (UTC)[reply]

Discussion

@Wqwt: you might be interested in joining Wikimedia Community User Group Math. There are several possibilities:

  • MathJax which we use to generate the formulas offers this possibility to define macros [1]. The problem with this is that unfortunately we do not use MathJax out-of-the-box but still have the setup (state-of-the-art 10 years ago), where people get delivered images of equations. Each formula is treated separately, which makes it impossible to have features other websites (like math.stackexchange you mention in village-pump) offer, i.e. macro definitions valid for several equations, cross-referencing equation numbers, automatic line-breaking and for me most annoying: Adjusting the math font properly to the text font.
  • Then, we have a list of global declarations already. They were defined in a pre-processing step called "texvc" which was needed when LaTeX was used to generate the images. Unfortunately some of the (re)definitions done in this pre-processing break any LaTeX document. We try to get rid of them so you can offer a LaTeX packet [2] and a corresponding MathJax packet [3] to render all Wikipedia equations with LaTeX or MathJax without the need for any pre-processing. Those macro definitions unfortunately do not contain useful things currently, e.g. in Wikipedia you can write \isin (like the html entity name) instead of \in or my personal favorite: You can write \varcoppa if you want to print \mbox{\\coppa}
  • I am not entirely against adding unproblematic definitions that are actually useful to this texvc package. However for pretty much all set of macros that people consider generally useful there are existing LaTeX packages. The \abs command you mention is part of the physics package [4] (and possibly others) in LaTeX and for this physics package there is also an equivalent MathJax package [5]. Unfortunately currently we do not include the physics package. Including such a package is very simple you want to do it on your own website. Unfortunately we in Wikipedia still have some remnants of texvc floating around where you have to try to teach it the behavior of all new macros so it does not reject or wrongly modify your code and secondly we are unfortunately not running the current version MathJax3, but the old MathJax2 and I am not entirly sure if the whole functionality of the physics package is also available in the old version.

@Physikerwelt: is of the very few volunteers, if not the only one, maintaining the math extension. There are plans to switch to MathJax3 and HTML rendering, he can probably tell more.--Debenben (talk) 22:04, 20 November 2020 (UTC)[reply]

  • Just a side remark. I personally am in favour of keeping the the approach to maintain a whitelist of allowed commands and to automatatically reformat LaTeX code to a standard format, w.r.t, to spacing and standard arguments. Adding new commands is thus independent of MathJax 2/3 which will primarily improve the rendering as described above. This being said, you or someone with basic programming skills can propose new aliases by extending this list:

https://github.com/wikimedia/mediawiki-services-texvcjs/blob/master/lib/texutil.js Note, that this will be availible to all wikis in all languages and all projects. Thus these additions should be very conservative. Moreover, the consensus on the changes by the Wikimedia Community User Group Math is required. --Physikerwelt (talk) 13:39, 27 November 2020 (UTC)[reply]

@Physikerwelt: Thank you for taking the time to answer and I am afraid it sounds ungrateful for all the work you have been doing over all the years, but I feel like can not leave your statement here without answer.
Maybe something changed that I am unaware of, but to my understanding texvcjs still tries to "validate" the expression. Consider e.g. the request for the \middle command task T137788. There is no reason to not support it, it does not need to be defined and would be supported already if texvc would not block it. In the ticket you say "a skilled nodejs programmer with a good understanding of a parser [...] should be able to implement it in two days." Just for this one command! There would be about 96 commands like this in the physics package.
Validating LaTeX without parsing the whole expression is like validating c++ code without compiling it. With the normal definitions "\sigma" is valid, "\color{blue}" is valid, "\color{\sigma}" is not. To determine if "\color{\sigma}" is valid you need to know the definition of \sigma, evaluate it, feed the result to the \color command and see if it can handle the input. This macro expansion is done in Mathjax already, why replicate it? You could simply go through the list of commands [6] and not load the packages and commands you don't want, that needs less than 2 days.
And the argument with spaces I also don't understand: Very often editors put unnecessary spaces and linebreaks in the code on purpose to improve readability. If you really need them removed, you can take MathJax and convert LaTeX->MathML->LaTeX which also takes less than 2 days. Note that the original form is more valuable, it contains the same information as the "validated" expression and additional information to improve readability of the source code which is lost in the conversion.--Debenben (talk) 22:33, 28 November 2020 (UTC)[reply]

Voting