3
$\begingroup$

Update: I have found out that my request below has nothing to do with this site. But because there are at least a few folks occasionally posting Mathematica code, I'll shortly provide an answer with approaches to obtain more easily readable Mathematica code.

For both Mathematica.StackExchange.com and Math.StackExchange.com there is an available button to format Mathematica code with the installation instructions found at https://mathematica.meta.stackexchange.com/questions/1043/additional-useful-buttons-for-our-m-se-editor.

This allows Mathematica coding for Greek letters such as $\alpha$ to be displayed as α rather than the default \[alpha] which makes for reading the code much nicer. Here is where that button shows up (with that button highlighted with a red rectangle):

Example of a Mathematica editor screen

Yes, there are not hordes of folks providing Mathematica code on this site and the same goes for Math.StackExchange.com but that site does provide that functionality.

So the question is: Should or can such a formatter be added for this site? (Or is such functionality already available and I'm just not aware of that?)

$\endgroup$
19
  • 1
    $\begingroup$ Does the user-script not work on all sites? If not I'd imagine it'd be easy to modify it. $\endgroup$ Sep 18, 2022 at 16:38
  • $\begingroup$ @Scortchi-ReinstateMonica If I'm understanding the process for installing it, it was installed in Chrome (as opposed to installing it specifically for Mathematica SE). I found it showed up for Math SE but not CrossValidated SE and Data Science SE. So maybe that means I should ask the creator of the button rather than asking here. $\endgroup$
    – JimB
    Sep 18, 2022 at 17:04
  • $\begingroup$ @Scortchi-ReinstateMonica I just asked halirutan in the Mathematica Chat and I'll report back when he answers.. $\endgroup$
    – JimB
    Sep 18, 2022 at 17:10
  • 4
    $\begingroup$ If you you look at the meta-data block in the code, there are lines such as // @include https://mathematica.stackexchange.com/* that specify on what sites the script is run. Try adding Cross Validated - odds are the S.E. sites are similar enough for the script to run on any of them. $\endgroup$ Sep 18, 2022 at 17:10
  • $\begingroup$ Thanks @Scortchi-ReinstateMonica ! That tells me how to solve the problem and therefore is not an issue for this forum so I should delete this question. $\endgroup$
    – JimB
    Sep 18, 2022 at 18:19
  • 5
    $\begingroup$ @JimB I think it would be more helpful to future readers if you posted an Answer sharing how you solved this problem, instead of deleting the question altogether. $\endgroup$
    – Sycorax Mod
    Sep 18, 2022 at 19:16
  • $\begingroup$ @Sycorax Good suggestion. I will do so after the author of the script responds. Someone else from the Mathematica SE chat suggested using TamperMonkey to modify the script with the change suggested by Scortchi-ReinstateMonica. That worked but such manipulations are probably more extreme than what most would want to do (at least it seems a bit extreme to me). $\endgroup$
    – JimB
    Sep 18, 2022 at 21:20
  • 2
    $\begingroup$ You could ask the maintainer of the code on GitHub to make the change, or fork the code yourself. $\endgroup$ Sep 19, 2022 at 8:22
  • 1
    $\begingroup$ Am I old fashioned when I believe that editors should not replace '\[alpha]' by 'α'? If it is a useful feature to be able to just type 'α' when you want '\[alpha]', then have the compiler change instead of the editor. $\endgroup$ Sep 19, 2022 at 11:25
  • $\begingroup$ @SextusEmpiricus My concern with this issue is to make the Mathematica code more readable for when questions deal with symbolic statistical manipulations (which I believe belong in this forum rather than the Math SE forum - but that's another issue). The available button converts all such Mathematica notation in a selected set of text in one fell swoop so it's not an onerous process. $\endgroup$
    – JimB
    Sep 19, 2022 at 23:08
  • $\begingroup$ @SextusEmpiricus And Mathematica is much more available now that one can download the "Wolfram Engine" with a limited license at no cost (but a more liberal license than SAS On Demand - which replaced the SAS University Edition. I have used Mathematica since version 1 (somewhere around 1989 to 1990 on a MacPlus) so I admit being partial/biased towards that software. $\endgroup$
    – JimB
    Sep 19, 2022 at 23:13
  • $\begingroup$ @JimB Mathematica is for free now, that's very nice. I had some times that I wanted to use it but the institute where I worked had only one or two licences for the mathematicians. (or maybe it was maple and I am mixing them up) $\endgroup$ Sep 20, 2022 at 5:38
  • $\begingroup$ @SextusEmpiricus It is the Wolfram Engine that is "free" which can be run in a command-line mode or in a "notebook" using Jupyter: mathematica.stackexchange.com/questions/195620/…. One should read the license carefully and a simplistic/approximate interpretation of the license is that you can use it if making money is not involved (similar to the SAS On Demand license). $\endgroup$
    – JimB
    Sep 20, 2022 at 16:25
  • 1
    $\begingroup$ It's not necessarily the case that whatever symbol is displayed is consistent. Your answer linked in the above comment looks fine to me, on both my 'phone & laptop; but with this one the phis aren't rendered on my 'phone. (For more fun with phi see meta.stackexchange.com/q/349370/225179.) MathJax - just by way of comparison, as I'm not of course suggesting you use it in code - uses web-fonts if the correct font isn't available on a reader's system (or even images in the last resort), to make sure that everyone sees the same thing. $\endgroup$ Sep 22, 2022 at 18:59
  • 1
    $\begingroup$ Syntax highlighting will only be activated if the question has the appropriate tag - 'mathematica' in this case. $\endgroup$ Sep 22, 2022 at 19:01

3 Answers 3

4
$\begingroup$

We as a community, or as moderators, have no way of adding it. It is a kind of change that can be done by the StackExchange developers.

Personally, I see no reason for adding it. Mathematica is far from the most popular among statisticians and data scientists. Moreover, we support $\TeX$ and if you look at the posts, most of the users have no problem with using it, so it would solve a problem for a small group of users who know Mathematica but don't know $\TeX$.

$\endgroup$
2
  • 2
    $\begingroup$ I have now discovered my request has nothing to do with this site and will be posting an answer for the minority who might want to convert Mathematica characters. $\endgroup$
    – JimB
    Sep 22, 2022 at 16:37
  • 2
    $\begingroup$ It's not an issue of "users who know Mathematic but don't know $\TeX$". It is simply making Mathematica code look like it does in Mathematica. Of course, any supporting equations should be posted in $\TeX$. And Mathematica can produce $\TeX$ from any Mathematica code - it then just won't work in Mathematica if pasted back in. $\endgroup$
    – JimB
    Sep 22, 2022 at 21:14
4
$\begingroup$

I think if I were writing Mathematica code to illustrate a statistical point for readers who probably aren't familiar with Mathematica, I shouldn't want to use Greek letters. On their own, they're only a small step towards mathematical notation, & while it would be nice to be able to write $\sigma_1^2$ rather than sigma1^2, it feels to me as if σ1^2 is neither fish nor fowl.

A less subjective concern is that not all readers will have the necessary fonts installed on their system to render the Unicode characters properly, or at all. For example, on my 'phone I see a script a rather than $\alpha$, & a 'white square' rather than $\varphi$.

$\endgroup$
3
  • $\begingroup$ "neither fish nor fowl": I don't see a major difference in the speciation of sigma1^2 and σ^2. $\endgroup$
    – JimB
    Sep 23, 2022 at 16:02
  • 1
    $\begingroup$ There's no reason in principle why Greek letters oughtn't to be used freely in code: it's just that to me, after decades of reading either mathematical expressions or ASCII code, σ1^2 seems a barbarism. I may be alone. $\endgroup$ Sep 23, 2022 at 18:10
  • 1
    $\begingroup$ Despite my obvious sarcasm at times, I appreciate your viewpoint. I've used Mathematica since version 1 so I'm used to such barbarisms. $\endgroup$
    – JimB
    Sep 23, 2022 at 21:28
3
$\begingroup$

When answering questions on this site with Mathematica code, Greek letters and special characters (which are valid in variable names in Mathematica) look like \[Alpha] and \[Beta], for example. This can make the code harder to read and understand.

It turns out that the button I was asking for above has nothing to do with this site's management and depends only on a script that can be made to work on any of the StackExchange sites.

There are a few ways to turn such characters in more readable characters with that script.

0. Use a special website that does the conversion.

https://steampiano.net/msc/

You can paste in text and all of the Mathematica codes (like \[Alpha]) get converted. From that webpage: "Some of these are mapped to characters in the Unicode character set, and can therefore be translated into Unicode, suitable for displaying outside Mathematica. Others, however, are in the Unicode Private area, and are displayed correctly only using Mathematica fonts."

1. Install the script:

https://mathematica.meta.stackexchange.com/questions/1043/additional-useful-buttons-for-our-m-se-editor.

This gets you a button to convert such characters (selecting some text and then pressing the added button) but works currently only on Mathematica SE and Math SE (because those sites are specifically mentioned in the script and CrossValidated SE is not).

You can then go to a "Your Answer" box on those sites (Mathematica or Math SE), type in your answer for CrossValidated, and then copy-and-paste it into "Your Answer" box on CrossValidated. (Yes, that's not a very attractive approach.)

2. Modify the script yourself.

This (in my opinion) is not for the faint at heart. One can use a script editor such as Tampermonkey to add in the 1 line of necessary code to the above script:

// @include       https://stats.stackexchange.com/* 

(as discovered by @Scortchi-ReinstateMonica). I am not recommending or giving more details to this approach but only give it as a possible alternative.

3. Wait until the authors of the script add in the above line of code.

Then it will work on CrossValidated directly. (I have asked the authors and am awaiting a response.) If and when this happens, this will be the best alternative as it doesn't require installing things like Tampermonkey.

$\endgroup$
2
  • 1
    $\begingroup$ (+1) Note that installing the script without modifying it will still "require installing things like Tampermonkey" with browsers other than Chrome (with which you still need to install a dedicated app.). $\endgroup$ Sep 23, 2022 at 11:03
  • $\begingroup$ @Scortchi-ReinstateMonica You might be correct. However, I have it working on Microsoft Edge for Mathematica SE and Math SE and didn't use anything special to install it. $\endgroup$
    – JimB
    Sep 23, 2022 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .