[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proper usage of .rd? Tutorial or Example?
From: |
Oliver Corff |
Subject: |
Re: Proper usage of .rd? Tutorial or Example? |
Date: |
Tue, 3 Dec 2024 21:57:27 +0100 |
User-agent: |
Mozilla Thunderbird |
Hi onf,
thank you very much for your kind suggestions.
I thought of precomposed files as well, but what I really want is to
make groff collect the necessary data during the compile run by
prompting the user at the CLI, very much like the original mail user agent.
Let's say I have a roff file named invoice.roff, and if I start the
compilation with
$ groff {macro package and preprocessor options} my_invoice.roff -Tpdf
it would, via .rd or any other suitable mechanism, prompt me for
$ Recipient: [user input] ACME
(a macro would then check for the existence of a recipient ACME and fill
in all data, and if not, will ask me to provide the necessary
information, which will be used for the current invoice and stored in
the recipient list)
$ Billable item:
$ Unit price:
$ Number of units:
$ New Item? <Y/N>:
etc.
until I signal that there is no more new item to follow.
Whenever a complete data set of Billable item, Unit price and Number of
units is gathered, a new line of code for a tbl is generated, while the
signal "end of items" will complete the tbl data and finish the
compilation run.
I once did a vaguely similar thing in LaTeX (the invoice package),
however here the user still has to enter the invoice data by saying
\Fee{<Item name>}{<unit price>}{<number of units>}; depending on the
number of \Fee{}{}{} lines the table was created dynamically. The main
idea of the invoice package was to spare the user all the overhead that
goes into constructing a table with sectional headers etc.
So, here I want to go a step further and make groff ask the user
directly for the data, without any need to produce anything which is
already in groff syntax.
I could, of course, also write something in any script language that
converts my input into roff data, but I thought it would be nice to have
groff do the job directly.
Best regards,
Oliver.
On 03/12/2024 21:40, onf wrote:
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
--
Dr. Oliver Corff
mailto:oliver.corff@email.de
Re: Proper usage of .rd? Tutorial or Example?, Deri, 2024/12/03