24

For people familiar with Fortran and related tag, there is no syntax highlighting. The following post confirms it by listing the supported languages, and Fortran is not in the list.

However, Fortran and related tag are much more popular than other supported programming languages. For example, as at the time of writing this post, we have the following statistics for Fortran and some of the supported languages (less popular one):

language tag total questions tagged
5665
4741
4271
3578
3577
2789
1441

Based on those numbers, it is a good idea for SO to add syntax highlighting for Fortran.

Google added some Fortran highlighting support at Issue 78 and PR #448, Fortran Syntax Highlighting.

Does anyone know if Fortran support will be added soon?

11
  • Wow fortran is still around? I wonder if people still program punch cards?
    – JonH
    Commented Jan 22, 2016 at 19:59
  • 6
    @JonH, well, fortran is still there and it will possibly stays there for a while. The popularity in some industry of capital importance keeps it alive. Fortran77 that follows the rules of punch cards is still the standards where old folks lead. However, there has been tremendous evolution in the fortran standard. fortran 90, 95, 2003 and 2008 have improved the language a lot. And the standard 2015 to be published adds other substantial improvements. Anyway, I get my paycheck from fortran, and the less people who use it, the more chances I have to keep my paycheck
    – innoSPG
    Commented Jan 22, 2016 at 20:14
  • True, but money isn't everything!
    – JonH
    Commented Jan 22, 2016 at 20:14
  • @JonH, the money think was just to kid. I actually use many other programming languages. And if it was the matter of money, I have enough experience to keep newcomer away. But I am also a teacher so I welcome and guide newcomers to replace me in the coming future.
    – innoSPG
    Commented Jan 22, 2016 at 20:17
  • 4
    In that post you linked it is explained that you can't ask SE for adding support, you have to ask the Google code-prettify project to add it first.
    – rene
    Commented Jan 22, 2016 at 20:49
  • @rene, my bad on non paying close attention to that note.
    – innoSPG
    Commented Jan 22, 2016 at 21:11
  • 7
    @JonH The academic, physical science community still relies on Fortran, because a powerful parallelization library for operation on supercomputers (MPI) only works with C++ and Fortran -- and the latter is much friendlier for scientific computing, where we care about ease of array manipulations more than the ability to make abstract classes. It is also blazingly fast, and is what powers numerical weather models (your weather forecasts) and climate models, as well as models in physics, chemistry, and bioinformatics (although these are not my field). Don't be too dismissive.
    – Luke Davis
    Commented Apr 16, 2019 at 23:40
  • @LukeDavis actually, only C and Fortran
    – Scientist
    Commented Oct 24, 2019 at 22:45
  • Still an issue in November, 2019; see How to solve “no reference to” error in gfortran Linux?
    – jww
    Commented Nov 24, 2019 at 6:13
  • 1
    @jww I'm guessing you're noloader from the Github pull request. :P Commented Nov 24, 2019 at 6:30
  • fyi, we write fortran all the time, still very useful for HPC computing
    – Vince W.
    Commented Jul 4, 2020 at 3:20

1 Answer 1

7

From: https://meta.stackexchange.com/a/184109/397248

  1. Check that the language is supported by highlight.js

Look at the list of highlight.js supported languages. If your language is not on the list, it needs to be created within the highlight.js project before it can be deployed by Stack Exchange.

If a language is already on the list but not used on Stack Exchange, please raise a feature request here on Meta to have it deployed on the network.

Fortran is mentioned in the linked file:

| Fortran | fortran, f90, f95 | |

And https://highlightjs.org/static/demo/ has this example on it:

subroutine test_sub(k)
    implicit none

  !===============================
  !   This is a test subroutine
  !===============================

    integer, intent(in)           :: k
    double precision, allocatable :: a(:)
    integer, parameter            :: nmax=10
    integer                       :: i

    allocate (a(nmax))

    do i=1,nmax
      a(i) = dble(i)*5.d0
    enddo

    print *, 'Hello world'
    write (*,*) a(:)

end subroutine test_sub

So the language is already supported by highlight.js.

  1. Check that the language is used by Stack Exchange

Look at the highlight-loader.js file on the dev CDN, open in your favourite editor, and search for the language hint. For example, searching for "dart" brings you to a line consisting of hljs.registerLanguage('dart', .... This means that lang-dart is an available language hint. Searching for "psh" or "powershell" doesn't return any results, meaning that psh is not supported by the Stack Exchange version of highlight.js.

[...]

Language codes currently available on Stack Exchange

But not by StackExchange's version. It's not on the list of "Language codes" and grep -i fortran highlightjs-loader.en.js yields nothing.

With that, it seems that the next step forward is asking for Fortran support on https://meta.stackexchange.com, as mentioned in the second item.

One such request already exists: No syntax highlight for Fortran?

But it was closed and answered with the following:

If this is a feature request for adding a specific language to the current set of syntax highlighting languages, then you should refer to the linked FAQ:

Stack Exchange does not have its own syntax highlighting engine. It uses Google Code Prettify. Therefore, any bugs and feature requests regarding syntax highlighting cannot be handled by Stack Exchange and should be directed to the team behind Google Code Prettify.

In the mean time (as suggested in comment), use lang-pascal as a partial alternative.

Since the close reason made sense at the time and since GCP is not used anymore, I suppose that the right thing to do would be to request it again in a new question.

Note: I don't personally use Fortran, so it wouldn't make sense for me to request it. If you're reading this and want to do so, feel free to copy/paste from my answer.


Original answer below, please ignore. Thanks @rene for the corrections.

> Does anyone know if Fortran support will be added soon?

It works now, thanks to highlight.js:

Goodbye, Prettify. Hello highlight.js! Swapping out our Syntax Highlighter

Example from https://highlightjs.org/static/demo/:

subroutine test_sub(k)
    implicit none

  !===============================
  !   This is a test subroutine
  !===============================

    integer, intent(in)           :: k
    double precision, allocatable :: a(:)
    integer, parameter            :: nmax=10
    integer                       :: i

    allocate (a(nmax))

    do i=1,nmax
      a(i) = dble(i)*5.d0
    enddo

    print *, 'Hello world'
    write (*,*) a(:)

end subroutine test_sub
4
  • 2
    To be fair, the highlighting rendered here is so horrible (based on my use of Fortran) that calling it "working" is a stretch, Commented Oct 19, 2020 at 13:48
  • 1
    @francescalus It indeed does not look too peachy, but I personally don't use Fortran, so I can't comment on it for sure. I just came across this question when searching for the syntax highlighting help section. On the bright side, it's probably easier to make the it look good now that there is at least some level of support. If only someone who knew Fortran could make a PR... (wink wink) github.com/highlightjs/highlight.js/blob/master/src/languages/…
    – kelvin
    Commented Oct 19, 2020 at 14:14
  • 7
    Fortran is not the supported list by SE: meta.stackexchange.com/questions/184108/… what you're seeing is the best effort attempt of the default highlighter.
    – rene
    Commented Oct 19, 2020 at 14:19
  • @rene Ahh that makes sense now. I saw class="lang-fortran s-code-block hljs" in the html and colors in the output, so I assumed that the Fortran highlighter was working. False alarm; sorry about that. Is there any way to check when the default highlighter is in effect?
    – kelvin
    Commented Oct 19, 2020 at 14:33

You must log in to answer this question.

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