groff
[Top][All Lists]
Advanced

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

Re: [Groff] Macro arguments question


From: Tadziu Hoffmann
Subject: Re: [Groff] Macro arguments question
Date: Mon, 14 Nov 2005 12:34:19 +0100
User-agent: Mutt/1.5.6i

> > But this is a consequence of wrapping it in \{...\}, so if
> > you just remove the quotes from your argument it comes out
> > right.

No, this interpretation appears to be incorrect.  The \{...\}
is at best ineffective here.  You can see this if you define
the macro as follows:

.de temp
# args: \\n(.$
.br
first arg: \(->\\$1\(<-
.if '\\$1'' (empty argument)
.br
..

\{ and \} only work with if, ie, and el.  In ".temp \{", the
macro gets called with one argument, which, however, expands
to an empty string.  The rest of what was intended to be the
macro argument is simply text that follows the macro, and is
not part of the macro argument.

> [...] and using \{-\} pairs keeps the quotes.  

See above.  The quotes are kept because quotes are always kept
in normal text.  They're only eaten up in macro expansions, and
in this case they're not part of a macro expansion.

As Ted already said, the correct way to have a macro argument
extend over several lines is to escape the end-of-line with a
backslash, effectively making the argument a single line.  Thus,
you can't really preserve the line breaks in the argument (e.g.,
printing the argument in no-fill mode will print a single line,
not several lines).  Furthermore, you can't use the technique if
your argument itself stems from a macro expansion (unlike TeX,
troff's syntax doesn't allow nesting of macro calls).  In this
case perhaps the best solution would be to have the macro store
the text in another macro, and then expand this when and where
necessary.


> I'm now having trouble with switching environments (something
> I've never properly understood).  I supposed that if you
> define a new environment, it would "inherit" the old
> environment except for re-defined variables, and when you
> switch back, it restores the old environment values (like a
> Unix shell would do).  Thus, if you have a .ps 12 and .vs 14
> before entering the new environment, it should maintain that
> size and leading.  However, in practice it seems to use a
> smaller (default?) size instead, unless I redefine the point
> size inside the new environment ("info groff" in my Cygwin on
> Windows 98 doesn't make that very clear).

For this purpose groff has the "evc" ("environment copy")
request, which copies (part of) the specified environment to
the current environment.


> On the other hand, if I redefine the .po and .ll values, the
> .po seems to work, but groff was running the text on the right
> to the end of the sheet before starting the next line.
> However, that seems to all be cleared up now.  [If this is
> confusing, it's because I'm a bit confused.]  But what I am
> seeing is that if I switch to .ev 1 and redefine ".po 3i"
> instead of ".po 1i", when I go back to the original
> environment, the page offset remains at 3i instead of going
> back to the old value while the line length seems to go back
> to its old value, running the text to the right side of the
> sheet(.po and .ll without arguments before the ".ev" request
> fixes the problem but doesn't look "clean".

See the troff users manual for a quick overview over which
parameters are part of the environment (section "request
summary").  The page offset is not part of the environment,
but the line length is.


> The way I see it now, it seems that before switching the
> environment, I seem to need to make a .br request at the start
> of the macro definition or make sure a .sp or something causes a
> break, then switch environments, do what I need to do, issue
> another .br, then switch the environment back.

Unless of course you *don't* want to interrupt the running
text, as, for example, in a page header or a floating keep.






reply via email to

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