Search code examples
linuxcommand-line-interfacelesspandocfile-format

I want to write a document to be viewed via the 'less' command. Where can I find the formatting standards specifications?


I would like to convert Markdown files so these can be viewed via less...

However, I want the formatting (bold, italic, etc.) to be preserved and displayed accordingly... Unfortunately I cannot find the specifications.


My preferred approach would have been to use Pandoc to convert the md-files into a file type that less can properly display...


Solution

  • Files of any format supported by pandoc can be read like Unix man pages:

    pandoc --standalone --to=man INPUT_FILE | man -l -
    

    This uses less by default, unless you have the PAGER variable set to some other value.

    A good way to use it is to create a shell function:

    mandoc () { pandoc --standalone --to=man "$@" | man -l - }
    

    Now you can read files using Markdown, docx, LaTeX, etc. as if they were manpages.

    mandoc README.md
    mandoc term-project.tex
    mandoc thesis.docx
    # and so on
    

    As you can see, the command causes pandoc to convert its input to a format called man, which is really groff man (see https://man.cx/groff_man(7)).