Difference between revisions of "Export"
(some minor restructuring) |
(add raw.xml) |
||
Line 218: | Line 218: | ||
TODO: explain differences between export variants | TODO: explain differences between export variants | ||
+ | |||
+ | == raw.xml == | ||
+ | |||
+ | <xmlcode> | ||
+ | <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
+ | |||
+ | <!-- | ||
+ | |||
+ | input filename : minimal | ||
+ | processing date : Sat Jan 17 19:42:37 2015 | ||
+ | context version : 2014.12.29 10:01 | ||
+ | exporter version : 0.33 | ||
+ | |||
+ | --> | ||
+ | <?xml-stylesheet type="text/css" href="styles/minimal-defaults.css" ?> | ||
+ | <?xml-stylesheet type="text/css" href="styles/minimal-images.css" ?> | ||
+ | <?xml-stylesheet type="text/css" href="styles/minimal-styles.css" ?> | ||
+ | |||
+ | <document xmlns:m="http://www.w3.org/1998/Math/MathML" title="My first eBook 1" version="0.33" author="{Hans 1} " context="2014.12.29 10:01" date="Sat Jan 17 19:42:37 2015" language="en" file="minimal"> | ||
+ | <section detail="chapter" chain="chapter" level="2"> | ||
+ | <metadata> | ||
+ | <metavariable name="author">Hans 3</metavariable> | ||
+ | <metavariable name="subtitle"></metavariable> | ||
+ | <metavariable name="title">My first eBook 3</metavariable> | ||
+ | <metavariable name="version">\date </metavariable> | ||
+ | </metadata> | ||
+ | <sectionnumber>1</sectionnumber> | ||
+ | <sectiontitle>Example</sectiontitle> | ||
+ | <sectioncontent> | ||
+ | <paragraph>We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats.</paragraph> | ||
+ | <section detail="section" chain="section" level="3"> | ||
+ | <sectionnumber>1.1</sectionnumber> | ||
+ | <sectiontitle>A section</sectiontitle> | ||
+ | <sectioncontent> | ||
+ | <paragraph>We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats. <itemgroup detail="itemize" chain="itemize" packed="yes" symbol="1" level="1"><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>First</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Second</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Third</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Fourth</itemcontent></item></itemgroup> </paragraph> | ||
+ | <paragraph>Thus, I came to the conclusion that the designer of a new system must not only be the implementer and first large--scale user; the designer should also write the first user manual. <break/> | ||
+ | The separation of any of these four components would have hurt TEX significantly. If I had not participated fully in all these activities, literally hundreds of improvements would never have been made, because I would never have thought of them or perceived why they were important. <break/> | ||
+ | But a system cannot be successful if it is too strongly influenced by a single person. Once the initial design is complete and fairly robust, the real test begins as people with many different viewpoints undertake their own experiments.</paragraph> | ||
+ | <paragraph>Coming back to the use of typefaces in electronic publishing: many of the new typographers receive their knowledge and information about the rules of typography from books, from computer magazines or the instruction manuals which they get with the purchase of a PC or software. There is not so much basic instruction, as of now, as there was in the old days, showing the differences between good and bad typographic design. Many people are just fascinated by their PC’s tricks, and think that a widely--praised program, called up on the screen, will make everything automatic from now on.</paragraph> | ||
+ | </sectioncontent> | ||
+ | </section> | ||
+ | </sectioncontent> | ||
+ | </section> | ||
+ | <section detail="chapter" chain="chapter" level="2"> | ||
+ | <sectionnumber>2</sectionnumber> | ||
+ | <sectiontitle>Quoth<descriptionsymbol detail="footnote"><sup>1</sup></descriptionsymbol></sectiontitle> | ||
+ | <sectioncontent> | ||
+ | <lines detail="lines" chain="lines"> | ||
+ | <line><delimited detail="quotation-1">“Prophet!”</delimited> said I, <delimited detail="quotation-1">“thing of evil!—prophet still, if bird or devil!”</delimited><line>By that Heaven that bends above us—by that God we both adore—</line><line>Tell this soul with sorrow laden if, within the distant Aidenn,</line><line>It shall clasp a sainted maiden whom the angels name Lenore—</line><line>Clasp a rare and radiant maiden whom the angels name Lenore.</line></line> | ||
+ | <line><highlight detail="emph">Quoth the Raven <delimited detail="quotation-1">“Nevermore.”</delimited></highlight></line> | ||
+ | </lines> | ||
+ | </sectioncontent> | ||
+ | <description detail="footnote" chain="footnote"> | ||
+ | <descriptiontag><sup>1</sup> </descriptiontag> | ||
+ | <descriptioncontent>by Edgar Allan Poe</descriptioncontent> | ||
+ | </description> | ||
+ | </section> | ||
+ | </document> | ||
+ | <break/> | ||
+ | |||
+ | </xmlcode> | ||
+ | |||
(WORK IN PROGRESS) | (WORK IN PROGRESS) | ||
Revision as of 14:23, 17 January 2015
TODO: This page is work in progress. (See: To-Do List) |
ConTeXt does not only produce beautiful PDFs, but can also export to XML/HTML. This is especially useful for creating eBooks in ePub format.
Contents
Minimal example
% mode=mkiv \setupbackend[export=yes] % this is all to activate export! \starttext \input tufte \stoptext
Exported structure
If you compile an example as above as minimal.tex
, you get a directory structure like this:
minimal.tex minimal.log minimal.pdf minimal.tuc minimal-export ├── cover.xhtml ├── images ├── minimal-div.xhtml ├── minimal-pub.lua ├── minimal-raw.xml ├── minimal-tag.xhtml └── styles ├── minimal-defaults.css ├── minimal-images.css ├── minimal-styles.css └── minimal-templates.css
We will further refer to these files without the prefix ("minimal-"). We reformatted the code copies a bit to make them smaller and better readable.
div.xhtml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!-- input filename : minimal processing date : Sat Jan 17 17:43:58 2015 context version : 2014.12.29 10:01 exporter version : 0.33 --> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML"> <head> <meta charset="utf-8"/> <title></title> <link type="text/css" rel="stylesheet" href="styles/minimal-defaults.css" /> <link type="text/css" rel="stylesheet" href="styles/minimal-images.css" /> <link type="text/css" rel="stylesheet" href="styles/minimal-styles.css" /> </head> <body> <div class="warning">Rendering can be suboptimal because there is no default/fallback css loaded.</div> <div> We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats. </div> </body> </html>
tag.xhtml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!-- input filename : minimal processing date : Sat Jan 17 17:43:58 2015 context version : 2014.12.29 10:01 exporter version : 0.33 --> <?xml-stylesheet type="text/css" href="styles/minimal-defaults.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-images.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-styles.css" ?> <document href="minimal" language="en" date="Sat Jan 17 17:43:58 2015" context="2014.12.29 10:01" xmlns:m="http://www.w3.org/1998/Math/MathML" file="minimal" version="0.33"> We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats. </document>
raw.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!-- input filename : minimal processing date : Sat Jan 17 17:43:58 2015 context version : 2014.12.29 10:01 exporter version : 0.33 --> <?xml-stylesheet type="text/css" href="styles/minimal-defaults.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-images.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-styles.css" ?> <document language="en" date="Sat Jan 17 17:43:58 2015" context="2014.12.29 10:01" xmlns:m="http://www.w3.org/1998/Math/MathML" file="minimal" version="0.33"> We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats. </document>
pub.lua
return { ["htmlfiles"]={ "minimal-div.xhtml" }, ["htmlroot"]="minimal-div.xhtml", ["identifier"]="3ce74458-4cdd-829d-ace4-cf535fb00519", ["imagefile"]="styles/minimal-images.css", ["imagepath"]="images", ["images"]={}, ["language"]="en", ["name"]="minimal", ["stylepath"]="styles", ["styles"]={ "minimal-defaults.css", "minimal-images.css", "minimal-styles.css" }, ["xhtmlfiles"]={ "minimal-tag.xhtml" }, ["xmlfiles"]={ "minimal-raw.xml" }, }
Required structuring of your ConTeXt code
The export contains usable content only for content that is "well structured" in an XML sense. In our above example all text ended up in the root tag document
.
That means, you need to mark everything, from markup spans over paragraphs and enumeration items to chapters and parts with \start... … \stop...
.
Also note that switches like \em don’t translate into output structure, you need to \definehighlight[emph][style=italic] and use as \emph{emphasized}.
More useful example
% mode=mkiv \mainlanguage[en] \setupbackend[export=yes] \setupinteraction[state=start, color=,contrastcolor=, % This metadata is used for the PDF title={My first eBook 1}, subtitle={}, keywords={}, author={Hans 1} ] \setupexport[ hyphen=yes, % This metadata is used by ConTeXt’s ePub script % title, subtitle and author are taken from \setupinteraction, if not set title={My first eBook 2}, subtitle={}, author={Hans 2} ] \settaggedmetadata[ % here you can set as many metadata entries as you like, but you need to process them yourself title={My first eBook 3}, author={Hans 3}, subtitle={}, version={\date} % TODO: doesn’t expand ] \definehighlight[emph][style=italic] % use \emph{something} instead of {\em something} \starttext \startchapter[title=Example] \startparagraph \input tufte \stopparagraph \startsection[title={A section}] \startparagraph \input tufte \startitemize[packed,joinup] \startitem First \stopitem \startitem Second \stopitem \startitem Third \stopitem \startitem Fourth\stopitem \stopitemize \stopparagraph \startparagraph \input knuth \stopparagraph \startparagraph \input zapf \stopparagraph \stopsection \stopchapter \startchapter[title=Quoth\footnote{by Edgar Allan Poe}] \startlines \quotation{Prophet!} said I, \quotation{thing of evil!—prophet still, if bird or devil! By that Heaven that bends above us—by that God we both adore— Tell this soul with sorrow laden if, within the distant Aidenn, It shall clasp a sainted maiden whom the angels name Lenore— Clasp a rare and radiant maiden whom the angels name Lenore.} \emph{Quoth the Raven \quotation{Nevermore.}} \stoplines \stopchapter \stoptext
There’s also an example of an export-friendly ConTeXt file in the sources: export-example.tex.
Choice of output files
Only after such tagging we find significant differences between the three content output files:
TODO: explain differences between export variants
raw.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!-- input filename : minimal processing date : Sat Jan 17 19:42:37 2015 context version : 2014.12.29 10:01 exporter version : 0.33 --> <?xml-stylesheet type="text/css" href="styles/minimal-defaults.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-images.css" ?> <?xml-stylesheet type="text/css" href="styles/minimal-styles.css" ?> <document xmlns:m="http://www.w3.org/1998/Math/MathML" title="My first eBook 1" version="0.33" author="{Hans 1} " context="2014.12.29 10:01" date="Sat Jan 17 19:42:37 2015" language="en" file="minimal"> <section detail="chapter" chain="chapter" level="2"> <metadata> <metavariable name="author">Hans 3</metavariable> <metavariable name="subtitle"></metavariable> <metavariable name="title">My first eBook 3</metavariable> <metavariable name="version">\date </metavariable> </metadata> <sectionnumber>1</sectionnumber> <sectiontitle>Example</sectiontitle> <sectioncontent> <paragraph>We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats.</paragraph> <section detail="section" chain="section" level="3"> <sectionnumber>1.1</sectionnumber> <sectiontitle>A section</sectiontitle> <sectioncontent> <paragraph>We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats. <itemgroup detail="itemize" chain="itemize" packed="yes" symbol="1" level="1"><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>First</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Second</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Third</itemcontent></item><item><itemtag><m:math xmlns:m="http://www.w3.org/1998/Math/MathML" display="inline"><m:mo>•</m:mo></m:math></itemtag><itemcontent>Fourth</itemcontent></item></itemgroup> </paragraph> <paragraph>Thus, I came to the conclusion that the designer of a new system must not only be the implementer and first large--scale user; the designer should also write the first user manual. <break/> The separation of any of these four components would have hurt TEX significantly. If I had not participated fully in all these activities, literally hundreds of improvements would never have been made, because I would never have thought of them or perceived why they were important. <break/> But a system cannot be successful if it is too strongly influenced by a single person. Once the initial design is complete and fairly robust, the real test begins as people with many different viewpoints undertake their own experiments.</paragraph> <paragraph>Coming back to the use of typefaces in electronic publishing: many of the new typographers receive their knowledge and information about the rules of typography from books, from computer magazines or the instruction manuals which they get with the purchase of a PC or software. There is not so much basic instruction, as of now, as there was in the old days, showing the differences between good and bad typographic design. Many people are just fascinated by their PC’s tricks, and think that a widely--praised program, called up on the screen, will make everything automatic from now on.</paragraph> </sectioncontent> </section> </sectioncontent> </section> <section detail="chapter" chain="chapter" level="2"> <sectionnumber>2</sectionnumber> <sectiontitle>Quoth<descriptionsymbol detail="footnote"><sup>1</sup></descriptionsymbol></sectiontitle> <sectioncontent> <lines detail="lines" chain="lines"> <line><delimited detail="quotation-1">“Prophet!”</delimited> said I, <delimited detail="quotation-1">“thing of evil!—prophet still, if bird or devil!”</delimited><line>By that Heaven that bends above us—by that God we both adore—</line><line>Tell this soul with sorrow laden if, within the distant Aidenn,</line><line>It shall clasp a sainted maiden whom the angels name Lenore—</line><line>Clasp a rare and radiant maiden whom the angels name Lenore.</line></line> <line><highlight detail="emph">Quoth the Raven <delimited detail="quotation-1">“Nevermore.”</delimited></highlight></line> </lines> </sectioncontent> <description detail="footnote" chain="footnote"> <descriptiontag><sup>1</sup> </descriptiontag> <descriptioncontent>by Edgar Allan Poe</descriptioncontent> </description> </section> </document> <break/>
(WORK IN PROGRESS)
Export options
From back-exp.mkiv, is this still current?
\setupexport[ align=\raggedstatus, bodyfont=\bodyfontsize, width=\textwidth, title={\directinteractionparameter\c!title}, % from interaction subtitle={\directinteractionparameter\c!subtitle}, % from interaction author={\directinteractionparameter\c!author}, % from interaction % firstpage=, % imagename % lastpage=, % imagename hyphen=no, ]
- The options align, bodyfont and width end up in the exported CSS.
- firstpage, lastpage: cover image? (how?)
- hyphen: include hyphenation (
?)
More TODO
- handling of images
- which files get overwritten, which stay