* tta/C/convert/convert_to_plaintext.c
(plaintext_conversion_initialization),
tta/perl/Texinfo/Convert/PlaintextNonXS.pm
(conversion_initialization): reorganize code, no functional change.
diff --git a/ChangeLog b/ChangeLog
index 5d85b6d..6f5babb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2026-08-29 Patrice Dumas  <pertusus@free.fr>
 
+	* tta/C/convert/convert_to_plaintext.c
+	(plaintext_conversion_initialization),
+	tta/perl/Texinfo/Convert/PlaintextNonXS.pm
+	(conversion_initialization): reorganize code, no functional change.
+
+2026-08-29 Patrice Dumas  <pertusus@free.fr>
+
 	* tta/perl/t/formats_encodings.t (at_commands_in_refs): skip test if
 	TEXINFO_XS_INCOMPLETE is set, as the result is different, there are no
 	line numbers in error message because elements are copied in C, not in
diff --git a/tta/C/convert/convert_to_plaintext.c b/tta/C/convert/convert_to_plaintext.c
index 33a01fe..686b20b 100644
--- a/tta/C/convert/convert_to_plaintext.c
+++ b/tta/C/convert/convert_to_plaintext.c
@@ -797,10 +797,6 @@
 {
   PLAINTEXT_CONVERTER_STATE *self_plaintext = self->plaintext_converter;
 
-  COUNT_CONTEXT bottom_count_context = { 0 };
-  push_count_context (&self_plaintext->count_context,
-                      bottom_count_context);
-
   converter_set_document (self, document);
 
   if (document->indices_info.number > 0)
@@ -833,10 +829,27 @@
   memset (self_plaintext->node_names_cache, 0,
           document->nodes_list.number * sizeof (STRING_WITH_WIDTH));
 
+  self_plaintext->encoding_object = 0;
+
+  /* it is an error to have index entries outside of nodes, so there
+     is no point optimizing the size of the hash */
+  init_c_hashmap (&self_plaintext->index_entries_no_node, 10);
+
+  init_c_hashmap (&self_plaintext->index_entry_node_colon,
+                  document->nodes_list.number);
+
+  init_c_hashmap (&self_plaintext->seen_node_descriptions,
+                  document->nodes_list.number);
+
+  init_c_hashmap (&self_plaintext->seenmenus,
+                  document->nodes_list.number);
+
   set_global_document_commands (self, CL_before, informative_global_commands);
   set_global_document_commands (self, CL_before, contents_commands);
 
-  /* TODO ... */
+  /* No need for disabling encoding in output_files, since in C conversion
+     is not setup there */
+
   self_plaintext->open_quote = "'";
   self_plaintext->close_quote = "'";
   self_plaintext->open_double_quote = "\"";
@@ -876,20 +889,11 @@
     self_plaintext->close_double_quote
        = self->conf->CLOSE_DOUBLE_QUOTE_SYMBOL.o.string;
 
-  self_plaintext->encoding_object = 0;
+  /* initialize context stacks */
 
-  /* it is an error to have index entries outside of nodes, so there
-     is no point optimizing the size of the hash */
-  init_c_hashmap (&self_plaintext->index_entries_no_node, 10);
-
-  init_c_hashmap (&self_plaintext->index_entry_node_colon,
-                  document->nodes_list.number);
-
-  init_c_hashmap (&self_plaintext->seen_node_descriptions,
-                  document->nodes_list.number);
-
-  init_c_hashmap (&self_plaintext->seenmenus,
-                  document->nodes_list.number);
+  COUNT_CONTEXT bottom_count_context = { 0 };
+  push_count_context (&self_plaintext->count_context,
+                      bottom_count_context);
 
   /* _Root_context in Perl, in C use CM_NONE */
   push_top_formatter (self, CM_NONE);
diff --git a/tta/perl/Texinfo/Convert/PlaintextNonXS.pm b/tta/perl/Texinfo/Convert/PlaintextNonXS.pm
index 8d74ace..c5e064c 100644
--- a/tta/perl/Texinfo/Convert/PlaintextNonXS.pm
+++ b/tta/perl/Texinfo/Convert/PlaintextNonXS.pm
@@ -434,16 +434,6 @@
 
   $self->set_document($document);
 
-  $self->set_global_document_commands('before', \@informative_global_commands);
-  $self->set_global_document_commands('before', \@contents_commands);
-
-  $self->{'context'} = [];
-  $self->{'format_context'} = [];
-  push @{$self->{'count_context'}}, {'lines' => 0,
-                                     'index_entry_locations' => [],
-                                     'pending_text' => [['']],
-  };
-
   $self->{'seenmenus'} = {};
   $self->{'index_entry_info'} = {};
 
@@ -464,9 +454,16 @@
 
   delete $self->{'current_node'};
 
+  delete $self->{'encoding_object'};
+
   # for INFO_MATH_IMAGES
   #$self->{'elements_images'};
 
+  $self->set_global_document_commands('before', \@informative_global_commands);
+  $self->set_global_document_commands('before', \@contents_commands);
+
+  # disable encoding in output_files related code, as the strings passed
+  # from Info or plaintext to write to files are already encoded.
   Texinfo::Convert::Utils::output_files_disable_output_encoding
     ($self->{'output_files'}, 1);
 
@@ -510,7 +507,13 @@
   $self->{'output_encoding_name'} = $self->get_conf('OUTPUT_ENCODING_NAME');
   $self->{'debug'} = $self->get_conf('DEBUG');
 
-  delete $self->{'encoding_object'};
+  # initialize context stacks
+  $self->{'context'} = [];
+  $self->{'format_context'} = [];
+  push @{$self->{'count_context'}}, {'lines' => 0,
+                                     'index_entry_locations' => [],
+                                     'pending_text' => [['']],
+  };
 
   $self->push_top_formatter('_Root_context');
 }