Difference between revisions of "Command/defineconversion"

From Wiki
Jump to navigation Jump to search
(new with template, WIP)
 
(More information and example)
 
Line 39: Line 39:
 
   </cd:command>
 
   </cd:command>
 
</cd:variants>
 
</cd:variants>
<cd:description>Predefined conversions:
+
<cd:description>Predefined conversions (selection):
</cd:description>
+
 
<cd:examples><cd:example title="Define new conversion set"><context source="yes" mode="mkiv">
+
{| class=wikitable
 +
|-
 +
| <code>a</code>  || {{cmd|characters}}
 +
|-
 +
| <code>A</code>  || {{cmd|Characters}}
 +
|-
 +
| <code>AK</code> || {{cmd|cap}}{{cmd|characters}}
 +
|-
 +
| <code>KA</code> || {{cmd|cap}}{{cmd|characters}}
 +
|-
 +
| <code>n</code>  || {{cmd|numbers}}
 +
|-
 +
| <code>N</code>  || {{cmd|Numbers}}
 +
|-
 +
| <code>m</code>  || {{cmd|mediaeval}}
 +
|-
 +
| <code>i</code>  || {{cmd|romannumerals}}
 +
|-
 +
| <code>I</code>  || {{cmd|Romannumerals}}
 +
|-
 +
| <code>r</code>  || {{cmd|romannumerals}}
 +
|-
 +
| <code>R</code>  || {{cmd|Romannumerals}}
 +
|-
 +
| <code>KR</code> || {{cmd|cap}}{{cmd|romannumerals}}
 +
|-
 +
| <code>RK</code> || {{cmd|cap}}{{cmd|romannumerals}}
 +
|-
 +
| <code>g</code>  || {{cmd|greeknumerals}}
 +
|-
 +
| <code>G</code>  || {{cmd|Greeknumerals}}
 +
|-
 +
| <code>o</code>  || {{cmd|oldstylenumerals}}
 +
|-
 +
| <code>O</code>  || {{cmd|oldstylenumerals}}
 +
|-
 +
| <code>or</code> || {{cmd|oldstyleromannumerals}}
 +
|-
 +
|}
 +
 
 +
or
 +
 
 +
{| class=wikitable
 +
|  || default || depends, mostly “Arabic” numbers
 +
|-
 +
| n, N || numbers || “Arabic” numbers (difference?)
 +
|-
 +
|  || zero || “Arabic” numbers, starting with 0
 +
|-
 +
| o ||  || Mediaeval numbers (oldstyle, {{cmd|os}})
 +
|-
 +
| a, A || alphabetic || Latin characters (lower/upper)
 +
|-
 +
| AK = KA ||  || Latin small caps
 +
|-
 +
|  || sloveniannumerals, slovenianNumerals || Slovenian characters (Latin with č, lower/upper)
 +
|-
 +
|  || spanishnumerals, spanishNumerals || Spanish characters (Latin with ñ, lower/upper)
 +
|-
 +
|  || russiannumerals, russianNumerals || Russian characters (Cyrillic lower/upper)
 +
|-
 +
| i = r, I = R || romannumerals || Roman numbers (lower/upper)
 +
|-
 +
| RK = KR ||  || Roman numbers in small caps
 +
|-
 +
| or ||  || Roman numbers with continuous lines
 +
|-
 +
| g, G || greeknumerals || Greek characters (lower/upper)
 +
|-
 +
|  || mathgreek || Greek lowercase characters from the math font
 +
|-
 +
|  || hebrewnumerals, yiddishnumerals || Hebrew/Yiddish numbers
 +
|-
 +
|  || month, month:mnem || Month names (full/abbreviated)
 +
|-
 +
|  || set 0 || Symbol set for itemizations
 +
|-
 +
|  || set 1 ... set 3 || Symbol sets for footnotes
 +
|-
 +
|  || empty, none ||
 +
|-
 +
|  || continued || always “(continued)”
 +
|-
 +
|  || words, Words || Numbers as words (lower/upper), so far only English
 +
|-
 +
|}
 +
 
 +
There are many more options, e.g. for Arabic, CJK and other languages/scripts; all the character conversions are language dependent.</cd:description>
 +
<cd:examples><cd:example title="Define new conversion set"><context mode="mkiv" source="yes">
 
\defineconversion[inventory][<3,!,\math{\therefore},?]
 
\defineconversion[inventory][<3,!,\math{\therefore},?]
  
 
Four are the things I'd been better without:
 
Four are the things I'd been better without:
 
\startitemize[inventory, packed][stopper=, width=2em]
 
\startitemize[inventory, packed][stopper=, width=2em]
     \item Love,  
+
     \item Love,
 
     \item curiosity,
 
     \item curiosity,
 
     \item freckles,
 
     \item freckles,
Line 53: Line 141:
 
\leftaligned{---Dorothy Parker, \quote{Inventory} (fragment)}
 
\leftaligned{---Dorothy Parker, \quote{Inventory} (fragment)}
 
</context>
 
</context>
</cd:example><cd:example title="Conversion set of stars"><context source="yes" mode="mkiv">
+
</cd:example><cd:example title="Change numbering in itemize to '(i)', '(ii)', ..."><context source="yes">
 +
\defineconversion[bracketroman][(\romannumerals]
 +
 
 +
Three be the things I shall never attain:
 +
\startitemize[bracketroman, packed][stopper=), width=2em]
 +
    \item Envy,
 +
    \item content, and
 +
    \item sufficient champagne.
 +
\stopitemize
 +
\leftaligned{---Dorothy Parker, \quote{Inventory} (fragment)}
 +
</context>
 +
</cd:example><cd:example title="Conversion set of stars"><context mode="mkiv" source="yes">
 
\defineconversion[starred][\m{*},\m{**},\m{***}] % Math mode gives better spacing, thus \m{...}
 
\defineconversion[starred][\m{*},\m{**},\m{***}] % Math mode gives better spacing, thus \m{...}
  
 
\startitemize[starred,packed][stopper=,width=2.5em]
 
\startitemize[starred,packed][stopper=,width=2.5em]
     \item First,  
+
     \item First,
 
     \item second,
 
     \item second,
 
     \item third.
 
     \item third.
 
\stopitemize
 
\stopitemize
</context></cd:example></cd:examples>
+
</context></cd:example><cd:example title="Conversion for numbers with leading zeros"><context source="yes">
 +
\startluacode
 +
interfaces.implement {
 +
    name      = "FourDigits",
 +
    public    = true,
 +
    arguments = "string",
 +
    actions  = function(s) context("%04d",tonumber(s)) end
 +
}
 +
\stopluacode
 +
 
 +
\defineconversion [FourDigits] [\FourDigits]
 +
 
 +
\setuphead[chapter][conversion=FourDigits]
 +
 
 +
\startchapter [title={Chapter}] \stopchapter
 +
</context>
 +
 
 +
(By Wolfgang Schuster, 2023-01-01)</cd:example></cd:examples>
 
<cd:notes></cd:notes>
 
<cd:notes></cd:notes>
 
<cd:seealso>
 
<cd:seealso>
Line 69: Line 185:
 
<cd:commandref name="convertnumber"></cd:commandref>
 
<cd:commandref name="convertnumber"></cd:commandref>
 
<cd:commandref name="setupitemize"></cd:commandref>
 
<cd:commandref name="setupitemize"></cd:commandref>
<cd:commandref name="startitemize"></cd:commandref></cd:seealso>
+
<cd:commandref name="startitemize"></cd:commandref>
 +
<cd:commandref name="setuphead"></cd:commandref></cd:seealso>
 
</cd:commandgroup>
 
</cd:commandgroup>

Latest revision as of 12:38, 1 January 2023


\defineconversion

Summary

The command \defineconversion is used to define a representation of numbers for numbered elements like itemizations and headers.


Settings

\defineconversion[...][...][...]
[...]language
[...]name
[...]csname

Settings list

\defineconversion[...][...][...,...]
[...]language
[...]name
[...,...]text

Description

Predefined conversions (selection):
a \characters
A \Characters
AK \cap\characters
KA \cap\characters
n \numbers
N \Numbers
m \mediaeval
i \romannumerals
I \Romannumerals
r \romannumerals
R \Romannumerals
KR \cap\romannumerals
RK \cap\romannumerals
g \greeknumerals
G \Greeknumerals
o \oldstylenumerals
O \oldstylenumerals
or \oldstyleromannumerals

or

default depends, mostly “Arabic” numbers
n, N numbers “Arabic” numbers (difference?)
zero “Arabic” numbers, starting with 0
o Mediaeval numbers (oldstyle, \os)
a, A alphabetic Latin characters (lower/upper)
AK = KA Latin small caps
sloveniannumerals, slovenianNumerals Slovenian characters (Latin with č, lower/upper)
spanishnumerals, spanishNumerals Spanish characters (Latin with ñ, lower/upper)
russiannumerals, russianNumerals Russian characters (Cyrillic lower/upper)
i = r, I = R romannumerals Roman numbers (lower/upper)
RK = KR Roman numbers in small caps
or Roman numbers with continuous lines
g, G greeknumerals Greek characters (lower/upper)
mathgreek Greek lowercase characters from the math font
hebrewnumerals, yiddishnumerals Hebrew/Yiddish numbers
month, month:mnem Month names (full/abbreviated)
set 0 Symbol set for itemizations
set 1 ... set 3 Symbol sets for footnotes
empty, none
continued always “(continued)”
words, Words Numbers as words (lower/upper), so far only English

There are many more options, e.g. for Arabic, CJK and other languages/scripts; all the character conversions are language dependent.

Examples

Define new conversion set

\defineconversion[inventory][<3,!,\math{\therefore},?]

Four are the things I'd been better without:
\startitemize[inventory, packed][stopper=, width=2em]
    \item Love,
    \item curiosity,
    \item freckles,
    \item and doubt.
\stopitemize
\leftaligned{---Dorothy Parker, \quote{Inventory} (fragment)}

Change numbering in itemize to '(i)', '(ii)', ...

\defineconversion[bracketroman][(\romannumerals]

Three be the things I shall never attain:
\startitemize[bracketroman, packed][stopper=), width=2em]
    \item Envy,
    \item content, and
    \item sufficient champagne.
\stopitemize
\leftaligned{---Dorothy Parker, \quote{Inventory} (fragment)}

Conversion set of stars

\defineconversion[starred][\m{*},\m{**},\m{***}] % Math mode gives better spacing, thus \m{...}

\startitemize[starred,packed][stopper=,width=2.5em]
    \item First,
    \item second,
    \item third.
\stopitemize

Conversion for numbers with leading zeros

\startluacode
interfaces.implement {
    name      = "FourDigits",
    public    = true,
    arguments = "string",
    actions   = function(s) context("%04d",tonumber(s)) end
}
\stopluacode

\defineconversion [FourDigits] [\FourDigits]

\setuphead[chapter][conversion=FourDigits]

\startchapter [title={Chapter}] \stopchapter

(By Wolfgang Schuster, 2023-01-01)

Notes

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: