Submitted By:            Douglas R. Reno <renodr at linuxfromscratch dot org>
Date:                    2024-04-15
Initial Package Version: 20240312
Upstream Status:         Applied
Origin:                  Upstream commits:
                         3ca9ef1101cf85561ee22ce2c7162e526ecd181f
                         d158ada96692145e1cc61ad8565a6fce0ffa54c4
                         2346aa2514723d60b539d287cd5cc09f1f6f9a8f
                         in https://git.texlive.info/texlive/log/?h=branch2024
Description:             Fixes a bug in the 'afterpage' package that causes
                         isuses with the \aftergroup \output routine, as well
                         as fixing a bug where PDFs become large when inserting
                         an identical image multiple times (in dvipdfm-x).

diff -Naurp texlive-20240312-source.orig/texk/dvipdfm-x/ChangeLog texlive-20240312-source/texk/dvipdfm-x/ChangeLog
--- texlive-20240312-source.orig/texk/dvipdfm-x/ChangeLog	2024-04-15 16:48:49.309001203 -0500
+++ texlive-20240312-source/texk/dvipdfm-x/ChangeLog	2024-04-15 16:49:49.569532006 -0500
@@ -1,3 +1,10 @@
+2024-04-07  Yukimasa Morimi  <h20y6m@yahoo.co.jp>
+
+	* pdfximage.c: fix an issue where the PDF becomes large when
+	inserting the same image multiple times.
+	https://github.com/texjporg/tex-jp-build/pull/169
+	* configure.ac: version 20240407.
+
 2024-03-10  Karl Berry  <karl@tug.org>
 
 	* TL'24 release.
diff -Naurp texlive-20240312-source.orig/texk/dvipdfm-x/configure texlive-20240312-source/texk/dvipdfm-x/configure
--- texlive-20240312-source.orig/texk/dvipdfm-x/configure	2024-04-15 16:48:49.310001195 -0500
+++ texlive-20240312-source/texk/dvipdfm-x/configure	2024-04-15 16:49:55.654484628 -0500
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.72 for dvipdfm-x (TeX Live) 20240305.
+# Generated by GNU Autoconf 2.72 for dvipdfm-x (TeX Live) 20240407.
 #
 # Report bugs to <dvipdfmx@tug.org>.
 #
@@ -614,8 +614,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='dvipdfm-x (TeX Live)'
 PACKAGE_TARNAME='dvipdfm-x--tex-live-'
-PACKAGE_VERSION='20240305'
-PACKAGE_STRING='dvipdfm-x (TeX Live) 20240305'
+PACKAGE_VERSION='20240407'
+PACKAGE_STRING='dvipdfm-x (TeX Live) 20240407'
 PACKAGE_BUGREPORT='dvipdfmx@tug.org'
 PACKAGE_URL=''
 
@@ -1383,7 +1383,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-'configure' configures dvipdfm-x (TeX Live) 20240305 to adapt to many kinds of systems.
+'configure' configures dvipdfm-x (TeX Live) 20240407 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1455,7 +1455,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20240305:";;
+     short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20240407:";;
    esac
   cat <<\_ACEOF
 
@@ -1586,7 +1586,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-dvipdfm-x (TeX Live) configure 20240305
+dvipdfm-x (TeX Live) configure 20240407
 generated by GNU Autoconf 2.72
 
 Copyright (C) 2023 Free Software Foundation, Inc.
@@ -2367,7 +2367,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by dvipdfm-x (TeX Live) $as_me 20240305, which was
+It was created by dvipdfm-x (TeX Live) $as_me 20240407, which was
 generated by GNU Autoconf 2.72.  Invocation command line was
 
   $ $0$ac_configure_args_raw
@@ -8928,7 +8928,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='dvipdfm-x--tex-live-'
- VERSION='20240305'
+ VERSION='20240407'
 
 
 printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
@@ -15995,7 +15995,7 @@ Usage: $0 [OPTIONS]
 Report bugs to <bug-libtool@gnu.org>."
 
 lt_cl_version="\
-dvipdfm-x (TeX Live) config.lt 20240305
+dvipdfm-x (TeX Live) config.lt 20240407
 configured by $0, generated by GNU Autoconf 2.72.
 
 Copyright (C) 2011 Free Software Foundation, Inc.
@@ -17938,7 +17938,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wri
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by dvipdfm-x (TeX Live) $as_me 20240305, which was
+This file was extended by dvipdfm-x (TeX Live) $as_me 20240407, which was
 generated by GNU Autoconf 2.72.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -18010,7 +18010,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config='$ac_cs_config_escaped'
 ac_cs_version="\\
-dvipdfm-x (TeX Live) config.status 20240305
+dvipdfm-x (TeX Live) config.status 20240407
 configured by $0, generated by GNU Autoconf 2.72,
   with options \\"\$ac_cs_config\\"
 
diff -Naurp texlive-20240312-source.orig/texk/dvipdfm-x/configure.ac texlive-20240312-source/texk/dvipdfm-x/configure.ac
--- texlive-20240312-source.orig/texk/dvipdfm-x/configure.ac	2024-04-15 16:48:49.310001195 -0500
+++ texlive-20240312-source/texk/dvipdfm-x/configure.ac	2024-04-15 16:50:00.347448088 -0500
@@ -8,7 +8,7 @@ dnl   This file is free software; the co
 dnl   gives unlimited permission to copy and/or distribute it,
 dnl   with or without modifications, as long as this notice is preserved.
 dnl
-AC_INIT([dvipdfm-x (TeX Live)], [20240305], [dvipdfmx@tug.org])
+AC_INIT([dvipdfm-x (TeX Live)], [20240407], [dvipdfmx@tug.org])
 AC_PREREQ([2.65])
 AC_CONFIG_SRCDIR([agl.c])
 AC_CONFIG_AUX_DIR([../../build-aux])
diff -Naurp texlive-20240312-source.orig/texk/dvipdfm-x/pdfximage.c texlive-20240312-source/texk/dvipdfm-x/pdfximage.c
--- texlive-20240312-source.orig/texk/dvipdfm-x/pdfximage.c	2024-04-15 16:48:49.312001179 -0500
+++ texlive-20240312-source/texk/dvipdfm-x/pdfximage.c	2024-04-15 16:50:05.924404665 -0500
@@ -396,6 +396,8 @@ load_image (const char *ident, const cha
 int utf8name_failed = 0;
 #endif /* WIN32 */
 
+#define dpx_streq(a, b) ((a) == (b) || (a) && (b) && strcmp(a, b) == 0)
+
 int
 pdf_ximage_load_image (const char *ident, const char *filename, load_options options)
 {
@@ -408,20 +410,21 @@ pdf_ximage_load_image (const char *ident
 
   for (i = 0; i < ic->count; i++) {
     I = &ic->ximages[i];
-    if (I->filename && !strcmp(filename, I->filename)) {
-      id = i;
-      break;
-    }
-  }
-  if (id >= 0) {
-    if (I->attr.page_no == options.page_no &&
-        (I->attr.page_name && options.page_name &&
-         strcmp(I->attr.page_name, options.page_name) == 0) &&
-        !pdf_compare_object(I->attr.dict, options.dict) && /* ????? */
-        I->attr.bbox_type == options.bbox_type) {
-      return id;
-    }
+    if (I->filename == NULL || strcmp(filename, I->filename) != 0)
+      continue;
+    id = i;
     f = I->fullname;
+
+    if (I->attr.page_no != options.page_no)
+      continue;
+    if (!dpx_streq(I->attr.page_name, options.page_name))
+      continue;
+    if (pdf_compare_object(I->attr.dict, options.dict) != 0) /* ????? */
+      continue;
+    if (I->attr.bbox_type != options.bbox_type)
+      continue;
+
+    return id;
   }
   if (f) {
     /* we already have converted this file; f is the temporary file name */
diff -Naurp texlive-20240312-source.orig/texk/web2c/ChangeLog texlive-20240312-source/texk/web2c/ChangeLog
--- texlive-20240312-source.orig/texk/web2c/ChangeLog	2024-04-15 16:48:49.427000284 -0500
+++ texlive-20240312-source/texk/web2c/ChangeLog	2024-04-15 16:49:12.720818914 -0500
@@ -1,3 +1,10 @@
+2024-03-24  Karl Berry  <karl@freefriends.org>
+
+	* unbalanced-braces.ch: fix from DRF in order to make
+	\aftergroup work again with the output routine. Report
+	from David Carlisle and Frank Mittelbach, thread starts at:
+	https://tug.org/pipermail/tex-live/2024-March/050290.html
+
 2024-03-10  Karl Berry  <karl@tug.org>
 
 	* TL'24 release.
diff -Naurp texlive-20240312-source.orig/texk/web2c/eptexdir/unbalanced-braces-eptex.ch texlive-20240312-source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch
--- texlive-20240312-source.orig/texk/web2c/eptexdir/unbalanced-braces-eptex.ch	2024-04-15 16:48:49.438000198 -0500
+++ texlive-20240312-source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch	2024-04-15 16:49:39.717608713 -0500
@@ -47,7 +47,7 @@
         begin decr(param_ptr);
         flush_list(param_stack[param_ptr]);
         end
-    else if (token_type=output_text)and(output_active) then
+    else if (token_type=output_text)and(not output_can_end) then
       fatal_error("Unbalanced output routine");
 @.Unbalanced output routine@>
 @z
@@ -103,6 +103,19 @@ while (loc=null)and(token_type<>v_templa
 % that we were just finished with it, so it's where the brace
 % came from.
 
+@x [45.989] l.19364 p.B417
+@!output_active:boolean; {are we in the midst of an output routine?}
+@y
+@!output_active:boolean; {are we in the midst of an output routine?}
+@!output_can_end:boolean; {is this an auspicious time for it to end?}
+@z
+
+@x [45.989] l.19367 p.B417
+output_active:=false; insert_penalties:=0;
+@y
+output_active:=false; output_can_end:=false; insert_penalties:=0;
+@z
+
 % In <Resume the page builder after an output routine has come to an end>:
 @x [45.1026] l.19938 p.B432
 begin if (loc<>null) or
@@ -121,8 +134,10 @@ begin
 end_token_list; {conserve stack space in case more outputs are triggered}
 end_graf; unsave; output_active:=false; insert_penalties:=0;@/
 @y
-end_graf; unsave; output_active:=false; insert_penalties:=0;@/
+output_can_end:=true;
 end_token_list; {conserve stack space in case more outputs are triggered}
+output_can_end:=false;
+end_graf; unsave; output_active:=false; insert_penalties:=0;@/
 @z
 
 % <Expand macros in the token list and...> had set mode:=0 while
diff -Naurp texlive-20240312-source.orig/texk/web2c/unbalanced-braces.ch texlive-20240312-source/texk/web2c/unbalanced-braces.ch
--- texlive-20240312-source.orig/texk/web2c/unbalanced-braces.ch	2024-04-15 16:48:49.521999544 -0500
+++ texlive-20240312-source/texk/web2c/unbalanced-braces.ch	2024-04-15 16:49:21.540750241 -0500
@@ -47,7 +47,7 @@
         begin decr(param_ptr);
         flush_list(param_stack[param_ptr]);
         end
-    else if (token_type=output_text)and(output_active) then
+    else if (token_type=output_text)and(not output_can_end) then
       fatal_error("Unbalanced output routine");
 @.Unbalanced output routine@>
 @z
@@ -103,6 +103,19 @@ while (loc=null)and(token_type<>v_templa
 % that we were just finished with it, so it's where the brace
 % came from.
 
+@x [45.989] l.19364 p.B417
+@!output_active:boolean; {are we in the midst of an output routine?}
+@y
+@!output_active:boolean; {are we in the midst of an output routine?}
+@!output_can_end:boolean; {is this an auspicious time for it to end?}
+@z
+
+@x [45.989] l.19367 p.B417
+output_active:=false; insert_penalties:=0;
+@y
+output_active:=false; output_can_end:=false; insert_penalties:=0;
+@z
+
 % In <Resume the page builder after an output routine has come to an end>:
 @x [45.1026] l.19938 p.B432
 begin if (loc<>null) or
@@ -121,8 +134,10 @@ begin
 end_token_list; {conserve stack space in case more outputs are triggered}
 end_graf; unsave; output_active:=false; insert_penalties:=0;@/
 @y
-end_graf; unsave; output_active:=false; insert_penalties:=0;@/
+output_can_end:=true;
 end_token_list; {conserve stack space in case more outputs are triggered}
+output_can_end:=false;
+end_graf; unsave; output_active:=false; insert_penalties:=0;@/
 @z
 
 % <Expand macros in the token list and...> had set mode:=0 while