function s2 = s_escape_tex ( s1 )

%*****************************************************************************80
%
%% s_escape_tex() de-escapes TeX escape sequences.
%
%  Discussion:
%
%    The Octave strcat() function refuses to allow trailing blanks in
%    a string, and so I have had to go through some extra steps
%    to preserve blanks!
%
%    In particular, every occurrence of the characters '\', '_',
%    '^', '{' and '}' will be replaced by '\\', '\_', '\^',
%    '\{' and '\}'.  A TeX interpreter, on seeing these character
%    strings, is then likely to return the original characters.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 September 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string s1: the string to be de-escaped.
%
%  Output:
%
%    string s2: a copy of the string, modified to avoid TeX escapes.
%
  s1_length = length ( s1 );

  s1_pos = 0;
  s2_pos = 0;
  s2 = char ( [] );

  while ( s1_pos < s1_length )

    s1_pos = s1_pos + 1;

    if ( s1(s1_pos) == '\' || ...
         s1(s1_pos) == '_' || ...
         s1(s1_pos) == '^' || ...
         s1(s1_pos) == '{' || ...
         s1(s1_pos) == '}' )
      s2_pos = s2_pos + 1;
      s2 = char ( [ s2, '\' ] );
    end

    s2_pos = s2_pos + 1;
    s2 = char ( [ s2, s1(s1_pos) ] );

  end

  return
end

