comp.lang.ada
 help / color / mirror / Atom feed
* Regex and/or LaTeX
@ 2001-02-22 11:01 Adrian Knoth
  2001-02-23  8:13 ` Lutz Donnerhacke
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Adrian Knoth @ 2001-02-22 11:01 UTC (permalink / raw)


Hi!

I'm facing the problem to escape some special characters before
outputting them to a LaTeX-file, i.e. '&' should be replaced
by "\&".

There is no difficulty in implementing this directly, but in order
to avoid unnecessary work I ask if there is already a package which
provides all the LaTeX-functionality I might need. If not, perhaps
a sed-like function exists to perform something like this:
	sed -e 's/\([&%]\)/\\\1/g'


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Lieber alternativ als alt und naiv.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-22 11:01 Regex and/or LaTeX Adrian Knoth
@ 2001-02-23  8:13 ` Lutz Donnerhacke
  2001-02-23  9:41 ` Florian Weimer
  2001-02-24  2:59 ` Rajagopalan Srinivasan
  2 siblings, 0 replies; 8+ messages in thread
From: Lutz Donnerhacke @ 2001-02-23  8:13 UTC (permalink / raw)


* Adrian Knoth wrote:
>I'm facing the problem to escape some special characters before
>outputting them to a LaTeX-file, i.e. '&' should be replaced
>by "\&".

No. You need a different TeX Macro file allowing you all the characters
directly.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-22 11:01 Regex and/or LaTeX Adrian Knoth
  2001-02-23  8:13 ` Lutz Donnerhacke
@ 2001-02-23  9:41 ` Florian Weimer
  2001-02-24  2:59 ` Rajagopalan Srinivasan
  2 siblings, 0 replies; 8+ messages in thread
From: Florian Weimer @ 2001-02-23  9:41 UTC (permalink / raw)


Adrian Knoth <adi@drcomp.erfurt.thur.de> writes:

> There is no difficulty in implementing this directly, but in order
> to avoid unnecessary work I ask if there is already a package which
> provides all the LaTeX-functionality I might need.

If you're using GNAT, you can try the package GNAT.Spitbol.Patterns.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-22 11:01 Regex and/or LaTeX Adrian Knoth
  2001-02-23  8:13 ` Lutz Donnerhacke
  2001-02-23  9:41 ` Florian Weimer
@ 2001-02-24  2:59 ` Rajagopalan Srinivasan
  2001-02-24 15:36   ` Adrian Knoth
  2 siblings, 1 reply; 8+ messages in thread
From: Rajagopalan Srinivasan @ 2001-02-24  2:59 UTC (permalink / raw)


assuming you are looking for an Ada95 package and assuming you are using
gnat, i will search the users guide for gnat.spitbol.patterns and/or
gnat.regexp

"Adrian Knoth" <adi@drcomp.erfurt.thur.de> wrote in message
news:972rhk$a13$1@drcomp.erfurt.thur.de...
> Hi!
>
> I'm facing the problem to escape some special characters before
> outputting them to a LaTeX-file, i.e. '&' should be replaced
> by "\&".
>
> There is no difficulty in implementing this directly, but in order
> to avoid unnecessary work I ask if there is already a package which
> provides all the LaTeX-functionality I might need. If not, perhaps
> a sed-like function exists to perform something like this:
> sed -e 's/\([&%]\)/\\\1/g'
>
>
> --
> mail: adi@thur.de  http://adi.thur.de PGP: v2-key via keyserver
>
> Lieber alternativ als alt und naiv.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-24  2:59 ` Rajagopalan Srinivasan
@ 2001-02-24 15:36   ` Adrian Knoth
  2001-02-26 11:41     ` Lutz Donnerhacke
  2001-02-26 11:48     ` Lutz Donnerhacke
  0 siblings, 2 replies; 8+ messages in thread
From: Adrian Knoth @ 2001-02-24 15:36 UTC (permalink / raw)


Rajagopalan Srinivasan <r.srinivasan@worldnet.att.net> wrote:

> gnat.regexp

Yeah, thank you, that's fine. I guess I'll use it in some projects.
Actually I don't want to limit my program to a special compiler,
so I implemented the desired functionality in this way:

        procedure texstring (ausdruck : in out ustring)
        is
                tmp : string := To_string(ausdruck);
                hs : ustring := To_Ustring("");
        begin
                ausdruck := To_ustring("");
                for I in tmp'range loop
                        case tmp(I) is
                                when '&' => hs := To_Ustring("\&");
                                when '%' => hs := To_Ustring("\%");
                                when others => hs := To_Ustring(tmp(I) & "");
                        end case;
                        ausdruck := ausdruck & hs;
                end loop;
        end texstring;

Perhaps I need to extend this for other LaTeX-symbols. For now, it works well.



-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Alle schimpfen �ber den Bundeskanzler. Dabei tut er doch gar nichts.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-24 15:36   ` Adrian Knoth
@ 2001-02-26 11:41     ` Lutz Donnerhacke
  2001-02-26 11:48     ` Lutz Donnerhacke
  1 sibling, 0 replies; 8+ messages in thread
From: Lutz Donnerhacke @ 2001-02-26 11:41 UTC (permalink / raw)


* Adrian Knoth wrote:
>   procedure texstring (ausdruck : in out ustring) is
>      tmp : string := To_string(ausdruck);
>      hs : ustring := To_Ustring("");
>   begin
>      ausdruck := To_ustring("");
>      for I in tmp'range loop
>         case tmp(I) is
>            when '&' => hs := To_Ustring("\&");
>            when '%' => hs := To_Ustring("\%");
>            when others => hs := To_Ustring(tmp(I) & "");
>         end case;
>         ausdruck := ausdruck & hs;
>      end loop;
>   end texstring;

This seems to be Perl Style.

function texify (ausdruck      : String;
                 escape_char   : Character := '\\';
                 to_be_escaped : String    := "\\{}[]%^_") return String is
   pattern : Ada.Strings.Maps.Character_Set :=
             Ada.Strings.Maps.To_Set (to_be_escaped);
   pos     : Ada.Strings.Fixed.Index (ausdruck, pattern);
begin
   if pos = 0 then
      return ausdruck;
   elsif i = ausdruck'Last then
      return ausdruck (ausdruck'First .. i - 1) & escape_char & ausdruck (i);
   else
      return ausdruck (ausdruck'First .. i - 1) & escape_char & ausdruck (i) &
             texify (ausdruck (i + 1 .. ausdruck'Last),
                     escape_char, to_be_escaped);
   end if;
end texify;



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-24 15:36   ` Adrian Knoth
  2001-02-26 11:41     ` Lutz Donnerhacke
@ 2001-02-26 11:48     ` Lutz Donnerhacke
  2001-02-26 20:15       ` Jeffrey Carter
  1 sibling, 1 reply; 8+ messages in thread
From: Lutz Donnerhacke @ 2001-02-26 11:48 UTC (permalink / raw)


* Adrian Knoth wrote:
>   procedure texstring (ausdruck : in out ustring) is
>      tmp : string := To_string(ausdruck);
>      hs : ustring := To_Ustring("");
>   begin
>      ausdruck := To_ustring("");
>      for I in tmp'range loop
>         case tmp(I) is
>            when '&' => hs := To_Ustring("\&");
>            when '%' => hs := To_Ustring("\%");
>            when others => hs := To_Ustring(tmp(I) & "");
>         end case;
>         ausdruck := ausdruck & hs;
>      end loop;
>   end texstring;

This seems to be Perl Style.

function texify (ausdruck      : String;
                 escape_char   : Character := '\\';
                 to_be_escaped : String    := "\\{}[]%^_") return String is
   pattern : Ada.Strings.Maps.Character_Set :=
             Ada.Strings.Maps.To_Set (to_be_escaped);
   i       : Ada.Strings.Fixed.Index (ausdruck, pattern);
begin
   if i = 0 then
      return ausdruck;
   elsif i = ausdruck'Last then
      return ausdruck (ausdruck'First .. i - 1) & escape_char & ausdruck (i);
   else
      return ausdruck (ausdruck'First .. i - 1) & escape_char & ausdruck (i) &
             texify (ausdruck (i + 1 .. ausdruck'Last),
                     escape_char, to_be_escaped);
   end if;
end texify;



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Regex and/or LaTeX
  2001-02-26 11:48     ` Lutz Donnerhacke
@ 2001-02-26 20:15       ` Jeffrey Carter
  0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Carter @ 2001-02-26 20:15 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 
> function texify (ausdruck      : String;
>                  escape_char   : Character := '\\';

'//' is not a character literal

The original poster might want to look at
PragmARC.Regular_Expression_Matcher, part of the PragmAda Reusable
Components, which is compiler and platform independent:

http://home.earthlink.net/~jrcarter010/pragmarc.htm

and mirrored at www.adapower.com.

-- 
Jeff Carter
"We burst our pimples at you."
Monty Python & the Holy Grail



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-02-26 20:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-22 11:01 Regex and/or LaTeX Adrian Knoth
2001-02-23  8:13 ` Lutz Donnerhacke
2001-02-23  9:41 ` Florian Weimer
2001-02-24  2:59 ` Rajagopalan Srinivasan
2001-02-24 15:36   ` Adrian Knoth
2001-02-26 11:41     ` Lutz Donnerhacke
2001-02-26 11:48     ` Lutz Donnerhacke
2001-02-26 20:15       ` Jeffrey Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox