groff
[Top][All Lists]
Advanced

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

Re: [Groff] Creating a table macro


From: Ted Harding
Subject: Re: [Groff] Creating a table macro
Date: Thu, 19 May 2011 07:47:30 +0100 (BST)

Ah, yes, I had overlooked temporarily disabling escaping
by using .eo anc .ec!

However, with the standard groff pipeline (tbl before troff)
you still cannot make a macro where the number of arguments
can be computed per-call. This is for the same reason as
before, namely that tbl has done its work (and therefore
set the column layout, including the number of columns)
once and for all on the first pass. tbl does not have any
looping facility -- nor indeed any facility for computing
anything once the initial format lines have been read in.

Nevertheless, it is in principle possible to work round
this by including in your macro a command to troff (using
the ".sy" request) to cause it to run tbl at partiocular
points during the execution of troff. Full flexibility
involves writing the relevant troff/tbl input lines to
a temporary file, processing these externally to compute
the required tbl header lines, feeding these to tbl,
and then feeding the tbl data lines to tbl, with tbl
writing its own output to a temorary file. Finally troff
reads in this second temporary file.

I will try to work out a suitable example of this for the
type of table that you describe. This approach also has the
advantage that you could make multiline tables with the
number of lines dependent on what is present at any given
call of the macro.

The procedure for doing all this is somewhat intricate,
but if carefully done it generally works well (also for
other preprocessors like pic and eqn).

Are you using a UNIX/Linux or similar (e.g. Mac OS X) system?

Till later,
Ted.


On 18-May-11 20:16:37, Automation Department wrote:
> 
> Thanks Ted. That answers my question.
> 
> This macro from:
> 
> http://www.port.de/cgi-bin/groff/TableInMacro
> 
> works as you describe -- ( includes .TE ):
> 
> .eo
> .de ATABLE ..
> .TS
> allbox tab(;);
> cl.
> \$1;\$2
> .TE
> ...
> .ec
> 
> ...with the limitation of not allowing an arbitrary number of
> arguments.
> Is it possible to toss in a while loop -
> 
> .while ( args > 0) \{\
>       ....etc
> \}
> 
>  to process unknown number of arguments?
> 
> Looking through the mans and docs on while loops in groff, but will not
> inquire further if this is not possible.
> 
> Thanks again.
> 
> Chad Roseburg
> 
> 
> On 05/18/2011 12:00 PM, (Ted Harding) wrote:
>> On 18-May-11 01:59:23, Automation Department wrote:
>>> Would like to create a very simple table macro.
>>> eg.,
>>>
>>> .de TABLE
>>> .TS
>>> box expand;
>>> l s
>>> l l.
>>> \fI\\$1\fP
>>>
>>> ..
>>>
>>> This does not work though other similarly crafted macros do.
>>> It 'starts' the macro at the macro definition. Do I need to
>>> escape it?
>>>
>>> Also, if I just do:
>>>
>>> .de TABLE
>>> box expand;
>>> l s
>>> l l.
>>> \fI\\$1\fP
>>>
>>> ..
>>>
>>> Then call with
>>>
>>> .TS
>>> .TABLE "Macro Junk"
>>> column1       column2
>>> .TE
>>>
>>> I get:
>>> tbl:final_rpt.roff:369: `.' not last character on line
>>> tbl:final_rpt.roff:369: giving up on this table
>>>
>>> Just hoping to save some typing.
>>>
>>> Thanks!
>>> - -- 
>>> Chad Roseburg
>> 
>> To deal first with your second example:
>> 
>> The problem here is that the "." at the beginning of the
>> second line will be interpreted as the "." that normally
>> occurs at the end of the formatting lines. Note that this
>> is different from the interpretation of "." when it occurs
>> in a numerical context, such as when you are defining a
>> minimum column width -- e.g.
>> 
>>   .TS
>>   box
>>   lw(1.5i) l.
>> 
>> since that occurs inside "w()" where tbl is expecting
>> to find a numerical expression. When the "." occurs at
>> "top level" as in your ".TABLE ..." it will be taken at
>> "face value", i.e. as the terminator for the formatting.
>> 
>> Now for your first example. The problem here is that
>> your macro ".TABLE" will be interpreted by troff, not
>> by the preprocessor tbl. Note *pre*processor -- tbl
>> does its work before troff sees the results. If troff
>> expands a macro (such as your .TABLE) then it is too
>> late -- the processing has moved on past tbl.
>> 
>> Incidentally, you will get no result at all unless you
>> include the ".TE" at the end of the macro definition,
>> as in
>> 
>> .de TABLE
>> .TS
>> box expand;
>> l s 
>> l l.
>> \fI\\$1\fP
>> .TE
>> ..
>> .TABLE "Macro Junk"
>> 
>> but even then it will not be the result you want. This
>> is because tbl has already done its work, as explained
>> above, as you can verify by deleting the line
>> .TABLE "Macro Junk"
>> (thus not calling the macro at all) -- tbl sees the .TS
>> and .TE, ignores the fact that they are inside a macro
>> definition (tbl does not recognise macros), and simply
>> creates troff code for what it finds between them.
>> 
>> Probably the simplest way to "save some typing" is to
>> use the copy-&-paste functionality of your editor to
>> copy down an existing instance of the table setup lines.
>> Some editors will alow you to define a block of text
>> and give it a name, so that when you invoke the name
>> it will automatically insert the whole block.
>> 
>> Hoping this helps,
>> Ted.
>> 
>> --------------------------------------------------------------------
>> E-Mail: (Ted Harding) <address@hidden>
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 18-May-11                                       Time: 20:00:01
>> ------------------------------ XFMail ------------------------------

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 19-May-11                                       Time: 07:47:26
------------------------------ XFMail ------------------------------



reply via email to

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