groff
[Top][All Lists]
Advanced

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

Re: [Groff] LaTeX-style `emph'


From: Werner LEMBERG
Subject: Re: [Groff] LaTeX-style `emph'
Date: Wed, 04 Dec 2002 00:23:46 +0100 (CET)

> Has anyone come up with a good way to implement a LaTeX-style emph -
> i.e., switches to italic font if the current font is roman, but
> roman if it is italic.  I thought of the following:
>
> .ds emph \R'nF (3-\\n(.f)'\f[\\n(nF]\\$1\fP
>
> but this is not very robust and only works for R <-> I (and it
> completely failed when I was using it in a refer database - maybe
> because the refer fields are themselves read into string
> registers?).  Any such string should also be able to turn B into BI
> and vice versa.  Who can do better?

What about this:

  .ds emphTR  TI
  .ds emphTI  TR
  .ds emphTB  TBI
  .ds emphTBI TB
  .
  .ds emphHR  HI
  .ds emphHI  HR
  .ds emphHB  HBI
  .ds emphHBI HB
  .
  .ds Emph \E*[emph]
  .ds emph \f[\\*[emph\\n[.fn]]]
  .
  .ft R
  This is normal text.
  \*[Emph]This is emphasized.
  \f[]This is normal again.
  .br
  .
  .ft I
  This is normal text.
  \*[Emph]This is emphasized.
  \f[]This is normal again.
  .br
  .
  .de xxx
  .  nop \F[H]\*[Emph]\F[]
  ..
  .
  .ft R
  .xxx "This is a \*[Emph]test\f[] for Emph."
  .br

This is quite elegant but has the disadvantage that you have to
`register' different font families.  Note the definition of `Emph' and
`emph': Similar to LaTeX's \protect command, `\E' prevents that
expansion happens too early (which would give wrong values to the
number registers), making it suitable even for macro arguments.

The following lengthy solution works for all families.  In a macro
package, the first four lines of the `emph' string should be called
while selecting the font family.

  .ds emph \
  \f[R]\R'tmp \\n[.f]'\f[]\
  \f[I]\R'emph\\n[tmp] \\n[.f]'\R'emph\\n[.f] \\n[tmp]'\f[]\
  \f[B]\R'tmp \\n[.f]'\f[]\
  \f[BI]\R'emph\\n[tmp] \\n[.f]'\R'emph\\n[.f] \\n[tmp]'\f[]\
  \f[\\n[emph\\n[.f]]]

I have not tested whether these solutions work with `refer'.

> (BTW, as I play around with inline macros like this, I keep thinking
> that groff needs some kind of inline conditional - is this
> possible?)

Make some syntax suggestions.


     Werner

reply via email to

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