groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper usage of .rd? Tutorial or Example?


From: onf
Subject: Re: Proper usage of .rd? Tutorial or Example?
Date: Tue, 03 Dec 2024 21:40:49 +0100

Hi Oliver,

On Tue Dec 3, 2024 at 4:52 PM CET, Oliver Corff wrote:
> my intention is to write a form letter mechanism that produces invoices.
> I want to select from a number of predefined recipients and set up an
> invoice which is filled with items like:
>
> Item    Value (EUR)
> A    100
> B    200
> =========
> Sum: 300
>
> I thought of using .rd to read Items and Values from stdin, perhaps with
> a prompt. If I say
>
> .rd Item
>
> I get the prompt "Item:" and can enter a name. However, the input then
> becomes immediate part of the text (analogue to .so).
>
> At the moment I am stuck with passing the values read by .rd to anything
> but immediate text. However, I'd like to store the keyboard input read
> by .rd to strings so I can construct a tbl with the collected data.
>
> I searched man 7 groff which only states "Read insertion" for .rd, the
> texinfo manual has more information but I cannot find information on how
> to absorb the input read by .rd into a variable.

There are several approaches that come to mind.

You can create a script which reads such data, transforms them into
the appropriate requests (e.g. `ds`), and saves them to a file,
then source this file with .so.

But if the number of items is variable (as is likely the case),
it might be easier to generate the troff input directly without
using the strings as an intermediary.

Alternatively, if all you are seeking is a table, sourcing the data
as a TSV inside a tbl block and using the soelim preprocessor is the
easiest way to do it, like so:
  .TS
  expand nokeep;
  cb cb
  l n.
  .so data.tsv
  .TE

where data.tsv looks like this:
  Item  Value (EUR)
  A     100
  B     200
  _
  Sum:  300

I am attaching an example of the second approach which generates
the sum automatically.

~ onf

Attachment: gen-invoice
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]