bug-texinfo
[Top][All Lists]
Advanced

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

Re: @ref in @multitable broken in Info output if split across lines


From: Patrice Dumas
Subject: Re: @ref in @multitable broken in Info output if split across lines
Date: Mon, 9 Feb 2015 02:04:04 +0100
User-agent: Mutt/1.5.20 (2009-12-10)

On Sun, Feb 08, 2015 at 02:42:56PM +0000, Gavin Smith wrote:
> On Fri, Feb 6, 2015 at 11:54 PM, Karl Berry <address@hidden> wrote:
> > Possibly any xref command inside a multitable should be implicitly
> > handled as if enclosed in @w, to avoid the unable-to-find-the-reference
> > problem.
> 
> Here's a possible fix.

The use of 'w' looks good to me.


There are potential issues with things like
  $in_multitable = 1;
and 
  grep in @{$self->{'format_context'}}
if there are some nestings.  I don't remember if nested @*ref are 
allowed, but if it is the case the $in_multitable variable will
be set to 0 upon getting out of the @*ref within.  Then there are more
complicated cases, such as footnotes as they may appear almost
everywhere and contain everything, including a @multitable with an @xref
within or @xref not within a multitable.

A test would be needed to know for sure, but in general it is not really
possible to use simple variable booleans, nor determine from the point
of view of a variable in which @-command it is.  In general, you have to
find the "context" that is relevant for the information, and add it to
that context with ++ and -- to be sure that everything goes well in case
of nesting (or a stack using an array in more complicated cases).  

A case of a nesting of multitable footnote xref leads the grep in
@{$self->{'format_context'}} to consider that the context is a
multitable context while it is not the case.

I may have overlooked something, but I do not see any existing context
correct for detecting whether the xref is in multitable or not, in which 
'in_multitable' could be incremented when entering a @multitable and
decremented when exiting, and that would have another context stacked
only if going in a @footnote.  Indeed, 'text_element_context' and
'format_context' are reset by many @-commands, 'context' is better but
still reset by @math or @flushright.

So I think that you need to add a new context that is set by @footnote 
or be the main document context.  My advice would be to add it in 
push_top_formatter, which is called by @footnote and when initializing 
the main document context, like

push @{$self->{'document_context'}}, {
    'in_multitable' => 0
  }

And not forget to pop it when leaving a footnote (l. 866) (and also
probably in l. 3314 though I don't really remember what it corresponds 
to).

And then when entering a @multitable there would be a
  @{$self->{'document_context'}}->[-1]->{'in_multitable'}++
and when leaving, a
  @{$self->{'document_context'}}->[-1]->{'in_multitable'}--

and then in xref, the 'in_multitable' in document_context would be
quieried like
if (@{$self->{'document_context'}}->[-1]->{'in_multitable'})

> Index: Plaintext.pm
> ===================================================================
> --- Plaintext.pm        (revision 6106)
> +++ Plaintext.pm        (working copy)
> @@ -2013,6 +2013,26 @@ sub _convert($$)
>            $args[3] = $args[2];
>            $args[2] = undef;
>          }
> +
> +        # Treat cross-reference commands in a multitable cell as if they
> +        # were surrounded by @w{ ... }, so the output will not be split 
> across
> +        # lines, leading text from other columns appearing to be part of the
> +        # cross-reference.
> +        #
> +        # Normally in this case, $self->{'format_context'}->[-2]->{'cmdname'}
> +        # is 'multitable' and $self->{'format_context'}->[-1]->{'cmdname'} is
> +        # one of 'headitem', 'item' and 'tab', but it is possible for other
> +        # contexts to follow (like 'quotation').  Hence we check if
> +        # 'multitable' occurs anywhere in the stack of format contexts.
> +        my $in_multitable = 0;
> +        if (grep {$_->{'cmdname'} eq 'multitable'}
> @{$self->{'format_context'}}) {
> +          $in_multitable = 1;
> +          $formatter->{'w'}++;
> +          $result .= $self->_count_added($formatter->{'container'},
> +            $formatter->{'container'}->set_space_protection(1,undef))
> +          if ($formatter->{'w'} == 1);
> +        }
> +
>          if ($command eq 'xref') {
>            $result = $self->_convert({'contents' => [{'text' => '*Note '}]});
>          } else {
> @@ -2112,6 +2132,13 @@ sub _convert($$)
>              unshift @{$self->{'current_contents'}->[-1]}, @added;
>            }
>          }
> +
> +        if ($in_multitable) {
> +          $formatter->{'w'}--;
> +          $result .= $self->_count_added($formatter->{'container'},
> +              $formatter->{'container'}->set_space_protection(0,undef))
> +            if ($formatter->{'w'} == 0);
> +        }
>          return $result;
>        }
>        return '';
> 



reply via email to

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