[luatex] A bug in show_context second line indentation
user202729 at protonmail.com
user202729 at protonmail.com
Thu Oct 17 18:05:51 CEST 2024
Hi, can I get an update on this?
Anyway, I think the short version is you can just apply this patch:
```
diff --git a/source/texk/web2c/luatexdir/tex/printing.c b/source/texk/web2c/luatexdir/tex/printing.c
index 8a52700..8ae11b4 100644
--- a/source/texk/web2c/luatexdir/tex/printing.c
+++ b/source/texk/web2c/luatexdir/tex/printing.c
@@ -482,7 +482,8 @@ void tprint(const char *sss)
}
/*tex What is left is the 3 term/log settings. */
if (dolog || doterm) {
- buffer = xmalloc(strlen(sss)*3);
+ size_t len = strlen(sss);
+ buffer = xmalloc(len*3);
buffer[0] = '\0';
/*tex The |wrapup_run| callback acts when the log file is already closed.*/
if (dolog && log_opened_global) {
@@ -532,6 +533,7 @@ void tprint(const char *sss)
fputs(buffer, term_out);
}
}
+ tally += len;
free(buffer);
}
}
```
This is a test file
```tex
\errorcontextlines=10000
\def\c{1 \errorerror 2}
\def\b #1 {7 #1 8}
\def\a{5 \b {3 \c 4} 6}
\hbox{7 \a 8}
\stop
```
Sent with Proton Mail secure email.
On Sunday, September 29th, 2024 at 1:22 PM, user202729 at protonmail.com <user202729 at protonmail.com> wrote:
> In the original TeX program, the `tally` variable is increased whenever `print_char` is called (except when character `s` is newline), regardless of `selector`.
>
> However, in `tprint` function of LuaTeX, `tally` is only called when `selector` is `pseudo`.
> This leads to incorrect indentation of the second line, for example the following TeX file
>
> `tex \\errorcontextlines=10000 \\def\\c{1 \\errorerror 2} \\def\\b #1 {7 #1 8} \\def\\a{5 \\b {3 \\c 4} 6} \\hbox{7 \\a 8} \\stop`
>
> would lead to the following error (observe that the `<argument>` line is wrong):
>
>
> ```
> \c ->1 \errorerror
>
> 2
> <argument> 3 \c
>
> 4
> \b #1 ->7 #1
>
> 8
> \a ->5 \b {3 \c 4}
>
> 6
> l.5 \hbox{7 \a
> 8}
> ``I have two ideas how to fix it. One is to add `strlen(sss)` to `tally` regardless. The other is the following. This would still be incorrect if `selector` is `no_print` or `term_only`, however I think these cases will not happen.`` diff
> diff --git a/source/texk/web2c/luatexdir/tex/printing.c b/source/texk/web2c/luatexdir/tex/printing.c
> index 8a52700..b628280 100644
> --- a/source/texk/web2c/luatexdir/tex/printing.c
> +++ b/source/texk/web2c/luatexdir/tex/printing.c
> @@ -498,6 +498,7 @@ void tprint(const char *sss)
> t_flush_buffer(log_file,file_offset);
> }
> }
> + tally++;
> }
> if (*buffer) {
> buffer[i++] = '\0';
> ``I'm not sure which option is faster (on one hand the `strlen()` option need a separate loop, on the other hand it's a built-in library function so it should be fast?) Regardless, if performance doesn't matter that much, I think `strlen()` option is better. ------ On an academical note, there is still a small difference between LuaTeX and PDFTeX with the following patch. With the following TeX code`` tex
> \errorcontextlines=10000
> \newlinechar=`u
> \def\c{1 \errorerror 2}
> \def\b #1 {7 #1 8}
> \def\a{5 \b {3 \c 4} 6}
> \hbox{7 \a 8}
> \stop
> `then the output of LuaTeX would contains`
> <arg
> ment> 3 \c
>
> 4
> ```
> with 16 spaces before `4`, while PDFTeX only has 15 spaces before `4`.
>
> In practice, chances are nobody cares. For performance reason it's fine to ignore this case.
More information about the luatex
mailing list.