https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Rik&feedformat=atomWiki - User contributions [en]2024-03-29T15:15:14ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Command/setupinitial&diff=33324Command/setupinitial2021-12-16T01:10:09Z<p>Rik: Noted requirement to define named initials</p>
<hr />
<div><cd:commandgroup name="setupinitial" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc>Initials (also known as drop caps, dropped caps, or versals) can be made in ConTeXt using the {{cmd|placeinitial}} command.<br />
<br />
The command {{cmd|setupinitial}} detailed here is used to customize this decorative first letter(s) at the start of chapters, sections, paragraphs, and so forth.<br />
<br />
<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command category="fonts" file="typo-drp.mkiv" interfacedate="2019-11-19T09:54" interfacefile="i-initial.xml" level="style" name="setupinitial" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:parameter name="n"><br />
<cd:paramdoc>number of lines in the paragraph that the initial should occupy. It defaults to 3. The size of the initial is adapted accordingly, but it can be changed with font parameter."</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="m"><br />
<cd:paramdoc>number of letters to capitalize</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="before"><br />
<cd:paramdoc>contains any commands that you would like to do prior to placing the initial. This parameter is empty by default.<br />
<br />
For example, to insert 2 big space before placement of the initial,<br />
<code>before={\blank[2*big]}]</code></cd:paramdoc><br />
<cd:constant type="cd:command"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="distance"><br />
<cd:paramdoc>the horizontal distance which initial line(s) of the paragraph should be indented beyond the space needed for the letter. It defaults to 0pt, and it can be negative.</cd:paramdoc><br />
<cd:constant type="cd:dimension"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="hoffset"><br />
<cd:paramdoc>the distance to the left (into the left margin), or to the right, that the initial should be shifted from its default position. This defaults to 0pt.<br />
</cd:paramdoc><br />
<cd:constant type="cd:dimension"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="voffset"><br />
<cd:paramdoc>the distance downward, or upward (negative value), from its default position that the initial should be shifted. This defaults to 0pt.<br />
<br />
Value 0pt gives a "top" alignment, i.e. corresponding with the first line of the paragraph.</cd:paramdoc><br />
<cd:constant default="yes" type="line"></cd:constant><br />
<cd:constant type="cd:dimension"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="style"><br />
<cd:paramdoc>style of the initial, for example <code>style=\it</code> for italic.</cd:paramdoc><br />
<cd:constant type="cd:style"></cd:constant><br />
<cd:constant type="cd:command"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="color"><br />
<cd:paramdoc>for example <code>color=darkred</code>. It defaults to the current color </cd:paramdoc><br />
<cd:constant type="cd:color"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="font"><br />
<cd:paramdoc>font specification. It defaults to boldface scaled to the number of text lines that the initial occupies, but can be customized, for example: <code>font=Bold at 32pt</code>.</cd:paramdoc><br />
<cd:constant type="cd:font"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="text"><br />
<cd:paramdoc>the text specified will be used as initial, instead of the letter following the <code>\placeinitial</code> command.</cd:paramdoc><br />
<cd:constant type="cd:text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="location"><br />
<cd:paramdoc>default is <code>text</code>, but initial can be placed in the margin with <code>location=margin</code></cd:paramdoc><br />
<cd:constant type="margin"></cd:constant><br />
<cd:constant default="yes" type="text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="method"><br />
<cd:paramdoc>to be determined.</cd:paramdoc><br />
<cd:constant type="first"></cd:constant><br />
<cd:constant type="last"></cd:constant><br />
<cd:constant type="auto"></cd:constant><br />
<cd:constant default="yes" type="none"></cd:constant><br />
</cd:parameter><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description></cd:description><br />
<cd:examples><cd:example title="color, distance, before + variations on n, m , location">The following example produces an awful-looking initial, but it illustrates how some of these parameters work.<br />
<br />
<context mode="mkiv" source="yes"><br />
\definepapersize[sheet][width=120mm,height=200mm]<br />
\setuppapersize[sheet]<br />
\setuppagenumbering[location=]<br />
\setuplayout[width=100mm,backspace=15mm,topspace=0mm,header=0mm,headerdistance=0mm,footer=0mm,footerdistance=0mm]<br />
<br />
\starttext<br />
<br />
\setupinitial<br />
[color=darkred,<br />
distance=10mm,<br />
before={\blank[big]\hairline\blank[big]}]<br />
<br />
\type[option=context]{\setupinitial[color=darkred,distance=10mm,before={\blank[big]\hairline\blank[big]}]}<br />
<br />
and<br />
<br />
\type[option=context]{\setupinitial[n=2, m=2]}<br />
<br />
\setupinitial[n=2, m=2]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
<br />
or \type[option=context]{\setupinitial[n=3, m=4]}<br />
<br />
\setupinitial[n=3, m=4]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
<br />
or \type[option=context]{\setupinitial[location=margin,n=3, m=1,distance=5mm]}<br />
<br />
\setupinitial[location=margin,n=3, m=1,distance=5mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\stoptext<br />
<br />
</context></cd:example><cd:example title="hoffset"><context mode="mkiv" source="yes"><br />
\definepapersize[sheet][width=120mm,height=200mm]<br />
\setuppapersize[sheet]<br />
\setuppagenumbering[location=]<br />
\setuplayout[width=100mm,backspace=15mm,topspace=0mm,header=0mm,headerdistance=0mm,footer=0mm,footerdistance=0mm]<br />
<br />
\starttext<br />
<br />
Here is some text 1.<br />
<br />
\setupinitial[color=darkred]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[hoffset=0mm]}<br />
<br />
\setupinitial[hoffset=0mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[hoffset=5mm]}<br />
<br />
\setupinitial[hoffset=5mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[hoffset=-5mm]}<br />
<br />
\setupinitial[hoffset=-5mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\stoptext<br />
<br />
</context></cd:example><cd:example title="voffset"><context mode="mkiv" source="yes"><br />
\definepapersize[sheet][width=120mm,height=200mm]<br />
\setuppapersize[sheet]<br />
\setuppagenumbering[location=]<br />
\setuplayout[width=100mm,backspace=15mm,topspace=0mm,header=0mm,headerdistance=0mm,footer=0mm,footerdistance=0mm]<br />
<br />
\starttext<br />
<br />
Here is some text 1.<br />
<br />
\setupinitial[color=darkred]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[voffset=0mm]}<br />
<br />
\setupinitial[voffset=0mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[voffset=5mm]}<br />
<br />
\setupinitial[voffset=5mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[voffset=-5mm]}<br />
<br />
\setupinitial[voffset=-5mm]<br />
\placeinitial<br />
\input knuth<br />
<br />
\stoptext<br />
<br />
</context></cd:example><cd:example title="font"><context mode="mkiv" source="yes"><br />
\definepapersize[sheet][width=120mm,height=150mm]<br />
\setuppapersize[sheet]<br />
\setuppagenumbering[location=]<br />
\setuplayout[width=100mm,backspace=15mm,topspace=0mm,header=0mm,headerdistance=0mm,footer=0mm,footerdistance=0mm]<br />
<br />
\starttext<br />
<br />
Here is some text 1.<br />
<br />
\setupinitial[color=darkred]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[font=Bold at 45pt]}<br />
<br />
\setupinitial[font=Bold at 45pt]<br />
\placeinitial<br />
\input knuth<br />
<br />
\blank[big]<br />
\type[option=context]{\setupinitial[font=SansBold at 45pt]}<br />
<br />
\setupinitial[font=SansBold at 45pt]<br />
<br />
\placeinitial<br />
\input knuth<br />
<br />
\stoptext<br />
<br />
</context></cd:example><cd:example title="text"><context mode="mkiv" source="yes"><br />
\definepapersize[sheet][width=120mm,height=80mm]<br />
\setuppapersize[sheet]<br />
\setuppagenumbering[location=]<br />
\setuplayout[width=100mm,backspace=15mm,topspace=0mm,header=0mm,headerdistance=0mm,footer=0mm,footerdistance=0mm]<br />
<br />
\starttext<br />
<br />
\type[option=context]{\setupinitial[text=Here]}<br />
<br />
\setupinitial[color=darkred,text=Here]<br />
\placeinitial<br />
\input knuth<br />
<br />
<br />
\stoptext<br />
<br />
</context></cd:example></cd:examples><br />
<cd:notes><br />
<cd:note author="Garulfo" date="2020-12-12T22:46:03+0100"><br />
<br />
<br />
<br />
<br />
<br />
<br />
Because the space carved out for the initial is rectangular, initials work best with a font with rectangular ornaments around the letter.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</cd:note><br />
<cd:note author="Rik" date="2021-12-16T02:10:09+0100"><br />
Named initials must be defined using {{cmd|defineinitial}}.<br />
</cd:note></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="defineinitial" originator="system"></cd:commandref><br />
<cd:source file="typo-drp.mkiv" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Fonts"></cd:wikipage><br />
<cd:commandref name="placeinitial"></cd:commandref><br />
<cd:commandref name="definefirstline">to apply specific style to the whole first line, or first words</cd:commandref></cd:seealso><br />
</cd:commandgroup></div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/_framedtext&diff=32095Command/ framedtext2020-11-30T21:08:49Z<p>Rik: </p>
<hr />
<div><cd:commandgroup generated="yes" name="framedtext" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><!-- a short command summary goes here --><br />
The instances of <tt>\<i>framedtext</i></tt> are used for wrapping frames, margins and/or backgrounds around longer blocks of text.<br />
</cd:shortdesc><br />
<cd:sequence><br />
<cd:instance value="framedtext"></cd:instance><br />
</cd:sequence><br />
<cd:instances><br />
<cd:constant value="framedtext">Like {{cmd|framed}}, but suited for multiple paragraphs.</cd:constant><br />
</cd:instances><br />
<cd:variants><br />
<cd:command category="rules" file="pack-rul.mkiv" generated="yes" interfacedate="2020-07-14T09:24" interfacefile="i-framed.xml" keywords="background" level="document" name="framedtext" variant="instance" variantnumber="1"><br />
<cd:arguments><br />
<cd:assignments list="yes" optional="yes" ordinal="1"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:inherit name="setupframedtext"></cd:inherit><br />
</cd:assignments><br />
<cd:content ordinal="2"></cd:content><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>The instances of {{gen|framedtext}} are defined by {{cmd|defineframedtext}}. That command also defines {{gen|startframedtext}} environment versions of the instances. Since the intended usage is around text containing multiple paragraphs, the environment form is usually more suited.<br />
</cd:description><br />
<cd:examples></cd:examples><br />
<cd:notes><br />
<cd:note author="Rik" date="2020-11-30T22:08:49+0100"><br />
The default width of the \framedtext frame is fixed at .75\hsize, unlike the frame produced by \framed, which defaults to width=fit.<br />
</cd:note></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="_startframedtext" originator="system"></cd:commandref><br />
<cd:commandref name="defineframedtext" originator="system"></cd:commandref><br />
<cd:commandref name="setupframedtext" originator="system"></cd:commandref><br />
<cd:source file="pack-rul.mkiv" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Rules"></cd:wikipage><br />
<cd:wikipage originator="system" page="Keywords:Background"></cd:wikipage><br />
<cd:commandref name="startframedtext"></cd:commandref></cd:seealso><br />
</cd:commandgroup></div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/setupregister&diff=23851Command/setupregister2018-08-09T13:24:04Z<p>Rik: added description of check option</p>
<hr />
<div>{{Reference<br />
|name=setupregister<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupregister<span class="first" >[...]</span><span class="second" style="color:red;">[...]</span><span class="third" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>singular </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[...]</td><br />
<td>name </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:n|n]]</td><br />
<td>[[Command/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:balance|balance]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:style|style]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small...|small...]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:pagestyle|pagestyle]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small...|small...]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:textstyle|textstyle]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small...|small...]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:indicator|indicator]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:coupling|coupling]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:check|check]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr> <tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:sectionnumber|sectionnumber]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:criterium|criterium]]</td><br />
<td>[[Command/value:section|section]] [[Command/value:local|local]] [[Command/value:all|all]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:symbol|symbol]]</td><br />
<td>1 2 ... [[Command/value:n|n]] [[Command/value:a|a]] ... [[Command/value:none|none]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:interaction|interaction]]</td><br />
<td>[[Command/value:pagenumber|pagenumber]] [[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:expansion|expansion]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:referencing|referencing]]</td><br />
<td>[[Command/value:on|on]] [[Command/value:off|off]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:left|left]] [[Command/value:middle|middle]] [[Command/value:right|right]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:maxwidth|maxwidth]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:unknownreference|unknownreference]]</td><br />
<td>[[Command/value:empty|empty]] [[Command/value:none|none]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:alternative|alternative]]</td><br />
<td>[[Command/value:a|a]] [[Command/value:b|b]] [[Command/value:A|A]] [[Command/value:B|B]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:prefix|prefix]]</td><br />
<td>[[Command/value:both|both]] [[Command/value:first|first]] [[Command/value:none|none]] </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:pagecommand|pagecommand]]</td><br />
<td>[[Command/value:command|command]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:textcommand|textcommand]]</td><br />
<td>[[Command/value:command|command]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:compress|compress]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:language|language]]</td><br />
<td>[[Command/value:language|language code]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:method|method]]</td><br />
<td>[[Command/value:default|default]] [[Command/value:before|before]] [[Command/value:after|after]] [[Command/value:first|first]] [[Command/value:last|last]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:pageleft|pageleft]]</td><br />
<td>[[Command/value:command|command]]</td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[[Command/keyword:pageright|pageright]]</td><br />
<td>[[Command/value:command|command]]</td><br />
</tr><br />
</table><br />
<br />
== Description == <br />
<br />
The options are as follows:<br />
<br />
<table cellspacing="4" cellpadding="2"><br />
<tr><br />
<th>Option</th><br />
<th>Description</th><br />
</tr><br />
<tr><br />
<td>n</td><br />
<td>number of columns</td><br />
</tr><br />
<tr><br />
<td>balance</td><br />
<td>balance columns?</td><br />
</tr><br />
<tr><br />
<td>align</td><br />
<td>balance related (it’s difficult; try which combination suits you)</td><br />
</tr><br />
<tr><br />
<td>style</td><br />
<td>overall style (no effect, at least in MkIV)</td><br />
</tr><br />
<tr><br />
<td>pagestyle</td><br />
<td>style of page number</td><br />
</tr><br />
<tr><br />
<td>textstyle</td><br />
<td>style of index word</td><br />
</tr><br />
<tr><br />
<td>indicator</td><br />
<td>create letter sections?</td><br />
</tr><br />
<tr><br />
<td>coupling</td><br />
<td>special feature for screen documents (no effect in MkIV?)</td><br />
</tr><br />
<tr><br />
<td>check</td><br />
<td>set {{cmd|seeindex}} entry as entered without verifying. Default no.</td><br />
</tr><br />
<tr><br />
<td>(section)number</td><br />
<td>print part/... numbers?</td><br />
</tr><br />
<tr><br />
<td>criterium</td><br />
<td>for part/chapter/section registers</td><br />
</tr><br />
<tr><br />
<td>distance</td><br />
<td>between text and pagenumber</td><br />
</tr><br />
<tr><br />
<td>symbol</td><br />
<td>for pagenumber (a=a,b,c; n=1,2,3; 1=dots; 2=blocks)</td><br />
</tr><br />
<tr><br />
<td>interaction</td><br />
<td>which part should be clickable?</td><br />
</tr><br />
<tr><br />
<td>expansion</td><br />
<td>When the entry is a command, it is expanded before writing to the register</td><br />
</tr><br />
<tr><br />
<td>referencing</td><br />
<td>create references for letter sections (like "index:a")?</td><br />
</tr><br />
<tr><br />
<td>textcommand</td><br />
<td>custom command for index word</td><br />
</tr><br />
<tr><br />
<td>pagecommand</td><br />
<td>custom command for page number</td><br />
</tr><br />
<tr><br />
<td>location</td><br />
<td>?</td><br />
</tr><br />
<tr><br />
<td>compress</td><br />
<td>collapse page numbers</td><br />
</tr><br />
<tr><br />
<td>maxwidth</td><br />
<td>Set the maximum length for the text of the index entry in the registerlist (the command uses {{cmd|limitatetext}} to do this)</td><br />
</tr><br />
<tr><br />
<td>unknownreference</td><br />
<td>insert a horizontal space before and after the reference in the text if you use interactive mode to move from one entry in the text to next or previous one and there is no previous or next reference.</td><br />
</tr><br />
<tr><br />
<td>alternative</td><br />
<td>?</td><br />
</tr><br />
<tr><br />
<td>language</td><br />
<td>language code like in {{cmd|language}}, influences sorting; see definitions in {{src|sort-lan.mkiv}}</td><br />
</tr><br />
<tr><br />
<td>method</td><br />
<td>sets up the sorter used for {{cmd|placeregister}}, explained at [[Command/keyword:method]]</td><br />
</tr><br />
<tr><br />
<td>pageleft</td><br />
<td>custom command before the first page number</td><br />
</tr><br />
<tr><br />
<td>pageright</td><br />
<td>custom command after the last page number</td><br />
</tr><br />
</table><br />
<br />
Some options don’t seem to have any effect, at least in MkIV.<br />
<br />
== Example ==<br />
<br />
Here is an example for MkII:<br />
<br />
<context source="yes" text="yields"><br />
\defineregister[nickname][nicknames]<br />
<br />
\setupregister [nickname]<br />
[partnumber=no,alternative=A,criterium=all,n=3,balance=yes,pagestyle=normal]<br />
\setupregister [nickname][foto][pagestyle=bold]<br />
<br />
\starttext<br />
<br />
Text about Mamut\nickname{Mamut}.<br />
\placefigure[]<br />
{Kuba\nickname[foto::]{Kuba} on the photo.}<br />
{\externalfigure[kuba][width=0.2\textwidth]}<br />
<br />
\page<br />
And text about Kuba\nickname{Kuba}.<br />
<br />
\completenickname<br />
\stoptext <br />
<br />
</context><br />
<br />
<br />
I found it safer to put \register command after punctuation e.g.: Mamut.\nickname{Mamut} [P.K.]<br />
<br />
For the MkIV version of setting the pagestyle, and more, see the material on {{cmd|defineprocessor}} that is on [[Registers#Prcoessors|this page]].<br />
<br />
== pageleft and pageright ==<br />
<br />
They were introduced in ConTeXt MkIV version 1.02 (2018.05.12 00:07).<br />
<br />
You can use them, for example, to move the page numbers to the right, with:<br />
<br />
<pre><br />
\setupregister[index][pageleft=\wordright\bgroup,pageright=\egroup]<br />
</pre><br />
<br />
See [http://www.mail-archive.com/ntg-context@ntg.nl/msg87812.html this thread]<br />
on the mailing list.<br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Registers|setupregister]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/definehighlight&diff=23819Command/definehighlight2018-07-18T16:55:36Z<p>Rik: Added admonition on command syntax when converting from font switches</p>
<hr />
<div>{{Reference<br />
|name=definehighlight<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\definehighlight<span class="first" >[...]</span><span class="second" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>name </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[...,...=...,...]</td><br />
<td>see [[Command/setuphighlight|\setuphighlight]] </td><br />
</tr><br />
</table><br />
<br />
== Description == <br />
<br />
(MkIV only)<br />
''Highlights'' are a generic facility for defining and maintaining<br />
different emphases.<br />
<br />
Highlights are respected by the XML export (see {{cmd|setupbackend}}),<br />
resulting in a tag {{code|highlight}}, with the respective names as<br />
argument to the attribute ''detail''.<br />
<br />
When converting from font switches (as {{code|{\bf text}}} to defined highlights,<br />
be sure to convert the syntax to command syntax ( {{code|\important{text}}} ).<br />
<br />
== Example ==<br />
<br />
<context source=yes mode=mkiv><br />
\definehighlight [important] [style=bold] %% define a highlight<br />
\definehighlight [reallyimportant] [important] %% inherit setups<br />
\setuphighlight [reallyimportant] [color=red] %% modify the copy<br />
\starttext<br />
This \important{you} need to know.\par<br />
This, however, \reallyimportant{everybody} needs to know!<br />
\stoptext<br />
</context><br />
<br />
<xmlcode><br />
<document language="en" file="example-highlight" date="Sat Jun 16 12:20:48 2012" <br />
context="2012.06.13 23:46" version="0.30" xmlns:m="http://www.w3.org/1998/Math/MathML"><br />
This <highlight detail="important">you</highlight> need to know.<br />
<break/><br />
This, however, <highlight detail="reallyimportant">everybody</highlight> needs to know!<br />
</document><br />
</xmlcode><br />
<br />
== See Also ==<br />
<br />
* {{cmd|setuphighlight}}<br />
* {{src|core-sys.mkiv#l197|core-sys.mkiv}}<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
<br />
All issues with:<br />
<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Fonts|definehighlight]]<br />
[[Category:Command/MkIV only|definehighlight]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/definelabel&diff=23716Command/definelabel2018-01-18T22:51:01Z<p>Rik: Changed suggestion that enumerations can replace labels completely, removed MkII only category</p>
<hr />
<div>{{Reference<br />
|name=definelabel<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\definelabel<span class="first" >[...]</span><span class="second" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>name </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:text|text]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:inmargin|inmargin]] [[Command/value:intext|intext]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:way|way]]</td><br />
<td>[[Command/value:bytext|bytext]] [[Command/value:bysection|bysection]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:blockway|blockway]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:headstyle|headstyle]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small|small]] ... [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:headcolor|headcolor]]</td><br />
<td>[[Command/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:before|before]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:after|after]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description == <br />
Define an autonumbered label type, including a command to place one.<br />
<br />
== Example ==<br />
<context source=yes><br />
\definelabel[mapA][text=Map A, location=inmargin]<br />
\definelabel[mapB][text=Map B, location=intext]<br />
<br />
\mapA One map<br />
<br />
\mapB\ Another map<br />
</context><br />
<br />
== See also ==<br />
* ''{{cmd|labeling}}'' to use a labeling defined with {{cmd|definelabel}}.<br />
* {{cmd|defineenumeration}} for a newer mechanism that can replace many uses of {{cmd|definelabel}}<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Numbered objects|definelabel]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/labeling&diff=23715Command/labeling2018-01-18T22:50:57Z<p>Rik: Changed suggestion that enumerations can replace labels completely, removed MkII only category</p>
<hr />
<div>{{Reference<br />
|name=labeling<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\<i>labeling</i><span class="first" style="color:red;">[ref]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[ref]</td><br />
</tr><br />
</table><br />
<br />
<br />
== Description == <br />
Place a numbered label that was defined with {{cmd|definelabel}}. This command is not actually called <code>\labeling</code>; the ''labeling'' part is merely a placeholder. The example should make things clear.<br />
<br />
== Example ==<br />
<context source=yes><br />
\definelabel[map][text=Map, location=inmargin]<br />
<br />
\map[smallmap] The first map.<br />
<br />
\map[bigmap] The second map.<br />
<br />
See \in{Map}[smallmap].<br />
</context><br />
<br />
== See also ==<br />
* {{cmd|definelabel}}<br />
* {{cmd|enumeration}} for a newer mechanism that can replace many uses of {{cmd|labeling}}<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Numbered objects|labeling]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/hyphenation&diff=23519Command/hyphenation2017-10-22T19:52:46Z<p>Rik: Added note on concurrent uses with \startexceptions</p>
<hr />
<div>{{Reference<br />
|name=hyphenation<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\hyphenation<!--<br />
--><span class="first">{...}</span><!--<br />
--></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">{...}</td><br />
<td>''se-ve-ral words cut in-to syl-la-bles with hy-phens''</td><br />
</tr><br />
</table><br />
<br />
== Description == <br />
Indicate how to hyphenate a word. Useful when there are some foreign or unusual words that are used a few times in your text.<br />
<br />
== Example ==<br />
<context source=yes><br />
\setuppapersize[A9]<br />
<br />
\hyphenation{ac-cord-ance Rein-heits-gebot}<br />
<br />
A lot of German beer is brewed in accordance with the <br />
{\it Reinheitsgebot} laid down in Munich in 1516.<br />
</context><br />
<br />
== Note ==<br />
<br />
If you are also using {{cmd|startexceptions}}...{{cmd|stopexceptions}} in your document, that must precede {{cmd|hyphenation}}.<br />
<br />
== See also ==<br />
{{Hyphenation see also}}<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Languages|hyphenation]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Template:Hyphenation_see_also&diff=23518Template:Hyphenation see also2017-10-22T19:51:52Z<p>Rik: Added reference to (at this point non-existent) \startexceptions</p>
<hr />
<div>* [[Hyphenation]]<br />
* {{cmd|hyphenation}} to define the hyphenation of a specific word<br />
* {{cmd|startexceptions}} to define language-specific hyphenations<br />
* {{cmd|-}} to define an ad-hoc breakpoint<br />
* {{cmd|unhyphenated}} to prevent hyphenation<br />
* {{tex|doublehyphendemerits}} to penalize hyphenation on consecutive lines<br />
* [[Command/setupalign#Nicer_justification_and_microtypography|{{cmd|setupalign|link=no}} justification parameters]] to tweak the auto-hyphenation algorithm<br />
* {{cmd|definebreakpoints}} to initialize a breakpoint set<br />
* {{cmd|definebreakpoint}} to add to a breakpoint set<br />
* {{cmd|setbreakpoints}} to activate a breakpoint set<br />
* {{cmd|language}} to activate a language's settings, including hyphenation</div>Rikhttps://wiki.contextgarden.net/index.php?title=Trackers/typesetters.suspects&diff=23030Trackers/typesetters.suspects2016-02-16T23:30:24Z<p>Rik: Initial description of typesetters.suspects tracker</p>
<hr />
<div>{{Reference<br />
|name=enabletrackers[typesetters.suspects]<br />
|attributes=<br />
}}<br />
<br />
<span style="color: red;">This page is based on one user’s observations. Some of the descriptions are undoubtedly incomplete, if not inaccurate. Please feel free to correct this.</span><br />
<br />
== Description == <br />
<br />
This tracker modifies the output document by adding colored background to suspect characters. Using it, a quick scan of the document may show these suspects.<br />
<br />
* Required spaces (such as generated by ~) are highlighted with orange<br />
<br />
* Paragraph-terminating . ? ! and : are highlighted with blue, even if followed by a footnote index. However, there is no highlight for a paragraph-terminating ) or ], and no highlighting for the preceding . ? ! or :.<br />
<br />
* Quotation ending punctuation inside the closing quotation mark is highlighted with blue.<br />
<br />
* Prime (') followed by space is highlighted with maroon.<br />
<br />
* Close single quotation marks (’) when preceded by space are highlighted by maroon.<br />
<br />
* Right-facing guillemets (») when preceded by space (as in some German usage) are highlighted by maroon.<br />
<br />
* The italic character in an upright/italic transition is highlighted with green.<br />
<br />
* The smallcap character in a smallcap/nonsmallcap transition is highlighted with green. (There is no highlight for a smallcap/punctuation transition.)<br />
<br />
* Less-commmon punctuation marks (… / @ & and others) are highlighted with blue.<br />
<br />
* Some punctuation marks when not followed by whitespace (. · , : and others) is highlighted with blue.<br />
<br />
* a digit preceding a comma in the index is highlighted with green.<br />
<br />
* a final-form letter followed by another letter is highlighted in green (seen with ς, not otherwise tested).</div>Rikhttps://wiki.contextgarden.net/index.php?title=Trackers/visualizers.justification&diff=23029Trackers/visualizers.justification2016-02-16T22:34:58Z<p>Rik: Initial documentation of visualizers.justification tracker</p>
<hr />
<div>{{Reference<br />
|name=enabletrackers[visualizers.justification]<br />
|attributes=<br />
}}<br />
<br />
<span style="color: red;">This page is based on one user’s observations. Some of the descriptions are undoubtedly incomplete, if not inaccurate. Please feel free to correct this.</span><br />
<br />
== Description == <br />
<br />
This tracker modifies the output document by adding colored bars to highlight justification. Using it, a quick scan of the document will show lines that may not be pleasingly justified.<br />
<br />
* Centered lines are marked by yellow bars to the left and right, in the text area.<br />
<br />
* Flush-right lines are marked by a cyan bar to the left of the text, in the text area.<br />
<br />
* Inserted line breaks are indicated by a magenta bar to the right of the text, in the text area.<br />
<br />
* Flush-left lines are marked by a green bar to the right of the text, in the text area<br />
<br />
* Justified lines are marked by a green bar in the text area, when there is no word-space compression (shrink) applied to the line.<br />
<br />
* Justified lines are marked by a blue bar in the right margin when compression has been applied. The width of the bar indicates the degree of compression.<br />
<br />
* Justified lines with severe compression may be marked with a red bar.</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/enabletrackers&diff=23028Command/enabletrackers2016-02-16T22:12:29Z<p>Rik: Update to point to visual debugging and two new trackers.</p>
<hr />
<div>{{Reference<br />
|name=enabletrackers<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\enabletrackers<!--<br />
--><span class="first">[...,...]</span><!--<br />
--></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...,...]</td><br />
<td>''tracker names''</td><br />
</tr><br />
</table><br />
<br />
== Description == <br />
Enable a [[Trackers|tracker]]. This causes extra information to be printed to the terminal and the {{code|*.log}} file during compilation.<br />
<br />
Some trackers also modify the output document to assist in visual debugging. Two such trackers are [[Trackers/visualizers.justification]] and [[Trackers/typesetters.suspects]]. See [[Visual Debugging]] for some other visual debugging aids. <br />
<br />
== Example ==<br />
<texcode><br />
\enabletrackers[graphics.locating]<br />
<br />
\starttext<br />
\externalfigure[cow]<br />
\stoptext<br />
</texcode><br />
<br />
graphics > inclusion > locations: local,global<br />
graphics > inclusion > path list: . .. ../..<br />
graphics > inclusion > strategy: unknown format, prefer quality<br />
graphics > inclusion > found: ./cow.pdf -> ./cow.pdf<br />
graphics > inclusion > format natively supported by backend: pdf<br />
<br />
== See also ==<br />
* [[Trackers]] for a list of available trackers.<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Debugging|enabletrackers]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Generate_Authorlist_from_Head_Content&diff=23004Generate Authorlist from Head Content2015-12-24T02:37:35Z<p>Rik: April change should have been to \expanded, not \expand</p>
<hr />
<div>An example on how to generate a sorted list of all authors contributed to a conference proceeding.<br />
<br />
<texcode><br />
\setuphead<br />
[title]<br />
[page=no,command=,]<br />
<br />
\setuphead<br />
[chapter]<br />
[command=\MyChapCMD]<br />
<br />
\setuplist<br />
[chapter]<br />
[criterium=all,alternative=command,command=\MyChapListCMD]<br />
<br />
\definesorting[author][authors]<br />
\setupsorting [author][criterium=all,expansion=yes]<br />
<br />
\define[2]\MyChapCMD<br />
{#1\enspace #2<br />
{\doifsomething<br />
{\structureuservariable{author}}<br />
\expanded{\author<br />
[\structureuservariable{name}] % -> sorted by "name"-variable<br />
{\bTABLE[width=broad]<br />
\bTR<br />
\bTD \structureuservariable{author} \eTD<br />
\bTD \structureuservariable{city} \eTD<br />
\bTD \structureuservariable{date} \eTD<br />
\bTD \structureuservariable{email} \eTD<br />
\bTD \structureuservariable{note} \eTD<br />
\eTR<br />
\eTABLE\nointerlineskip}%<br />
\tfxx (\structureuservariable{author}, \structureuservariable{city})}}}<br />
<br />
\define[3]\MyChapListCMD<br />
{#1 #2 (\structurelistuservariable{author})\hfill #3\blank}<br />
<br />
<br />
\starttext \showframe[text]<br />
<br />
\starttitle[title=Contents]<br />
\placelist[chapter]<br />
\stoptitle<br />
<br />
\starttitle[title=List of Authors in Alphabetical Order]<br />
\placelistofauthors<br />
\stoptitle<br />
<br />
\startchapter<br />
[title=Text by Ward]<br />
[name=ward,<br />
author=Peter D. Ward,<br />
city=Washington,<br />
email=ward@sample.com]<br />
<br />
\input ward<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Zapf]<br />
[name=zapf,<br />
author=Hermann Zapf,<br />
city=Nürnberg,<br />
date=8. November 1918,<br />
email=zapf@sample.de]<br />
<br />
\input zapf<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Bryson]<br />
[name=bryson,<br />
author=Bill Bryson,<br />
city=Norfolk,<br />
date={December 8, 1951},<br />
note=best-selling American author]<br />
<br />
\input Bryson<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Tufte]<br />
[name=tufte,<br />
author=Edward R. Tufte,<br />
city=Kansas City,<br />
date=1942,<br />
note=has criticized the way Microsoft PowerPoint is typically used]<br />
<br />
\input tufte<br />
\stopchapter<br />
<br />
\stoptext<br />
<br />
</techcode></div>Rikhttps://wiki.contextgarden.net/index.php?title=Generate_Authorlist_from_Head_Content&diff=22783Generate Authorlist from Head Content2015-04-11T15:59:56Z<p>Rik: Fix received from Wolfgang, \expand sort entry contents in \MyChapCMD</p>
<hr />
<div>An example on how to generate a sorted list of all authors contributed to a conference proceeding.<br />
<br />
<texcode><br />
\setuphead<br />
[title]<br />
[page=no,command=,]<br />
<br />
\setuphead<br />
[chapter]<br />
[command=\MyChapCMD]<br />
<br />
\setuplist<br />
[chapter]<br />
[criterium=all,alternative=command,command=\MyChapListCMD]<br />
<br />
\definesorting[author][authors]<br />
\setupsorting [author][criterium=all,expansion=yes]<br />
<br />
\define[2]\MyChapCMD<br />
{#1\enspace #2<br />
{\doifsomething<br />
{\structureuservariable{author}}<br />
\expand{\author<br />
[\structureuservariable{name}] % -> sorted by "name"-variable<br />
{\bTABLE[width=broad]<br />
\bTR<br />
\bTD \structureuservariable{author} \eTD<br />
\bTD \structureuservariable{city} \eTD<br />
\bTD \structureuservariable{date} \eTD<br />
\bTD \structureuservariable{email} \eTD<br />
\bTD \structureuservariable{note} \eTD<br />
\eTR<br />
\eTABLE\nointerlineskip}%<br />
\tfxx (\structureuservariable{author}, \structureuservariable{city})}}}<br />
<br />
\define[3]\MyChapListCMD<br />
{#1 #2 (\structurelistuservariable{author})\hfill #3\blank}<br />
<br />
<br />
\starttext \showframe[text]<br />
<br />
\starttitle[title=Contents]<br />
\placelist[chapter]<br />
\stoptitle<br />
<br />
\starttitle[title=List of Authors in Alphabetical Order]<br />
\placelistofauthors<br />
\stoptitle<br />
<br />
\startchapter<br />
[title=Text by Ward]<br />
[name=ward,<br />
author=Peter D. Ward,<br />
city=Washington,<br />
email=ward@sample.com]<br />
<br />
\input ward<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Zapf]<br />
[name=zapf,<br />
author=Hermann Zapf,<br />
city=Nürnberg,<br />
date=8. November 1918,<br />
email=zapf@sample.de]<br />
<br />
\input zapf<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Bryson]<br />
[name=bryson,<br />
author=Bill Bryson,<br />
city=Norfolk,<br />
date={December 8, 1951},<br />
note=best-selling American author]<br />
<br />
\input Bryson<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Tufte]<br />
[name=tufte,<br />
author=Edward R. Tufte,<br />
city=Kansas City,<br />
date=1942,<br />
note=has criticized the way Microsoft PowerPoint is typically used]<br />
<br />
\input tufte<br />
\stopchapter<br />
<br />
\stoptext<br />
<br />
</techcode></div>Rikhttps://wiki.contextgarden.net/index.php?title=Common_errors&diff=22667Common errors2014-10-27T14:27:39Z<p>Rik: Another common mistake that Wolfgang often points out</p>
<hr />
<div>== Common ConTeXt Errors ==<br />
<br />
Here, we collect a list of your favorite, common ConTeXt coding errors. Look carefully to see what is wrong...<br />
<br />
* \startext<br />
<br />
* \stopMPage<br />
<br />
* \startchapter[title=Space, the final frontier]<br />
<br />
* \somecommand[parameter,key=value]<br />
<br />
* context text (after editing test.tex)<br />
<br />
Creative users are invited to add some real puzzlers here!<br />
<br />
== Common MetaPost Errors ==<br />
<br />
* i = i + 1 ;</div>Rikhttps://wiki.contextgarden.net/index.php?title=Generate_Authorlist_from_Head_Content&diff=22662Generate Authorlist from Head Content2014-10-18T19:10:56Z<p>Rik: Note that the example does not work.</p>
<hr />
<div>'''The following example fails with versions from TL14 (and likely earlier) to 2014-10-18 (when this note was added). It will likely continue to fail until something is changed, either in the example or in the code.''' <br />
<br />
An example on how to generate a sorted list of all authors contributed to a conference proceeding.<br />
<br />
<texcode><br />
\setuphead<br />
[title]<br />
[page=no,command=,]<br />
<br />
\setuphead<br />
[chapter]<br />
[command=\MyChapCMD]<br />
<br />
\setuplist<br />
[chapter]<br />
[criterium=all,alternative=command,command=\MyChapListCMD]<br />
<br />
\definesorting[author][authors]<br />
\setupsorting [author][criterium=all,expansion=yes]<br />
<br />
\define[2]\MyChapCMD<br />
{#1\enspace #2<br />
{\doifsomething<br />
{\structureuservariable{author}}<br />
{\author<br />
[\structureuservariable{name}] % -> sorted by "name"-variable<br />
{\bTABLE[width=broad]<br />
\bTR<br />
\bTD \structureuservariable{author} \eTD<br />
\bTD \structureuservariable{city} \eTD<br />
\bTD \structureuservariable{date} \eTD<br />
\bTD \structureuservariable{email} \eTD<br />
\bTD \structureuservariable{note} \eTD<br />
\eTR<br />
\eTABLE\nointerlineskip}%<br />
\tfxx (\structureuservariable{author}, \structureuservariable{city})}}}<br />
<br />
\define[3]\MyChapListCMD<br />
{#1 #2 (\structurelistuservariable{author})\hfill #3\blank}<br />
<br />
<br />
\starttext \showframe[text]<br />
<br />
\starttitle[title=Contents]<br />
\placelist[chapter]<br />
\stoptitle<br />
<br />
\starttitle[title=List of Authors in Alphabetical Order]<br />
\placelistofauthors<br />
\stoptitle<br />
<br />
\startchapter<br />
[title=Text by Ward]<br />
[name=ward,<br />
author=Peter D. Ward,<br />
city=Washington,<br />
email=ward@sample.com]<br />
<br />
\input ward<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Zapf]<br />
[name=zapf,<br />
author=Hermann Zapf,<br />
city=Nürnberg,<br />
date=8. November 1918,<br />
email=zapf@sample.de]<br />
<br />
\input zapf<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Bryson]<br />
[name=bryson,<br />
author=Bill Bryson,<br />
city=Norfolk,<br />
date={December 8, 1951},<br />
note=best-selling American author]<br />
<br />
\input Bryson<br />
\stopchapter<br />
<br />
\startchapter<br />
[title=Text by Tufte]<br />
[name=tufte,<br />
author=Edward R. Tufte,<br />
city=Kansas City,<br />
date=1942,<br />
note=has criticized the way Microsoft PowerPoint is typically used]<br />
<br />
\input tufte<br />
\stopchapter<br />
<br />
\stoptext<br />
<br />
</techcode></div>Rikhttps://wiki.contextgarden.net/index.php?title=Epub_Sample&diff=22661Epub Sample2014-10-18T19:03:07Z<p>Rik: </p>
<hr />
<div>< [[Epub]] | [[XML]] ><br />
<br />
Creating an ebook with ConTeXt is still tedious and needs a lot of manual work - that will not change, since everyone has other needs, uses different structures etc.<br />
Here I’ll show you my workflow for creating ebooks of my songbooklets (that use [[LilyPond]] via [[modules:t-filter|filter module]] for the notes).<br />
<br />
I’m using ConTeXt’s [[Project structure]], separating content in products (for me: single booklets) and components (for me: single songs) with a common stylesheet (environment).<br />
<br />
Beware, you need a current beta version of ConTeXt, since Hans fixed some export related bugs in the last few days!<br />
<br />
--[[User:Hraban|Hraban]] 13 September 2014.<br />
<br />
== ConTeXt setup ==<br />
<br />
In your environment or product, you need these settings (perhaps not all of them):<br />
<br />
<texcode><br />
\setupexport[<br />
hyphen=yes,<br />
%firstpage={cover.jpg}, % is ignored<br />
title={Songbook},<br />
subtitle={},<br />
author={Hraban}<br />
]<br />
\setupbackend[export=export.xml]<br />
\settaggedmetadata[<br />
% here you can set as many metadata entries as you like<br />
title={Songbook},<br />
name=ebook, % this becomes the name of the output directory<br />
author={Hraban},<br />
subtitle={},<br />
version={\expanded\currentdate} % doesn’t work<br />
]<br />
\setupinteraction[state=start,<br />
color=,contrastcolor=,<br />
% these settings are for PDF metadata<br />
title={Songbook},<br />
subtitle={},<br />
keywords={},<br />
author={Hraban}<br />
]<br />
<br />
\definehighlight[emph][style=italic] % use \emph{something} instead of {\em something}<br />
</texcode><br />
<br />
Make sure to tag all your structural elements with {{cmd|start...}}-{{cmd|stop...}}, e.g. {{cmd|startchapter}}, but even {{cmd|startparagraph}}!<br />
<br />
In places where {{cmd|startparagraph}} does not work, such as itemizations, where it causes a blank line after the bullet and before the item text, use {{cmd|bpar}} (and closing {{cmd|epar}}) to tag paragraphs.<br />
<br />
Then you can call ConTeXt and its ePub script:<br />
<pre><br />
context mysongbook<br />
mtxrun --script epub --make mysongbook<br />
</pre><br />
<br />
The first creates {{code|export.xml}} and a bunch of other files.<br />
The second creates a directory {{code|ebook.tree}} with the proper structure for ePub. The ePub file in the tree directory is unusable.<br />
<br />
We’ll mostly work with "export.xml" that contains all your content (check that, you’ll miss everything that was not properly tagged).<br />
<br />
== ePub structure ==<br />
<br />
This is the directory structure that we need for our ePub:<br />
<br />
<pre><br />
/songbook.tree/<br />
├── META-INF<br />
│ └── container.xml<br />
├── OEBPS<br />
│ ├── Fonts<br />
│ │ └── somefont.otf<br />
│ ├── Images<br />
│ │ ├── ...<br />
│ │ ├── c_farewell-1.png<br />
│ │ ├── c_farewell-2.png<br />
│ │ ├── c_farewell.png<br />
│ │ ├── ...<br />
│ │ └── cover.jpg<br />
│ ├── Styles<br />
│ │ └── style.css<br />
│ ├── Text<br />
│ │ ├── _intro.html<br />
│ │ ├── aut_1.html<br />
│ │ ├── ...<br />
│ │ └── aut_99.html<br />
│ ├── cover.html<br />
│ ├── songbook.opf<br />
│ └── toc.ncx<br />
└── mimetype<br />
</pre><br />
<br />
We use mimetype and container.xml unchanged from ConTeXt’s epub script and (re)create everything else.<br />
At the end this structure is just zipped with an "epub" file ending.<br />
<br />
== Unchanged files ==<br />
<br />
For the records:<br />
<br />
=== {{code|mimetype}} ===<br />
<br />
<pre><br />
application/epub+zip<br />
</pre><br />
<br />
=== {{code|container.xml}} ===<br />
<br />
<xmlcode><br />
<?xml version="1.0" encoding="UTF-8"?><br />
<br />
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"><br />
<rootfiles><br />
<rootfile full-path="OEBPS/songbook.opf" media-type="application/oebps-package+xml"/><br />
</rootfiles><br />
</container><br />
</xmlcode><br />
<br />
== Transform XML to HTML ==<br />
<br />
Even if the ePub format is supposed to work with any XML, most readers only accept HTML.<br />
I use the free version of [http://saxon.sourceforge.net Saxon] and some XSL transformations for the conversion.<br />
<br />
The incantation goes like {{code|saxon -o:content.xhtml -s:export.xml -xsl:export2html.xsl}}.<br />
I installed Saxon on my Mac with MacPorts, then instead of just "saxon" you must call {{code|java -jar /opt/local/share/java/saxon9he.jar}}.<br />
<br />
=== {{code|export2html.xsl}} ===<br />
<br />
<xmlcode><br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet version= "2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<br />
<xsl:output <br />
method="xml"<br />
encoding="utf-8"<br />
indent="yes"<br />
omit-xml-declaration="yes"<br />
/><br />
<br />
<xsl:variable name="within-paragraph">0</xsl:variable ><br />
<xsl:variable name="within-section">0</xsl:variable ><br />
<xsl:variable name="previous-section">0</xsl:variable ><br />
<br />
<xsl:template match='section'><br />
<!--<br />
<xsl:if test="@detail='part'"><br />
<xsl:text disable-output-escaping="yes"><![CDATA[</div></body></html>]]></xsl:text><br />
</xsl:if><br />
--><br />
<xsl:result-document method="xml" href="aut_{@implicit}.html"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta charset="utf-8" /><br />
<title><xsl:value-of select='./sectiontitle'/></title><br />
<xsl:for-each select="//metavariable"><br />
<meta><br />
<xsl:attribute name="name"><br />
<xsl:value-of select="@name"/><br />
</xsl:attribute><br />
<xsl:attribute name="content"><br />
<xsl:apply-templates/><br />
</xsl:attribute><br />
</meta><br />
</xsl:for-each><br />
<link rel="stylesheet" href="../Styles/style.css" type="text/css" ></link><br />
</head><br />
<body><br />
<xsl:attribute name="lang"><br />
<xsl:value-of select='//document/@language'/><br />
</xsl:attribute><br />
<!--<br />
<xsl:variable name="previous-section">{$within-section}</xsl:variable ><br />
<xsl:variable name="within-section">{@detail}</xsl:variable ><br />
--><br />
<xsl:apply-templates/><br />
<!--<br />
<xsl:variable name="within-section">{$previous-section}</xsl:variable ><br />
<xsl:variable name="previous-section">0</xsl:variable ><br />
--><br />
</body><br />
</html><br />
</xsl:result-document><br />
</xsl:template> <br />
<br />
<br />
<xsl:template match="sectiontitle"><br />
<xsl:choose><br />
<xsl:when test="../@detail='part'"><br />
<h1><xsl:apply-templates/></h1><br />
</xsl:when><br />
<xsl:when test="../@detail='chapter'"><br />
<h2><xsl:apply-templates/></h2><br />
</xsl:when><br />
<xsl:when test="../@detail='Titel'"><br />
<h2><xsl:apply-templates/></h2><br />
</xsl:when><br />
<xsl:when test="../@detail='TitelKlein'"><br />
<h2><xsl:apply-templates/></h2><br />
</xsl:when><br />
<xsl:when test="../@detail='section'"><br />
<h3><xsl:apply-templates/></h3><br />
</xsl:when><br />
<xsl:when test="../@detail='subsection'"><br />
<h4><xsl:apply-templates/></h4><br />
</xsl:when><br />
<xsl:otherwise><br />
<h6 class="../@detail"><xsl:apply-templates/></h6><br />
</xsl:otherwise><br />
</xsl:choose><br />
</xsl:template><br />
<br />
<xsl:template match="sectioncontent"><br />
<div class="{../@detail}-content"><br />
<xsl:apply-templates/><br />
</div><br />
</xsl:template><br />
<br />
<xsl:template match="externalfilter"><br />
<div class="{@detail}"><br />
<xsl:apply-templates/><br />
</div><br />
</xsl:template><br />
<br />
<xsl:template match="lines"><br />
<div class="lines"><br />
<xsl:apply-templates/><br />
</div><br />
</xsl:template><br />
<br />
<xsl:template match="line"><br />
<xsl:apply-templates/> <br /><br />
</xsl:template><br />
<br />
<xsl:template match="list"><br />
<ul><br />
<xsl:apply-templates/><br />
</ul><br />
</xsl:template><br />
<br />
<xsl:template match="listitem"><br />
<li><xsl:apply-templates/></li><br />
</xsl:template><br />
<br />
<xsl:template match="listcontent"><br />
<span class="listcontent"><xsl:apply-templates/></span><br />
</xsl:template><br />
<br />
<xsl:template match="listpage"><br />
<span class="listpage"><xsl:apply-templates/></span><br />
</xsl:template><br />
<br />
<xsl:template match="break"><br />
<xsl:if test="within-paragraph = 0"><br />
<xsl:text disable-output-escaping="yes"><![CDATA[</p><p>]]></xsl:text><br />
</xsl:if><br />
<xsl:if test="within-paragraph > 0"><br />
<br/><br />
</xsl:if><br />
</xsl:template><br />
<br />
<xsl:template match="paragraph"><br />
<xsl:variable name="within-paragraph">1</xsl:variable ><br />
<p><xsl:apply-templates/></p><br />
<xsl:variable name="within-paragraph">0</xsl:variable ><br />
</xsl:template><br />
<br />
<xsl:template match="delimited"><br />
<span class="delim-{@detail}"><xsl:apply-templates/></span><br />
</xsl:template><br />
<br />
<xsl:template match="construct"><br />
<div class="struct-{@detail}"><xsl:apply-templates/></div><br />
</xsl:template><br />
<br />
<xsl:template match="highlight"><br />
<xsl:if test="@detail = 'emph'"><br />
<em><xsl:apply-templates/></em><br />
</xsl:if><br />
</xsl:template><br />
<br />
<!-- all the images in my songbook are notes generated by LilyPond via t-filter; in ePub I shorten the file names --><br />
<br />
<xsl:template match="image"><br />
<img src="../Images/{substring-after(@name,'prd_hraban-temp-lilypond-')}.png" id="{@id}" alt="{@name}" /><br />
</xsl:template><br />
<br />
<xsl:template match="link"><br />
<a href="{@location}" title="{@destination}"><xsl:apply-templates/></a><br />
</xsl:template><br />
<br />
<xsl:template match="register"><br />
</xsl:template><br />
<br />
<xsl:template match="registerentry"><br />
</xsl:template><br />
<br />
<xsl:template match="registerpage"><br />
</xsl:template><br />
<br />
<br />
</xsl:stylesheet><br />
<br />
</xmlcode><br />
<br />
=== {{code|style.css}} ===<br />
<br />
Now you have a (hopefully usable) (X)HTML file, you need a CSS for the styling.<br />
<br />
A simple example:<br />
<br />
<pre><br />
body {<br />
font-family: TeX Gyre Schola, Century Schoolbook, serif;<br />
font-size: 12pt;<br />
margin: 0 auto;<br />
max-width: 40em;<br />
line-height: 1.44;<br />
-webkit-hyphens: auto;<br />
-moz-hyphens: auto;<br />
-ms-hyphens: auto;<br />
hyphens: auto;<br />
}<br />
<br />
h1, h2, h3, h4, h4, h6 {<br />
font-family: TeX Gyre Heros, Helvetica, Arial, sans-serif;<br />
color: #286000;<br />
-webkit-hyphens: manual;<br />
-moz-hyphens: manual;<br />
-ms-hyphens: manual;<br />
hyphens: manual;<br />
}<br />
<br />
.Titel, .chapter {<br />
margin-top: 1em;<br />
border-top: 1px solid #600a00;<br />
}<br />
<br />
img {<br />
max-width: 100%;<br />
max-height: 100%;<br />
}<br />
<br />
.lilypond {<br />
margin: 1em 0;<br />
}<br />
<br />
.lilypond img {<br />
width: 100%;<br />
margin-bottom: 0.25em;<br />
}<br />
</pre><br />
<br />
== Create a Cover ==<br />
<br />
Create a {{code|cover.xhtml}}:<br />
<br />
=== {{code|export2cover.xsl}} ===<br />
<br />
<xmlcode><br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet version= "2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<br />
<xsl:output <br />
method="xml"<br />
encoding="utf-8"<br />
indent="yes"<br />
omit-xml-declaration="yes"<br />
/><br />
<br />
<xsl:template match="/"><br />
<html><br />
<head><br />
<title><xsl:value-of select='//metavariable[@name="title"]'/></title><br />
<link rel="stylesheet" href="style.css" type="text/css" ></link><br />
<link rel="stylesheet" href="Styles/style.css" type="text/css" ></link><br />
</head><br />
<body><br />
<div><br />
<img src="Images/cover.jpg"><br />
<xsl:attribute name="alt"><br />
<xsl:value-of select='//metavariable[@name="title"]'/><br />
</xsl:attribute><br />
</img><br />
</div><br />
</body><br />
</html><br />
</xsl:template><br />
<br />
</xsl:stylesheet><br />
</xmlcode><br />
<br />
If you don’t have a different cover picture, create one from the first page of your PDF (using ImageMagick’s {{code|convert}}):<br />
<br />
<pre><br />
convert -density 196 songbook.pdf'[0]' +repage cover.jpg<br />
</pre><br />
<br />
== Create OPF ==<br />
<br />
The [http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm OPF file] keeps the others together, it lists all resources of the ebook.<br />
<br />
You will have to adapt the listing of images (since I use only PDFs converted to PNG) and add fonts manually, if you ship any.<br />
<br />
=== {{code|export2opf.xsl}} ===<br />
<br />
<xmlcode><br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet version= "2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<br />
<xsl:output <br />
method="xml"<br />
encoding="utf-8"<br />
indent="yes"<br />
/><br />
<br />
<xsl:template match="/"><br />
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId"><br />
<!-- see http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm --><br />
<br />
<identifier id="1"><xsl:value-of select='//metavariable[@name="identifier"]'/></identifier><br />
<identifier id="isbn" scheme="isbn"><xsl:value-of select='//metavariable[@name="isbn"]'/></identifier><br />
<title><xsl:value-of select='//metavariable[@name="title"]'/></title><br />
<creator><xsl:value-of select='//metavariable[@name="author"]'/></creator><br />
<subject><xsl:value-of select='//metavariable[@name="subject"]'/></subject><br />
<description><xsl:value-of select='//metavariable[@name="description"]'/></description><br />
<publisher><xsl:value-of select='//metavariable[@name="publisher"]'/></publisher><br />
<language><xsl:value-of select='//document/@language'/></language><br />
<rights><xsl:value-of select='//metavariable[@name="rights"]'/></rights><br />
<br />
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"><br />
<dc:title><xsl:value-of select='//metavariable[@name="title"]'/></dc:title><br />
<dc:language><xsl:value-of select='//document/@language'/></dc:language><br />
<dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:3bbe3f04-4275-841f-44d7-7d3a4e0794a5</dc:identifier><br />
<dc:creator><xsl:value-of select='//metavariable[@name="author"]'/></dc:creator><br />
<dc:date><xsl:value-of select='//document/@date'/></dc:date><br />
<meta name="cover" content="cover-html" /><br />
</metadata><br />
<br />
<manifest><br />
<item id="cover-html" href="cover.html" media-type="application/xhtml+xml"/><br />
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/><br />
<item id="style" href="Styles/style.css" media-type="text/css"/><br />
<item id="intro-html" href="Text/_intro.html" media-type="application/xhtml+xml"/><br />
<xsl:for-each select='//section'><br />
<item media-type="application/xhtml+xml"><br />
<xsl:attribute name="id">aut_<xsl:value-of select="@implicit"/>-html</xsl:attribute><br />
<xsl:attribute name="href">Text/aut_<xsl:value-of select="@implicit"/>.html</xsl:attribute><br />
</item><br />
</xsl:for-each><br />
<item media-type="image/jpeg" id="cover" href="Images/cover.jpg"/><br />
<!-- again, LilyPond related images --><br />
<xsl:for-each select='//image'><br />
<item media-type="image/png" id="{@id}"><br />
<xsl:attribute name="href">Images/<xsl:value-of select="substring-after(@name,'prd_hraban-temp-lilypond-')"/>.png</xsl:attribute><br />
</item><br />
</xsl:for-each><br />
<!-- add fonts manually --><br />
<!--<br />
<item media-type="application/x-font-otf" id="" href="Fonts/xyz.otf" /><br />
<item media-type="application/x-font-ttf" id="" href="Fonts/xyz.ttf" /><br />
--><br />
</manifest><br />
<br />
<spine toc="ncx"><br />
<itemref idref="cover-html" /><br />
<itemref idref="intro-html" /><br />
<xsl:for-each select='//section'><br />
<itemref><br />
<xsl:attribute name="idref">aut_<xsl:value-of select="@implicit"/>-html</xsl:attribute><br />
</itemref><br />
</xsl:for-each><br />
</spine><br />
<br />
</package><br />
</xsl:template><br />
<br />
</xsl:stylesheet><br />
</xmlcode><br />
<br />
== Create NCX (table of contents) ==<br />
<br />
This one will probably differ from your setup – I (ab)use an index for an alphabetically ordered table of contents.<br />
The structure that ConTeXt outputs for index entries is somewhat uncomfortable...<br />
<br />
=== {{code|export2ncx.xsl}} ===<br />
<br />
<xmlcode><br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet version= "2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><br />
<br />
<xsl:output <br />
method="xml"<br />
encoding="utf-8"<br />
indent="yes"<br />
/><br />
<br />
<xsl:template match="/"><br />
<!--<br />
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"><br />
--><br />
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1"><br />
<br />
<head><br />
<meta name="dtb:uid" content="BookId" /><br />
<meta name="dtb:depth" content="1" /><br />
<meta name="dtb:totalPgeCount" ><br />
<xsl:attribute name="content"><br />
<xsl:value-of select='count(section[starts-with(@detail,"Titel")])' /><br />
</xsl:attribute><br />
</meta><br />
<meta name="dtb:maxPageNumber"><br />
<xsl:attribute name="content"><br />
<xsl:value-of select='count(section[starts-with(@detail,"Titel")])' /><br />
</xsl:attribute><br />
</meta><br />
</head><br />
<br />
<docTitle><br />
<text><xsl:value-of select='//metavariable[@name="title"]'/></text><br />
</docTitle><br />
<br />
<docAuthor><br />
<text><xsl:value-of select='//metavariable[@name="author"]'/></text><br />
</docAuthor><br />
<br />
<navMap><br />
<navPoint id="aut_0" origin="aut_0" playOrder="0"><br />
<navLabel><br />
<text>Cover</text><br />
</navLabel><br />
<content src="cover.html"/><br />
</navPoint><br />
<navPoint id="aut_1" origin="aut_1" playOrder="1"><br />
<navLabel><br />
<text>Start</text><br />
</navLabel><br />
<content src="Text/_intro.html"/><br />
</navPoint><br />
<br />
<xsl:for-each select="//registerentry"><br />
<xsl:variable name="location"><br />
<xsl:value-of select='(./descendant::link/@location)[1]'/><br />
</xsl:variable ><br />
<xsl:variable name="origin"><br />
<xsl:value-of select='//registerlocation[@internal=$location]/ancestor::section[starts-with(@detail,"Titel")]/@implicit'/><br />
</xsl:variable ><br />
<br />
<navPoint><br />
<xsl:attribute name="id"><br />
<xsl:value-of select='$location'/><br />
</xsl:attribute><br />
<xsl:attribute name="origin"><xsl:value-of select="$origin" /></xsl:attribute><br />
<xsl:attribute name="playOrder"><br />
<xsl:value-of select="2 + count(preceding-sibling::registerentry)" /><br />
</xsl:attribute><br />
<navLabel><br />
<text><xsl:value-of select='./registercontent'/></text><br />
</navLabel><br />
<content><br />
<xsl:attribute name="src">Text/aut_<xsl:value-of select='$origin' />.html</xsl:attribute><br />
</content><br />
</navPoint><br />
</xsl:for-each><br />
<br />
</navMap><br />
</ncx><br />
</xsl:template><br />
<br />
</xsl:stylesheet><br />
</xmlcode><br />
<br />
The links to a named anchor should work, but don’t in my reader. I must investigate further...<br />
<br />
== Converting images ==<br />
<br />
In my case, all images are note lines, generated by LilyPond in one temporary directory. Your mileage will vary.<br />
ConTeXt’s epub script creates a list of images in {{code|export-images.css}}, you might want to parse that to find all images.<br />
<br />
<pre><br />
cd $LILYPONDTEMPDIR<br />
for IMG in prd_songbook-temp-lilypond-*.pdf; do<br />
NEWIMG=${IMG#prd_songbook-temp-lilypond-}<br />
convert -density 196 $IMG'[0]' -trim +repage ../songbook.tree/OEBPS/Images/${NEWIMG%.pdf}.png<br />
done<br />
</pre><br />
<br />
== Create ePub ==<br />
<br />
Look at the tree above - are all your files in the right location? Then zip your tree!<br />
<br />
<pre><br />
cd songbook.tree<br />
zip -uqr ../songbook.epub *<br />
</pre><br />
<br />
Now test it with your reader or editor (e.g. Calibre). (Apple iBooks or Adobe Digital Editions don’t work.)<br />
<br />
== Shell script ==<br />
<br />
Of course I don’t do all these steps above manually. Here’s my little shell script.<br />
<br />
=== {{code|epub.sh}} ===<br />
<br />
<pre><br />
#!/bin/bash<br />
# call as "./epub.sh productname"<br />
<br />
# ConTeXt is not in my usual path (setuptex needs too long to be called with every shell);<br />
# probably your installation is at a different location<br />
if [ "$TEXROOT" == "" ]; then<br />
source ~/Library/texmf/tex/setuptex ~/Library/texmf/tex<br />
fi<br />
<br />
# all my products are named like "prd_something.tex"<br />
PRD=$1<br />
if [ ! -e prd_${PRD}.tex ]; then<br />
echo "Product ${PRD} not found!"<br />
exit 1<br />
fi<br />
<br />
# all XSL files are in this WORKDIR<br />
WORKDIR=epub-workflow<br />
<br />
# my ConTeXt wrapper "makeit.sh" script creates PDFs with a date<br />
ISODATE=`date +"%Y-%m-%d"`<br />
PRDPDF=${PRD}_${ISODATE}.pdf<br />
<br />
# LilyPond is run in this TEMPDIR and creates its note images there<br />
TEMPDIR=lilytemp<br />
<br />
EPUBPREFIX=epub_<br />
TREE=${PRD}.tree<br />
OEBPS=${TREE}/OEBPS<br />
SAXON="java -jar /opt/local/share/java/saxon9he.jar"<br />
# http://saxonica.com/documentation/html/using-xsl/commandline.html<br />
<br />
if [ ! -f export.xml ]; then<br />
echo "File export.xml not found! Trying to run ConTeXt..."<br />
# you should replace this call with your own<br />
./makeit.sh ${PRD}<br />
exit 2<br />
fi<br />
<br />
if [ ! -f $PRDPDF ]; then<br />
echo Product $PRDPDF not found!<br />
echo Please run "makeit.sh $PRD"<br />
exit 3<br />
fi<br />
<br />
if [ ! -d $OEBPS ]; then<br />
echo Directory $OEBPS missing!<br />
echo Creating new ePub ...<br />
mtxrun --script epub --make ${PRD}<br />
fi<br />
<br />
if [ -d $OEBPS ]; then<br />
echo "Creating directories (might exist) ..."<br />
mkdir $OEBPS/Styles<br />
mkdir $OEBPS/Images<br />
mkdir $OEBPS/Fonts<br />
mkdir $OEBPS/Text<br />
<br />
echo Creating HTML ...<br />
$SAXON -o:$OEBPS/Text/_intro.html -s:export.xml -xsl:$WORKDIR/export2html.xsl<br />
echo Creating OPF ...<br />
$SAXON -o:$OEBPS/${PRD}.opf -s:export.xml -xsl:$WORKDIR/export2opf.xsl<br />
echo Creating ToC NCX ...<br />
$SAXON -o:$OEBPS/toc.ncx -s:export.xml -xsl:$WORKDIR/export2ncx.xsl<br />
echo Creating Cover ...<br />
$SAXON -o:$OEBPS/cover.html -s:export.xml -xsl:$WORKDIR/export2cover.xsl<br />
echo Creating cover image from first page of PDF ...<br />
convert -density 196 $PRDPDF'[0]' +repage $OEBPS/Images/cover.jpg<br />
<br />
echo Copying files ...<br />
cp style.css $OEBPS/Styles/<br />
# This copies only fonts from your project directory; adapt.<br />
cp *.?tf $OEBPS/Fonts/<br />
<br />
echo Converting images from PDF to PNG ...<br />
cd $TEMPDIR<br />
for IMG in prd_${PRD}-temp-lilypond-*.pdf; do<br />
NEWIMG=../$OEBPS/Images/${IMG#prd_${PRD}-temp-lilypond-}<br />
NEWIMG=${NEWIMG%.pdf}.png<br />
if [ ! -f $NEWIMG ]; then<br />
convert -density 196 $IMG'[0]' -trim +repage ${NEWIMG}<br />
fi<br />
done<br />
cd ..<br />
<br />
# delete old epub<br />
rm $TREE/${PRD}.epub<br />
rm ${EPUBPREFIX}${PRD}.epub<br />
echo Creating ePub ${EPUBPREFIX}${PRD}.epub ...<br />
cd $TREE<br />
zip -uqr ../${EPUBPREFIX}${PRD}.epub *<br />
cd ..<br />
fi<br />
echo Ready.<br />
</pre></div>Rikhttps://wiki.contextgarden.net/index.php?title=Fonts_-_Old_Content&diff=22525Fonts - Old Content2014-07-01T20:28:50Z<p>Rik: Updated link for Junicode</p>
<hr />
<div>< [[Visuals]] | [[Symbols]] ><br />
= How to use fonts in ConTeXt =<br />
'''The ConTeXt way of handling fonts are [[TypeScripts]].''' It’s a system of abstraction and aliases, which may seem “strange” at first for new users of ConTeXt.<br />
* If it fits your needs, consider first to use the former [[Simplefonts]] module, now in the core as {{src|font-sel.mkvi}}.<br />
* There is now a [http://context.aanhet.net/svn/contextman/context-reference/en/co-fonts.pdf manual chapter on fonts].<br />
* If you happen to use [[XeTeX]] then you can forget almost all the magic and start using your system fonts (see [[Fonts_in_XeTeX]]).<br />
* If you use [[LuaTeX]], see [[Fonts_in_LuaTeX]]<br />
* If you want to keep using [[pdfTeX]], read on.<br />
<br />
= Font support & configuration =<br />
== Type 1 fonts ==<br />
<br />
Type 1 fonts come in multiple files. The various components are:<br />
<br />
* '''.pfb''': "Printer Font, Binary".<br />
* '''.pfa''': "Printer Font, ASCII".<br />
* '''.pfm''': "Printer Font Metrics", binary.<br />
* '''.afm''': "Adobe Font Metrics".<br />
<br />
Typically each font will have a set of outlines in a pfb or pfa file, and a set of metrics in a pfm or afm file.<br />
<br />
Which file variations are preferred depends on platform. Linux prefers pfa and afm (the ASCII versions). Windows prefers pfb and pfm (the binary versions). Mac OS X prefers pfm and afm.<br />
<br />
On the Mac, you may encounter old-style PostScript Type 1 fonts which have an extensionless file containing the font outlines. These are a relic from the days when bitmaps were used to display fonts on screen, and the PostScript was downloaded to the printer. Your best bet is to throw them away and get an up-to-date OpenType version, or use a font editing utility such as fontforge to convert them.<br />
<br />
On Windows 7, the OS will identify only the .pfm file as the actual font. However, when you install the font, Windows invisibly locates the matching .pfb file from the same directory, and copies them both to the C:\Windows\Fonts directory.<br />
<br />
* Using [[psnfss]] metrics in ConTeXt<br />
* Matt Gushee's introduction to [http://havenrock.com/textips/bookfonts.html virtual fonts], especially for getting expert fonts to work.<br />
* [[URW Garamond]]<br />
* [[Lucida]] : large font family designed by Bigelow & Holmes; suitable e.g. for presentations<br />
* [http://dl.contextgarden.net/myway/expertfonts.pdf Installing Expert Fonts: Minion Pro] by Idris Samawi Hamid; contains step-by-step instructions, from preinstallation to writing typescripts<br />
* [http://www.stormtype.com Storm Type Foundry] : [http://modules.contextgarden.net/stormfontsupport support] of selected fonts<br />
<br />
== True Type fonts ==<br />
* [http://tug.org/pracjourn/2005-2/schmitz/schmitz.pdf Integrating TrueType Fonts into ConTeXt] by Thomas A. Schmitz (PracTeX Journal)<br />
* [[Installing a TrueType font, step by step]]. If you just need to install a TrueType font, this may be what you are looking for.<br />
* [[Palatino Linotype under MKIV]].<br />
<br />
== OpenType fonts ==<br />
* [[otfinstall|otfinst - a script for using OpenType fonts in ConTeXt]]<br />
<br />
== Basic Hints ==<br />
<br />
How to change to Palatino for text with Euler for math: [[Palatino with Euler for Math]]<br />
<br />
''Some hints by Taco from the mailing list on 2005-11-20:''<br />
<br />
Q: How up to date or out of date is the information in [http://www.pragma-ade.com/general/manuals/mfonts.pdf mfonts manual]?<br />
<br />
A: It looks like it is still quite up-to-date, but some of the examples it gives may no longer be the very best and latest way of doing things, and possibly there are some new developments that do not get as much attention as desired (like [http://www.pragma-ade.com/general/manuals/mtexfont.pdf texfont], and the issues arising from font map files). Overall, the document appears accurate, though.<br />
<br />
An important thing to remember is this:<br />
<br />
'''ConTeXt does not share font metric conventions with LaTeX.'''<br />
<br />
(at one point it started doing so, like supporting the ''Karl Berry naming scheme'' and the ''PSNFSS'' style font family names, but that has since been abandoned).<br />
<br />
Another important thing is that it also does not share font map files with LaTeX and, specifically,<br />
<br />
'''ConTeXt does not make pdfeTeX read <tt>pdftex.map</tt>.'''<br />
<br />
(this is at the root of a great many problems reported by users only familiar with PSNFSS)<br />
<br />
The preferred format for metric files in ConTeXt is<br />
<br />
<tt><vendor>/<familyname>/<encoding>-<fontname>.tfm</tt><br />
<br />
for metrics and<br />
<br />
<tt><encoding>-<vendor>-<familyname>.map</tt><br />
<br />
for the mapping files.<br />
<br />
* <fontname> is usually derived from the font source (afm or ttf),<br />
* <encoding> is a 'controlled' list, (see [[Encodings and Regimes]])<br />
* <vendor> and <familyname> are user-supplied (at install time).<br />
<br />
There are ways to trick ConTeXt into using different conventions, but if you do that you are likely to run into trouble.<br />
<br />
== Hints by Language ==<br />
* general: [[Encodings and Regimes]]<br />
* [[Arabic and Hebrew]]<br />
* [[Chinese]]<br />
* [[Czech]]<br />
* [[Greek]]<br />
* [[Russian]]<br />
* [[Vietnamese]]<br />
<br />
= Unsorted links =<br />
<br />
* [http://www.pragma-ade.com/general/manuals/mtexfont.pdf font installation with texfont] by Pragma<br />
* [http://www.pragma-ade.com/general/manuals/mfonts.pdf ConTeXt's font mechanism in detail] by Pragma<br />
* [http://tug.org/TUGboat/Articles/tb28-2/tb89mahajan.pdf ConTeXt basics for users: Font styles] by Aditya Mahajan (2007)<br />
* [http://www.pragma-ade.com/general/manuals/mmakempy.pdf making outlines] by Pragma<br />
* [http://pragma-ade.com/specials/fonts/fontspecial-p.pdf Here] you can try out several TeX fonts online (PDF interface!)<br />
* Troubleshooting: solving [[TeXfont]] problems.<br />
* Character [[Protrusion]] (also known as hanging or font handling) is a more subtle typographic effect.<br />
* [[Font Handling Internals]]<br />
* [http://watershade.net/wmcclain/context-help.html Bill McClain's ConTeXt beginners page] has also a lot about fonts<br />
* [[Pseudo Small Caps]] by Vit Zyka<br />
* [[Understanding how fonts work in ConTeXt]]<br />
* Fonts rely on [[Encodings and Regimes]], and it helps to know what happens underneath the hood, from time to time.<br />
* In newer distributions, map files belong in <tt>&hellip;/fonts/map/pdftex/context</tt>!<br />
* Don't forget to look at [[cont-sys.tex]]!<br />
<br />
= Where to find fonts =<br />
<br />
== Available Free Fonts ==<br />
* [http://www.georgduffner.at/ebgaramond/ EB Garamond] is still in development, but it has nice-looking oldstyle numbers.<br />
* [http://ctan.tug.org/tex-archive/info/Free_Math_Font_Survey/survey.html Free Math Fonts] : overview of different free Math fonts; [http://www.geocities.com/hartke01/ links to other free fonts]<br />
* [http://greekfontsociety.gr/ GFS Didot] : Latin, full set of polytonik Greek, small caps, oldstyle figures, full f-ligatures ([http://modules.contextgarden.net/gfsdidot Module for ConTeXt])<br />
* [[TeX Gyre]] : a set of great text fonts by our GUST friends, based on URW's free PostScript standard fonts for GhostScript.<br />
* [http://www.janusz.nowacki.strefa.pl/kurier.html Foto Alfa] : some TeX related fonts from Poland (Antykwa Toruńska. Antykwa Półtawskiego, Kurier, Iwona...)<br />
* [http://linuxlibertine.sourceforge.net Libertine Open Fonts Project]: GPL/OFL serif font [[Linux Libertine on mkiv|sample]]<br />
* [http://scripts.sil.org SIL International] : great Unicode fonts for scholars by SIL (Gentium, Doulos, Charis, etc.)<br />
* [http://ist-socrates.berkeley.edu/~pinax/greekkeys/GreekKeys.html GreekKeys] : links to polytonic Greek fonts<br />
* [http://scholarsfonts.net Scholar's Fonts] : Font for Scholars (Latin, Germanic languages, Greek, Hebrew and Linguistics)<br />
* [http://junicode.sourceforge.net/ Junicode] : Junius-Unicode, a font for medievalists<br />
* [http://www.freelang.net/fonts/index.html FreeLang fonts] : fonts for exotic languages<br />
* [http://www.blambot.com Blambot] : Comic fonts<br />
* [http://www.chank.com/freefonts.php Chank] : some free Chank fonts<br />
* [http://www.fontface.com/fonts/ FontFace] : free fonts<br />
* [http://www.dafont.com DaFont] : more free fonts<br />
* [http://fonts.tom7.com/fonts98.html Divide by Zero] : more fonts<br />
* [http://moorstation.org/typoasis/typoasis1.htm TypOasis] : lots of nice fonts, but a bit hard to find (have a look at designers Apostrophic Lab, Manfred Klein and Dieter Steffmann)<br />
* [http://kadyellebee.com/fonts/ Kristine's Font Organization] : find a font in a sorted directory<br />
* [http://www.fontlover.com FontLover] : font news portal site<br />
* [http://www.stormtype.com/family-lido-stf.html Lido] : OpenType and TrueType typefaces by Storm Type Foundry, free for non-commercial use. [http://modules.contextgarden.net/stormfontsupport Support].<br />
* [http://www.alanwood.net/unicode/fontsbyrange.html Alan Wood’s Unicode Resources] : find fonts by Unicode character range<br />
* [http://www.josbuivenga.demon.nl/ exljbris] Free Quality Font Foundry by Jos Buivenga<br />
* [http://www.stixfonts.org/ STIX Fonts] Beta download of the STIX-Fonts<br />
* [http://www.fontsquirrel.com/ Font Squirrel] Handpicked free fonts for graphic designers with commercial-use licenses<br />
* [http://www.theleagueofmoveabletype.com/ The league of Moveable Type] : a collection of open source fonts<br />
* [http://www.1stwebdesigner.com/resources/65-popular-and-professional-free-fonts-for-creative-typography/ 65 Popular And Professional Free Fonts For Creative Typography] and [http://www.1stwebdesigner.com/resources/52-really-high-quality-free-fonts-for-modern-and-cool-design/ 52 Really High Quality Free Fonts For Modern And Cool Design]<br />
* [http://www.paratype.com/public/]: Public fonts for minority languages of Russia [[Paratype typescript for mkiv|sample]]<br />
* ''... many more to be added ...''<br />
<br />
<br />
[[Category:Fonts]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/setupcaptions&diff=22478Command/setupcaptions2014-04-22T14:52:37Z<p>Rik: Modified description of suffix; added descriptions of separator and stopper.</p>
<hr />
<div>{{Reference<br />
|name=setupcaptions<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupcaptions<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:top|top]] [[Command/value:bottom|bottom]] [[Command/value:none|none]] [[Command/value:high|high]] [[Command/value:low|low]] [[Command/value:middle|middle]] [[Command/value:left|left]] [[Command/value:right|right]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:width|width]]</td><br />
<td>[[Command/value:fit|fit]] [[Command/value:broad|broad]] [[Command/value:max|max]] [[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:minwidth|minwidth]]</td><br />
<td>[[Command/value:fit|fit]] [[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:headstyle|headstyle]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small|small...]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:style|style]]</td><br />
<td>[[Command/value:normal|normal]] [[Command/value:bold|bold]] [[Command/value:slanted|slanted]] [[Command/value:boldslanted|boldslanted]] [[Command/value:type|type]] [[Command/value:cap|cap]] [[Command/value:small|small...]] [[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:number|number]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:inbetween|inbetween]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:left|left]] [[Command/value:flushleft|flushleft]] [[Command/value:middle|middle]] [[Command/value:flushright|flushright]] [[Command/value:right|right]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:numberconversion|numberconversion]]</td><br />
<td>[[Command/value:numbers|numbers]] [[Command/value:characters|characters]] [[Command/value:Characters|Characters]] [[Command/value:romannumerals|romannumerals]] [[Command/value:Romannumerals|Romannumerals]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:conversion|conversion]]</td><br />
<td>[[Command/value:numbers|numbers]] [[Command/value:characters|characters]] [[Command/value:Characters|Characters]] [[Command/value:romannumerals|romannumerals]] [[Command/value:Romannumerals|Romannumerals]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:way|way]]</td><br />
<td>[[Command/value:bytext|bytext]] [[Command/value:bysection|bysection]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:separator|separator]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:stopper|stopper]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:prefix|prefix]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:suffix|suffix]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:prefixsegments|prefixsegments]]</td><br />
<td>[[Command/value:none|none]] [[Command/value:section|section]] ...</td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:command|command]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:spaceafter|spaceafter]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
</table><br />
<br />
== Description ==<br />
<br />
{| class=wikitable<br />
|- style="vertical-align: top" <br />
| {{key|location}}<br />
| The first option defines the location of the caption relative to the figure itself. The option <code>[location=right]</code> e.g. puts the caption on the right of the figure. The values of the location can be combined, so that <code>[location={right,low}]</code> adjusts the caption position to be to the right of the figure and in a low vertical position. <br />
|- style="vertical-align: top"<br />
| {{key|width}} <br />
| This is the width of the figure caption. If you do not like default captions that are driven by figure (table) width, try: <code>\setupcaptions[minwidth=textwidth, align=middle]</code><br />
|- style="vertical-align: top"<br />
| {{key|headstyle}}<br />
| This defines the formatting of the label, i.e. usually the word ''figure'' or ''table'' and its number. For example, <code>[headstyle=\it]</code> will change it to ''italic''.<br />
|- style="vertical-align: top"<br />
| {{key|style}}<br />
| The formatting of the text of the caption, use <code>[style=\it]</code> to get an ''italic'' text. Several values can be given using curly brackets: <code>[style={\it\tfx}]</code>. Please note, that some formatting (such as font size) will affect the head as well.<br />
|- style="vertical-align: top"<br />
| {{key|number}}<br />
| The option <code>[number=no]</code> suppresses the label and figure number.<br />
|- style="vertical-align: top"<br />
| {{key|inbetween}}<br />
| The macros given here are executed after placing the figure and before placing the caption. To set the space between figure and caption to zero use <code>[inbetween=]</code><br />
|- style="vertical-align: top"<br />
| {{key|align}}<br />
| This can change the alignment of the caption. It can lead to confusion, since ''left'' and ''right'' means ''raggedleft'' and ''raggedright''. So to align a caption ''flush left'', use <code>[align=flushleft]</code>. <br />
|- style="vertical-align: top"<br />
| {{key|numberconversion}}<br />
| Here, it is possible to change the number of the e.g. figure. ''romannumerals'' means, well, roman numerals, the capitalized version capitalizes the number as well. In MkIV, ''numberconversion'' must be used instead of ''conversion''. Example: <code>numberconversion=Romannumerals</code><br />
|- style="vertical-align: top" <br />
| {{key|conversion}}<br />
| This is the MkII version of ''numberconversion''.<br />
|- style="vertical-align: top" <br />
| {{key|way}}<br />
| Using option <code>[way=bysection]</code> resets the numbering to 1 at each new section, but does not prefix the numbers with the section number, to do that, use the following options: <code>\setupcaptions[way=bysection,prefixsegments=section]</code>. If one has only a small number of figures and wishes to label them sequentially from 1 to ''n'', the following works:<code>\setupcaptions[way=bytext, prefixsegments=none]</code>.<br />
|- style="vertical-align: top" <br />
| {{key|stopper'''}}<br />
| The stopper (in MKIV, ''numberstopper'') text follows the number and, if present, the ''suffix'', and precedes the caption text. It does not appear in references.<br />
|- style="vertical-align: top" <br />
| {{key|separator'''}}<br />
| The separator (in MKIV, ''prefixconnector'') text separates components of the number in the caption and in references when sectioned numbers are used.<br />
|- style="vertical-align: top" <br />
| {{key|suffix'''}}<br />
| The suffix text immediately follows the number in the caption and in references.<br />
|- style="vertical-align: top" <br />
| {{key|prefixsegments}}<br />
| To have a figure number such as ''Figure 2.3'', where 2 is the section number and 3 the figure number, you can use this option. Normally, you want to reset the figure number with every section as well, so that ''Figure 2.1'' follows ''Figure 1.12'' instead of ''Figure 2.13''. Therefore, you have to use <code>\setupcaptions[prefix=yes,way=bysection,prefixsegments=section]</code>.<br />
|-<br />
| {{key|spaceafter}}<br />
| Add some vertical space after the caption.<br />
|}<br />
<br />
== Example ==<br />
<context source=yes><br />
\setuppapersize[A6]<br />
\setupexternalfigures[location=default]<br />
\setupcaptions[<br />
style={\tfx\setupinterlinespace[line=10pt]}, <br />
headstyle=\rm, <br />
stopper={:}]<br />
<br />
\placefigure<br />
{Oh caption, my caption!\crlf<br />
(Apologies to Walt Whitman)}<br />
{\externalfigure[cow][width=2cm]}<br />
<br />
\input linden<br />
</context><br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Floating|setupcaptions]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=String_manipulation&diff=22426String manipulation2014-03-05T22:51:31Z<p>Rik: Correct again the name utilities.strings.striplong</p>
<hr />
<div>[[Extensions_to_the_Lua_I/O_library|The I/O-Library]] ><br />
<br />
=Overview=<br />
<br />
In comparison with other scripting languages the bare Lua string library<br />
lacks some very useful “features”.<br />
But before a texnician reimplements all the goodies that E knows from Eir<br />
favorite language, E should first have a look at the helper functions that<br />
ConTeXt already provides.<br />
The following section briefly introduces these extensions with regard to <br />
string manipulation.<br />
<br />
The function name and its arguments are given as heading, the content is split<br />
into, first, an example and, second, a short description of what the function<br />
does and its peculiarities if applicable.<br />
The examples are so designed that they should work when copy-pasted into an<br />
empty Lua file and processed with context.<br />
<br />
=l-string.lua=<br />
<br />
==string.esc(string)==<br />
<br />
<pre><br />
print(string.esc([[^([\"\'])(.*)%1$","%2]]))<br />
</pre><br />
<br />
Returns <tt>string</tt> with all occurrences of <br />
<tt>%</tt>,<br />
<tt>.</tt>,<br />
<tt>+</tt>,<br />
<tt>-</tt>,<br />
<tt>*</tt>,<br />
<tt>^</tt>,<br />
<tt>$</tt>,<br />
<tt>[</tt>,<br />
<tt>]</tt>,<br />
<tt>(</tt>,<br />
<tt>)</tt>,<br />
<tt>{</tt>, and<br />
<tt>}</tt><br />
escaped with the percent symbol.<br />
Cf. [[#string.escapedpattern.28string.29_.7C_string.partialescapedpattern.28string.29|string.escapedpattern]].<br />
<br />
==string.unquote(string)==<br />
<br />
<pre><br />
print(string.unquote[["Do you see any quotes around here?"]])<br />
print(string.unquote[['Do you see any quotes around here?']])<br />
print(string.unquote[["Do you see any quotes around here?']]) -- Doesn't match<br />
print(string.unquote[[“Do you see any quotes around here?”]]) -- Doesn't match<br />
</pre><br />
<br />
Returns <tt>string</tt> with surrounding quotes removed iff they are<br />
of the same kind (ascii single/double quote only).<br />
<br />
==string.quote(string)==<br />
<br />
Equivalent to <tt>string.format("%q", string)</tt>.<br />
<br />
==string.count(string, pattern)==<br />
<br />
<pre><br />
print(string.count("How many a's?", "a"))<br />
print(string.count("How many many's?", "many"))<br />
</pre><br />
<br />
Returns the count of matches for <tt>pattern</tt> in <tt>string</tt>.<br />
<br />
==string.limit(string, max, [tail])==<br />
<br />
<pre><br />
s = "This string is too long for our purpose."<br />
print(string.limit(s, 15))<br />
print(string.limit(s, 15, " …")) -- "…" seems to be three bytes long.<br />
</pre><br />
<br />
Returns the string capped at position <tt>max</tt> (minus the byte<br />
count of <tt>tail</tt>) with <tt>tail</tt> appended. The optional <tt>tail</tt><br />
defaults to <tt>"..."</tt>.<br />
<br />
==string.strip(string)==<br />
<br />
<pre><br />
print(string.strip([[ I once used to be surrounded by whitespace. <br />
]]))<br />
</pre><br />
<br />
Yields <tt>string</tt> with leading and trailing whitespace (spaces, horizontal<br />
and vertical tabs, newlines) removed.<br />
<br />
==string.is_empty(string)==<br />
<br />
<pre><br />
print(string.is_empty([[]]))<br />
print(string.is_empty([[notempty]]))<br />
print(string.is_empty(9))<br />
</pre><br />
<br />
Returns <tt>true</tt> if the argument is an empty string and<br />
<tt>false</tt> for nonempty strings and numbers.<br />
(Throws an error with functions, booleans or <tt>nil</tt>.)<br />
<br />
==string.enhance(string, pattern, function)==<br />
<br />
<pre><br />
s = "I'd like to file a complaint."<br />
f = function () <br />
return "have an argument!"<br />
end<br />
io.write(string.enhance(s, "file a complaint.", f))<br />
</pre><br />
<br />
Returns the input string with <tt>function</tt> applied to all matches<br />
for <tt>pattern</tt>. <br />
''Note'': <tt>string.enhance</tt> relies on <tt>gsub</tt> from the lua<br />
string library so unfortunately you can't pass it an LPEG as second<br />
argument.<br />
<br />
==string.characters(string)==<br />
<br />
<pre><br />
n = 0<br />
for chr in string.characters("Some bytes") do<br />
n = n + 1<br />
io.write(string.format("Nr. %2u is %s.\n", n, chr))<br />
end<br />
</pre><br />
<br />
Returns an iterator over the ascii characters in <tt>string</tt>.<br />
''Note'': As this relies on the string library you should expect<br />
unwelcome results (e.g. invalid utf8 sequences) when using it for<br />
anything else than 7-bit ascii.<br />
<br />
Cf.<br />
[[#string.characters(string) .7C string.utfcharacters(string)|string.utfcharacters]]<br />
from LuaTeX.<br />
<br />
==string.bytes(string)==<br />
<br />
<pre><br />
n = 0<br />
for byte in string.bytes("Some bytes") do<br />
n = n + 1<br />
io.write(string.format("Nr. %2u is %3u.\n", n, byte))<br />
end<br />
</pre><br />
<br />
The same as <tt>string.characters</tt> but returns bytes as base 10<br />
integers.<br />
<br />
==string.lpadd(string, n, character) | string.rpadd(string, n, character)==<br />
<br />
<pre><br />
s = "Some string."<br />
print(string.rpadd(s, 15, "r"))<br />
print(string.lpadd(s, 15, "l"))<br />
</pre><br />
<br />
Adds as many times <tt>character</tt> as needed to the left or right<br />
respectively to get a string of length <tt>n</tt> from<br />
<tt>string</tt>. ''Note'': <tt>character</tt> can in fact be a string<br />
of any length which can distort the result.<br />
<br />
==string.escapedpattern(string) | string.partialescapedpattern(string)==<br />
<br />
<pre><br />
print(string.escapedpattern("Some characters like *, + and ] need to be escaped for formatting."))<br />
print(string.partialescapedpattern("Some characters like *, + and ] need to be escaped for formatting."))<br />
</pre><br />
<br />
<tt>string.escapedpattern</tt> escapes all occurences of the characters<br />
<tt>-</tt>,<br />
<tt>.</tt>,<br />
<tt>+</tt>,<br />
<tt>*</tt>,<br />
<tt>%</tt>,<br />
<tt>(</tt>,<br />
<tt>)</tt>,<br />
<tt>[</tt>, and<br />
<tt>]</tt><br />
using percent signs (<tt>%</tt>);<br />
<tt>string.partialescapedpattern</tt> only escapes <br />
<tt>-</tt> and<br />
<tt>.</tt> using percent signs whereas<br />
<tt>?</tt> and<br />
<tt>*</tt> are prefixed with dots (<tt>.</tt>).<br />
The latter is used for pattern building, e.g. in [[source:trac-set.lua|trac-set.lua]].<br />
<br />
<br />
==string.tohash(string)==<br />
<br />
<pre><br />
t = string.tohash("Comma,or space,separated values")<br />
for k,v in pairs(t) do<br />
print(k,v)<br />
end<br />
</pre><br />
<br />
Returns a hashtable with every substring of <tt>string</tt><br />
between spaces and commas as keys and <tt>true</tt> as values.<br />
<br />
==string.totable(string)==<br />
<br />
<pre><br />
t = string.totable("Insert your favorite string here!")<br />
for k,v in pairs(t) do<br />
print(k,v)<br />
end<br />
</pre><br />
<br />
Returns a list of ascii characters that constitute <tt>string</tt>.<br />
''Note'': As this relies on LPEG's character pattern it <br />
'''is guaranteed'''<br />
to turn your multi-byte sequences into garbage!<br />
<br />
==string.tabtospace(string, [tabsize])==<br />
<br />
<pre><br />
local t = {<br />
"1234567123456712345671234567",<br />
"a\tb\tc",<br />
"aa\tbb\tcc",<br />
"aaa\tbbb\tccc",<br />
"aaaa\tbbbb\tcccc",<br />
"aaaaa\tbbbbb\tccccc",<br />
"aaaaaa\tbbbbbb\tcccccc",<br />
}<br />
for k,v in ipairs(t) do<br />
print(string.tabtospace(t[k]))<br />
end<br />
</pre><br />
<br />
(Modified example from [[source:l-string.lua|the context sources]].)<br />
Replaces tabs with spaces depending on position. The optional argument<br />
<tt>tabsize</tt> defaults to <em>7</em>.<br />
<br />
==string.compactlong(string) | utilities.strings.striplong(string)==<br />
<br />
<pre><br />
s = [[<br />
This is <br />
a fairly<br />
long<br />
string<br />
with some<br />
rather<br />
silly<br />
indents.]]<br />
<br />
print(string.compactlong(s))<br />
printutilities.strings.striplong(s))<br />
</pre><br />
<br />
<tt>string.compactlong</tt> removes newlines (dos and unix) and<br />
leading spaces from <tt>string</tt>.<br />
<br />
<tt>utilities.strings.striplong</tt> removes leading spaces and converts dos<br />
newlines to unix newlines.<br />
<br />
==string.topattern(string, lowercase, strict)==<br />
<br />
<pre><br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", false, false))<br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", true, false))<br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", true, true ))<br />
</pre><br />
<br />
Returns a valid pattern from <tt>string</tt> that can be used with<br />
<tt>string.find</tt> et&nbsp;al.<br />
The return value is essentially the same as with<br />
<tt>string.escapedpattern</tt> plus two options:<br />
the boolean <tt>lowercase</tt> specifies whether the string is to be<br />
lowercased first,<br />
whereas <tt>strict</tt> results in a whole line pattern.<br />
<br />
=l-lpeg.lua=<br />
<br />
==Predefined Patterns==<br />
<br />
Dozens of the most common patterns including<br />
hexadecimal numbers, diverse whitespace and line endings, punctuation,<br />
and even an XML path parser etc. are already predefined.<br />
To get an impression about what they do you can check them with the<br />
followings snippet:<br />
<br />
<pre><br />
function show_patterns (p, super)<br />
for i,j in pairs(p) do<br />
i = super and super..":"..i or i<br />
print(string.rpadd("=== " .. i .. " ", 80, "="))<br />
if type(j) == "userdata" then<br />
j:print()<br />
else -- descend into next level<br />
show_patterns(j, i)<br />
end <br />
end <br />
end<br />
<br />
local p = lpeg.patterns<br />
<br />
show_patterns(p)<br />
</pre><br />
<br />
==lpeg.anywhere(string|pattern)==<br />
<br />
<pre><br />
str = "Fetchez la vache!"<br />
print(lpeg.anywhere("a" ):match(str))<br />
print(lpeg.anywhere("la"):match(str))<br />
print(lpeg.anywhere("ac"):match(str))<br />
</pre><br />
<br />
Returns a pattern that matches the first occurrence of<br />
<tt>string</tt>, returning the position of the last character in the<br />
matched sequence.<br />
Keep in mind that you can pass it patterns as well:<br />
<br />
<pre><br />
print(lpeg.anywhere(lpeg.P"a"*lpeg.patterns.whitespace):match(str))<br />
</pre><br />
<br />
==lpeg.splitter(delimiter, function)==<br />
<br />
<pre><br />
wedge = function (str)<br />
local dict = {<br />
Romanes = "Romani",<br />
evnt = "ite",<br />
domvs = "domvm",<br />
}<br />
return dict[str] or ""<br />
end<br />
<br />
splitme = "Romanes evnt domvs"<br />
print(lpeg.splitter(" ", wedge):match(splitme))<br />
</pre><br />
<br />
Returns a pattern that can be used to apply <tt>function</tt> to all<br />
substrings delimited by <tt>delimiter</tt> which can be a string or a<br />
pattern.<br />
<br />
==string.splitlines(string)==<br />
<br />
<pre><br />
str = [[<br />
Bravely bold Sir Robin rode forth from Camelot.<br />
He was not afraid to die, O brave Sir Robin!<br />
He was not at all afraid to be killed in nasty ways,<br />
Brave, brave, brave, brave Sir Robin!<br />
]]<br />
<br />
for n,line in ipairs(string.splitlines(str)) do<br />
io.write(string.format("%u: %s\n", n, line))<br />
end<br />
</pre><br />
<br />
Splits <tt>string</tt> into a list of lines where empty lines &ndash; i.e.<br />
consecutive <tt>\n</tt>'s &ndash; yield the empty string.<br />
<br />
==lpeg.splitat(delimiter, [single])==<br />
<br />
<pre><br />
str = [[<br />
Number twenty-three. The shin.<br />
Number twenty-four. Reginald Maudling's shin.<br />
Number twenty-five. The brain.<br />
Number twenty-six. Magaret Thatcher's brain.<br />
Number twenty-seven. More naughty bits.<br />
]]<br />
<br />
t = {lpeg.splitat("Number", false):match(str)}<br />
for n,element in pairs(t) do <br />
element = element == "" and element .. "\n" or element<br />
io.write(n..": "..element) <br />
end<br />
</pre><br />
<br />
Returns a pattern that produces a list of substrings delimited by<br />
<tt>delimiter</tt> (which can be a pattern or a string).<br />
The optional boolean <tt>single</tt> determines whether the string<br />
should be split only at the first match.<br />
<br />
==string.split(string, separator) | string.checkedsplit(string, separator)==<br />
<br />
<pre><br />
theory = [[All brontosauruses are thin at one end, much much thicker in the middle, and then thin again at the far end.]]<br />
<br />
theorems = string.split(theory, lpeg.P", " * lpeg.P"and "^-1) <br />
<br />
for n, element in ipairs(theorems) do<br />
io.write (string.format("Theorem %u: %s\n", n, element))<br />
end<br />
</pre><br />
<br />
<tt>string.split</tt> returns, as you would expect, a list of<br />
substrings of <tt>string</tt> delimited by <tt>separator</tt>.<br />
Consecutive separators result in the empty string;<br />
its counterpart <tt>string.checkedsplit</tt> does not match these <br />
sequences, returning <tt>nil</tt> instead.<br />
<br />
''Note'': The corresponding pattern generators are <tt>lpeg.split</tt><br />
and <tt>lpeg.checkedsplit</tt>.<br />
<br />
==lpeg.stripper(string|pattern) | lpeg.keeper(string|pattern)==<br />
<br />
<pre><br />
str = "A dromedary has one hump and a camel has a refreshment car, buffet, and ticket collector."<br />
print(lpeg.stripper("aeiou") :match(str))<br />
print(lpeg.stripper(lpeg.P"camel "):match(str))<br />
</pre><br />
<br />
<tt>lpeg.stripper</tt> returns a pattern that removes either, if the<br />
argument is a string, all occurrences of every character of that<br />
string or, if the argument is a pattern, all occurrences of that pattern.<br />
Its complement, <tt>lpeg.keeper</tt>, removes anything but the string<br />
or pattern respectively.<br />
''Note'': <tt>string.keeper</tt> does not seem to work as expected with<br />
patterns consisting of more than one byte, e.g. <tt>lpeg.P("camel")</tt>.<br />
<br />
==lpeg.replacer(table)==<br />
<br />
<pre><br />
str = "Luxury Yacht"<br />
<br />
rep = {<br />
[1] = { "Luxury", "Throatwobbler" },<br />
[2] = { "Yacht", "Mangrove" },<br />
}<br />
<br />
print("My name is spelled “" .. str .. "”, but it's pronounced “" .. lpeg.replacer(rep):match(str) .. "”.")<br />
</pre><br />
<br />
Accepts a list of pairs and returns a pattern that substitutes any<br />
first elements of a given pair by its second element.<br />
The latter can be a string, a hashtable, or a function (whatever fits<br />
with <tt>lpeg.Cs</tt>).<br />
<br />
''Note'': Choose the order of elements in <tt>table</tt> with care.<br />
Due to LPEG's matching the leftmost element of disjunction first<br />
it might turn out to be as crucial as in the following example:<br />
<br />
<pre><br />
str = "aaababaaba"<br />
rep1 = {<br />
{ "a", "x" },<br />
{ "aa", "y" },<br />
}<br />
<br />
rep2 = {<br />
{ "aa", "y" },<br />
{ "a", "x" },<br />
}<br />
<br />
print(lpeg.replacer(rep1):match(str))<br />
print(lpeg.replacer(rep2):match(str))<br />
</pre><br />
<br />
==lpeg.firstofsplit(separator) | lpeg.secondofsplit(separator)==<br />
<br />
<pre><br />
str = "menu = spam, spam, spam, spam, spam, baked beans, spam, spam and spam"<br />
print(lpeg.firstofsplit (" = "):match(str))<br />
print(lpeg.secondofsplit(" = "):match(str))<br />
</pre><br />
<br />
<tt>lpeg.firstofsplit</tt> returns a pattern that matches the<br />
substring until the first occurrence of <tt>separator</tt>, its<br />
complement generated by <tt>lpeg.secondofsplit</tt> matches the whole<br />
rest after that regardless of any further occurrences of <tt>separator</tt>.<br />
<br />
= util-prs.lua = <br />
<br />
== utilities.parsers.settings_to_hash(str) ==<br />
<br />
<pre><br />
str = 'a=1, b=2, c=3'<br />
utilities.parsers.settings_to_hash(str)<br />
--> { a = 1, b = 2, c = 3 }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated key=value statements, and returns an associative array of {{code|1=["key"] = value}} entries. Very useful for parsing and accessing macro arguments at the Lua end.<br />
<br />
== utilities.parsers.settings_to_array(str) ==<br />
<br />
<pre><br />
str = 'top, inmargin=2, top, {here,now}'<br />
utilities.parsers.settings_to_array(str)<br />
--> { "top", "inmargin=2", "top", "here,now" }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear. Duplicates are not filtered. <tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed<br />
<br />
== utilities.parsers.settings_to_set(str) ==<br />
<br />
<pre><br />
str = 'top, inmargin=2, top, {here,now}'<br />
utilities.parsers.settings_to_set(str)<br />
--> { ["top"]=true, ["inmargin=2"]=true, ["here,now"]=true }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear, with duplicates removed.<br />
<tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed<br />
<br />
== Other function in utilities.parsers ==<br />
{| class="wikitable"<br />
|-<br />
| utilities.parsers.add_settings_to_array<br />
| parse and write directly into table<br />
|-<br />
| utilities.parsers.arguments_to_table<br />
| parse arguments, return table<br />
|-<br />
| utilities.parsers.array_to_string(a,sep)<br />
| concatenates a with custom sep or comma<br />
|-<br />
| utilities.parsers.getparameters<br />
| write settings_to_hash to an array with a metatable. A metatable is a sort of parent: when a table is accessed, undefined values will be looked up in the metatable.<br />
|-<br />
| utilities.parsers.hash_to_string<br />
| turn a hash into a string, with optional strictness settings<br />
|-<br />
| utilities.parsers.simple_hash_to_string<br />
| concatenate the values of a hash<br />
|-<br />
| utilities.parsers.make_settings_to_hash_pattern<br />
| returns parser pattern for strict, tolerant, or normal arg-parsing<br />
|-<br />
| utilities.parsers.settings_to_hash_strict<br />
| like settings_to_hash with strict parsing<br />
|-<br />
| utilities.parsers.settings_to_hash_tolerant<br />
| like settings_to_hash with tolerant parsing<br />
|-<br />
| utilities.parsers.splitthousands<br />
| turns 12345678.44 into 12,345,678.44<br />
|-<br />
|}<br />
<br />
=LuaTeX=<br />
<br />
Some very useful functionality is already implemented at the lowest<br />
level.<br />
See the [http://www.luatex.org/svn/trunk/manual/luatexref-t.pdf LuaTeX Reference] for further information.<br />
<br />
==string.explode(string, [character])==<br />
<br />
<pre><br />
str = "Amongst our weaponry are such diverse elements as fear, surprise, ruthless efficiency, and an almost fanatical devotion to the Pope, and nice red uniforms."<br />
<br />
for _, elm in ipairs(string.explode(str, ",")) do<br />
print(elm)<br />
end<br />
</pre><br />
<br />
Returns a list of strings from <tt>string</tt> split at every<br />
occurrence of <tt>character</tt>. Adding <tt>"+"</tt> to <tt>character</tt> ignores consecutive occurrences (not<br />
producing the empty string). (default: <tt>" +"</tt>).<br />
''Note'': <tt>character</tt> should consist of only one-byte else only<br />
the first byte will be respected.<br />
<br />
==string.characters(string) | string.utfcharacters(string)==<br />
<br />
<pre><br />
alphabet = "abcdefghijklmnopqrstuvwxyz"<br />
alphabit = "абвгдежзийклмнопрстуфхцчшщъыьэюя"<br />
<br />
for char in alphabet:characters() do io.write(char .. ",") end<br />
io.write("\n")<br />
for char in alphabit:utfcharacters() do io.write(char .. ",") end<br />
io.write("\n")<br />
</pre><br />
<br />
These iterators can be used to walk over strings character by<br />
character. They are extremely fast in comparison with equivalent<br />
LPEG's. For instance, when hopping once through<br />
[http://az.lib.ru/t/tolstoj_lew_nikolaewich/text_0080.shtml Anna Karenina]<br />
(about 3M of 2-byte utf8 characters) <tt>string.utfcharacters</tt><br />
turned out to be almost twice as fast as an LPEG iterator.<br />
<br />
=Recipes=<br />
<br />
General: [http://lua-users.org/wiki/StringRecipes string section of the Lua wiki].<br />
<br />
You have a useful function for string manipulation and want to share<br />
it? Do go on!<br />
<br />
==Iterator: words (string, chr)==<br />
<br />
<pre><br />
local function words (str, chr)<br />
local C, Cp, P = lpeg.C, lpeg.Cp, lpeg.P<br />
<br />
local chr = chr and P(chr) or P" "<br />
local g = C((1 - chr)^1) * chr^1 * Cp()<br />
local pos = 1<br />
<br />
function iterator()<br />
local word, newpos = g:match(str, pos)<br />
pos = newpos<br />
return word<br />
end<br />
return iterator<br />
end<br />
</pre><br />
<br />
Iterates over substrings delimited by pattern <tt>chr</tt> <br />
(defaults to space, ignores consecutive occurrences).<br />
<br />
Usage:<br />
<br />
<pre><br />
for char in words(text, " ") do<br />
-- pass<br />
end<br />
</pre><br />
<br />
Comparison with similar iterators (Empty loop; <tt>texlua</tt><br />
v.&nbsp;beta-0.62.0-2010082314; <tt>text</tt> is the aforementioned Anna<br />
Karenina, 3MB&nbsp;UTF-8):<br />
<br />
<pre><br />
ipairs(string.explode(text, " +")) : 0.262s<br />
unicode.utf8.gmatch(text,"%w+") : 0.363s<br />
unicode.utf8.gmatch(text,"%S+") : 0.384s<br />
words(text, " ") : 0.448s<br />
</pre><br />
<br />
The results slightly differ depending on the treatment of consecutive spaces.<br />
<tt>words</tt> has the advantage that it allows for arbitrary patterns as<br />
delimiters.<br />
<br />
= String formatter =<br />
<br />
The <code>context()</code> function uses its own formatter, of the form <code>context("something %Z something", object_formatted_by_Z)</code> Below is a table of the available formatting codes.<br />
<br />
{| class="wikitable"<br />
! result type || code || input type<br />
|-<br />
| integer || %...i || number<br />
|-<br />
| integer || %...d || number<br />
|-<br />
| unsigned || %...u || number<br />
|-<br />
| utf character || %...c || number<br />
|-<br />
| hexadecimal || %...x || number<br />
|-<br />
| HEXADECIMAL || %...X || number<br />
|-<br />
| octal || %...o || number<br />
|-<br />
| string || %...s || string, number<br />
|-<br />
| float || %...f || number<br />
|-<br />
| exponential || %...e || number<br />
|-<br />
| exponential || %...E || number<br />
|-<br />
| autofloat || %...g || number<br />
|-<br />
| autofloat || %...G || number<br />
|-<br />
| force tostring || %...S || any<br />
|-<br />
| force tostring || %Q || any<br />
|-<br />
| force tonumber || %N || number (strips leading zeros)<br />
|-<br />
| signed number || %I || number<br />
|-<br />
| rounded number || %r || number<br />
|-<br />
| 0xhexadecimal || %...h || character, number<br />
|-<br />
| 0xHEXADECIMAL || %...H || character, number<br />
|-<br />
| U+hexadecimal || %...u || character, number<br />
|-<br />
| U+HEXADECIMAL || %...U || character, number<br />
|-<br />
| points || %p || number in scaled points (65536sp = 1pt)<br />
|-<br />
| basepoints || %b || number in scaled points<br />
|-<br />
| table concat || %...t || table<br />
|-<br />
| true or false || %l || boolean<br />
|-<br />
| TRUE or FALSE || %L || boolean<br />
|-<br />
| ''number'' spaces || %...w || number<br />
|-<br />
| escaped XML || %!xml! || string<br />
|-<br />
| escaped TeX || %!tex! || string, number<br />
|-<br />
|}<br />
<br />
<br />
[[Category:Lua]]<br />
[[Category:Programming]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=String_manipulation&diff=22425String manipulation2014-03-05T16:25:41Z<p>Rik: Changed incorrect string.striplong to strings.striplong</p>
<hr />
<div>[[Extensions_to_the_Lua_I/O_library|The I/O-Library]] ><br />
<br />
=Overview=<br />
<br />
In comparison with other scripting languages the bare Lua string library<br />
lacks some very useful “features”.<br />
But before a texnician reimplements all the goodies that E knows from Eir<br />
favorite language, E should first have a look at the helper functions that<br />
ConTeXt already provides.<br />
The following section briefly introduces these extensions with regard to <br />
string manipulation.<br />
<br />
The function name and its arguments are given as heading, the content is split<br />
into, first, an example and, second, a short description of what the function<br />
does and its peculiarities if applicable.<br />
The examples are so designed that they should work when copy-pasted into an<br />
empty Lua file and processed with context.<br />
<br />
=l-string.lua=<br />
<br />
==string.esc(string)==<br />
<br />
<pre><br />
print(string.esc([[^([\"\'])(.*)%1$","%2]]))<br />
</pre><br />
<br />
Returns <tt>string</tt> with all occurrences of <br />
<tt>%</tt>,<br />
<tt>.</tt>,<br />
<tt>+</tt>,<br />
<tt>-</tt>,<br />
<tt>*</tt>,<br />
<tt>^</tt>,<br />
<tt>$</tt>,<br />
<tt>[</tt>,<br />
<tt>]</tt>,<br />
<tt>(</tt>,<br />
<tt>)</tt>,<br />
<tt>{</tt>, and<br />
<tt>}</tt><br />
escaped with the percent symbol.<br />
Cf. [[#string.escapedpattern.28string.29_.7C_string.partialescapedpattern.28string.29|string.escapedpattern]].<br />
<br />
==string.unquote(string)==<br />
<br />
<pre><br />
print(string.unquote[["Do you see any quotes around here?"]])<br />
print(string.unquote[['Do you see any quotes around here?']])<br />
print(string.unquote[["Do you see any quotes around here?']]) -- Doesn't match<br />
print(string.unquote[[“Do you see any quotes around here?”]]) -- Doesn't match<br />
</pre><br />
<br />
Returns <tt>string</tt> with surrounding quotes removed iff they are<br />
of the same kind (ascii single/double quote only).<br />
<br />
==string.quote(string)==<br />
<br />
Equivalent to <tt>string.format("%q", string)</tt>.<br />
<br />
==string.count(string, pattern)==<br />
<br />
<pre><br />
print(string.count("How many a's?", "a"))<br />
print(string.count("How many many's?", "many"))<br />
</pre><br />
<br />
Returns the count of matches for <tt>pattern</tt> in <tt>string</tt>.<br />
<br />
==string.limit(string, max, [tail])==<br />
<br />
<pre><br />
s = "This string is too long for our purpose."<br />
print(string.limit(s, 15))<br />
print(string.limit(s, 15, " …")) -- "…" seems to be three bytes long.<br />
</pre><br />
<br />
Returns the string capped at position <tt>max</tt> (minus the byte<br />
count of <tt>tail</tt>) with <tt>tail</tt> appended. The optional <tt>tail</tt><br />
defaults to <tt>"..."</tt>.<br />
<br />
==string.strip(string)==<br />
<br />
<pre><br />
print(string.strip([[ I once used to be surrounded by whitespace. <br />
]]))<br />
</pre><br />
<br />
Yields <tt>string</tt> with leading and trailing whitespace (spaces, horizontal<br />
and vertical tabs, newlines) removed.<br />
<br />
==string.is_empty(string)==<br />
<br />
<pre><br />
print(string.is_empty([[]]))<br />
print(string.is_empty([[notempty]]))<br />
print(string.is_empty(9))<br />
</pre><br />
<br />
Returns <tt>true</tt> if the argument is an empty string and<br />
<tt>false</tt> for nonempty strings and numbers.<br />
(Throws an error with functions, booleans or <tt>nil</tt>.)<br />
<br />
==string.enhance(string, pattern, function)==<br />
<br />
<pre><br />
s = "I'd like to file a complaint."<br />
f = function () <br />
return "have an argument!"<br />
end<br />
io.write(string.enhance(s, "file a complaint.", f))<br />
</pre><br />
<br />
Returns the input string with <tt>function</tt> applied to all matches<br />
for <tt>pattern</tt>. <br />
''Note'': <tt>string.enhance</tt> relies on <tt>gsub</tt> from the lua<br />
string library so unfortunately you can't pass it an LPEG as second<br />
argument.<br />
<br />
==string.characters(string)==<br />
<br />
<pre><br />
n = 0<br />
for chr in string.characters("Some bytes") do<br />
n = n + 1<br />
io.write(string.format("Nr. %2u is %s.\n", n, chr))<br />
end<br />
</pre><br />
<br />
Returns an iterator over the ascii characters in <tt>string</tt>.<br />
''Note'': As this relies on the string library you should expect<br />
unwelcome results (e.g. invalid utf8 sequences) when using it for<br />
anything else than 7-bit ascii.<br />
<br />
Cf.<br />
[[#string.characters(string) .7C string.utfcharacters(string)|string.utfcharacters]]<br />
from LuaTeX.<br />
<br />
==string.bytes(string)==<br />
<br />
<pre><br />
n = 0<br />
for byte in string.bytes("Some bytes") do<br />
n = n + 1<br />
io.write(string.format("Nr. %2u is %3u.\n", n, byte))<br />
end<br />
</pre><br />
<br />
The same as <tt>string.characters</tt> but returns bytes as base 10<br />
integers.<br />
<br />
==string.lpadd(string, n, character) | string.rpadd(string, n, character)==<br />
<br />
<pre><br />
s = "Some string."<br />
print(string.rpadd(s, 15, "r"))<br />
print(string.lpadd(s, 15, "l"))<br />
</pre><br />
<br />
Adds as many times <tt>character</tt> as needed to the left or right<br />
respectively to get a string of length <tt>n</tt> from<br />
<tt>string</tt>. ''Note'': <tt>character</tt> can in fact be a string<br />
of any length which can distort the result.<br />
<br />
==string.escapedpattern(string) | string.partialescapedpattern(string)==<br />
<br />
<pre><br />
print(string.escapedpattern("Some characters like *, + and ] need to be escaped for formatting."))<br />
print(string.partialescapedpattern("Some characters like *, + and ] need to be escaped for formatting."))<br />
</pre><br />
<br />
<tt>string.escapedpattern</tt> escapes all occurences of the characters<br />
<tt>-</tt>,<br />
<tt>.</tt>,<br />
<tt>+</tt>,<br />
<tt>*</tt>,<br />
<tt>%</tt>,<br />
<tt>(</tt>,<br />
<tt>)</tt>,<br />
<tt>[</tt>, and<br />
<tt>]</tt><br />
using percent signs (<tt>%</tt>);<br />
<tt>string.partialescapedpattern</tt> only escapes <br />
<tt>-</tt> and<br />
<tt>.</tt> using percent signs whereas<br />
<tt>?</tt> and<br />
<tt>*</tt> are prefixed with dots (<tt>.</tt>).<br />
The latter is used for pattern building, e.g. in [[source:trac-set.lua|trac-set.lua]].<br />
<br />
<br />
==string.tohash(string)==<br />
<br />
<pre><br />
t = string.tohash("Comma,or space,separated values")<br />
for k,v in pairs(t) do<br />
print(k,v)<br />
end<br />
</pre><br />
<br />
Returns a hashtable with every substring of <tt>string</tt><br />
between spaces and commas as keys and <tt>true</tt> as values.<br />
<br />
==string.totable(string)==<br />
<br />
<pre><br />
t = string.totable("Insert your favorite string here!")<br />
for k,v in pairs(t) do<br />
print(k,v)<br />
end<br />
</pre><br />
<br />
Returns a list of ascii characters that constitute <tt>string</tt>.<br />
''Note'': As this relies on LPEG's character pattern it <br />
'''is guaranteed'''<br />
to turn your multi-byte sequences into garbage!<br />
<br />
==string.tabtospace(string, [tabsize])==<br />
<br />
<pre><br />
local t = {<br />
"1234567123456712345671234567",<br />
"a\tb\tc",<br />
"aa\tbb\tcc",<br />
"aaa\tbbb\tccc",<br />
"aaaa\tbbbb\tcccc",<br />
"aaaaa\tbbbbb\tccccc",<br />
"aaaaaa\tbbbbbb\tcccccc",<br />
}<br />
for k,v in ipairs(t) do<br />
print(string.tabtospace(t[k]))<br />
end<br />
</pre><br />
<br />
(Modified example from [[source:l-string.lua|the context sources]].)<br />
Replaces tabs with spaces depending on position. The optional argument<br />
<tt>tabsize</tt> defaults to <em>7</em>.<br />
<br />
==string.compactlong(string) | strings.striplong(string)==<br />
<br />
<pre><br />
s = [[<br />
This is <br />
a fairly<br />
long<br />
string<br />
with some<br />
rather<br />
silly<br />
indents.]]<br />
<br />
print(string.compactlong(s))<br />
print(strings.striplong(s))<br />
</pre><br />
<br />
<tt>string.compactlong</tt> removes newlines (dos and unix) and<br />
leading spaces from <tt>string</tt>.<br />
<br />
<tt>strings.striplong</tt> removes leading spaces and converts dos<br />
newlines to unix newlines.<br />
<br />
==string.topattern(string, lowercase, strict)==<br />
<br />
<pre><br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", false, false))<br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", true, false))<br />
print(string.topattern("Sudo make Me a Pattern from '*' and '-'!", true, true ))<br />
</pre><br />
<br />
Returns a valid pattern from <tt>string</tt> that can be used with<br />
<tt>string.find</tt> et&nbsp;al.<br />
The return value is essentially the same as with<br />
<tt>string.escapedpattern</tt> plus two options:<br />
the boolean <tt>lowercase</tt> specifies whether the string is to be<br />
lowercased first,<br />
whereas <tt>strict</tt> results in a whole line pattern.<br />
<br />
=l-lpeg.lua=<br />
<br />
==Predefined Patterns==<br />
<br />
Dozens of the most common patterns including<br />
hexadecimal numbers, diverse whitespace and line endings, punctuation,<br />
and even an XML path parser etc. are already predefined.<br />
To get an impression about what they do you can check them with the<br />
followings snippet:<br />
<br />
<pre><br />
function show_patterns (p, super)<br />
for i,j in pairs(p) do<br />
i = super and super..":"..i or i<br />
print(string.rpadd("=== " .. i .. " ", 80, "="))<br />
if type(j) == "userdata" then<br />
j:print()<br />
else -- descend into next level<br />
show_patterns(j, i)<br />
end <br />
end <br />
end<br />
<br />
local p = lpeg.patterns<br />
<br />
show_patterns(p)<br />
</pre><br />
<br />
==lpeg.anywhere(string|pattern)==<br />
<br />
<pre><br />
str = "Fetchez la vache!"<br />
print(lpeg.anywhere("a" ):match(str))<br />
print(lpeg.anywhere("la"):match(str))<br />
print(lpeg.anywhere("ac"):match(str))<br />
</pre><br />
<br />
Returns a pattern that matches the first occurrence of<br />
<tt>string</tt>, returning the position of the last character in the<br />
matched sequence.<br />
Keep in mind that you can pass it patterns as well:<br />
<br />
<pre><br />
print(lpeg.anywhere(lpeg.P"a"*lpeg.patterns.whitespace):match(str))<br />
</pre><br />
<br />
==lpeg.splitter(delimiter, function)==<br />
<br />
<pre><br />
wedge = function (str)<br />
local dict = {<br />
Romanes = "Romani",<br />
evnt = "ite",<br />
domvs = "domvm",<br />
}<br />
return dict[str] or ""<br />
end<br />
<br />
splitme = "Romanes evnt domvs"<br />
print(lpeg.splitter(" ", wedge):match(splitme))<br />
</pre><br />
<br />
Returns a pattern that can be used to apply <tt>function</tt> to all<br />
substrings delimited by <tt>delimiter</tt> which can be a string or a<br />
pattern.<br />
<br />
==string.splitlines(string)==<br />
<br />
<pre><br />
str = [[<br />
Bravely bold Sir Robin rode forth from Camelot.<br />
He was not afraid to die, O brave Sir Robin!<br />
He was not at all afraid to be killed in nasty ways,<br />
Brave, brave, brave, brave Sir Robin!<br />
]]<br />
<br />
for n,line in ipairs(string.splitlines(str)) do<br />
io.write(string.format("%u: %s\n", n, line))<br />
end<br />
</pre><br />
<br />
Splits <tt>string</tt> into a list of lines where empty lines &ndash; i.e.<br />
consecutive <tt>\n</tt>'s &ndash; yield the empty string.<br />
<br />
==lpeg.splitat(delimiter, [single])==<br />
<br />
<pre><br />
str = [[<br />
Number twenty-three. The shin.<br />
Number twenty-four. Reginald Maudling's shin.<br />
Number twenty-five. The brain.<br />
Number twenty-six. Magaret Thatcher's brain.<br />
Number twenty-seven. More naughty bits.<br />
]]<br />
<br />
t = {lpeg.splitat("Number", false):match(str)}<br />
for n,element in pairs(t) do <br />
element = element == "" and element .. "\n" or element<br />
io.write(n..": "..element) <br />
end<br />
</pre><br />
<br />
Returns a pattern that produces a list of substrings delimited by<br />
<tt>delimiter</tt> (which can be a pattern or a string).<br />
The optional boolean <tt>single</tt> determines whether the string<br />
should be split only at the first match.<br />
<br />
==string.split(string, separator) | string.checkedsplit(string, separator)==<br />
<br />
<pre><br />
theory = [[All brontosauruses are thin at one end, much much thicker in the middle, and then thin again at the far end.]]<br />
<br />
theorems = string.split(theory, lpeg.P", " * lpeg.P"and "^-1) <br />
<br />
for n, element in ipairs(theorems) do<br />
io.write (string.format("Theorem %u: %s\n", n, element))<br />
end<br />
</pre><br />
<br />
<tt>string.split</tt> returns, as you would expect, a list of<br />
substrings of <tt>string</tt> delimited by <tt>separator</tt>.<br />
Consecutive separators result in the empty string;<br />
its counterpart <tt>string.checkedsplit</tt> does not match these <br />
sequences, returning <tt>nil</tt> instead.<br />
<br />
''Note'': The corresponding pattern generators are <tt>lpeg.split</tt><br />
and <tt>lpeg.checkedsplit</tt>.<br />
<br />
==lpeg.stripper(string|pattern) | lpeg.keeper(string|pattern)==<br />
<br />
<pre><br />
str = "A dromedary has one hump and a camel has a refreshment car, buffet, and ticket collector."<br />
print(lpeg.stripper("aeiou") :match(str))<br />
print(lpeg.stripper(lpeg.P"camel "):match(str))<br />
</pre><br />
<br />
<tt>lpeg.stripper</tt> returns a pattern that removes either, if the<br />
argument is a string, all occurrences of every character of that<br />
string or, if the argument is a pattern, all occurrences of that pattern.<br />
Its complement, <tt>lpeg.keeper</tt>, removes anything but the string<br />
or pattern respectively.<br />
''Note'': <tt>string.keeper</tt> does not seem to work as expected with<br />
patterns consisting of more than one byte, e.g. <tt>lpeg.P("camel")</tt>.<br />
<br />
==lpeg.replacer(table)==<br />
<br />
<pre><br />
str = "Luxury Yacht"<br />
<br />
rep = {<br />
[1] = { "Luxury", "Throatwobbler" },<br />
[2] = { "Yacht", "Mangrove" },<br />
}<br />
<br />
print("My name is spelled “" .. str .. "”, but it's pronounced “" .. lpeg.replacer(rep):match(str) .. "”.")<br />
</pre><br />
<br />
Accepts a list of pairs and returns a pattern that substitutes any<br />
first elements of a given pair by its second element.<br />
The latter can be a string, a hashtable, or a function (whatever fits<br />
with <tt>lpeg.Cs</tt>).<br />
<br />
''Note'': Choose the order of elements in <tt>table</tt> with care.<br />
Due to LPEG's matching the leftmost element of disjunction first<br />
it might turn out to be as crucial as in the following example:<br />
<br />
<pre><br />
str = "aaababaaba"<br />
rep1 = {<br />
{ "a", "x" },<br />
{ "aa", "y" },<br />
}<br />
<br />
rep2 = {<br />
{ "aa", "y" },<br />
{ "a", "x" },<br />
}<br />
<br />
print(lpeg.replacer(rep1):match(str))<br />
print(lpeg.replacer(rep2):match(str))<br />
</pre><br />
<br />
==lpeg.firstofsplit(separator) | lpeg.secondofsplit(separator)==<br />
<br />
<pre><br />
str = "menu = spam, spam, spam, spam, spam, baked beans, spam, spam and spam"<br />
print(lpeg.firstofsplit (" = "):match(str))<br />
print(lpeg.secondofsplit(" = "):match(str))<br />
</pre><br />
<br />
<tt>lpeg.firstofsplit</tt> returns a pattern that matches the<br />
substring until the first occurrence of <tt>separator</tt>, its<br />
complement generated by <tt>lpeg.secondofsplit</tt> matches the whole<br />
rest after that regardless of any further occurrences of <tt>separator</tt>.<br />
<br />
= util-prs.lua = <br />
<br />
== utilities.parsers.settings_to_hash(str) ==<br />
<br />
<pre><br />
str = 'a=1, b=2, c=3'<br />
utilities.parsers.settings_to_hash(str)<br />
--> { a = 1, b = 2, c = 3 }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated key=value statements, and returns an associative array of {{code|1=["key"] = value}} entries. Very useful for parsing and accessing macro arguments at the Lua end.<br />
<br />
== utilities.parsers.settings_to_array(str) ==<br />
<br />
<pre><br />
str = 'top, inmargin=2, top, {here,now}'<br />
utilities.parsers.settings_to_array(str)<br />
--> { "top", "inmargin=2", "top", "here,now" }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear. Duplicates are not filtered. <tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed<br />
<br />
== utilities.parsers.settings_to_set(str) ==<br />
<br />
<pre><br />
str = 'top, inmargin=2, top, {here,now}'<br />
utilities.parsers.settings_to_set(str)<br />
--> { ["top"]=true, ["inmargin=2"]=true, ["here,now"]=true }<br />
</pre><br />
<br />
{{code|utilities.parsers.settings_to_array}} takes a string of comma-separated keywords, and returns a array of those keywords in the order in which they appear, with duplicates removed.<br />
<tt>Key=value</tt> strings are taken as a single keyword. Surrounding braces are removed<br />
<br />
== Other function in utilities.parsers ==<br />
{| class="wikitable"<br />
|-<br />
| utilities.parsers.add_settings_to_array<br />
| parse and write directly into table<br />
|-<br />
| utilities.parsers.arguments_to_table<br />
| parse arguments, return table<br />
|-<br />
| utilities.parsers.array_to_string(a,sep)<br />
| concatenates a with custom sep or comma<br />
|-<br />
| utilities.parsers.getparameters<br />
| write settings_to_hash to an array with a metatable. A metatable is a sort of parent: when a table is accessed, undefined values will be looked up in the metatable.<br />
|-<br />
| utilities.parsers.hash_to_string<br />
| turn a hash into a string, with optional strictness settings<br />
|-<br />
| utilities.parsers.simple_hash_to_string<br />
| concatenate the values of a hash<br />
|-<br />
| utilities.parsers.make_settings_to_hash_pattern<br />
| returns parser pattern for strict, tolerant, or normal arg-parsing<br />
|-<br />
| utilities.parsers.settings_to_hash_strict<br />
| like settings_to_hash with strict parsing<br />
|-<br />
| utilities.parsers.settings_to_hash_tolerant<br />
| like settings_to_hash with tolerant parsing<br />
|-<br />
| utilities.parsers.splitthousands<br />
| turns 12345678.44 into 12,345,678.44<br />
|-<br />
|}<br />
<br />
=LuaTeX=<br />
<br />
Some very useful functionality is already implemented at the lowest<br />
level.<br />
See the [http://www.luatex.org/svn/trunk/manual/luatexref-t.pdf LuaTeX Reference] for further information.<br />
<br />
==string.explode(string, [character])==<br />
<br />
<pre><br />
str = "Amongst our weaponry are such diverse elements as fear, surprise, ruthless efficiency, and an almost fanatical devotion to the Pope, and nice red uniforms."<br />
<br />
for _, elm in ipairs(string.explode(str, ",")) do<br />
print(elm)<br />
end<br />
</pre><br />
<br />
Returns a list of strings from <tt>string</tt> split at every<br />
occurrence of <tt>character</tt>. Adding <tt>"+"</tt> to <tt>character</tt> ignores consecutive occurrences (not<br />
producing the empty string). (default: <tt>" +"</tt>).<br />
''Note'': <tt>character</tt> should consist of only one-byte else only<br />
the first byte will be respected.<br />
<br />
==string.characters(string) | string.utfcharacters(string)==<br />
<br />
<pre><br />
alphabet = "abcdefghijklmnopqrstuvwxyz"<br />
alphabit = "абвгдежзийклмнопрстуфхцчшщъыьэюя"<br />
<br />
for char in alphabet:characters() do io.write(char .. ",") end<br />
io.write("\n")<br />
for char in alphabit:utfcharacters() do io.write(char .. ",") end<br />
io.write("\n")<br />
</pre><br />
<br />
These iterators can be used to walk over strings character by<br />
character. They are extremely fast in comparison with equivalent<br />
LPEG's. For instance, when hopping once through<br />
[http://az.lib.ru/t/tolstoj_lew_nikolaewich/text_0080.shtml Anna Karenina]<br />
(about 3M of 2-byte utf8 characters) <tt>string.utfcharacters</tt><br />
turned out to be almost twice as fast as an LPEG iterator.<br />
<br />
=Recipes=<br />
<br />
General: [http://lua-users.org/wiki/StringRecipes string section of the Lua wiki].<br />
<br />
You have a useful function for string manipulation and want to share<br />
it? Do go on!<br />
<br />
==Iterator: words (string, chr)==<br />
<br />
<pre><br />
local function words (str, chr)<br />
local C, Cp, P = lpeg.C, lpeg.Cp, lpeg.P<br />
<br />
local chr = chr and P(chr) or P" "<br />
local g = C((1 - chr)^1) * chr^1 * Cp()<br />
local pos = 1<br />
<br />
function iterator()<br />
local word, newpos = g:match(str, pos)<br />
pos = newpos<br />
return word<br />
end<br />
return iterator<br />
end<br />
</pre><br />
<br />
Iterates over substrings delimited by pattern <tt>chr</tt> <br />
(defaults to space, ignores consecutive occurrences).<br />
<br />
Usage:<br />
<br />
<pre><br />
for char in words(text, " ") do<br />
-- pass<br />
end<br />
</pre><br />
<br />
Comparison with similar iterators (Empty loop; <tt>texlua</tt><br />
v.&nbsp;beta-0.62.0-2010082314; <tt>text</tt> is the aforementioned Anna<br />
Karenina, 3MB&nbsp;UTF-8):<br />
<br />
<pre><br />
ipairs(string.explode(text, " +")) : 0.262s<br />
unicode.utf8.gmatch(text,"%w+") : 0.363s<br />
unicode.utf8.gmatch(text,"%S+") : 0.384s<br />
words(text, " ") : 0.448s<br />
</pre><br />
<br />
The results slightly differ depending on the treatment of consecutive spaces.<br />
<tt>words</tt> has the advantage that it allows for arbitrary patterns as<br />
delimiters.<br />
<br />
= String formatter =<br />
<br />
The <code>context()</code> function uses its own formatter, of the form <code>context("something %Z something", object_formatted_by_Z)</code> Below is a table of the available formatting codes.<br />
<br />
{| class="wikitable"<br />
! result type || code || input type<br />
|-<br />
| integer || %...i || number<br />
|-<br />
| integer || %...d || number<br />
|-<br />
| unsigned || %...u || number<br />
|-<br />
| utf character || %...c || number<br />
|-<br />
| hexadecimal || %...x || number<br />
|-<br />
| HEXADECIMAL || %...X || number<br />
|-<br />
| octal || %...o || number<br />
|-<br />
| string || %...s || string, number<br />
|-<br />
| float || %...f || number<br />
|-<br />
| exponential || %...e || number<br />
|-<br />
| exponential || %...E || number<br />
|-<br />
| autofloat || %...g || number<br />
|-<br />
| autofloat || %...G || number<br />
|-<br />
| force tostring || %...S || any<br />
|-<br />
| force tostring || %Q || any<br />
|-<br />
| force tonumber || %N || number (strips leading zeros)<br />
|-<br />
| signed number || %I || number<br />
|-<br />
| rounded number || %r || number<br />
|-<br />
| 0xhexadecimal || %...h || character, number<br />
|-<br />
| 0xHEXADECIMAL || %...H || character, number<br />
|-<br />
| U+hexadecimal || %...u || character, number<br />
|-<br />
| U+HEXADECIMAL || %...U || character, number<br />
|-<br />
| points || %p || number in scaled points (65536sp = 1pt)<br />
|-<br />
| basepoints || %b || number in scaled points<br />
|-<br />
| table concat || %...t || table<br />
|-<br />
| true or false || %l || boolean<br />
|-<br />
| TRUE or FALSE || %L || boolean<br />
|-<br />
| ''number'' spaces || %...w || number<br />
|-<br />
| escaped XML || %!xml! || string<br />
|-<br />
| escaped TeX || %!tex! || string, number<br />
|-<br />
|}<br />
<br />
<br />
[[Category:Lua]]<br />
[[Category:Programming]]</div>Rikhttps://wiki.contextgarden.net/index.php?title=Command/defineparagraphs&diff=22424Command/defineparagraphs2014-03-01T22:16:21Z<p>Rik: Update command names for postponenotes and flushnotes</p>
<hr />
<div>{{Reference<br />
|name=defineparagraphs<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\defineparagraphs<span class="first" >[...]</span><span class="second" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>name </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:n|n]]</td><br />
<td>[[Command/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:rule|rule]]</td><br />
<td>[[Command/value:on|on]] [[Command/value:off|off]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:height|height]]</td><br />
<td>[[Command/value:fit|fit]] [[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:before|before]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:after|after]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:inner|inner]]</td><br />
<td>[[Command/value:command|command]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:tolerance|tolerance]]</td><br />
<td>[[Command/value:verystrict|verystrict]] [[Command/value:strict|strict]] [[Command/value:tolerant|tolerant]] [[Command/value:verytolerant|verytolerant]] [[Command/value:stretch|stretch]] </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:flushleft|flushleft]] [[Command/value:flushright|flushright]] [[Command/value:middle|middle]] </td><br />
</tr><br />
</table><br />
<br />
== Description == <br />
<br />
== Examples ==<br />
<br />
<context source="yes" text="yields"><br />
\setuppapersize[A5]<br />
% Source: ConText Manual ms-cb-en.pdf<br />
<br />
% Define a paragraph environment with 3 columns. <br />
% Insert a blank line just before and just after the environment. <br />
\defineparagraphs <br />
[mypar][n=3,before={\blank},after={\blank}] <br />
<br />
% The first column occupies 10% of the text's width and is rendered bold. <br />
\setupparagraphs [mypar][1][width=.1\textwidth,style=bold] <br />
<br />
% The second column occupies 40% of the text's width. <br />
\setupparagraphs [mypar][2][width=.4\textwidth]<br />
<br />
% The third column uses default settings. It will occupy <br />
% the remaining 50% of the text's width.<br />
<br />
\startmypar % begin the side-by-side paragraphs; start with the first one<br />
1252 <br />
\mypar % switch to 2nd column<br />
Hasselt obtains its city charter from bishop Hendrik van Vianden. <br />
\mypar % switch to 3rd column<br />
Hendrik van Vianden was pressed by other towns not to agree <br />
with the charter. It took Hasselt a long period of time to <br />
convince the Bishop. After supporting the Bishop in a small <br />
war against the Drents, the charter was released. <br />
\stopmypar % end paragraph body <br />
</context><br />
<br />
Footnotes need special treatment, as follows.<br />
<br />
<context source="yes" text="This gives:"><br />
\setuppapersize[A10,landscape]<br />
% when using footnotes, you have to use the following trick<br />
% (from Hans on mailinglist, Date: Tue, 15 Jun 2004 00:53:48 +0200)<br />
% but the names have changed since then from postponefootnotes<br />
% to postponenotes and flushfootnotes to flushnotes<br />
<br />
\defineparagraphs[Par][n=3]<br />
\starttext<br />
\startPar<br />
Text <br />
\Par <br />
and\postponenotes\footnote{A footnote whose placement is postponed...}<br />
\Par <br />
text <br />
\stopPar<br />
\flushnotes<br />
\stoptext<br />
</context><br />
<br />
== See also ==<br />
* {{cmd|setupparagraphs}} to setup the individual paragraphs/columns.<br />
* {{cmd|startparagraph}} to start a paragraphs environment.<br />
* {{cmd|paragraph}} to switch to the next paragraph.<br />
* {{cmd|starttable}} and {{cmd|starttabulate}} to create more traditional tables,<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
{{Columns navbox}}<br />
<br />
[[Category:Command/Paragraphs|defineparagraphs]]<br />
[[Category:Command/Tables|defineparagraphs]]<br />
[[Category:Command/Columns|defineparagraphs]]</div>Rik