Page MenuHomePhabricator

Allow copying formulas from <math> markup
Open, LowPublic

Description

For example, it would be nice to be able to copy "4(a + 2)" into the user's copy-paste buffer from the markup <math>4(a + 2)</math>.
For more complex formulas where it's difficult to serialize, perhaps the LaTeX markup would be what is copied, though often intelligent conversions can be made, like "\frac{\sqrt{a + 2}}{5}" could be mapped to "√(a + 2)/5".

If this can't be done with highlighting + Ctrl+c, some JavaScript mechanism could work, for example adding a "Copy formula" option to the right-click menu.

Event Timeline

The proposal sounds a bit unpredictable what exactly you'd expect when copying?

I've a bit of javascript which allows copying formula on a double click

jQuery( document ).ready( function( $ ) {
    $(".mwe-math-mathml-a11y").each(function(ind,ele) {
		root = ele.parentElement;
		$(root).dblclick(function(ev) {
			console.log(ev.delegateTarget);
			var root = ev.delegateTarget;
			var anno = $(root).find("annotation");
			var latex = $(root).find("annotation").text();
			var $temp = $("<input>")
			$("body").append($temp);
			$temp.val(latex).select();
			document.execCommand("copy");
			$temp.remove();
		});
});

Vanalla MathJax does provide a right click menu which allows copying an equation. It would no be too tricky to do something similar here.

image.png (233×521 px, 59 KB)

As to the actual task description, there are three possible options for what should be copied.

  1. The latex code
  2. The semantic MathML code
  3. a translation of the equation into some Unicode type expression.

1 and 2 are easy, the data is already embedded in the HTML source code. 3 Is a much harder task, it might be possible for some simple equations like polynomials, but it gets considerably harder as the size of the expression grows. Defining the desired output for 3 is a task in itself. Wondering if there is some code out there that converts MathML into some useful format.

Physikerwelt subscribed.

@SalixAlba a few comments
For 1 the latex code is wrapped into a display style command. This was done to preserve backward-compatibility. For 2 the MathML code is purely presentational, it can be for example copied to word or Mathematica or maple. What uses do you have in mind?

I am asking myself. If we would restrict ourselves to 1 and 2 would that be a feature that would be desired by the community? Who would use it?