In ConTeXt, one option is to export your document as XML. You can then manipulate the resulting XML document using standard XML tools in your favourite programming language.
As an example, consider this example:
\setupbackend[export=yes]
\setupinteraction[state=start]
\starttext
\startsection[title={Test of export}]
This is to test how \CONTEXT\ export works. First, we input a test file
below.
\startnarrower
\input ward
\stopnarrower
Let's see some other environments, such as\footnote{Note that we define a
float in \in{Figure}[fig:mill].}
\startitemize[n]
\item A table:
\startTABLE
\NC 1 \NC 2 \NC 3 \NC \NR
\NC 1 \NC 2 \NC 3 \NC \NR
\NC 1 \NC 2 \NC 3 \NC \NR
\stopTABLE
\item A formula
\startformula
α^2 + β^2 = 2
\stopformula
\item A figure
\externalfigure[mill.png][width=5cm]
\stopitemize
\startplacefigure
[title={This is a Mill}, reference={fig:mill}]
\externalfigure[mill.png][width=5cm]
\stopplacefigure
\stopsection
\stoptext
and process it using context filename
. This will create a directory \jobname-export
with the following structure:
\jobname-export
|
+-- images
| +--- <image file1>
| +---- ....
+-- style
| +-- \jobname-defaults.css
| +-- \jobname-images.css
| +-- \jobname-styles.css
| +-- \jobname-template.css
+-- \jobname-div.xhtml
+-- \jobname-pub.lua
+-- \jobname-raw.xml
+-- \jobname-tag.xhtml
Out of these, the \jobname-raw.xml
contains the AST of the complete document. For the above document it is:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!--
input filename : test
processing date : Tue Jun 14 19:58:26 2016
context version : 2016.06.02 21:28
exporter version : 0.34
-->
<?xml-stylesheet type="text/css" href="styles/test-defaults.css" ?>
<?xml-stylesheet type="text/css" href="styles/test-images.css" ?>
<?xml-stylesheet type="text/css" href="styles/test-styles.css" ?>
<document date="Tue Jun 14 19:58:26 2016" file="test" context="2016.06.02 21:28" language="en" xmlns:m="http://www.w3.org/1998/Math/MathML" version="0.34">
<metadata>
</metadata>
<section detail="section" chain="section" implicit="1" level="3">
<sectionnumber>1</sectionnumber>
<sectiontitle>Test of export</sectiontitle>
<sectioncontent>
This is to test how ConTEXt export works. First, we input a test file below.
<break/>
The Earth, as a habitat for animal life, is in old age and has a fatal illness. Several, in fact. It would be happening whether humans had ever evolved or not. But our presence is like the effect of an old-age patient who smokes many packs of cigarettes per day <subsentencesymbol symbol="middle">—</subsentencesymbol> and we humans are the cigarettes.
<break/>
Let’s see some other environments, such as<descriptionsymbol detail="footnote" insert="1"><sup>1</sup></descriptionsymbol>
<itemgroup detail="itemize" chain="itemize" level="1" symbol="n">
<item>
<itemtag>1.</itemtag>
<itemcontent>A table:<table><tablerow><tablecell align="flushleft"> 1 </tablecell><tablecell align="flushleft"> 2 </tablecell><tablecell align="flushleft"> 3 </tablecell></tablerow><tablerow><tablecell align="flushleft"> 1 </tablecell><tablecell align="flushleft"> 2 </tablecell><tablecell align="flushleft"> 3 </tablecell></tablerow><tablerow><tablecell align="flushleft"> 1 </tablecell><tablecell align="flushleft"> 2 </tablecell><tablecell align="flushleft"> 3 </tablecell></tablerow></table></itemcontent>
</item>
<item>
<itemtag>2.</itemtag>
<itemcontent>A formula<formula> <formulacontent><m:math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><m:mrow><m:msup><m:mi>𝛼</m:mi><m:mn>2</m:mn></m:msup><m:mo>+</m:mo><m:msup><m:mi>𝛽</m:mi><m:mn>2</m:mn></m:msup><m:mo>=</m:mo><m:mn>2</m:mn></m:mrow></m:math></formulacontent> </formula></itemcontent>
</item>
<item>
<itemtag>3.</itemtag>
<itemcontent>A figure<image width="5.000cm" height="3.750cm" id="image-1" name="mill.png" label="3.750cm"></image></itemcontent>
</item>
</itemgroup>
<float detail="figure" chain="figure" implicit="4" explicit="fig:mill" reference="fig:mill">
<floatcontent><image width="5.000cm" height="3.750cm" id="image-2" name="mill.png" label="3.750cm"></image></floatcontent>
<floatcaption><floatlabel detail="figure">Figure </floatlabel><floatnumber detail="figure">1</floatnumber> <floattext>This is a Mill</floattext></floatcaption>
</float>
<description detail="footnote" chain="footnote" insert="1">
<descriptiontag><sup>1</sup> </descriptiontag>
<descriptioncontent>Note that we define a float in <link destination="fig:mill" location="fig:mill">Figure 1</link>.</descriptioncontent>
</description>
</sectioncontent>
</section>
</document>
Note that the math formula has been exported to (formatted for clarity).
<formula> <formulacontent><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="block">
<m:mrow>
<m:msup><m:mi>𝛼</m:mi><m:mn>2</m:mn></m:msup>
<m:mo>+</m:mo>
<m:msup><m:mi>𝛽</m:mi><m:mn>2</m:mn></m:msup>
<m:mo>=</m:mo>
<m:mn>2</m:mn>
</m:mrow>
</m:math></formulacontent> </formula>
Now, if you want, you can easily filter out the math (or any other part of the document).
\def\keyword{hello}\keyword
I would expect all such convertors to make that indistinguishable fromhello
isn't that what you want? – David Carlisle Jun 15 '16 at 15:39