ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* XML in ConTeXt & verbatim text
@ 2004-12-14 15:48 Richard Gabriel
  2004-12-14 17:27 ` Adam Lindsay
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Gabriel @ 2004-12-14 15:48 UTC (permalink / raw)


Hi all,

I'm back here with the following problem:

I'm processing XML files (DocBook DTD) which also may contain the 
<programlisting> tag with some preformatted text.

In a sample TeX file, I've tested the following:

\starttyping
<somecontext>
  <variable name="Var">
    Value of Var
  </variable>
</somecontext>
\stoptyping

This works and the result is great.

So I defined a macro to process the <programlisting> tag from the XML file:
\defineXMLenvironment[programlisting]{\starttyping}{\stoptyping}

This causes an error while processing. Most probably the \starttyping 
command breaks things inside the \defineXMLenvironment macro...

Any guess how to solve this issue?

Many thanks!

Richard

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

* Re: XML in ConTeXt & verbatim text
  2004-12-14 15:48 XML in ConTeXt & verbatim text Richard Gabriel
@ 2004-12-14 17:27 ` Adam Lindsay
  2004-12-15 15:43   ` Richard Gabriel
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Lindsay @ 2004-12-14 17:27 UTC (permalink / raw)


Richard Gabriel said this at Tue, 14 Dec 2004 16:48:05 +0100:

>So I defined a macro to process the <programlisting> tag from the XML file:
>\defineXMLenvironment[programlisting]{\starttyping}{\stoptyping}

Richard, 

Have you taken a look at x-contml to see how it solves this problem with
verbatim?

adam
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Adam T. Lindsay, Computing Dept.     atl@comp.lancs.ac.uk
 Lancaster University, InfoLab21        +44(0)1524/510.514
 Lancaster, LA1 4WA, UK             Fax:+44(0)1524/510.492
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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

* Re: XML in ConTeXt & verbatim text
  2004-12-14 17:27 ` Adam Lindsay
@ 2004-12-15 15:43   ` Richard Gabriel
  2004-12-15 16:57     ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Gabriel @ 2004-12-15 15:43 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 1598 bytes --]

Hi Adam,

I did so right now (thanks for the hint!).
But in that file ther's only solved a case when each line of the 
verbatim text is placed in a special tag:

<verbatim>
  <line>Dit \is nogal verbatim !</line>
  <line>Dit is {nogal} verbatim !</line>
  <line>Dit is <nogal> verbatim !</line>
</verbatim>

This is trivial because you can pass the contents of each <line> element 
as an argument to the \type command ( \defineXMLargument[line]{\type} )

But this solution is unusable e.g. for longer program or configuration 
file listings, and, mainly, the DocBook DTD doesn't define such tags.
I need to process multiline verbatims enclosed in a single tag:

<programlisting>
Line 1
      Line 2
Line 3
</programlisting>

---
Of course I have some "dirty" workaround, but the result is really ugly...

\defineXMLenvironment[programlisting]{
  \bgroup
  \startpacked
  \tttf
  \obeylines\obeyspaces\obeytabs
}{
  \stoppacked
  \egroup
}

The line breaks are processed correctly. But all the tabs and spaces are 
treated as a single space. It seems the \obeyspaces and \obeytabs 
command are ignored or they do not work the way I'd expect. This will 
totally break the indentation and tabulation of the verbatim text...


-Richard





Adam Lindsay wrote:

>Richard Gabriel said this at Tue, 14 Dec 2004 16:48:05 +0100:
>
>  
>
>>So I defined a macro to process the <programlisting> tag from the XML file:
>>\defineXMLenvironment[programlisting]{\starttyping}{\stoptyping}
>>    
>>
>
>Richard, 
>
>Have you taken a look at x-contml to see how it solves this problem with
>verbatim?
>
>adam
>  
>

[-- Attachment #1.2: Type: text/html, Size: 2310 bytes --]

[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

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

* Re: XML in ConTeXt & verbatim text
  2004-12-15 15:43   ` Richard Gabriel
@ 2004-12-15 16:57     ` Hans Hagen
  2004-12-16 15:36       ` Richard Gabriel
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2004-12-15 16:57 UTC (permalink / raw)


Richard Gabriel wrote:
> Hi Adam,
> 
> I did so right now (thanks for the hint!).
> But in that file ther's only solved a case when each line of the 
> verbatim text is placed in a special tag:
> 
> <verbatim>
>   <line>Dit \is nogal verbatim !</line>
>   <line>Dit is {nogal} verbatim !</line>
>   <line>Dit is <nogal> verbatim !</line>
> </verbatim>
> 
> This is trivial because you can pass the contents of each <line> element 
> as an argument to the \type command ( \defineXMLargument[line]{\type} )
> 
> But this solution is unusable e.g. for longer program or configuration 
> file listings, and, mainly, the DocBook DTD doesn't define such tags.
> I need to process multiline verbatims enclosed in a single tag:
> 
> <programlisting>
> Line 1
>       Line 2
> Line 3
> </programlisting>
> 
> ---
> Of course I have some "dirty" workaround, but the result is really ugly...
> 
> \defineXMLenvironment[programlisting]{
>   \bgroup
>   \startpacked
>   \tttf
>   \obeylines\obeyspaces\obeytabs
> }{
>   \stoppacked
>   \egroup
> }
> 
> The line breaks are processed correctly. But all the tabs and spaces are 
> treated as a single space. It seems the \obeyspaces and \obeytabs 
> command are ignored or they do not work the way I'd expect. This will 
> totally break the indentation and tabulation of the verbatim text...

maybe the following is better

\defineXMLenvironment
   [programlisting]
   {\processtaggeddisplayverbatim{</programlisting>}}
   {}

\startbuffer
<programlisting>
Line 1
       Line 2
Line 3
</programlisting>
\stopbuffer

\starttext

\processXMLbuffer

\stoptext

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: XML in ConTeXt & verbatim text
  2004-12-15 16:57     ` Hans Hagen
@ 2004-12-16 15:36       ` Richard Gabriel
  2004-12-16 16:02         ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Gabriel @ 2004-12-16 15:36 UTC (permalink / raw)


Hello Hans,

thank you very much for the advice. It works almost perfectly, except 
one small (but important) detail:
Let's have a HTML source code in the <programlisting> tag. It will be 
stored the following way in the XML file:
<programlisting>
&lt;html&gt;
&lt;body&gt;
&lt;p&gt;Some text&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</programlisting>

I have defined the entity conversion:
\defineXMLentity[gt]{\char`\>{}}
\defineXMLentity[lt]{\char`\<{}}

This works OK if the entities occur somewhere in the normal text but it 
doesn't matter in the verbatim text.
Is there any solution for this? Maybe changing catcodes of the & and ; 
characters?

Thanks again...

Richard





Hans Hagen wrote:

> Richard Gabriel wrote:
>
> maybe the following is better
>
> \defineXMLenvironment
>   [programlisting]
>   {\processtaggeddisplayverbatim{</programlisting>}}
>   {}
>
> \startbuffer
> <programlisting>
> Line 1
>       Line 2
> Line 3
> </programlisting>
> \stopbuffer
>
> \starttext
>
> \processXMLbuffer
>
> \stoptext
>
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
>                                              | www.pragma-pod.nl
> -----------------------------------------------------------------
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

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

* Re: XML in ConTeXt & verbatim text
  2004-12-16 15:36       ` Richard Gabriel
@ 2004-12-16 16:02         ` Hans Hagen
  2004-12-17  7:50           ` Richard Gabriel
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2004-12-16 16:02 UTC (permalink / raw)


Richard Gabriel wrote:
> Hello Hans,
> 
> thank you very much for the advice. It works almost perfectly, except 
> one small (but important) detail:
> Let's have a HTML source code in the <programlisting> tag. It will be 
> stored the following way in the XML file:
> <programlisting>
> &lt;html&gt;
> &lt;body&gt;
> &lt;p&gt;Some text&lt;/p&gt;
> &lt;/body&gt;
> &lt;/html&gt;
> </programlisting>
> 
> I have defined the entity conversion:
> \defineXMLentity[gt]{\char`\>{}}
> \defineXMLentity[lt]{\char`\<{}}
> 
> This works OK if the entities occur somewhere in the normal text but it 
> doesn't matter in the verbatim text.
> Is there any solution for this? Maybe changing catcodes of the & and ; 
> characters?

maybe it's enough to add

\catcode`\&=\active

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: XML in ConTeXt & verbatim text
  2004-12-16 16:02         ` Hans Hagen
@ 2004-12-17  7:50           ` Richard Gabriel
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Gabriel @ 2004-12-17  7:50 UTC (permalink / raw)


Great!

Thank you very, very much for your help, Hans!

Richard



Hans Hagen wrote:

> Richard Gabriel wrote:
>
>> Hello Hans,
>>
>> thank you very much for the advice. It works almost perfectly, except 
>> one small (but important) detail:
>> Let's have a HTML source code in the <programlisting> tag. It will be 
>> stored the following way in the XML file:
>> <programlisting>
>> &lt;html&gt;
>> &lt;body&gt;
>> &lt;p&gt;Some text&lt;/p&gt;
>> &lt;/body&gt;
>> &lt;/html&gt;
>> </programlisting>
>>
>> I have defined the entity conversion:
>> \defineXMLentity[gt]{\char`\>{}}
>> \defineXMLentity[lt]{\char`\<{}}
>>
>> This works OK if the entities occur somewhere in the normal text but 
>> it doesn't matter in the verbatim text.
>> Is there any solution for this? Maybe changing catcodes of the & and 
>> ; characters?
>
>
> maybe it's enough to add
>
> \catcode`\&=\active
>
> Hans
>
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
>                                              | www.pragma-pod.nl
> -----------------------------------------------------------------
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

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

end of thread, other threads:[~2004-12-17  7:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-14 15:48 XML in ConTeXt & verbatim text Richard Gabriel
2004-12-14 17:27 ` Adam Lindsay
2004-12-15 15:43   ` Richard Gabriel
2004-12-15 16:57     ` Hans Hagen
2004-12-16 15:36       ` Richard Gabriel
2004-12-16 16:02         ` Hans Hagen
2004-12-17  7:50           ` Richard Gabriel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).