function tsp_display ( prefix, n, x )

%*****************************************************************************80
%
%% tsp_display() plots cities and a tour connecting them.
%
%  Discussion:
%
%    The code automatically adds a final return to the first city.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 July 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string prefix: a string that defines the name of
%    the problem.  It is also used to create file names needed for
%    input to gnuplot().
%
%    integer n: the number of cities.
%
%    real x(n,2): the x and y coordinates of the cities.
%

  clf ( );
  hold ( 'on' );
    plot ( x(:,1), x(:,2), 'm.', 'MarkerSize', 20 );
    for i = 1 : n
      text ( x(i,1), x(i,2), int2str ( i ) );
    end
    x = [ x; x(1,1), x(1,2) ];
    plot ( x(:,1), x(:,2), 'r-', 'LineWidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  prefix2 = s_escape_tex ( prefix );
  title ( prefix2 );
  filename = sprintf ( '%s.png', prefix );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  close ( );

  return
end
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

