quoting a (part of) linux man page in a writer document

I write Linux system administration documents.

I need to quote man pages in whole or in parts in my own documents, with my own formatting, using styles.

What is the most effective way to do it ? (quickest/simplest).

TIA

Getting started with professional text composition in Writer

What is your source text? Do you insert screenshots (images)? Do you retrieve the original text from some file? I think it is troff formatted in the man directories; therefore the formatting directives must be removed or “translated” into styles.

To better answer your question, mention OS name (some Linux distro presumably), LO version and save format.

For illustration purpose, attach an example (limited to 2 pages).

ask114147.odt (31.3 KB)

Not the easiest setup, but I would try to write a python-converter like the man2xml mentioned in the link below.
This aproach can adapt easiest to possible changes in the man-files…
https://www.linuxquestions.org/questions/linux-newbie-8/man-pages-in-json-or-xml-format-930670/
.

1 Like

Thank you to all of you who commented my question.

As “new users can only mention 2 users in a post”, I won’t address the posters individually.

Because I’m more interested in the information than presentation, I prefer not to investigate the man pages formatting chain (a terra incognita for me).

For the same reason, I don’t want to deal with raw files.

Remember, there is a first step : locating the needed information. It’s easier for me to browse the man pages in the konsole and copy the pertinent information to the clipboard.

I’m building a POC based on a perl script to remove the newlines, called as KDE klipper action.

Until now, I select the man page lines displayed in a konsole window, and I paste them in the writer window.

Tried a few paste options, but I can’t avoid a lot of editing to remove extra linefeeds.

I’m looking for another way to proceed.

A visual inspection and selection step is mandatory, as I need to include only the pertinent lines or words
sample.odt (13.8 KB)
.

Libreoffice version: 24.8.1.2 (X86_64) LibreOffice Community Build ID: 480(Build:2)
Operating System: openSUSE Leap 15.5
KDE Plasma Version: 5.27.9
Kernel Version: 5.14.21-150500.55.83-default (64-bit)

If you want to have control over text formatting attributes, you always use the paste-special command in order to paste characters only from a browser or other formatted text contents. Text pasted directly from a terminal is plain text anyway (as far as I know).
If you want many documents like the one I’ve uploaded, do the following preparation:

  1. Open a new document.
  2. Modify paragraph style “Formatted Text” with black background and white font.
  3. menu:File>Templates>Save… and give a name to the template.

From now on, when you create new documentation:

  1. Create a new document based on your template via menu:File>Template>Manage [Ctrl+Shift+N] (or choose the template view on the welcome screen)
  2. Write your text and whenever you need to insert terminal text from clipboard, insert a new paragraph (Enter key), double-click paragraph style “Formatted Text” and paste-special unformatted text.

When you right-click>Edit a template in the template manager, you can edit the template itself.

menu:Edit>Find&Replace…
Check option “regular expressions” and possibly “current selection only”
Search: ^$
Replace with nothing

@argnou
Defining new styles like man_page_extract is the right way to go. However the key step in the process is extracting data from the manual. To avoid issues with linewraps which may be paragraph or line breaks (your sample shows a line break), I suggest you work directly with man data. It is located at /usr/share/man/man<xy> (xhare x is “chapter” number and y an optional modifier).

The files are .gz. Expand them and copy what you need from them. Take care that their formatting is different from ODF and you need to “translate” bold, italic, underline, … to the proper style (I recommend you use character styles for this instead of direct formatting). The difficult part will be to design an adequate list style (and perhaps several) for man lists (e.g. list of options, defintions, …).

I don’t know if your sample is a quick’n’dirty one. In any case, in your final document, don’t use Default Paragraph Style: it is the ancestor of all others and what you set here is forwarded to all others. This is handy for document-wide preferred attributes but leads to formatting hell if you apply it to topic text. Also don’t space vertically with empty paragraphs. They’ll play nasty tricks on your back sooner or later. Incorporate spacing in your paragraph styles.

Following the suggestions already given by @Wanderer, just try on commandline:

sudo apt-get install doclifter groff  # replace »apt-get« with something like yum … 
man -Thtml ls > ls_man_page.html  # convert $(man ls) to ….html
»your-webbrowser« ls_man_page.html