3
$\begingroup$

This recent question on chemistry.se includes a snippet of Fortran. Contrasting to anticipation, the addition of fortran after the initial three grave accents does not enable the syntax highlighting (do and end do would qualify as keywords here):

h_core = e1ints
do q =1,norb
    do p =1,q
        h_core(p,q) = h_core(q,p) !lower triangular to symmetric
    end do
end do

Following the discussion here, an explicit example how it is supposed to be used, and a check that Fortran per se is considered by highlight.js here, I notice currently none of the following approaches work on chemistry.se.

do i = 1, 5  ! backticks & fortran
   write (*,*) i
end do
do i = 1, 5  ! backticks & f90
   write (*,*) i
end do
do i = 1, 5  ! backticks & f95
   write (*,*) i
end do

On the contrary, python for Python works on the get-go:

for i in range(4):
    print(i)
    if i >= 2:
        print("i .ge. 2")

Question/suggest: may there be (again?) support for syntax highlighting Fortran? Copy-paste of the three Fortran loops e.g., into the standard question box on mattermodelling.se promptly highlights all relevant keywords. Or, is there policy specific to chemistry.se to constrain highlight.js' action to general purpose language Python only?

$\endgroup$

3 Answers 3

8
$\begingroup$

There is no official support for Fortran highlighting on Stack Exchange, see https://meta.stackexchange.com/a/184109/312770, which mentions that not all languages supported by highlight.js work on SE.

Anyway, from what I can tell, the supposed Fortran highlighting observed on Matter Modeling is not correct. Superficially it looks as if there is syntax highlighting, but notice how the comment is not correctly detected (in fact, it thinks that the word lower in the comment is a keyword).

Most likely, what is happening is that fortran is not recognised as a valid language, which leads to a different language being inferred—which just so happens to also have end and do as keywords. I don't know why the behaviour on Chemistry is different, but in my opinion, no code highlighting wins out over bad code highlighting.

enter image description here

Or, is there policy specific to chemistry.se to constrain highlight.js' action to general purpose language Python only?

No, there isn't, and this isn't under our control anyway. You could try making a feature request on Meta.SE for Fortran highlighting, but unfortunately, the same post linked above suggests that this is unlikely to get any traction.

$\endgroup$
10
  • $\begingroup$ I tested only the three simpler loops in mattermodelling.se; the colorscheme applied for the larger snippet is beyond expectation. Well, Fortran's rank #17 of Tiobe's top 20 might be only a weak additional justification to file a request. $\endgroup$
    – Buttonwood
    Commented Jan 3, 2022 at 14:23
  • $\begingroup$ The thought about Fortran isn't that new (given Fortran's age, no pun intended): by Dec 2020, a post (meta.stackexchange.com/questions/358865/…) basically returned to a then already 7 yo request. $\endgroup$
    – Buttonwood
    Commented Jan 3, 2022 at 14:28
  • $\begingroup$ @Buttonwood Ah, well, I'm not surprised you found an existing request. I imagine most languages with reasonable usage stats would be requested by now. But admittedly, while adding syntax highlighting for other languages is a "nice thing to have", it's also not very useful and mostly cosmetic, so I can understand why they don't really prioritise it. Sorry we can't really help more. $\endgroup$ Commented Jan 3, 2022 at 16:06
  • $\begingroup$ Or expressed differently, chemistry.se /= stackoverflow. All right. $\endgroup$
    – Buttonwood
    Commented Jan 3, 2022 at 17:06
  • $\begingroup$ @orthocresol I vaguely remember that there was a tag-based system to get the request to at least be reviewed by staff. Any recollection of that? Other mods (not only current, not only chemistry) please also advise. $\endgroup$ Commented Jan 3, 2022 at 18:54
  • $\begingroup$ @Martin-マーチン You mean on per-site metas? I think tagging with either feature-request or bug would work. $\endgroup$ Commented Jan 3, 2022 at 19:15
  • 1
    $\begingroup$ I thought there was a moderator only tag approach on the site metas. I guess it's status-review, but I'm hesitant to use my tablet to try and look that up. And I don't know from which corner of my brain this information was collected. It can be old, it could also be a dream.... $\endgroup$ Commented Jan 3, 2022 at 19:19
  • $\begingroup$ @Martin-マーチン Oh, you're right, I forgot about that one. It's here. I'm pretty pessimistic about getting Fortran syntax highlighting, but go ahead and add the tag if you'd like. $\endgroup$ Commented Jan 3, 2022 at 19:21
  • $\begingroup$ I guess it doesn't hurt. Even if they just slap a declined on it, we just know it was looked at and can regard this as settled. $\endgroup$ Commented Jan 3, 2022 at 22:21
  • $\begingroup$ I guess it's good we have remembered that for something else then. It at least works like on mmse if you use the hinting correctly. $\endgroup$ Commented Jan 3, 2022 at 23:09
4
$\begingroup$

TL;DR: No, it isn't. Use lang-fortran as identifier.

Also referring to https://meta.stackexchange.com/a/184109/312770 using triple backticks and a language identifier lang-<lang> or does switch on code highlighting.

We do not have and hence there is no language highlighting associated with it. At least that is my best guess, as it works(ish?) with lang-fortran:

h_core = e1ints
do q =1,norb
    do p =1,q
        h_core(p,q) = h_core(q,p) !lower triangular to symmetric
    end do
end do

Whether or not this actually works correctly is not something I can judge. I see some colour and that is all that I can say.

If it doesn't work correctly, then that might be an issue on the development platform, iirc gitlab or so and such … . So we need to be sure that this works correctly there first.

I have no idea why this works (out of the gate) for as there is currently no highlighting associated with it either. I guess this might be a network wide implementation, a best guess condition or default or … . However, this tag shouldn't exist here anyway. So don't get used to it. (And thanks for pointing this out again.)

So while it might be flawed, it isn't blocked, and following the discussion about introducing code highlighting, the consensus was to explicitly specify it, everything works as well as can be expected. (I guess.)

$\endgroup$
5
  • 1
    $\begingroup$ I briefly mentioned this in my answer, but I'm pretty sure that highlighting is incorrect, and it's instead inferring some other language. I'm guessing that with Python code, it correctly infers that it's Python, but with Fortran code, it infers something else (what exactly, I don't know). I kinda wonder if there's a sneaky way to inspect what's going on, using the browser's JS console or something. $\endgroup$ Commented Jan 3, 2022 at 23:16
  • $\begingroup$ @orthocresol yes, it doesn't look all that correct and it's not in the list. However, if it were in the list, then the lang identifier must be used, as there will not (imo: shall never ever) be tag called fortran and referring to a programming language here. Assuming of course the highlight implementation is correct in the first place. And I'm sure there's a way to look under the hood while is rendering, but I'm not able to come up with such a way. $\endgroup$ Commented Jan 3, 2022 at 23:30
  • $\begingroup$ The colour scheme doesn't match the keywords (in the examples, this were do, end do or endo, write). In Linux Debian and a copy-paste of the snippets, mousepad, gedit, vim, Emacs (even if running by emacs -q) and Emacs org-mode within an explicit code block (either f90 for the free form, or -- if pasted with the heading free columns -- fortran for the fixed form) are examples which «do it the right way» though they are not an IDE like e.g., code::blocks. It simply would be a nice addition. $\endgroup$
    – Buttonwood
    Commented Jan 4, 2022 at 4:47
  • $\begingroup$ (continuation) Geert Jan Bex' MOOC about Fortran on futurelearn a couple of weeks ago didn't use syntax highlights -- labeled as a safety feature.* In contrast to e.g., posts on fortran-lang, (one example, or a nicer one). *) Fear of JS, not Fortran. $\endgroup$
    – Buttonwood
    Commented Jan 4, 2022 at 4:59
  • 1
    $\begingroup$ @Buttonwood I don't understand your comments. The example has colourful words you quote. And it uses the same codebase as Matter Modeling where you say it works. So I really don't know what your comments are about. And I don't understand what should be the takeaway from all the links. There is currently no official support as orthocresol mentioned already, but he has escalated this post, so let's wait. $\endgroup$ Commented Jan 4, 2022 at 19:59
3
$\begingroup$

I wrote about how we handle syntax highlighting in an answer on Meta Stack Exchange to a question requesting that we add highlighting for Julia:

Syntax highlighting happens on the client side currently. This means that if we add too many different languages, the size of the distributable gets very large and can make the site slower to load. While any one language might be a good addition, we get enough language requests that if we added them all, we'd have a long list and a big problem.

I've talked with Ben Kelly, one of our Stacks team developers and, while he really hopes to eventually support nearly all languages that highlight.js supports, it'll require some big changes to how we process syntax highlighting and we don't know when we'll be able to get this work scheduled.

I wrote this in August last year and we haven't made any progress and, as far as I'm aware, we haven't scheduled any work to build this in. Assuming that Fortran highlighting is available in Highlight.JS, we should eventually have highlighting for it at some point in the future, but I don't know when that will be.

$\endgroup$

You must log in to answer this question.

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