Quotation in ConTeXt

This time I read the guide on ConTeXt Wiki and learned some basic commands doing quotation.
Not very much today in fact.
1.single quotes (‘):

\quote{some text}

2.double quotes (“):

\quotation{some text}

3.long quote sections:
For single quote:

\startquote ... \stopquote

For double quotes:

\startquotation ... \stopquotation

4.Nested quotations:
Add following lines first:

\setupdelimitedtext
  [quotation]
  [1]
  [left={\symbol[leftquotation]},
   right={\symbol[rightquotation]}]
 
\setupdelimitedtext
  [quotation]
  [2]
  [left={\symbol[leftquote]},
   right={\symbol[rightquote]}]
 
\setupdelimitedtext
  [quotation]
  [3]
  [left={\symbol[leftquotation]},
   right={\symbol[rightquotation]}]

Then try with:

\starttext
Testing, \quotation{A long quotation in which one character says,
\quotation{Eh? What am I supposed to say? Something like, \quotation
{Quotations in this sentence are nested}?}} testing, 1, 2, 3.
\stoptext

Font fallback in ConTeXt Mininals

Indubitably, I need to remix Chinese and English in one document. But English characters in Chinese fonts aren’t look good in most time as others, so font fallback is needed here.
First, make a English font as a fallback of Chinese font:

\definefontsynonym[song][name:adobesongstd]
\definefontfallback[hereos][name:texgyreherosregular][0x0000-0x0400]
\definefontsynonym[fbsong][song][fallbacks=hereos]
 
\definefont[newsong][fbsong]
\setscript[hanzi]
 
\starttext
\newsong 夹杂 English 的中文文本
\stoptext

This means we use texgyreherosregular as the fallback English font and name it as hereos, 0x0000-0x0400 is the interval of English characters in UTF-8 encoding. Then make “fbsong” the new font that is the remix of song (adobesongstd) and fallback hereos (texgyreherosregular).
But on the tutorial I am following, the author said such action will lose some feature when ConTeXt processing English, so change to using a Chinese font as a fallback of English font:

\definefontsynonym[hereos][name:texgyreherosregular]
\definefontfallback[song][name:adobesongstd][0x00400-0x2FA1F]
\definefontsynonym[fbsong][hereos][fallbacks=song]
\definefont[newsong][fbsong]
\setscript[hanzi]
 
\starttext
\newsong 夹杂~English~的中文文本
\stoptext

Then I’ve rewritten my type-myfonts.tex with fallback font:

\starttypescript[serif][fbfont]
 
\definefontsynonym[enserif][name:dejavuserif]
\definefontsynonym[enserifbd][name:dejavuserifbold]
\definefontsynonym[enserifit][name:dejavuserifitalic]
\definefontsynonym[enserifbi][name:dejavuserifbolditalic]
 
\definefontfallback[umingcn][name:arplumingcn][0x00400-0x2FA1F]
 
\definefontsynonym[Serif][enserif][fallbacks=umingcn]
\definefontsynonym[SerifBold][enserifbd][fallbacks=umingcn]
\definefontsynonym[SerifItalic][enserifit][fallbacks=umingcn]
\definefontsynonym[SerifBoldItalic][enserifbi][fallbacks=umingcn]
 
\stoptypescript
 
\starttypescript [sans][fbfont]
 
\definefontsynonym[ensans][name:dejavusans]
\definefontsynonym[ensansbd][name:dejavusansbold]
\definefontsynonym[ensansob][name:dejavusansoblique]
\definefontsynonym[ensansbo][name:dejavusansboldoblique]
 
\definefontfallback[ukaicn][name:arplukaicn][0x00400-0x2FA1F]
 
\definefontsynonym[Sans][ensans][fallbacks=ukaicn]
\definefontsynonym[SansBold][ensansbd][fallbacks=ukaicn]
\definefontsynonym[SansOblique][ensansob][fallbacks=ukaicn]
 
\definefontsynonym[SansBoldOblique][ensansbo][fallbacks=ukaicn]
 
\stoptypescript
 
\starttypescript [mono][fbfont]
 
\definefontsynonym[enmono][name:dejavusansmono]
\definefontsynonym[enmonobd][name:dejavusansmonobold]
\definefontsynonym[enmonoob][name:dejavusansmonooblique]
\definefontsynonym[enmonobo][name:dejavusansmonoboldoblique]
 
\definefontfallback[microhei][name:wenquanyimicroheimono][0x00400-0x2FA1F]
 
\definefontsynonym[Mono][enmono][fallbacks=microhei]
\definefontsynonym[MonoBold][enmonobd][fallbacks=microhei]
\definefontsynonym[MonoOblique][enmonoob][fallbacks=microhei]
 
\definefontsynonym[MonoBoldOblique][enmonobo][fallbacks=microhei]
 
\stoptypescript
 
\starttypescript[myfonts]
\definetypeface[myfonts][rm][serif][fbfont]
\definetypeface[myfonts][ss][sans][fbfont]
\definetypeface[myfonts][tt][mono][fbfont]
\stoptypescript

And here is an example:

\usetypescriptfile[type-myfonts]
\usetypescript[myfonts]
\setupbodyfont[myfonts,rm,12pt]
\setupbodyfontenvironment [default] [em=italic] % slanted is default emphasize in ConTeXt
\setscript[hanzi]
 
\pdfoptionpdfminorversion=6
\pdfcompresslevel=9
 
\starttext
 
\startcomment
this is a test comment, you shouldn't see me.
\stopcomment
 
我们在运行 \CONTEXT{}
 
\rm 这是 fbfont 里的 serif,dejavuserif+arplumingcn \\
\ss 这是 fbfont 里的 sans,dejavusans+arplukaicn \\
\tt 这是 fbfont 里的 mono,dejavusansmono+wenquanyimicroheimono \\
 
\stoptext

“setupbodyfontenvironment” is a command that tell ConTeXt our body’s font environment, here we change nothing but emphasis to italic instead of default slanted face.
“%” is used to take comments and the TeX engine won’t do anything with items after it to the line’s ending. Multi-lines comments can be achieved by using “\startcomment … \stopcomment”.
“\pdfoptionpdfminorversion” is the setting for pdf option in minor version, and we can have a table to list it:
* (1993) – PDF 1.0 / Acrobat 1.0
* (1994) – PDF 1.1 / Acrobat 2.0
* (1996) – PDF 1.2 / Acrobat 3.0
* (1999) – PDF 1.3 / Acrobat 4.0
* (2001) – PDF 1.4 / Acrobat 5.0
* (2003) – PDF 1.5 / Acrobat 6.0
* (2005) – PDF 1.6 / Acrobat 7.0
* (2006) – PDF 1.7 / Acrobat 8.0
* (2008) – PDF 1.7, Adobe Extension Level 3 / Acrobat 9.0
The value of “pdfoptionpdfminorversion” is that x in “1.x”, in this example, “\pdfoptionpdfminorversion=6”, we set the version to PDF 1.6, correspond to Acrobat 7.0. The default setting is version 5 – PDF 1.5 for Acrobat 6.0.
“pdfcompresslevel” is the compress level of output pdf file, 0 is the least and 9 highest. Default setting is 0.
“\CONTEXT” is a sequence to produce the effect of sinking e in TEX. Other interesting are “\LATEX” “\TEX”, also “\LaTeX” and “\TeX” is acceptable, but I didn’t find how to produce a LaTeX2e, not “\LaTeXe” in LaTeX.
The {} after “\CONTEXT{}” tell the TeX engine don’t eat all extra whitespace and empty lines.
“\\” means force line breaking, we cannot use “\newline” as LaTeX does.

Font model in ConTeXt – quick view from a starter

There are three basic fonts in Chinese, Song, Hei and Fangsong, corresponding to Serif, Sans and Monospace in Latin characters. Another category is numbers, it is recognized as a separate category by ConTeXt.
Using Adobe’s three fonts as a example, we can define type-myfonts.tex, a typescript file:

\starttypescript[serif][zhfont]
    \definefontsynonym[Serif][name:adobesongstd]
    \definefontsynonym[SerifBold][name:adobesongstd]
    \definefontsynonym[SerifItalic][name:adobesongstd]
    \definefontsynonym[SerifBoldItalic][name:adobesongstd]
\stoptypescript
 
\starttypescript [sans][zhfont]
    \definefontsynonym[Sans][name:adobeheitistd]
    \definefontsynonym[SansBold][name:adobeheitistd]
    \definefontsynonym[SansItalic][name:adobeheitistd]
    \definefontsynonym[SansBoldItalic][name:adobeheitistd]
\stoptypescript
 
\starttypescript [mono][zhfont]
    \definefontsynonym[Mono][name:adobefangsongstd]
    \definefontsynonym[MonoBold][name:adobefangsongstd]
    \definefontsynonym[MonoItalic][name:adobefangsongstd]
    \definefontsynonym[MonoBoldItalic][name:adobefangsongstd]
\stoptypescript
 
\starttypescript[myfonts]
    \definetypeface[myfonts][rm][serif][zhfont]
    \definetypeface[myfonts][ss][sans][zhfont]
    \definetypeface[myfonts][tt][mono][zhfont]
\stoptypescript

Explanation by line:
“\starttypescript[serif][zhfont]” means starting a typescript profile, named “serif” and classify it in “zhfont”;
“\definefontsynonym[Serif][name:adobesongstd]” means start a font synonym definition, and assign “Serif” to “adobesongstd”;
“\stoptypescript” means finishing a profile.
We need to pay some attention at the last profile, that is to say “\definetypeface[myfonts][rm][serif][zhfont]”, we define the typeface series “myfonts” in this profile, and this line represent the “rm”, roman, face is assigned to serif, which we have defined in previous profiles, and “ss” fo “sans”, “tt” for “teletype” or rather “monospace” as we know.
Then write another file, save as test.tex:

\usetypescriptfile[type-myfonts]
\usetypescript[myfonts]
\setupbodyfont[myfonts,rm,12pt]
 
\starttext
所有动物都生而平等,但有些动物比其他动物更平等
\ss 所有动物都生而平等,但有些动物比其他动物更平等
\tt 所有动物都生而平等,但有些动物比其他动物更平等
\stoptext

For explanation, “\usetypescriptfile[type-myfonts]” tell the TeX engine to find a typescript file named type-myfonts.tex in the same directory as current file, and include the contents here; \usetypescript[myfonts]” tell it we are using “myfonts” typescript set as defined in type-myfonts.tex; “\setupbodyfont[myfonts,rm,12pt]” is telling that set the body font to myfonts’s rm style, with 12pt as the size.
Between “\starttext”…”\stoptext” is the text, first line using default font, \rm, and second line change to \ss finaly \tt.
Here is a list to tell font model:
Font model from ConTeXt wiki
Next we need to make ConTeXt know how to wrap lines for Chinese, that is, to break a long sentence into lines in a page. What we need to do is add “\setscript[hanzi]” to the header. Another example of test.tex:

\usetypescriptfile[type-myfonts]\usetypescript[myfonts]\setupbodyfont[myfonts,rm,12pt]
 
\setscript[hanzi]
 
\starttext
明亡后,朝鲜和日本认为中国已亡,日本从此蔑称中国为“支那”。明治维新后,自认为华夏正统的日本曾打着“攘夷主义”的旗号发动甲午战争等对清战争。


\stoptext

Installing ConTeXt Minimals

I’ve chosen to study a TeX, and finally choose ConTeXt because it uses LuaTeX engine that can support Chinese with less pain than using LaTeX as well as someone is complaining about XeTeX may output a lower quality. I don’t know who’s true, but according to my own perception, ConTeXt Minimals with LuaTex may be the best choice, so I start this category of blog to track my course studing it.
Today, I am trying to install it and output my first result file.

Installation is quite easy:

mkdir ~/usr/context && cd ~/usr/context
wget http://minimals.contextgarden.net/setup/first-setup.sh

It will call rsync and use ruby to achieve this, so make sure they are installed on system.

sh first-setup.sh

This will give you a dev-shot of ConTeXt Minimals, if a stable version is needed, run the following instead:

sh first-setup.sh --context=current

I continue with the dev version. Note, every time we want do an update of the program or move it somewhere else, we need to run the command above to make all things work.
If we don’t have a connective Internet available but still want to change the directory, we may run the following command in the context/ folder with tex/ under it:

mtxrun --verbose --script ./bin/mtx-update.lua --update --make --force --engine=all --context=beta --texroot=$PWD/tex $@

Next, make sure there are fonts needed installed, on my system it’s /usr/share/fonts, with wqy-zenhei and wqy-microhei as my Chinese fonts and others like DejaVu and Droid as English fonts.
We need to refresh the system’s font cache before continue, otherwise some fonts won’t work.

sudo fc-cache -f

Then add the system’s font directory to setuptex, which file is placed at ~/usr/context/tex/setuptex in my installation, add the following line at the end of file:

export OSFONTDIR=/usr/share/fonts

Reload font cache for ConTeXt:

mtxrun --script fonts --reload

Generate a list of usable fonts:

mtxrun --script fonts --list --all > font-names.txt

First row represents the font name we will use in our tex file, second is descriptions like font name in true life, the third line is the path to the font file in system.
Finally source the setuptex file to make this environment sensible for current console:

source ~/usr/context/tex/setuptex

Now, we’ve finished setting up a environment that can work.
The easiest example may be like this:

\starttext
Hello world!
\stoptext

Have another test with Chinese:

\definefont[uming][name:arplumingcn]               
\starttext
\uming  
终于看到中文了!
\stoptext

First line assign “uming” as “arplumingcn”, that is “uming” will be used in the following of this file to represent the “arplumingcn”, which is the name of this font that we can see in the first row of former generated font-names.txt.
Second line tell the program we are starting the text, and the next line tell it we are choosing font “uming” for following text. And the last line tell it the text is finished.
I save the file as hello.tex, and use this command to produce the result:

context hello

also we can use hello.tex, but like other Tex environment, ConTeXt knows that it is processing a TeX file so the suffix can be omitted safely.
The the program print many things to our console and finally stopped with several hello.* files in our working directory, and hello.pdf is lying there.

This work by Aron Xu is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported.