bug-texinfo
[Top][All Lists]
Advanced

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

Re: protection of space inside @w is wrong


From: Patrice Dumas
Subject: Re: protection of space inside @w is wrong
Date: Thu, 20 Oct 2022 22:37:10 +0200

On Thu, Oct 20, 2022 at 07:39:51PM +0100, Gavin Smith wrote:
> In texi2any, as well as stopping line breaks, multiple spaces are
> protected, so @w{a  b} outputs as 'a  b' not 'a b'.

Indeed.  I have not checked, but I think that it dates back to makeinfo
in C.  It follows the same logic in HTML.

> (However, I checked that in contexts where you would like multiple spaces
> to be protected, like @samp{a  b}, this doesn't happen.)

I don't get the point above.  To me, in @samp{a  b} you do not want
anything special to be done to spaces, such that a double space should
become a simple space in the plaintext/Info output.  It can remain a
double space in HTML, LaTeX, DocBook...

> I've got code written for this (at bottom of mail).  However, since this
> is quite a major change to what @w does, and stems from confusion and/or
> disagreement about the purpose of @w, and since it is does not appear to
> be causing any problems for anybody at the moment, I propose that this
> change (and any others for @samp, @code etc.) be delayed until after the
> Texinfo 7.0 release.

I agree that it should be delayed, I would not be surprised if users
were assuming that spaces are kept as is in Info in @w.  I checked the
manual, nothing is explicitely said about double spaces in @w.  To me
keeping all spaces in @w seemed in line with the description, but it
could also be otherwise as you propose in the patch (something similar
would need to be done for HTML).

> 
> 
> diff --git a/tp/Texinfo/Convert/ParagraphNonXS.pm 
> b/tp/Texinfo/Convert/ParagraphNonXS.pm
> index 1cb442846b..b947fb675e 100644
> --- a/tp/Texinfo/Convert/ParagraphNonXS.pm
> +++ b/tp/Texinfo/Convert/ParagraphNonXS.pm
> @@ -330,17 +330,19 @@ sub add_text($$)
>        print STDERR "SPACES($paragraph->{'counter'}) `"
>            ._print_escaped_spaces($spaces)."'\n" if $debug_flag;
>        if ($protect_spaces_flag) {
> -        $paragraph->{'word'} .= $spaces;
> -        $paragraph->{'last_char'} = substr($spaces, -1);
> -        $paragraph->{'word_counter'} += length($spaces);
> -        $paragraph->{'word'} =~ s/\n/ /g;
> -
> -        # The $paragraph->{'counter'} != 0 is here to avoid having an
> -        # additional line output when the text is longer than the max.
> -        if ($paragraph->{'counter'} != 0 and 
> -            $paragraph->{'counter'} + $paragraph->{'word_counter'} + 
> -               length($paragraph->{'space'}) > $paragraph->{'max'}) {
> -          $result .= _cut_line($paragraph);
> +        if ($paragraph->{'word'} !~ /\s$/) {
> +          $paragraph->{'word'} .= substr($spaces, 0,  1);
> +          $paragraph->{'last_char'} = substr($spaces, 0, 1);
> +          $paragraph->{'word_counter'}++;
> +          $paragraph->{'word'} =~ s/\n/ /g;
> +
> +          # The $paragraph->{'counter'} != 0 is here to avoid having an
> +          # additional line output when the text is longer than the max.
> +          if ($paragraph->{'counter'} != 0 and 
> +              $paragraph->{'counter'} + $paragraph->{'word_counter'} + 
> +                 length($paragraph->{'space'}) > $paragraph->{'max'}) {
> +            $result .= _cut_line($paragraph);
> +          }
>          }
>        } else {
>          my $pending_word = $paragraph->{'word'};
> diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
> index bf4ef91650..8dfff95f98 100644
> --- a/tp/Texinfo/XS/xspara.c
> +++ b/tp/Texinfo/XS/xspara.c
> @@ -845,29 +845,23 @@ xspara_add_text (char *text)
>            /* If protect_spaces is on, ... */
>            if (state.protect_spaces)
>              {
> -              /* Append the spaces to the pending word. */
> -              text_append_n (&state.word, p, char_len);
> -              state.word_counter++;
> -
> -              if (strchr (state.word.text, '\n'))
> +              if (state.word.end == 0 || !isspace
> +                    ((unsigned char) state.word.text[state.word.end - 1]))
>                  {
> -                  /* Replace any '\n' with a ' '. Note that 
> state.word_counter 
> -                     will still be correct after this. */
> -                  char *ptr = state.word.text;
> -                  while (*ptr)
> +                  state.last_letter = L' ';
> +                  /* Append the spaces to the pending word. */
> +                  if (*p == '\n')
> +                    text_append_n (&state.word, " ", 1);
> +                  else
> +                    text_append_n (&state.word, p, 1);
> +                  state.word_counter++;
> +
> +                  if (state.counter != 0 && state.counter
> +                      + state.word_counter + state.space_counter > state.max)
>                      {
> -                      if (*ptr == '\n')
> -                        *ptr = ' ';
> -                      ptr++;
> +                      xspara__cut_line (&result);
>                      }
>                  }
> -
> -              if (state.counter != 0
> -                  && state.counter + state.word_counter + state.space_counter
> -                     > state.max)
> -                {
> -                  xspara__cut_line (&result);
> -                }
>              }
>            else /* protect_spaces off */
>              {
> 
> 
> 



reply via email to

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