On Thu Jan 2, 2025 at 6:47 PM CET, Ihor Radchenko wrote:
> "onf" <o...@disroot.org> writes:
> [...]
> > It's important to understand that troff commands don't really use
> > nesting or a stack as one might be used to from HTML and similar
> > markup languages. That's why it's also not possible to e.g. nest
> > bold and italic like this:
> >   Normal \fBbold \fIbold-italic\fP bold\fP normal
> >
> > ...which actually gives you:
> >   Normal bold italic bold italic
>
> Yikes!
>
> We currently implicitly rely on the assumption that things are working
> differently:
>
>     normal *bold /italic/ bold* normal
>
> is exported as
>
>     .TH "" "1" 
>     .PP
>     normal \fBbold \fIitalic\fP bold\fP normal
>
> and the last "normal" is indeed rendered as italic.
>
> > One has to do one of these instead:
> >   Normal \fBbold \f[BI]bold-italic\fP bold\fR normal
> >   Normal \fBbold \f[BI]bold-italic\fB bold\fR normal
> >   Normal \fBbold\fP \f[BI]bold-italic\fP \fBbold\fP normal
>
> I'm afraid that I'll need to rethink that export algo for ox-man to
> account for this nuance.
>
> Probably, the simplest way implementation-wise will be applying faces to
> each "plain text" segment individually:
>
>    \fRnormal \fR\fBbold \fR\f[BI]italic\fR\fB bold\fR\fR normal\fR

I assume you meant:
  \fRnormal \fP\fBbold \fP\f[BI]italic\fP\fB bold\fP\fR normal\fP

You might find it easier to omit the \fP escapes, since they have
little effect here anyway. Situation might be different if you're
targetting non-troff man processors too, though; no idea how
robust their handling of font changes is.

But I agree; I would track each style change (bold -> not bold,
italic -> not italic) and emit an appropriate \f sequence that
would match the currently active styles after each such change,
like so:
  code & bold & italic  \f[CBI]
  code & bold           \fC\f(CB
  code & italic         \fC\f(CI
  code                  \fC\f(CR
  bold & italic         \f(BI
  bold                  \fB
  italic                \fI
  none                  \fR

Note that \f[CBI] will break in old troffs due to the "new" \f[]
syntax, so a warning should probably be emitted. And I have no
idea how good support for {bold,italic} Courier is in older troffs
either. (That is assuming Org-mode markup allows code to be styled
like that.)

Also note that if a change involving italic happens between two
non-whitespace characters, like so:
  groff(/7/)

...an italic correction should be emitted to prevent the two glyphs
colliding into each other:
  groff(\,\fI7\fR\/)
where:
  \,  is left italic correction
  \/  is right italic correction

~ onf

Reply via email to