Giu's Journal

Wikipedia TeX Source Extractor Bug Fix

The Extractor didn't display the TeX source behind a simple derivation correctly, so I had to fix it.

I just pushed an updated version of the Wikipedia TeX Source Extractor userscript to both userscripts.org and GitHub.

The old version had an issue displaying the TeX source of mathematical formulas containing apostrophes ('), e.g. derivations.

If the TeX string contained an apostrophe, the string's part after the apostrophe (including the apostrophe itself) got cropped. For example, if the TeX source behind a derivation looked like f\!\,'(x_0), the Extractor somehow only managed to display f\!\,.

The cause of this issue is my usage of apostrophes for the declaration of strings directly in the JavaScript code.

Because of this conflict with apostrophes, the following snippet of code, in which I inject a textbox containing the TeX source didn't work as expected (shortened version):

var a = $t.attr("alt");
$t.parent().append("<input id='wte_texsource_"+counter+"' type='text' value='"+a+"' />");

To fix the issue, I now first append the textbox without a value, and right after that I inject the TeX source, avoiding any conflicts involving apostrophes:

$t.parent().append("<input id='wte_texsource_"+counter+"' type='text' />");
$("#wte_texsource_"+counter).val($t.attr("alt"));

The updated version now displays any TeX source containing apostrophes correctly:

Wikipedia TeX Source Extractor Bugfix