Changes

Jump to navigation Jump to search
3,658 bytes added ,  08:33, 11 October 2010
m
continuing
== Our xml file ==
Philostratus's text is in ancient Greek, but since the text itself doesn't matter much when we talk about structure and typesetting xml, I have replaced it here with a simple lorem ipsum text that is easier to display. So here's what the first paragraphs of the xml file philostratus.xml look like:
<xmlcode>
<xmlcode>
<div xml:id="VS1" n="I" type="book">
<div xml:id="VS1pVS1.1" n="praef1" type="chapter"> <div xml:id="VS1p1VS1.1.1" n="1" type="section">
</div>
</div>
== The ConTeXt style file ==
In order to typeset such a file with ConTeXt, we need a style file which will map xml elements and attributes to specific ConTeXt commands. We have to save this file (let's call it tei-style.tex) somewhere where ConTeXt can find it (e.g., somewhere in your personal texmf tree or in the same directory as the xml file) and then typeset with the command <tt>context --environment=tei-style philostratus.xml</tt>. We will look at this file in detail: <texcode>\startxmlsetups xml:teisetups \xmlsetsetup{#1}{*}{-}\stopxmlsetups</texcode> We define a set of <tt>xmlsetups</tt> in a <tt>start stop</tt> environment, and we give it a name in the namespace <tt>xml:</tt>. The first line of these setups does only one thing: the <code>\xmlsetsetup</code> operates on the current xml tree (that's what the first argument <code>{#1}</code> refers to), takes all its elements (<code>{*}</code>) and discards them (<code>{-}</code>). That means '''only''' elements which we address explicitly will be typeset. This is necessary in our case because we do not want the information in the TEI header to be typeset. For those elements we '''do''' want typeset, we have to add instructions. This involves a three-step process: # We have to add their names to a line which defines a <code>\xmlsetsetup</code># We define a specific setup for them# (optional) we define TeX commands for typesetting Let us begin with some easy steps. The xml tree we are operating on is empty now. So we first have to tell ConTeXt to pass the content of rge topmost elements to its typesetting engine. The topmost element is TEI, so we write: <texcode>\startxmlsetups xml:teisetups \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{TEI}{xml:*}\stopxmlsetups \xmlregistersetup{xml:teisetups} \startxmlsetups xml:TEI \xmlflush{#1}\stopxmlsetups</texcode> So: we add the <tt>TEI</tt> element to a new <code>\xmlsetsetup</code>. We "register" the setups we have defined. And then we declare that the content of the element <tt>TEI</tt> should be passed to ConTeXt; this is what the line <code>\xmlflush{#1}</code> does. Of course, we will do the same for the <tt>text</tt> element, but not for the <tt>TEIheader</tt> element, which we do not want to be typeset. So we now have: <texcode>\startxmlsetups xml:teisetups \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{TEI|text}{xml:*}\stopxmlsetups \xmlregistersetup{xml:teisetups} \startxmlsetups xml:TEI \xmlflush{#1}\stopxmlsetups \startxmlsetups xml:text \xmlflush{#1}\stopxmlsetups</texcode> Things become a bit more interesting when we look at the next level. We will start with the text proper, which is contained in the <tt>body</tt> element. For the text, we want line numbers in the margin, and we want this linenumbers in steps of five, in a small font. Here you can see the three steps we have to take: <texcode>\startxmlsetups xml:teisetups \xmlsetsetup{#1}{*}{-} \xmlsetsetup{#1}{TEI|text|body}{xml:*}\stopxmlsetups \xmlregistersetup{xml:teisetups} \startxmlsetups xml:TEI \xmlflush{#1}\stopxmlsetups \startxmlsetups xml:text \xmlflush{#1}\stopxmlsetups \startxmlsetups xml:body \startlinenumbering \xmlflush{#1} \stoplinenumbering\stopxmlsetups \setuplinenumbering[location=inner, step=5, method=page, style=\tfxx, align=left, distance=0.3em, width=0.3cm] </texcode> So we have: # add the element <tt>body</tt> to our <code>\xmlsetsetup</code># add a specific setup for the element which puts its content within a <code>\startlinenumbering</code> environment # add ConTeXt setup commands for the <code>\startlinenumbering</code> environment.
--[[User:Thomas|Thomas]] 11:37, 10 October 2010 (UTC)
gardener
111

edits

Navigation menu