ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Minimal code for exporting custom tags
@ 2020-05-18  7:09 Aditya Mahajan
  2020-05-18  9:34 ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2020-05-18  7:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

What is needed to enable export of user defined macros? Consider the following example:


```
\def\startmycommand{\dostarttagged{mycommand}\empty}
\def\stopmycommand {\dostoptagged}

\setupbackend[export=xml, level=0]

\starttext
\startsection[title={Sample document}]
   \startparagraph
     This is a paragraph
   \stopparagraph
   \startmycommand
     This is mycommand
   \stopmycommand
\stopsection
\stoptext
```

If I compile using `context --trackers=structures.tags filename`, I get

```
backend         > tags > U+0031:1 => U+0031:1 : 00004 document>1 section>1 sectioncaption>1 sectionnumber>1
backend         > tags > U+0053:S => U+0074:t : 00005 document>1 section>1 sectioncaption>1 sectiontitle>1
backend         > tags > U+0054:T => U+0068:h : 00007 document>1 section>1 sectioncontent>1 paragraph>1
backend         > tags > U+0054:T => U+0064:d : 00008 document>1 section>1 sectioncontent>1 mycommand>1
```

so the tag is applied. I can also verify this by looking at the PDF which contains

```
<< /K 27 0 R /ParentTree 2 0 R /RoleMap << /document /Div /mycommand /Span /paragraph /P /section /Sect /sectioncaption /Div /sectioncontent /Div /sectionnumber /H /sectiontitle /H >> /Type /StructTreeRoot >>
```

and the tag `mycommand` is used at appropriate location.

However, the exported xml file contains no tag:

```
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!--

     input filename   : test-tag
     processing date  : 2020-05-18T03:00:33-04:00
     context version  : 2020.04.30 11:10
     exporter version : 0.35

-->

<!-- This export file is used for filtering runtime only! -->

<document context="2020.04.30 11:10" date="2020-05-18T03:00:33-04:00" file="test-tag" language="en" version="0.35" xmlns:m="http://www.w3.org/1998/Math/MathML">
  <metadata>
  </metadata>
  <section detail="section" chain="section" implicit="1" level="3">
   <sectioncaption>
    <sectionnumber>1</sectionnumber>
    <sectiontitle>Sample document</sectiontitle>
   </sectioncaption>
   <sectioncontent>
    <paragraph>This is a paragraph</paragraph>
   </sectioncontent>
  </section>
</document>
```

What am I missing in order to pass user-defined macros to the exporter?

Thanks,
Aditya

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Minimal code for exporting custom tags
  2020-05-18  7:09 Minimal code for exporting custom tags Aditya Mahajan
@ 2020-05-18  9:34 ` Hans Hagen
  2020-05-18 13:50   ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2020-05-18  9:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Aditya Mahajan

On 5/18/2020 9:09 AM, Aditya Mahajan wrote:
> Hi,
> 
> What is needed to enable export of user defined macros? Consider the 
> following example:
> 
> 
> ```
> \def\startmycommand{\dostarttagged{mycommand}\empty}
> \def\stopmycommand {\dostoptagged}
> 
> \setupbackend[export=xml, level=0]
> 
> \starttext
> \startsection[title={Sample document}]
>    \startparagraph
>      This is a paragraph
>    \stopparagraph
>    \startmycommand
>      This is mycommand
>    \stopmycommand
> \stopsection
> \stoptext
> ```
> 
> If I compile using `context --trackers=structures.tags filename`, I get
> 
> ```
> backend         > tags > U+0031:1 => U+0031:1 : 00004 document>1 
> section>1 sectioncaption>1 sectionnumber>1
> backend         > tags > U+0053:S => U+0074:t : 00005 document>1 
> section>1 sectioncaption>1 sectiontitle>1
> backend         > tags > U+0054:T => U+0068:h : 00007 document>1 
> section>1 sectioncontent>1 paragraph>1
> backend         > tags > U+0054:T => U+0064:d : 00008 document>1 
> section>1 sectioncontent>1 mycommand>1
> ```
> 
> so the tag is applied. I can also verify this by looking at the PDF 
> which contains
> 
> ```
> << /K 27 0 R /ParentTree 2 0 R /RoleMap << /document /Div /mycommand 
> /Span /paragraph /P /section /Sect /sectioncaption /Div /sectioncontent 
> /Div /sectionnumber /H /sectiontitle /H >> /Type /StructTreeRoot >>
> ```
> 
> and the tag `mycommand` is used at appropriate location.
> 
> However, the exported xml file contains no tag:
> 
> ```
> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
> 
> <!--
> 
>      input filename   : test-tag
>      processing date  : 2020-05-18T03:00:33-04:00
>      context version  : 2020.04.30 11:10
>      exporter version : 0.35
> 
> -->
> 
> <!-- This export file is used for filtering runtime only! -->
> 
> <document context="2020.04.30 11:10" date="2020-05-18T03:00:33-04:00" 
> file="test-tag" language="en" version="0.35" 
> xmlns:m="http://www.w3.org/1998/Math/MathML">
>   <metadata>
>   </metadata>
>   <section detail="section" chain="section" implicit="1" level="3">
>    <sectioncaption>
>     <sectionnumber>1</sectionnumber>
>     <sectiontitle>Sample document</sectiontitle>
>    </sectioncaption>
>    <sectioncontent>
>     <paragraph>This is a paragraph</paragraph>
>    </sectioncontent>
>   </section>
> </document>
> ```
> 
> What am I missing in order to pass user-defined macros to the exporter?
you're probably missing documentation + a high level define command

This registers (extra) elements:

\setelementbackendtag[mycommand]
\setelementnature    [mycommand][mixed]

after that you can use \startelement[mycommamd]

\starttext
\startsection[title={Sample document}]
   \startparagraph
     This is a paragraph
   \stopparagraph
   \startelement[mycommand]
     This is mycommand
   \stopelement
\stopsection
\stoptext



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Minimal code for exporting custom tags
  2020-05-18  9:34 ` Hans Hagen
@ 2020-05-18 13:50   ` Aditya Mahajan
  2020-05-18 17:31     ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2020-05-18 13:50 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

On Mon, 18 May 2020, Hans Hagen wrote:

> On 5/18/2020 9:09 AM, Aditya Mahajan wrote:
>> Hi,
>> 
>> What is needed to enable export of user defined macros? Consider the 
>> following example:
>> 
>> What am I missing in order to pass user-defined macros to the exporter?
> you're probably missing documentation + a high level define command
>
> This registers (extra) elements:
>
> \setelementbackendtag[mycommand]
> \setelementnature    [mycommand][mixed]
>

Thanks! This also helped me find the documentation in hybrid.pdf.

I am not using a high-level interface because I was looking at how to get the output of `t-filter` and `t-vim` modules export correctly.

Aditya

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Minimal code for exporting custom tags
  2020-05-18 13:50   ` Aditya Mahajan
@ 2020-05-18 17:31     ` Aditya Mahajan
  2020-05-19  5:45       ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2020-05-18 17:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 18 May 2020, Aditya Mahajan wrote:

> On Mon, 18 May 2020, Hans Hagen wrote:
>
>> On 5/18/2020 9:09 AM, Aditya Mahajan wrote:
>>> Hi,
>>> 
>>> What is needed to enable export of user defined macros? Consider the 
>>> following example:
>>> 
>>> What am I missing in order to pass user-defined macros to the exporter?
>> you're probably missing documentation + a high level define command
>>
>> This registers (extra) elements:
>>
>> \setelementbackendtag[mycommand]
>> \setelementnature    [mycommand][mixed]
>>
>
> Thanks! This also helped me find the documentation in hybrid.pdf.

How do I pass options so that the export is

<mycommand name=whatever>...</mycommand>

(or some variant of that). I thought that

\startelement[mycommand][name=whatever]

should work (there are some such examples in the texmf tree), but it does not.

```
\setelementbackendtag[mycommand]
\setelementnature    [mycommand][mixed]

\setupbackend[export=xml, level=0]

\starttext
\startsection[title={Sample document}]
   \startparagraph
     This is a paragraph
   \stopparagraph
   \startelement[mycommand][name=whatever]
     This is mycommand
   \stopelement
\stopsection
\stoptext
```

Using `\dostarttagged{mycommand}{whatever}` does export as `<mycommand detail="whatever">`, and looking at the code, I don't see why `\startelement` should behave differently.

Thanks,
Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Minimal code for exporting custom tags
  2020-05-18 17:31     ` Aditya Mahajan
@ 2020-05-19  5:45       ` Aditya Mahajan
  2020-05-19  6:16         ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2020-05-19  5:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 18 May 2020, Aditya Mahajan wrote:

>> Thanks! This also helped me find the documentation in hybrid.pdf.

Also epub-mkiv.pdf. Not sure why I didn't think of looking there.

> How do I pass options so that the export is
>
> <mycommand name=whatever>...</mycommand>
>
> (or some variant of that). I thought that
>
> \startelement[mycommand][name=whatever]
>
> should work (there are some such examples in the texmf tree), but it does 
> not.

epub-mkiv.pdf states that I need `\setupexport[properties=yes]`, but that doesn't work either:

```
\setupbackend[export=xml]
\setupexport [properties=my]

\setelementbackendtag[mycommand]
\setelementnature    [mycommand][mixed]

\starttext
\startsection[title={Sample document}]
   \startparagraph
     This is a paragraph
   \stopparagraph
   \startelement[mycommand][name=whatever]
     This is mycommand
   \stopelement
\stopsection
\stoptext
```

gives

```
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!--

     input filename   : test-tag
     processing date  : 2020-05-19T01:34:41-04:00
     context version  : 2020.05.09 15:37
     exporter version : 0.35

-->

<!-- This export file is used for filtering runtime only! -->

<document context="2020.05.09 15:37" date="2020-05-19T01:34:41-04:00" file="test-tag" language="en" version="0.35" xmlns:m="http://www.w3.org/1998/Math/MathML">
  <metadata>
  </metadata>
  <section detail="section" chain="section" implicit="1" level="3">
   <sectioncaption>
    <sectionnumber>1</sectionnumber>
    <sectiontitle>Sample document</sectiontitle>
   </sectioncaption>
   <sectioncontent>
    <paragraph>This is a paragraph</paragraph>
    <mycommand>This is mycommand</mycommand>
   </sectioncontent>
  </section>
</document>
```

What am I still missing?

On a different note, I didn't realize that interfaces.implement could create macros which could be used like this:

```
\unexpanded\def\dostartexport
   {%\glet\dostartexport\relax
    \let\currentexport\empty
    \clf_setupexport
        align      {\exportparameter\c!align}%
        bodyfont   \dimexpr\exportparameter\c!bodyfont\relax
        width      \dimexpr\exportparameter\c!width\relax
        properties {\exportparameter\c!properties}%
        hyphen     {\exportparameter\c!hyphen}%
        title      {\exportparameter\c!title}%
        subtitle   {\exportparameter\c!subtitle}%
        author     {\exportparameter\c!author}%
        firstpage  {\exportparameter\c!firstpage}%
        lastpage   {\exportparameter\c!lastpage}%
        svgstyle   {\exportparameter\c!svgstyle}%
        cssfile    {\exportparameter\c!cssfile}%
        file       {\exportparameter\c!file}%
        export     {\backendparameter\c!export}%
    \relax}

```

This nicely gets around TeX's limitation of 9 arguments!

Aditya


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Minimal code for exporting custom tags
  2020-05-19  5:45       ` Aditya Mahajan
@ 2020-05-19  6:16         ` Aditya Mahajan
  0 siblings, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2020-05-19  6:16 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, 19 May 2020, Aditya Mahajan wrote:

> On Mon, 18 May 2020, Aditya Mahajan wrote:
>
>>> Thanks! This also helped me find the documentation in hybrid.pdf.
>
> Also epub-mkiv.pdf. Not sure why I didn't think of looking there.
>
>> How do I pass options so that the export is
>>
>> <mycommand name=whatever>...</mycommand>
>>
>> (or some variant of that). I thought that
>>
>> \startelement[mycommand][name=whatever]
>>
>> should work (there are some such examples in the texmf tree), but it does 
>> not.
>
> epub-mkiv.pdf states that I need `\setupexport[properties=yes]`, but that 
> doesn't work either:

There is a bug in back-exp.lua:

--- /tmp/back-exp.lua	2020-05-19 02:13:54.961276226 -0400
+++ /opt/luametatex/texmf-context/tex/context/base/mkiv/back-exp.lua	2020-05-19 02:13:01.687385009 -0400
@@ -2305,8 +2305,10 @@
                  if not p then
                      -- skip
                  elseif exportproperties == v_yes then
+                    n = n+1
                      r[n] = attributes(p)
                  else
+                    n = n+1
                      r[n] = properties(p)
                  end
              end

Patching this fixes the export.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2020-05-19  6:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18  7:09 Minimal code for exporting custom tags Aditya Mahajan
2020-05-18  9:34 ` Hans Hagen
2020-05-18 13:50   ` Aditya Mahajan
2020-05-18 17:31     ` Aditya Mahajan
2020-05-19  5:45       ` Aditya Mahajan
2020-05-19  6:16         ` Aditya Mahajan

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).