• Creating a PDF with source code highlighting

    From Beliavsky@21:1/5 to All on Thu Mar 10 07:19:31 2022
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Duffy@21:1/5 to Beliavsky on Thu Mar 10 21:08:29 2022
    Beliavsky <beliavsky@aol.com> wrote:
    I would like to collect my Fortran tweets https://twitter.com/fortrantip
    into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.

    I was going to suggest Lout, but that is even more of a niche approach
    and you still have to learn the language ;). How about a literate
    programming tool such as noweb, which can be used from the
    WYSIWYG Lyx editor...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Beliavsky@21:1/5 to David Duffy on Thu Mar 10 15:52:07 2022
    On Thursday, March 10, 2022 at 4:08:37 PM UTC-5, David Duffy wrote:
    Beliavsky <beli...@aol.com> wrote:
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.
    I was going to suggest Lout, but that is even more of a niche approach
    and you still have to learn the language ;). How about a literate programming tool such as noweb, which can be used from the
    WYSIWYG Lyx editor...

    I can get Fortran syntax highlighting in HTML by pasting code at http://hilite.me/ , which does recognize Fortran among other languages. Presumably I could find a program that does this. Explanatory text can be added before the HTML block. Once I have an
    HTML file with text and code, there are ways to convert HTML to PDF.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent MAGNIN@21:1/5 to All on Fri Mar 11 08:25:12 2022
    Le 10/03/2022 à 16:19, Beliavsky a écrit :
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.

    Last year, I replaced the LaTeX lstlisting package by the minted package
    in my documents:
    http://tug.ctan.org/macros/latex/contrib/minted/minted.pdf

    It is based on Pygments:
    https://pygments.org/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Vincent MAGNIN on Fri Mar 11 03:49:15 2022
    On Friday, March 11, 2022 at 8:25:20 AM UTC+1, Vincent MAGNIN wrote:
    Le 10/03/2022 à 16:19, Beliavsky a écrit :
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.
    Last year, I replaced the LaTeX lstlisting package by the minted package
    in my documents:
    http://tug.ctan.org/macros/latex/contrib/minted/minted.pdf

    It is based on Pygments:
    https://pygments.org/

    I use Latex quite a bit and the listlisting package is really nice. I do not know minted.

    @beliavsky, we ought to be able to get up and running with Latex again ;). It is not at all difficult, unless you want to do sophisticated things.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gary Scott@21:1/5 to Beliavsky on Fri Mar 11 08:47:32 2022
    On 3/10/2022 9:19 AM, Beliavsky wrote:
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.
    Sounds something ripe for MS Word mail merge via Excel perhaps.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Nagle@21:1/5 to All on Fri Mar 11 09:04:05 2022
    Hi,

    On Mar 10, 2022, Beliavsky wrote
    (in article<da13fa43-db95-40b6-86c0-dbc40f78b993n@googlegroups.com>):

    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.

    Michel Olagnon distributed, at one time, a "tops" program,
    which produced a color-highlighted postscript listing from Fortran source.

    I can't find a link now. :-(

    I might be able to find a copy, contact me if all else fails. :-)

    (If you have access to /glade, there might be a copy under ftools.)

    --
    Cheers!

    Dan Nagle

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Sat Mar 12 07:18:07 2022
    Do not know of a perfect solution out of the box, but know some places I would look.

    I have used many utilities over time but some like f90ppr appear to be gone, or have not been kept up to date (enscript, ...) and you are posting modern syntax, so some that are up to date or nearly or still being updated that are non-commercial include
    lfortran, which can generate colorized output and emacs and vim, and the highlighters used primarily by extended markdown.

    LFortran is under development and most likely to do submodules and more recent features properly, there are a lot of examples of how to extract the highlighted text from vim and emacs, I think the shell script by Steve Kinzler called colorize is a good
    example for getting HTML from vim without knowing vim, pandoc should be able to convert an extended markdown file but you might have to install the colorizers as separate packages, .... there are other pretty printers and colorizers that are parts of
    commercial compilers (so depends on what you have) and colorizers (mostly for supporting markdown variants) that are useable as seperate packages.

    Did you find what you wanted?

    Since the editors and web forums often support highlighters.

    github and ford and doxygen are all using Fortran highlighters that might be seperate packages as well.

    Did not expect the Olagnon site to disappear. There was quite a bit there still linked to by other sites like the Fortran Wiki

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Sat Mar 12 08:59:12 2022
    One example using pandoc(1) on a linux box with bash(1). Make the Fortran file into an extended markdown file by adding ```fortran and ``` header and footer and use pandoc(1) to make and Adobe PDF file. read the PDF file into an HTML file using <IFRAME
    . IFRAME gives you more control over geometry than <A....>. Could just do it as a markdown file and convert to HTML, etc. LOTS of options to play with with pandoc. Requires latex to be installed underneath for this particular pandoc command. Not a
    very robust script, but it shows the steps.

    #!/bin/bash
    set -x
    FFILE=${1:-/tmp/dice.f90}
    (
    echo '```fortran'
    cat $FFILE
    echo '```'
    ) >/tmp/show.md
    pandoc /tmp/show.md -s -o /tmp/fortran.pdf --highlight-style=kate -V geometry:margin=1in
    cat >/tmp/show.html <<\EOF
    <!DOCTYPE html>
    <html>
    <head>
    <title>Title of the document</title>
    </head>
    <body>
    This is some text to show
    <h1>PDF Example with iframe</h1>
    <iframe src="fortran.pdf" width="80%" height="500px">
    </iframe>
    </body>
    </html>
    EOF
    cd /tmp
    xdg-open show.html
    exit

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Sat Mar 12 10:04:01 2022
    lfortran fmt code.f90 |ansi2html >code.html

    worked well with several modern Fortran files for coloring it; ansi2html is at

    https://raw.githubusercontent.com/pixelb/scripts/master/scripts/ansi2html.sh

    Did not see a way to write HTML directly from lfortran, although I thought there was one.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Beliavsky@21:1/5 to John on Sat Mar 12 13:46:14 2022
    On Saturday, March 12, 2022 at 1:04:04 PM UTC-5, John wrote:
    lfortran fmt code.f90 |ansi2html >code.html

    worked well with several modern Fortran files for coloring it; ansi2html is at

    https://raw.githubusercontent.com/pixelb/scripts/master/scripts/ansi2html.sh

    Did not see a way to write HTML directly from lfortran, although I thought there was one.

    Thanks for this and your other suggestions. I emailed Michel Olagnon at Michel dot Olagnon at ifremer dot fr , but it bounced. It would be nice if someone who
    has saved his tools can upload them. I may request this at Fortran Discourse in a week.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MAGNIN Vincent@21:1/5 to All on Sun Mar 13 12:38:45 2022
    Here is a minimalist LaTeX document to start with. Under ubuntu, you
    need the package python3-pygments. And you can compile the LaTeX file with:
    $ pdflatex -shell-escape poly_algo.tex


    \documentclass[12pt,english,a4paper]{book}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}

    \usepackage{xcolor}
    \definecolor{bg_listing}{rgb}{0.95,0.95,0.95}

    \usepackage{minted}
    \setminted[Fortran]{linenos, autogobble, breaklines, breakanywhere, bgcolor=bg_listing}
    \setminted[Bash]{style=bw, frame=single, breaklines, breakanywhere}
    \setmintedinline{bgcolor={}}

    \begin{document}

    \tableofcontents

    \chapter{Introduction}

    \chapter{Fortran Tip}

    \section{Bitwise}

    \begin{minted}{Fortran}
    program bitwise
    implicit none
    print*,iand(1,1),iand(1,0),iand(0,1),iand(0,0) ! 1 0 0 0 print*,iand(2,2),iand(2,1),iand(2,0) ! 2 0 0 print*,ior(1,1),ior(1,0),ior(0,1),ior(0,0) ! 1 1 1 0 print*,ieor(1,1),ieor(1,0),ieor(0,1),ieor(0,0) ! 0 1 1 0 print*,iany([1,1]),iany([1,0]),iany([0,0]) ! 1 1 0
    end program bitwise
    \end{minted}

    \end{document}


    Le 11/03/2022 à 12:49, Arjen Markus a écrit :
    On Friday, March 11, 2022 at 8:25:20 AM UTC+1, Vincent MAGNIN wrote:
    Le 10/03/2022 à 16:19, Beliavsky a écrit :
    I would like to collect my Fortran tweets https://twitter.com/fortrantip into a PDF where the codes are in boxes with syntax highlighting. What software would you recommend for creating such a document?

    I used LaTeX decades ago. It's powerful, but I have forgotten how to use it.
    Last year, I replaced the LaTeX lstlisting package by the minted package
    in my documents:
    http://tug.ctan.org/macros/latex/contrib/minted/minted.pdf

    It is based on Pygments:
    https://pygments.org/

    I use Latex quite a bit and the listlisting package is really nice. I do not know minted.

    @beliavsky, we ought to be able to get up and running with Latex again ;). It is not at all difficult, unless you want to do sophisticated things.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to MAGNIN Vincent on Tue Mar 15 06:53:43 2022
    On Sunday, March 13, 2022 at 12:38:48 PM UTC+1, MAGNIN Vincent wrote:
    Here is a minimalist LaTeX document to start with. Under ubuntu, you
    need the package python3-pygments. And you can compile the LaTeX file with:
    $ pdflatex -shell-escape poly_algo.tex


    \documentclass[12pt,english,a4paper]{book}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}

    \usepackage{xcolor}
    \definecolor{bg_listing}{rgb}{0.95,0.95,0.95}

    \usepackage{minted}
    \setminted[Fortran]{linenos, autogobble, breaklines, breakanywhere, bgcolor=bg_listing}
    \setminted[Bash]{style=bw, frame=single, breaklines, breakanywhere} \setmintedinline{bgcolor={}}

    \begin{document}

    \tableofcontents

    \chapter{Introduction}

    \chapter{Fortran Tip}

    \section{Bitwise}

    \begin{minted}{Fortran}
    program bitwise
    implicit none
    print*,iand(1,1),iand(1,0),iand(0,1),iand(0,0) ! 1 0 0 0 print*,iand(2,2),iand(2,1),iand(2,0) ! 2 0 0 print*,ior(1,1),ior(1,0),ior(0,1),ior(0,0) ! 1 1 1 0 print*,ieor(1,1),ieor(1,0),ieor(0,1),ieor(0,0) ! 0 1 1 0 print*,iany([1,1]),iany([1,0]),iany([0,0]) ! 1 1 0
    end program bitwise
    \end{minted}

    \end{document}

    I ran into difficulties using TeXnicCenter on WIndows (I was supposed to run Latex with some option). So I tried the example with the listings package. Here is the Tex code:

    \documentclass[12pt,english,a4paper]{book}

    %\usepackage[utf8]{inputenc}
    %\usepackage[T1]{fontenc}
    %\usepackage{lmodern}
    %
    %\usepackage{xcolor}
    %\definecolor{bg_listing}{rgb}{0.95,0.95,0.95}
    %
    %\usepackage{minted}
    %\setminted[Fortran]{linenos, autogobble, breaklines, breakanywhere, %bgcolor=bg_listing}
    %\setminted[Bash]{style=bw, frame=single, breaklines, breakanywhere} %\setmintedinline{bgcolor={}}

    \usepackage{xcolor}
    \usepackage{listings}

    \definecolor{codegreen}{rgb}{0,0.6,0}
    \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} \definecolor{backcolour}{rgb}{0.95,0.95,0.92}

    \lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{blue},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
    }

    \lstset{style=mystyle}
    \lstset{language=Fortran}


    \begin{document}

    \tableofcontents

    \chapter{Introduction}

    \chapter{Fortran Tip}

    \section{Bitwise}

    \begin{lstlisting}[language=Fortran]
    program bitwise
    implicit none
    print*,iand(1,1),iand(1,0),iand(0,1),iand(0,0) ! 1 0 0 0 print*,iand(2,2),iand(2,1),iand(2,0) ! 2 0 0 print*,ior(1,1),ior(1,0),ior(0,1),ior(0,0) ! 1 1 1 0 print*,ieor(1,1),ieor(1,0),ieor(0,1),ieor(0,0) ! 0 1 1 0 print*,iany([1,1]),iany([1,0]),iany([0,0]) ! 1 1 0
    end program bitwise
    \end{lstlisting}

    \end{document}

    Just an alternative, mind you :).

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)