https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Adeimantos&feedformat=atom
Wiki - User contributions [en]
2024-03-29T09:32:48Z
User contributions
MediaWiki 1.34.1
https://wiki.contextgarden.net/index.php?title=Command/_startframedtext&diff=34438
Command/ startframedtext
2024-03-17T14:01:49Z
<p>Adeimantos: </p>
<hr />
<div><cd:commandgroup generated="yes" name="framedtext" type="environment" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><!-- a short command summary goes here --><br />
The instances of <tt>\start<i>framedtext</i> ... \stop<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 bigger.</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" type="environment" variant="instance" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords optional="yes" ordinal="1"><br />
<cd:keywordsdoc>set a horizontal placement, like in {{cmd|setupalign}}</cd:keywordsdoc><br />
<cd:constant type="left">left-aligned box</cd:constant><br />
<cd:constant type="right">right-aligned box</cd:constant><br />
<cd:constant type="middle">horizontally centered box</cd:constant><br />
<cd:constant type="none">whatever the surrounding default is</cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" optional="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:inherit name="setupframedtext"></cd:inherit><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>While this is a very powerful way to add decorations to a bit of text, note that framedtexts do not break across pages. See {{cmd|starttextbackground}} for a similar environment that will break across pages.<br />
</cd:description><br />
<cd:examples><cd:example title=""><context source="yes"><br />
\starttext<br />
\startframedtext[width=.8\makeupwidth]<br />
It was essential for Hasselt to have a bridge across the river Zwarte<br />
Water. The bishop of Utrecht gave Hasselt his consent in 1486.<br />
\blank<br />
Other cities in the neighbourhood of Hasselt were afraid of the toll<br />
money to be paid when crossing this bridge so they prevented the<br />
construction.<br />
\stopframedtext<br />
\startframedtext[right][width=.8\makeupwidth]<br />
This one is shifted to the right.<br />
\stopframedtext<br />
\stoptext<br />
</context><br />
</cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="_framedtext" 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></cd:seealso><br />
</cd:commandgroup></div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Command/_startframedtext&diff=34437
Command/ startframedtext
2024-03-17T14:01:24Z
<p>Adeimantos: add commands 'starttext' and 'stoptext' to the script of the first example</p>
<hr />
<div><cd:commandgroup generated="yes" name="framedtext" type="environment" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><!-- a short command summary goes here --><br />
The instances of <tt>\start<i>framedtext</i> ... \stop<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 bigger.</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" type="environment" variant="instance" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords optional="yes" ordinal="1"><br />
<cd:keywordsdoc>set a horizontal placement, like in {{cmd|setupalign}}</cd:keywordsdoc><br />
<cd:constant type="left">left-aligned box</cd:constant><br />
<cd:constant type="right">right-aligned box</cd:constant><br />
<cd:constant type="middle">horizontally centered box</cd:constant><br />
<cd:constant type="none">whatever the surrounding default is</cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" optional="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:inherit name="setupframedtext"></cd:inherit><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>While this is a very powerful way to add decorations to a bit of text, note that framedtexts do not break across pages. See {{cmd|starttextbackground}} for a similar environment that will break across pages.<br />
</cd:description><br />
<cd:examples><cd:example title=""><context source="yes"><br />
\startext<br />
\startframedtext[width=.8\makeupwidth]<br />
It was essential for Hasselt to have a bridge across the river Zwarte<br />
Water. The bishop of Utrecht gave Hasselt his consent in 1486.<br />
\blank<br />
Other cities in the neighbourhood of Hasselt were afraid of the toll<br />
money to be paid when crossing this bridge so they prevented the<br />
construction.<br />
\stopframedtext<br />
\startframedtext[right][width=.8\makeupwidth]<br />
This one is shifted to the right.<br />
\stopframedtext<br />
\stoptext<br />
</context><br />
</cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="_framedtext" 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></cd:seealso><br />
</cd:commandgroup></div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34433
Bibliography
2024-03-11T13:27:53Z
<p>Adeimantos: /* Before using any database: the buffer method */ modification of 'Cicéron' into 'Cicero'</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicero, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
</texcode><br />
<br />
<texcode><br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
</texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
</texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
</texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
See also : [[Simple_Bibliography]]<br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34428
Bibliography
2024-03-10T18:57:02Z
<p>Adeimantos: </p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
</texcode><br />
<br />
<texcode><br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
</texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
</texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
</texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
See also : [[Simple_Bibliography]]<br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34425
Bibliography
2024-03-10T15:07:31Z
<p>Adeimantos: /* Simple manual bibliography */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<\texcode><br />
<br />
<texcode><br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<\texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
See also : [[Simple_Bibliography]]<br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34424
Bibliography
2024-03-10T15:05:49Z
<p>Adeimantos: /* Simple manual bibliography */ add Simple_Bibliography's link</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<\texcode><br />
<br />
<texcode><br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<\texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
See also : [[Simple_Bibliography]]<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34423
Bibliography
2024-03-10T15:02:47Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<\texcode><br />
<br />
<texcode><br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<\texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34422
Bibliography
2024-03-10T15:00:51Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<\texcode><br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34421
Bibliography
2024-03-10T14:59:52Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34420
Bibliography
2024-03-10T14:58:04Z
<p>Adeimantos: /* Before using any database: the buffer method */ cleaning some cmd</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer}}<br />
<br />
<br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
\usebtxdefinitions[apa]<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
\setupbtxrendering[continue =yes]<br />
<br />
<br />
<br />
\starttext<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
\stopchapter<br />
\starttext<br />
\startbackmatter<br />
\startchapter[title={Bibliographie}]<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
\placelistofpublications}}[philosophie ancienne][method=local]<br />
\stopsection}}<br />
\stopchapter}}<br />
\stopbackmatter}}<br />
\stoptext}}<br />
<br />
<br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34419
Bibliography
2024-03-10T14:52:56Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<br />
{{cmd|\startbuffer}}[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
{{cmd |\stopbuffer}}<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<br />
<br />
{{cmd|\usebtxdataset}}[ancient philosophy][biblio.buffer]<br />
<br />
{{cmd|\usebtxdefinitions}}[apa]<br />
<br />
{{cmd|\definebtxrendering}}[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
{{cmd|\setupbtxrendering}}[continue =yes]<br />
<br />
<br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<br />
{{cmd|\startbuffer}}[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
{{cmd|\stopbuffer}}<br />
<br />
<br />
<br />
<texcode><br />
{{cmd|\usebtxdataset}}[philosophie ancienne][biblio.buffer]<br />
{{cmd|\usebtxdefinitions}}[apa]<br />
{{cmd|\definebtxrendering}}[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
{{cmd|\setupbtxrendering}}[continue =yes]<br />
<br />
<br />
<br />
\starttext<br />
{{cmd|\startchapter}}[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<br />
{{cmd|\stopchapter}}<br />
{{cmd|\starttext}}<br />
{{cmd|\startbackmatter}}<br />
{{cmd|\startchapter}}[title={Bibliographie}]<br />
{{cmd|\startsection}}[title={Philosophie ancienne}]<br />
<br />
{{cmd|\placelistofpublications}}[philosophie ancienne][method=local]<br />
{{cmd|\stopsection}}<br />
{{cmd|\stopchapter}}<br />
{{cmd|\stopbackmatter}}<br />
<br />
{{cmd|\stoptext}}<br />
<br />
<br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34418
Bibliography
2024-03-10T14:51:08Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
{{cmd|\startbuffer}}[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
{{cmd |\stopbuffer}}<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<texcode><br />
<br />
{{cmd|\usebtxdataset}}[ancient philosophy][biblio.buffer]<br />
<br />
{{cmd|\usebtxdefinitions}}[apa]<br />
<br />
{{cmd|\definebtxrendering}}[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
{{cmd|\setupbtxrendering}}[continue =yes]<br />
<br />
<\texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
<br />
{{cmd|\startbuffer}}[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
{{cmd|\stopbuffer}}<br />
<br />
<\texcode><br />
<br />
<texcode><br />
{{cmd|\usebtxdataset}}[philosophie ancienne][biblio.buffer]<br />
{{cmd|\usebtxdefinitions}}[apa]<br />
{{cmd|\definebtxrendering}}[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
{{cmd|\setupbtxrendering}}[continue =yes]<br />
<br />
<\texcode><br />
<br />
\starttext<br />
{{cmd|\startchapter}}[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<texcode><br />
{{cmd|\stopchapter}}<br />
{{cmd|\starttext}}<br />
{{cmd|\startbackmatter}}<br />
{{cmd|\startchapter}}[title={Bibliographie}]<br />
{{cmd|\startsection}}[title={Philosophie ancienne}]<br />
<br />
{{cmd|\placelistofpublications}}[philosophie ancienne][method=local]<br />
{{cmd|\stopsection}}<br />
{{cmd|\stopchapter}}<br />
{{cmd|\stopbackmatter}}<br />
<br />
{{cmd|\stoptext}}<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34417
Bibliography
2024-03-10T14:46:05Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
* Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<texcode><br />
<br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
* As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
* Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer method :<br />
<br />
<texcode><br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
<\texcode><br />
<br />
<texcode><br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
\usebtxdefinitions[apa]<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
\starttext<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
<texcode><br />
\stopchapter<br />
\starttext<br />
\startbackmatter<br />
\startchapter[title={Bibliographie}]<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
\placelistofpublications[philosophie ancienne][method=local]<br />
\stopsection<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34416
Bibliography
2024-03-10T14:41:55Z
<p>Adeimantos: /* Before using any database: the buffer method */</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer.<br />
<br />
<texcode><br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
\placelistofpublications[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Bibliography&diff=34415
Bibliography
2024-03-10T14:38:37Z
<p>Adeimantos: /* Quickstart */ add a sub-section on buffer</p>
<hr />
<div>__TOC__<br />
<br />
<br />
{{TwoColumnsUnderLevel1<br />
|<br />
Support for bibliographies is integrated in MkIV’s and LMTX’s core (for the curious, the files are named [https://source.contextgarden.net/&#63;search&#61;bibl-tra bibl-tra]. Two other important sources of information are: <br />
* [[manual:mkiv-publications.pdf|Bibliographies manual]]<br />
* [http://meeting.contextgarden.net/2014/talks/2014-09-09-alan-bibtex/From_BibTeX_to_ConTeXt_MKVI.pdf From BibTEX to ConTEXt mkiv], a 2014 presentation about BibTeX and the state of Bibliography in MkIV.<br />
<br />
For older ConTeXt MkII, support for bibliographies was added by Taco. The '''[[Bibliography_mkii|Bibliography mkii]]''' page explains a few basic facts and points you to the manual of the module.<br />
|<br />
TeX offers excellent ways to handle bibliographic references. BibTeX allows you to use a database to manage your references and to insert citations and a list of references into your document. If you’re completely new to this subject, you should probably begin to read some basic hints about BibTeX databases. You will find a good selection of resources (most of them are free and available on-line) at the section “Bibliographies and Citations” of the [[http://texfaq.net/index.html#Bibliographiesandcitations TeX faq]]. A good place for beginners is Nicolas Markey’s [[http://mirror.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf Tame the Beast]]. If you have TeXLive installed, it may already be on your hard disk.<br />
}}<br />
<br />
<br />
<br />
=Quickstart=<br />
<br />
From the manual:<br />
<br />
<texcode><br />
\usebtxdataset[mkiv-publications.bib]<br />
\starttext<br />
<br />
\startbodymatter<br />
a citation: \cite[article,book]<br />
\stopbodymatter<br />
<br />
\startbackmatter<br />
\startchapter[title=Bibliography]<br />
\placelistofpublications<br />
\stopchapter<br />
\stopbackmatter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
==Before using any database: the buffer method==<br />
<br />
Before using a bibliographic database built with tools such as [https://www.jabref.org/ JabRef] or [https://www.zotero.org/ Zotero] (among others), it is possible to use the BibTeX format for bibliographic data by buffering it. With ConTexT MKIV, a relatively simple document of a few pages can be composed with simple commands such as \startbuffer .... \stopbuffer, between which you copy all the bibliographic references to be used in the text like this :<br />
<br />
<texcode><br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<\texcode><br />
<br />
Next, we will write text between the starttext and stoptext tags, before defining how the references will be printed after the body of the text, in the area defined for the table of contents (and possibly the various indexes, index rerum and index nominum). For the simplest texts, the bibliographic references after the \stopbuffer command can, for example, be defined (with our example) as follows:<br />
<br />
<texcode><br />
\usebtxdataset[ancient philosophy][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[ancient philosophy][apa][dataset=ancient philosophy]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
<\texcode><br />
<br />
As you can see, the memory buffer named 'biblio' will be associated with a database named 'ancient philosophy'; the format will follow the American Psychological Association (APA) model. We are writing a short text on Aristotle and Cicero with two bibliographical references in footnotes (one for each philosopher).<br />
<br />
Then, we have to give place to what is called 'backmatter', say the the space where the bibliographic references given in the text will be printed, either in the body of the text or, as in our example, as footnotes. In this way, at the end of the document, all the references used from the buffer are summarised. Personally, I find the buffer method simple and easy, but much less powerful and convenient than the method of feeding a bibliographic file, constructed in the form *.bib, using software such as JabRef. ConTeXt will fetch the references from this file as and when they are called up using the \cite command, instead of having to copy each reference into the buffer.<br />
<br />
Below a sample using a buffer.<br />
<br />
<texcode><br />
<br />
\startbuffer[biblio]<br />
<br />
@Book{cicero-tuscu2011,<br />
author = {Cicéron, Marcus Tullius},<br />
editor = {Fohlen, G.},<br />
publisher = {Les Belles Lettres},<br />
title = {Tusculanes},<br />
year = {2011},<br />
address = {Paris},<br />
edition = {7e tirage},<br />
isbn = {9782251010830},<br />
series = {œuvres philosophiques},<br />
volume = {1},<br />
ppn_gvk = {1823774121},<br />
translator = {Jules Humbert},<br />
}<br />
<br />
@Book{Aristote2008,<br />
Title = {Les Politiques},<br />
Author = {Aristote},<br />
Editor = {Pellegrin, Pierre},<br />
Publisher = {Garnier-Flammarion},<br />
Year = {2008},<br />
Address = {Paris, France},<br />
Series = {Le monde de la philosophie},<br />
Date = {2008},<br />
ISBN = {978-2-08-121816-1},<br />
Location = {Paris, France},<br />
Pagetotal = {xxiii+518},<br />
Translator = {Pierre Pellegrin}<br />
}<br />
\stopbuffer<br />
<br />
\usebtxdataset[philosophie ancienne][biblio.buffer]<br />
<br />
\usebtxdefinitions[apa]<br />
<br />
\definebtxrendering[philosophie ancienne][apa][dataset=philosophie ancienne]<br />
<br />
\setupbtxrendering[continue =yes]<br />
<br />
\starttext<br />
<br />
\startchapter[title={An Introduction To Philosophy}]<br />
<br />
In the notes that follow, we will focus on philosophical thought as political philosophy. Aristotle, the Greek philosopher who published and commented on the Constitutions of the ancient Greek cities, begins his work {Politics} with the thesis that {man is a political animal}\footnote{cite[alternative=entry][ancient philosophy::Aristotle2008]}.<br />
<br />
<br />
Cicéron, ce grand homme politique et cet écrivain savant, a eu la formule bien connue, selon laquelle \quotation{Socrate fit descendre la philosophie du ciel sur la terre.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, qui désigne la question fondamentale de l’intérêt nourri par la philosophie pour les {\it choses humaines}.<br />
<br />
Cicero, the great politician and scholarly writer, had the well-known phrase, \quotation{Socrates brought philosophy down from heaven to earth.}\footnote{\cite[alternative=entry][philosophie ancienne::cicero-tuscu2011]}, which refers to the fundamental question of philosophy's interest in {\it human things}.<br />
<br />
\stopchapter<br />
<br />
\starttext<br />
<br />
\startbackmatter<br />
<br />
\startchapter[title={Bibliographie}]<br />
<br />
\startsection[title={Philosophie ancienne}]<br />
<br />
\placelistofpublications[philosophie ancienne][method=local]<br />
<br />
\stopsection<br />
<br />
\stopchapter<br />
<br />
\stopbackmatter<br />
<br />
\stoptext<br />
<br />
<\texcode><br />
<br />
=Database Formats=<br />
<br />
ConTeXt can read several different formats of bibliographic databases:<br />
<br />
==BibTeX .bib format==<br />
<br />
ConTeXt is independent from the BibTeX program, but can read .bib databases, if they’re not too polluted with non-standardized (LaTeX) commands.<br />
This format is the oldest, but supported by most bibliography management programs. The other supported formats use the same structure of records, just ported to different “languages”.<br />
<br />
A BibTeX database is a text file, consisting of entries like:<br />
<br />
@Article {Hagen2010,<br />
author = "One or more authors",<br />
title = "Some interesting title",<br />
journal = "Publisher’s Weekly",<br />
volume = "27",<br />
number = "2",<br />
pages = "21--30",<br />
month = may,<br />
year = "2020",<br />
ISSN = "1234-5678"<br />
}<br />
<br />
{{code|@Article}} is an example for a common category, like {{code|@Book}}, {{code|@unpublished}} etc. Letter case doesn’t matter.<br />
The first argument reference must not contain spaces and is ended with a comma.<br />
Spacing within an entry doesn’t matter. If values consist of only one word, you don’t need quotes, otherwise you can also use brackets.<br />
<br />
ConTeXt understands UTF-8 encoded bib files as well as old fashioned TeX accent combinations.<br />
<br />
;Fields: Some known fields of {{code|@Article}} are (see [http://pragma-ade.nl/general/manuals/mkiv-publications.pdf#&#91;19,{%22name%22:%22Fit%22}&#93; manual p.19]):<br />
:* Title (also Title:en, Title:de etc.), Subtitle<br />
:* Author (see manual for possible formats)<br />
:* Journal, Type, Number, Volume, Pages, Review<br />
:* Year, Month, Day<br />
:* Warning, Comment, Note<br />
:* XCrossref<br />
:* Doi<br />
:* Keywords<br />
:* Language<br />
:* Url<br />
:* author, editor: fields are parsed as "Firstname(s) Lastname", multiple entries separated by 'and' (see manual p.6/14)<br />
:* keywords: separated by semicolons<br />
: There’s a (complete?) overview of categories and their fields in the manual on page 18 (Table 3.2).<br />
<br />
;Commands in entries: you can define unknown commands like this:<br />
<br />
<texcode><br />
\definebtxcommand\TUB {TUGboat}<br />
\definebtxcommand\sltt{\tt}<br />
\definebtxcommand\<#1>{\type{#1}}<br />
</texcode><br />
: btx commands use a separate namespace.<br />
<br />
==MkII .bbl format==<br />
<br />
This intermediate format is still supported, but obsolete. Just an example to let you know what it means:<br />
<br />
<texcode><br />
\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01] <br />
\artauthor[]{Hans}[H.]{}{Hagen}<br />
\arttitle{Who knows more?}<br />
\journal{MyJournal}<br />
\pubyear{2013}<br />
\month{8}<br />
\volume{1}<br />
\issue{3}<br />
\issn{1234-5678}<br />
\pages{123--126}<br />
\stoppublication<br />
</texcode><br />
<br />
==Lua tables==<br />
<br />
Since internally everything anyway are Lua tables, you can use them directly as a database format:<br />
<br />
return { ["Hagen:First"] = {<br />
author = "Hans Hagen",<br />
category = "article",<br />
issn = "1234-5678",<br />
issue = "3",<br />
journal = "MyJournal",<br />
month = "8",<br />
pages = "123--126",<br />
tag = "Hagen:First",<br />
title = "Who knows nothing?",<br />
volume = "1",<br />
year = "2013", },<br />
}<br />
<br />
==XML==<br />
<br />
<xmlcode><br />
<?xml version="2.0" standalone="yes" ?><br />
<bibtex><br />
<entry tag="Hagen:First" category="article"><br />
<field name="author">Hans Hagen</field><br />
<field name="category">article</field><br />
<field name="issn">1234-5678</field><br />
<field name="issue">3</field><br />
<field name="journal">MyJournal</field><br />
<field name="month">8</field><br />
<field name="pages">123--126</field><br />
<field name="tag">Hagen:First</field><br />
<field name="title">Who knows nothing?</field><br />
<field name="volume">1</field><br />
<field name="year">2013</field><br />
</entry><br />
</bibtex><br />
</xmlcode><br />
<br />
=Setup=<br />
<br />
<texcode><br />
\usebtxdataset[default][mybooks.bib]<br />
\setupbtx[dataset=default]<br />
\usebtxdefinitions[apa] % see p.15<br />
\placelistofpublications<br />
</texcode><br />
<br />
* The mentioned database file formats are recognized by their extension: .bib, .bbl., .lua and .xml<br />
* `default` is the name for this database. If you load several files into the same name space, they get merged.<br />
* {{cmd|definebtxrendering}}, {{cmd|setupbtxrendering}}<br />
<br />
<texcode><br />
\definebtxrendering[example][apa][% setup "example" inherits from "apa"<br />
specification=apa,<br />
sorttype=authoryear,<br />
numbering=no<br />
]<br />
</texcode><br />
<br />
==sorttypes==<br />
<br />
* default, none, cite, list: don’t sort, use original order<br />
* dataset, index: sort after dataset index<br />
* reference: sort by reference tag<br />
* key: sort by `key` (traditionally used in BibTeX as sortkey)<br />
* short: sort by `short`<br />
* authoryear: sort by author(s) and publication year<br />
<br />
==bib list rendering==<br />
<br />
See manual, p.24ff.<br />
<br />
<texcode><br />
\setupbtxlist[apa][<br />
alternative=paragraph,<br />
width=fit,<br />
distance=.5em,<br />
margin=3em % hanging list<br />
]<br />
</texcode><br />
<br />
Predefined renderings include:<br />
* apa (by American Psychological Assoc.)<br />
* mla<br />
* chicago<br />
* harvard<br />
* ieee,<br />
* aps (used in physical sciences)<br />
* vancouver (used in biological sciences)<br />
* [https://github.com/jjmccollum/context-sbl sbl] (used in theology), external project<br />
<br />
Note: Only apa, aps, and chicago styles are currently provided as a showcase.<br />
<br />
==Language==<br />
<br />
Bibliography lists and citations are rendered in the language of the document (`\mainlanguage`). If an entry includes a language field, this can be used, depending on the rendering specification.<br />
<br />
You can force the main language on all entries with {{cmd|setupdelimitedtext}}`[language=global]`.<br />
<br />
You can define and use translated titles with language modifiers, e.g. `title:de` or `booktitle:fr`.<br />
<br />
==Complex example==<br />
To see how the concepts play together, here a relatively complete example:<br />
<br />
<texcode><br />
\definebtxdataset[main] % choose a name for a dataset to use<br />
\usebtxdataset[main][testbib.bib] % fill the dataset with bib entries<br />
\setupbtx[dataset=main] % make \cite use our dataset by default<br />
\setupbtx[default:cite][alternative=authoryear] % make \cite[ref] work like \cite[authoryear][ref]<br />
\usebtxdefinitions[apa] % activate apa style for \cite rendering (also *load* apa style for bib entry rendering)<br />
\setupbtx[apa:cite][otherstext={ et al.}] % modify the apa \cite rendering style (remove comma after sole author name)<br />
\definebtxrendering[mainlist][apa][dataset=main] % define a bib entry rendering to use with \placebtxrendering<br />
<br />
% in the document:<br />
\placebtxrendering[mainlist][method=global]<br />
</texcode><br />
<br />
=Citations=<br />
<br />
See p.31ff. of the manual.<br />
E.g.<br />
<br />
<texcode><br />
\cite[num][reference] % [77]<br />
\cite[authoryear][reference] % (Hagen 1977)<br />
\cite[short][reference] % [HHH+77b]<br />
and even<br />
\cite[num][ref1,ref2,ref3] % [2,15,77] see p.35f.<br />
</texcode><br />
<br />
The first argument defaults to the default citation rendering, as defined by `\setupbtx[default:cite][alternative=num]`.<br />
<br />
=Custom bibliographical styles=<br />
<br />
Users who wish to develop their own custom styles could start with the files in the distribution, copy them to different names and then modify them (e.g., the files `publ-imp-apa.lua` and `publ-imp-apa.mkvi`). However, these files contain a number of advanced code to deal with the numerous exceptions and rules. Hence, in some cases, it may be easier to write your own custom style. Here, I will provide you with an example what a minimal setup will be to get you started. Once you have a style in place and understand what's needed, it is easy to experiment further.<br />
<br />
==Files==<br />
<br />
For every style, you will need two files: one with the TeX setups and one with the Lua definitions. They have to follow the naming conventions that the bibliographic subsystem expects so they can be found. If your style is called `mycustom`, these two files should be `publ-imp-mycustom.mkiv` and `publ-imp-mycustom.lua`.<br />
<br />
==The Lua code==<br />
<br />
A minimal Lua file can be very brief. It has to contain a little bit of boiler plate with the required tables and the "categories" (i.e. publication types) that your bibliography will process. A minimal example will look like this:<br />
<br />
<pre><br />
local specification = {<br />
name = "mycustom",<br />
categories = { },<br />
}<br />
<br />
local categories = specification.categories<br />
<br />
categories.book = {<br />
required = { "title" },<br />
optional = {"author", "editor",<br />
"year", "editor",<br />
"edition", "series", "volume", "number",<br />
"address", "publisher",<br />
},<br />
}<br />
return specification<br />
</pre><br />
<br />
For every type `publicationtype` you want processed, you need an entry `categories.publicationtype`. This entry needs to have a list of fields that will be processed, divided into "required" fields (that every entry needs to have) and "optional" fields (that they may or may not have). Every book needs to have a title, but not necessarily an author. Remember: only types that have a category will be processed. Only fields that are listed in the category will be processed.<br />
<br />
==The TeX code==<br />
<br />
The TeX file is where the formatting is done. Again, you need to start with a few lines that make the `publ-imp-mycustom.mkiv` file work:<br />
<br />
<texcode><br />
\startbtxrenderingdefinitions[mycustom]<br />
<br />
\definebtx<br />
[mycustom]<br />
[default=default,<br />
specification=mycustom]<br />
<br />
\definebtxrendering<br />
[mycustom]<br />
[specification=mycustom,<br />
numbering=yes]<br />
<br />
\stopbtxrenderingdefinitions<br />
</texcode><br />
<br />
This will make ConTeXt use your definitions. Further on, you include formatting directives for every type of publication you have included in your Lua file. If you want to modify the way the `cite` command will be displayed, these directives will be in the form `\startsetups btx:mycustom:cite`. For formatting the bibliographic list, they will be in the form `\startsetups btx:mycustom:list:categroy`. In our example, the only category is "book," so that's what our minimal definition will look like:<br />
<br />
<texcode><br />
\startsetups btx:mycustom:list:book<br />
\btxdoif {author} {<br />
\color[blue]{\btxflush{author}}<br />
\btxcomma<br />
}<br />
\btxdoifelse {title} {<br />
\color[red]{\btxflush{title}}<br />
} {<br />
No Title<br />
}<br />
\removeunwantedspaces<br />
\stopsetups<br />
</texcode><br />
<br />
The most important command here is the `btxflush`: it will typeset the corresponding field of your bibliographic entry. You include it within formatting directives. As you can see, in our example, the author name will be typeset in blue; the title will be typeset in red. In the first section, `btxdoif {author}` checks whether there is a field "author"; if it exists, it will be typeset; if it doesn't exist, nothing happens. In the second example, the `btxdoifelse {title}` checks whether the field "title" exists. If it exists, the code within the first pair of braces will be executed, i.e., the title will be typeset in red. If it doesn't exist, the second pair of braces will be executed, and ConTeXt will typeset "No Title" in your document.<br />
<br />
This should get you started with your custom style and let you experiment to your heart's content. The fields will be typeset in the order in which you include them in the setups. If you want to know more about these fields and about the commands that are available, check Chapter 6 of `mkiv-publications.pdf`.<br />
<br />
=Simple manual bibliography=<br />
<br />
If you don’t need bibliographical databases, but just references within one document, this approach might be enough for you:<br />
<br />
<texcode><br />
% LMTX: <br />
\tolerant\def\startbibitem[#1]#*[#2]% LMTX!<br />
{\doifsomethingelse{#2}%<br />
{\startBibItem[reference={#1},title={#2}]}%<br />
{\startBibItem[reference={#1},title={#1}]}%<br />
}<br />
\def\stopbibitem{\stopBibItem}<br />
<br />
% MkIV:<br />
%\def\dostartbibitem[#1][#2]%<br />
% {\doifsomethingelse{#2}%<br />
% {\startBibItem[reference={#1},title={#2}]}%<br />
% {\startBibItem[reference={#1},title={#1}]}%<br />
%}<br />
%\def\startbibitem{\dodoubleempty\dostartbibitem}<br />
%\def\stopbibitem{\stopBibItem}<br />
<br />
\definedescription[BibItem][<br />
width=broad,<br />
margin=4em,<br />
indenting={no},<br />
indentnext=no,<br />
alternative=hanging,<br />
hang=1,<br />
headcommand=\gobbleoneargument,<br />
align=flushleft<br />
]<br />
<br />
\def\bibitemrule{\noindentation\vrule height0.5pt width4em depth0pt\thinspace}<br />
<br />
\definereferenceformat [cite] [type=title,left={},right={}]<br />
\definereferenceformat [bibpage] [type=page]<br />
<br />
\starttext<br />
<br />
\section{Content}<br />
<br />
While we wait for the perfect book about ConTeXt\footnote{Maybe \cite[Hagen 2050]}, we can at least read a nice novel (\cite[Hagen 2014]).<br />
<br />
\section{Bibliography}<br />
<br />
\startbibitem[Hagen 2014]<br />
Hagen, Hans: \emph{The Cow in the Ridderstraat.} Hasselt 2014.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2050]<br />
\bibitemrule \emph{ConTeXt complete compendium.} Hasselt 2050.<br />
\stopbibitem<br />
<br />
\startbibitem[Hagen 2060][The Wizard 1899] % First parameter is reference, second gets displayed<br />
\bibitemrule \emph{Optional differing reference title.} Hasselt 2060<br />
\stopbibitem<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
[[Manual_Bibliography|Here’s a similar approach]] using {{cmd|defineitemgroup}}.<br />
<br />
[[Category:Bibliography]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34411
mixed languages
2024-03-09T17:16:20Z
<p>Adeimantos: </p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
{{cmd|\quotation}}{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}<br />
<br />
<br />
== See also ==<br />
<br />
* [[Palatino_Linotype_under_MKIV]]<br />
* [[Greek]]<br />
* [[Arabic_fonts]]<br />
* [[Arabic_and_Hebrew]]<br />
* [[Chinese_Japanese_and_Korean]]<br />
* [[CJK fonts]]<br />
<br />
[[Category:Fonts]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34410
mixed languages
2024-03-09T17:14:59Z
<p>Adeimantos: </p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}<br />
<br />
<br />
== See also ==<br />
<br />
* [[Palatino_Linotype_under_MKIV]]<br />
* [[Greek]]<br />
* [[Arabic_fonts]]<br />
* [[Arabic_and_Hebrew]]<br />
* [[Chinese_Japanese_and_Korean]]<br />
* [[CJK fonts]]<br />
<br />
[[Category:Fonts]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34384
mixed languages
2024-03-04T12:05:10Z
<p>Adeimantos: </p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}<br />
<br />
<br />
== See also ==<br />
<br />
* [[Palatino_Linotype_under_MKIV]]<br />
* [[Greek]]<br />
* [[Arabic_fonts]]<br />
* [[Arabic_and_Hebrew]]<br />
* [[Chinese_Japanese_and_Korean]]<br />
* [[CJK fonts]]<br />
<br />
[[Category:Fonts]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34383
mixed languages
2024-03-04T12:04:00Z
<p>Adeimantos: add <context> and <\context></p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<context><br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}<br />
<br />
<\context><br />
<br />
== See also ==<br />
<br />
* [[Palatino_Linotype_under_MKIV]]<br />
* [[Greek]]<br />
* [[Arabic_fonts]]<br />
* [[Arabic_and_Hebrew]]<br />
* [[Chinese_Japanese_and_Korean]]<br />
* [[CJK fonts]]<br />
<br />
[[Category:Fonts]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34382
mixed languages
2024-03-04T11:25:46Z
<p>Adeimantos: add references to other wiki pages like Arabic, Hebrew, Japanese and Korean fonts</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}<br />
<br />
== See also ==<br />
<br />
* [[Palatino_Linotype_under_MKIV]]<br />
* [[Greek]]<br />
* [[Arabic_fonts]]<br />
* [[Arabic_and_Hebrew]]<br />
* [[Chinese_Japanese_and_Korean]]<br />
* [[CJK fonts]]<br />
<br />
[[Category:Fonts]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34381
mixed languages
2024-03-04T11:13:55Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the English translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\TwoColumns}}<br />
<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with ConTeXT as an alternative to LaTeX}<br />
<br />
%''Note : if you want to transcript the words TeX, LaTeX and other TeX in the appropriate face, add a backslash before the word, like that : \LaTeX; \ConTeXt.''<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to ConTeXt, which is not an alternative to LaTeX, but a more synthetic (or even more elegant) way of using LaTeX. ConTeXt, like LaTeX, is a software suite which contains the macros of LaTeX, the routines of the {\em Perl} language, as well as the macros of LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34380
mixed languages
2024-03-04T11:07:17Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
<br />
% ''Definition of the frame style (printed at the end of the document)''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
% ''Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34379
mixed languages
2024-03-04T11:06:21Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% ''Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
%''\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
''% Choose now between two Arabic fonts''<br />
<br />
<br />
%''{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
% ''Definition of the frame style (at the end of the document''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34378
mixed languages
2024-03-04T11:03:42Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there some text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
''% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
''%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
''% Choose between two Arabic fonts''<br />
<br />
''%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
% ''Definition of the frame style (at the end of the document''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34377
mixed languages
2024-03-04T11:02:38Z
<p>Adeimantos: /* Define the main text font */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
''% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
''%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
''% Choose between two Arabic fonts''<br />
<br />
''%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
% ''Definition of the frame style (at the end of the document''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34376
mixed languages
2024-03-04T11:01:16Z
<p>Adeimantos: /* Mainlanguage */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
<br />
and this one :<br />
<br />
{{code|mtxrun}} --script fonts --reload<br />
<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
''% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
''%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
''% Choose between two Arabic fonts''<br />
<br />
''%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
% ''Definition of the frame style (at the end of the document''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34375
mixed languages
2024-03-04T10:58:34Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
% ''We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% ''Use Theano Didot as Ancient Greek font''<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
''% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
''%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
''% Choose between two Arabic fonts''<br />
<br />
''%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
% ''Definition of the frame style (at the end of the document''<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
% ''Main text in English''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
% ''The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% ''Here below, the Greek text is on the left columns; the translation is on the right columns''<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
% ''Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34374
mixed languages
2024-03-04T10:55:39Z
<p>Adeimantos: /* An example of mixed languages */ Add several comments</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (''Minimum Working Example''), because it also contains footnotes, an header and a footer, as well as a framed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
<br />
''% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
''% Use Theano Didot as Ancient Greek font''<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
''% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)''<br />
<br />
''%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]''<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
''% Choose between two Arabic fonts''<br />
<br />
''%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]''<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
''% Definition of the frame style (at the end of the document''<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
''%width=\textwidth'',<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
''% Using MPGraphic (MetaPost), with appropriate syntax''<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
''% Main text''<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
''% The quotation in ancient Greek is in a narrower style''<br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
''% Here below a paragraph which contains Chinese text and Arabic''<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34373
mixed languages
2024-03-04T10:47:29Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 backslashes : one is enough ...<br />
<br />
<br />
''% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).''<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34372
mixed languages
2024-03-04T10:46:44Z
<p>Adeimantos: /* Define a font for Arabic */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 backslashes : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34371
mixed languages
2024-03-04T10:46:26Z
<p>Adeimantos: /* Define a font for Traditional Chinese (TC) */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between 'ipaexmincho' font and 'NotoSansTC' (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 backslashes : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34370
mixed languages
2024-03-04T10:45:32Z
<p>Adeimantos: /* Define a font for Traditional Chinese (TC) */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|language}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{code|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{code|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{code|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{code|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese) as follow :<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 backslashes : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|mainlanguage}}[en]<br />
<br />
{{cmd|setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|setupbodyfont}}[mainface]<br />
<br />
{{cmd|setupindenting}}[1.5em]<br />
<br />
{{cmd|setupindenting}}[yes]<br />
<br />
{{cmd|setupcolors}}[state=start]<br />
<br />
{{cmd|defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|stopuseMPgraphic}}<br />
<br />
{{cmd|defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|setupwhitespace}}[medium]<br />
<br />
{{cmd|setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|setuphead}}[title][header=empty]<br />
<br />
{{cmd|setupheader}}[style={\sc}]<br />
<br />
{{cmd|setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|starttext}}<br />
<br />
{{cmd|title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|noindent}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|startTwoColumns}}<br />
<br />
{{cmd|quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|stopTwoColumns}}<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|stopnarrower}}<br />
<br />
{{cmd|quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|showframe}}<br />
<br />
{{cmd|startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|stopMyFrame}}<br />
<br />
{{cmd|stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34367
mixed languages
2024-03-03T18:21:50Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 backslashes : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34366
mixed languages
2024-03-02T20:58:34Z
<p>Adeimantos: </p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot :<br />
<br />
{{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 anti-slash : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34365
mixed languages
2024-03-02T20:57:35Z
<p>Adeimantos: </p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
==Mainlanguage==<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot : {{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 anti-slash : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34364
mixed languages
2024-03-02T20:54:46Z
<p>Adeimantos: /* An example of mixed languages */</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
===Mainlanguage===<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot : {{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
>Note : for some reason, each command here begin with 2 anti-slash : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34363
mixed languages
2024-03-02T20:51:29Z
<p>Adeimantos: /* An example of mixed languages */adding a note on anti-slash</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
===Mainlanguage===<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot : {{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
Note : for some reason, each command here begin with 2 anti-slash : one is enough ...<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=mixed_languages&diff=34362
mixed languages
2024-03-02T20:46:40Z
<p>Adeimantos: Page on how defining and print multi languages text with \ConTeXt</p>
<hr />
<div>== Introduction ==<br />
<br />
Some users of ConTeXt (mainly in Humanities) are sometimes led to introduce different languages into a text mainly written in a Romance language (English, Spanish, French, Dutch, German, Italian, etc.). In a text in a European Latin language, the best way to switch from one language to another is to use the command :<br />
<br />
{{cmd|\definefallbackfamily}}<br />
<br />
<br />
==How to achieve it ==<br />
<br />
===Mainlanguage===<br />
<br />
If you want to use several languages, you need to ask ConTeXt which language you want to switch to for each of them. In the preamble, write the main language of the text and the languages you want to switch to. For example, our text is written mainly in English. We want to comment on a text in Ancient Greek, but in the course of the commentary we want to make references to texts in Arabic and Chinese. So, as a basic preamble, we would have something like this:<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
As you see, English will be the main language of our text (or choose [fr], [ger], etc.); but along with Ancient Greek (agr).<br />
<br />
Then, after the {{cmd|\setuplanguage}} command, you have to precise which main language you want to use. Here, this is English, which language is setup by this command :<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
ConTeXt now understands that you will be using English and Ancient Greek. But you need to give it the right fonts to achieve this goal, bearing in mind that English and Ancient Greek do not use the same glyphs, even though some font families, such as TeX Gyre Pagella, are very versatile. So now you need to place the command for the Ancient Greek text. You will need to check that these fonts are available on your system. Refer to the Wiki page on installing and checking fonts, bearing in mind that installing them on your system from the Internet is not enough: they must also be supported by \ConTeXt. You can pass the following command in a console, in order to list all the installed fonts on your system :<br />
<br />
<br />
{{cmd|mtxrun}} --script fonts --list --all<br />
<br />
<br />
Or, in order to find a particular font, say GFS Didot : {{cmd|mtxrun}} --script fonts --list --pattern=gfsdidot --all<br />
<br />
If you are sure to have previously installed some police, but you can see it, as a reminder, two commands are useful: <br />
<br />
{{cmd|mtxrun}} --script cache --erase && mtxrun --generate<br />
<br />
and this one {{cmd|mtxrun}} --script fonts --reload<br />
<br />
Again, if you are a beginner, read some documentation like which are listed here [[https://wiki.contextgarden.net/Documentation]]<br />
<br />
<br />
=== Define a font for Ancient Greek ===<br />
<br />
Use Theano Didot as Ancient Greek font<br />
<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek,force=yes]<br />
<br />
=== Define a font for Traditional Chinese (TC) ===<br />
You can choose between several fonts. In order to test them, you can write your preamble as follow (the "%" is to comment the line) :<br />
<br />
Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
<br />
=== Define a font for Arabic ===<br />
<br />
Choose between two Arabic fonts<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
<br />
===Define the main text font ===<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
<br />
== An example of mixed languages ==<br />
<br />
There is below an example of 5 pages printed mainly in English, where you can find Ancient Greek, Traditional Chinese and Arabic. This text is more than a MWE (Minimum Working Example), because it also contains footnotes, a header and a footer, as well as boxed text. But even if at first glance this page seems difficult for a beginner, you can practise with the code on this page. Details: the Arabic text is printed correctly, i.e. from right to left. You can adjust the size of the text with a number of commands concerning the number of lines per page, the font size, etc.<br />
<br />
<br />
% We are writing an example of a text written in a Latin language, in which we want to print here and there text in ancient Greek, Arabic and Chinese.(The sign '%' means that ConTeXT ignores the text or the command. It's a comment).<br />
<br />
{{cmd|\setuplanguage}}[en][patterns={en,agr}]<br />
<br />
{{cmd|\mainlanguage}}[en]<br />
<br />
{{cmd|\setuplayout}}[backspace=40mm]<br />
<br />
{{cmd|\setuppagenumbering}}[alternative=doublesided, location={header, inmargin}]<br />
<br />
{{cmd|\setupmargindata}}[inmargin][location=inner, style={\ssx\setupinterlinespace[line=2.8ex]}]<br />
<br />
{{cmd|\setupmarginframed}}[inmargin][align=right]<br />
<br />
{{cmd|\setupbodyfontenvironment}}[default][em=italic]<br />
<br />
% Use Theano Didot as Ancient Greek font<br />
{{cmd|\definefallbackfamily}}[mainface][serif][Theano Didot][preset=range:greek, it={Old Standard Italic}, force=yes]<br />
<br />
% Choose between Ipaexmincho font and NotoSansTC (Traditional Chinese)<br />
<br />
%\definefallbackfamily [mainface] [rm] [ipaexmincho] [range=cjkunifiedideographs]<\pre><br />
<br />
{{cmd|\definefallbackfamily}} [mainface] [rm] [notosanstc] [range=cjkunifiedideographs]<br />
<br />
% Choose between two Arabic fonts<br />
%{{cmd|\definefallbackfamily}}[mainface] [serif] [nafeesnastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefallbackfamily}}[mainface] [serif] [hussaininastaleeq] [range=arabic]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [serif] [GaramondNo8][sc=NewG8 Regular SC]<br />
<br />
{{cmd|\definefontfamily}} [mainface] [sans] [FreeSans] [rscale=0.7]<br />
<br />
{{cmd|\definefontfamily}}[mainface] [serif] [GFS Didot]<br />
<br />
{{cmd|\setupbodyfont}}[mainface]<br />
<br />
{{cmd|\setupindenting}}[1.5em]<br />
<br />
{{cmd|\setupindenting}}[yes]<br />
<br />
{{cmd|\setupcolors}}[state=start]<br />
<br />
{{cmd|\defineframedtext}}<br />
[MyFrame]<br />
[before={\blank},<br />
after={\blank},<br />
frame=off,<br />
background=MyFrame,<br />
%width=\textwidth,<br />
width=max,<br />
height=fit,<br />
style=italic]<br />
<br />
{{cmd|\definelabel}}<br />
[Definition]<br />
[headstyle=\bf\smallcaps]<br />
<br />
{{cmd|\startuseMPgraphic}}{MyFrame}<br />
path b;<br />
picture p;<br />
%p := textext.rt("\white\Définition");<br />
p := textext.rt("\white\framedtextparameter{Title}");<br />
%p := textext.rt("\white\getvariable{text}{text1}");<br />
p := p shifted (2BodyFontSize,OverlayHeight-ypart center p+.25ExHeight);<br />
b := boundingbox p leftenlarged .5EmWidth rightenlarged .5EmWidth;<br />
fill OverlayBox withcolor lightgray; %\MPcolor{<br />
fill b withcolor darkred;<br />
draw bottomboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw topboundary OverlayBox withpen pencircle scaled 1pt withcolor<br />
darkred;<br />
draw p;<br />
setbounds currentpicture to boundingbox currentpicture enlarged 2mm;<br />
<br />
{{cmd|\stopuseMPgraphic}}<br />
<br />
{{cmd|\defineoverlay}} [MyFrame][\useMPgraphic{MyFrame}]<br />
<br />
{{cmd|\setupwhitespace}}[medium]<br />
<br />
{{cmd|\setupinterlinespace}}[line=3.2ex]<br />
<br />
{{cmd|\setuphead}}[title][header=empty]<br />
<br />
{{cmd|\setupheader}}[style={\sc}]<br />
<br />
{{cmd|\setupfooter}}[style={\itxx}]<br />
<br />
{{cmd|\setupheadertexts}}[How to several languages in the same text with \ConTeXt][][][{\getmarking[section]}]<br />
<br />
{{cmd|\setupfootertexts}}[][][][© Copyright — The reproduction of this text is under authorisation.]<br />
<br />
{{cmd|\defineparagraphs}}[TwoColumns][n=2, align={hz, hanging}]<br />
<br />
{{cmd|\setupparagraphs}}[TwoColumns][1][width=210pt, style=rm, align=left]}<br />
<br />
{{cmd|\starttext}}<br />
<br />
{{cmd|\title}}{\ConTeXt : or how to print non-roman languages}<br />
<br />
{{cmd|\section}} {\sc Preamble}<br />
<br />
When it comes to submitting a document in a national language (as English, or German, or French), everything is fine. When it comes to writing a slightly complex document in any Romance language, but with quotations — or references — in another language, which in particular does not have the same requirements as your own Romance language, nor the same {\em diacritical marks}, we run into a few difficulties. Software suites such as Microsoft Office or LibreOffice are not lacking in power, but the truth is that as soon as we get into the requirements and detail of professional publishing, which consists of presenting a readable text enriched (with notes, etc.), the situation quickly becomes technically rather difficult. The most common situation we encounter in Philosophy, History, or and more generally in the Humanities, is that of a text in which there are quotations from Greek or Latin authors, with references in footnotes, which contain Greek, or even Arabic, or any other language. It could be something like this sample: <br />
<br />
{{cmd|\blank}}{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.<br />
<br />
{{cmd|\noindent}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house".<\pre>}{{cmd|\inmargin{Platon, {\em Symposium}, 174a}.}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
Editing could certainly be improved. For example, put the Greek text on the left and its translation on the right on the same page, which would look something like this:<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
% Here below, the Greek text is on the left columns; the translation is on the right columns<br />
<br />
{{cmd|\startTwoColumns}}<br />
<br />
{{cmd|\quotation}}<br />
<br />
{Ἔφη γάρ οἱ Σωκράτη ἐντυχεῖν λελουμένον τε καὶ τὰς βλαύτας ὑποδεδεμένον, ἃ ἐκεῖνος ὀλιγάκις ἐποίει· καὶ ἐρέσθαι αὐτὸν ὅποι ἴοι οὕτω καλὸς γεγενημένος. καὶ τὸν εἰπεῖν ὅτι· Ἐπὶ δεῖπνον εἰς Ἀγάθωνος. χθὲς γὰρ αὐτὸν διέφυγον τοῖς ἐπινικίοις, φοβηθεὶς τὸν ὄχλον· ὡμολόγησα δ᾽ εἰς τήμερον παρέσεσθαι. ταῦτα δὴ ἐκαλλωπισάμην, ἵνα καλὸς παρὰ καλὸν ἴω}.\TwoColumns<br />
\quotation{I met Socrates," he said, "coming out of the bath with sandals on his feet, which is hardly his custom, and I asked him where he was going looking so good. He replied: "I'm going to Agathon's for dinner. Yesterday I avoided the party he gave in honour of his victory, because I was afraid of the crowds; but I promised to come the next day: that's why I dressed up; I wanted to look good so I could come to a good-looking man's house.}<br />
<br />
{{cmd|\stopTwoColumns}}<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\section}}{Éditing with \TeX : \ConTeXt — an alternative}<br />
<br />
Readers familiar with this type of language will have recognised from the previous paragraphs the brand name and technique used in the \TeX language. However, the use of this software relies on a fairly large set of declarations and it takes a great deal of practice to be able to play with, if not the power, at least the finesse of \LaTeX. There are a great many commands, and it is often necessary to refer to a manual to remember the subtleties that have made it possible to achieve a particular printed result. Of course, there is commercial software to help with professional publishing in the Humanities sector. But on the one hand they are not free and are relatively expensive for an individual, not to mention the cost of licences for professional groups of teachers and researchers.<br />
<br />
Given this state of affairs, we can turn to \ConTeXt, which is not an alternative to \LaTeX, but a more synthetic (or even more elegant) way of using \LaTeX. \ConTeXt, like \LaTeX, is a software suite which contains the macros of \LaTeX, the routines of the {\em Perl} language, as well as the macros of \LuaTeX. It is therefore possible to define just about everything that is required for professional publishing, without going into the technical knowledge of the \LaTeX language. Of course, there are a number of technical issues to be addressed if you want to work with this type of tool: for mathematicians, perfect presentation and editing of complex equations, diagrams and tables requires a fairly advanced apprenticeship. This is also true for users who come from the humanities, who know their field, and who want to write a simple document, a journal article, or even entire chapters of an academic work. Very often, it is the publishers who take care of the layout of the document you want to publish, based on a Word style sheet. But sometimes, if it is a dossier of several articles, or even an edition with financial support for publication, you would like to have control over the quality of the printed document.<br />
<br />
This is one of the reasons why you might want to control the editorial chain, not just to do without an editor, but to have an overview of your own work, or a collective work.<br />
<br />
{{cmd|\section}}{How to get Greek, Chinese and Arabic to coexist on the same page?}<br />
<br />
It is not a common habit to read in the same document text in English, in which we find a reference in Greek; for example, when in the {\em Timaeus}, Plato indicates that the most difficult thing is to begin with a beginning that is natural (κατὰ φύσιν ἀρχήν)\inmargin{Plato, {\em Timaeus}, 29b. }, an indication of the name of the Chinese philosopher Chouang Tseu (in {\em pinyin}\footnote{The {\em pinyin} (classical Chinese 漢語拼音, literally "to assemble the sounds of the language of the Han"), is a romanisation of the Chinese language, which is written in the Latin alphabet. So instead of writing 漢語拼音 (Zhuangzi, Tchouang Tseu) in traditional Chinese, or 汉语拼音 in simplified Chinese, we will write the name in Pīnyīn ({\em Hànyù Pīnyīn}), thus: Zhuangzi; and in classical and simplified Chinese: 莊周 or 庄周}), could add to this difficulty, given that \quotation{while most people understand the usefulness of what is useful, few understand the usefulness of what is useless}. Which is here below :<br />
<br />
{{cmd|\startnarrower}}[1*left,1*right]\tfx\setupinterlinespace<br />
<br />
惠子謂莊子曰。<br />
<br />
子言無用。莊子曰。<br />
<br />
知無用。而始可與言用矣。<br />
<br />
夫地。非不廣且大也。<br />
<br />
人之所用容足耳。<br />
<br />
然則廁足而墊之致黃泉。<br />
<br />
人尚有用乎。惠子曰。無用。莊子曰。<br />
<br />
然則無用之為用也亦明矣。<br />
<br />
{{cmd|\stopnarrower}}<br />
<br />
{{cmd|\quotation}}{Huizi said to Zhuangzi, “Your words are useless!”<br />
<br />
Zhuangzi said, “A man has to understand the useless before you can talk to him about the useful. The earth is certainly vast and broad, though a man uses no more of it than the area he puts his feet on. If, however, you were to dig away all the earth from around his feet until you reached the Yellow Springs, then would the man still be able to make use of it?”<br />
<br />
“No, it would be useless,” said Huizi.<br />
<br />
“It is obvious, then,” said Zhuangzi, “that the useless has its use.{{cmd|\footnote}}{{\em External Things}, Zhuangzi, trans. Burton Watson.}}<br />
<br />
We are certainly a long way from the thinking of the 10th century Arab philosopher Farabi. Farabi was a commentator on Plato's and Aristotle's philosophy; here we return to the beginning. Then we add to this throughout the text a reference to the Arabo-Persian philosopher Farabi\footnote{Al-Fārābī is named in medieval Arabic philosophy {\em the second master}: (ضابط), the first being Aristotle. } Al-Fārābī ( فارابي), a tenth-century Persian philosopher, by means of a clarification on Plato, and Aristotle (see his commentary on the {\em Peri Hermeneias}), entitled شرح الفارابي لكتاب أرسطوطاليس في العبارة / الفارابي] ; عني بنشره وقدم له ولهام كوتش وستانلي مارو\footnote{The Aristotle's text Περὶ Ἑρμηνείας ({\em peri hermeneias}) is one of the work named {\em Organon}. It his the second work of the {\em Organon}, and well-known because of its Chapter 9, on the {\em future contingents}. } with indications on his name in Arabic, we will have come round to some of the difficulties that present themselves to those who would like to carefully establish somewhat demanding documents.<br />
<br />
<br />
% Here the conclusion is within a frame<br />
<br />
{{cmd|\showframe}}<br />
<br />
{{cmd|\startMyFrame}}[Title=Conclusion]<br />
<br />
To edit a complex text, with several non-Romanic languages used occasionally, you can use \ConTeXt. This appears to be a wise choice: for mathematicians, presenting and editing complex equations, diagrams and tables in the best possible way requires a fairly extensive learning curve, which can be solved by a number of macros that automate the tasks. The code is reusable, and this is also true for users who come from the multiple horizons of the {\em Humanities}, who know their area of expertise and want to write a simple document, a magazine article, or even entire chapters of a book.<br />
<br />
{{cmd|\stopMyFrame}}<br />
<br />
{{cmd|\stoptext}}</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=User:Adeimantos&diff=34221
User:Adeimantos
2023-09-25T18:05:11Z
<p>Adeimantos: Created page with "I can't remember how long it's been since I learned the basics of ConTeXt: around 2015, more or less. I needed to write texts containing ancient Greek and their translations...."</p>
<hr />
<div>I can't remember how long it's been since I learned the basics of ConTeXt: around 2015, more or less. I needed to write texts containing ancient Greek and their translations. I'd already worked a bit with LaTeX. ConTeXt was an extraordinary discovery for me because of the power and precision of this tool, with which you can do almost anything on a page. I'm a philosophy teacher and I live in the middle of France. And I'm still a beginner with ConTeXt ...</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Greek&diff=34220
Greek
2023-09-25T17:49:19Z
<p>Adeimantos: Change \definebodyfontenvironment[36] into \definebodyfontenvironment[24] as shows the code.</p>
<hr />
<div>{{todo|Please add fonts that contain polytonic Greek to the last section!}}<br />
<br />
= Introduction =<br />
<br />
Historically, the development of Greek language can be divided in:<br />
<br />
* Ancient and Medieval Greek (–1453): language identifier is <code>grc</code>.<br />
* Modern Greek (1453–): language identifiers are <code>ell</code>, <code>ell</code> or <code>gre</code><br />
<br />
This is different from the main two ways of writing Greek:<br />
<br />
* Monotonic (or single–accented): diacritical marks are only the acute accent (or simply the accent) and the diairesis.<br />
* Polytonic (or multiple–accented): diacritical marks are three accents (acute, grave and circumflex) and two breathings (rough and smooth).<br />
<br />
After a long development,<ref>For historical background, see https://en.wikipedia.org/wiki/Greek_language_question. This reference contains the recommendation for the [https://de.wikipedia.org/wiki/Griechische_Sprachfrage article from the German ''Wikipedia''].</ref> monotonic orthography became law in 1982.<ref>See Law 1228/1982 and Decree 297/1982. Both legatl texts were written with polytonic orthography, but they contain the provisions for the monotonic system.</ref> Greek was polytonic before and ancient Greek is polytonic because it was before 1982.<ref>Just in case you may wonder, this is independent from the popular (δημοτική) v. purified (καθαρέυουσα) dispute for Greek language. See Law 309/1976. The legal text was written in the purified Greek, but it ordered the popular Greek to be the official language.</ref> This means that polytonic Greek is not only ancient Greek, since the main part of modern Greek was polytonic.<br />
<br />
=Sample=<br />
<br />
Here is a minimal sample to start with:<br />
<br />
<context source="yes"><br />
\setuplanguage[en][patterns={en, agr}]<br />
\definefallbackfamily<br />
[mainface]<br />
[rm]<br />
[Gentium]<br />
[preset=range:greek,<br />
force=yes]<br />
<br />
\definefontfamily<br />
[mainface]<br />
[rm]<br />
[TeX Gyre Pagella]<br />
<br />
\definebodyfontenvironment[24pt]<br />
<br />
\setupbodyfont[mainface, 24pt]<br />
<br />
\starttext<br />
\startTEXpage[pagestate=start, offset=1em, width=15em, align=middle]<br />
«χαλεπὰ τὰ καλά» is Greek for “beauty is hard”<br />
\stopTEXpage<br />
\stoptext<br />
</context><br />
<br />
{{cmd|definebodyfontenvironment|[24pt]}} is only required to display the font in the wiki. You may not pay attention to it.<br />
<br />
As it happens with texts with mixed scripts, the font family used for the Latin script may be well missing the required glyphs for the Greek script.<br />
<br />
{{cmd|definefallbackfamily}} provides a fallback typeface for certain scripts (or even characters).<br />
<br />
* It requires a range of characters for the fallback (here as a preset, that equals to <code>range:greek</code><ref>It may look tricky, but the whole preset is <code>range:greek</code>, so the whole option reads <code>preset=range:greek</code> (<code>preset</code> is the key name and <code>range:greek</code> is one of its values).</ref>).<br />
* <code>force=yes</code> would be required to avoid mixing some glyphs that the main typeface might have (such as <code>μ</code>, <code>ν</code> or <code>π</code> in Greek) and the rest of the glyphs from the fallback font.<ref>To give an idea of the poor impression this makes:<context source="yes">\setuplanguage[en][patterns={en, agr}]<br />
\definefallbackfamily<br />
[mainface]<br />
[rm]<br />
[Gentium]<br />
[preset=range:greek]<br />
<br />
\definefontfamily<br />
[mainface]<br />
[rm]<br />
[TeX Gyre Pagella]<br />
<br />
\definebodyfontenvironment[24pt]<br />
<br />
\setupbodyfont[mainface, 24pt]<br />
<br />
\starttext<br />
\startTEXpage[pagestate=start, offset=1em, width=15em, align=middle]<br />
«χαλεπὰ τὰ καλά» is Greek for “beauty is hard”<br />
\stopTEXpage<br />
\stoptext</context></ref><br />
<br />
===Mixed Hyphenation Patterns===<br />
<br />
As you might have already noticed, {{cmd|setuplanguage}} is loading for US English (the default language in TeX) patterns for both US English and ancient Greek.<br />
<br />
There are some considerations in how this works:<br />
<br />
# Basically, each language has a different script, so mixing patterns has no problem. Each script is handled only by a set of hyphenation patterns.<br />
# Other hyphenation patterns might be added (as <code>uk</code> for Ukranian)<ref>Hyphenation patterns for British English are <code>gb</code>.</ref>, since Cyrillic is a different script from Latin and Greek (and it is only used to hyphenate a single language).<br />
# This avoids marking the Greek fragments in the text with its proper language.<br />
# This doesn’t work when having mixed ancient Greek and contemporary Greek fragments (because two different hyphenation patterns would be needed for the same script).<br />
# All other options determined by {{cmd|setuplanguage}} will be the ones from the main language, not the ones for Greek (in this case. Among others, these affect to the minimum number of characters to hyphenate a word (at the end of the line and at the beginning of the new line).<br />
# This approach only applies proper hyphenation patterns to Greek. In order to have all other options related to the language, marking with {{cmd|agr}} (or {{cmd|gr}} in the case of contemporary Greek) is required.<br />
<br />
With this sample in mind, there are other considerations that may help when dealing with Greek in computers (and with ConTeXt). <br />
<br />
=Unicode=<br />
<br />
Monotonic Greek needs the characters from the [https://en.wikipedia.org/wiki/Greek_and_Coptic “Greek and Coptic” Unicode block] (only the Greek part of it, not the Coptic part).<br />
<br />
Polytonic Greek also needs the characters from the [https://en.wikipedia.org/wiki/Greek_Extended “Greek Extended” Unicode block].<br />
<br />
All you need is to choose the proper font that contains the characters you require.<br />
<br />
Just in case you wonder, there are much more fonts that contain glyphs for monotonic Greek that for polytonic Greek.<br />
<br />
==Monotonic and Acute Accent==<br />
<br />
Although the monotonic accent was acute, Unicode defines a pair of characters for monotonic accented vowels and polytonic acute accented vowels (both uppercase and lowercase and with diairesis).<br />
<br />
These are the different characters in lowercase:<br />
<br />
<pre><br />
ά έ ή ί ΐ ό ύ ΰ ώ<br />
ά έ ή ί ΐ ό ύ ΰ ώ<br />
</pre><br />
<br />
In theory, both characters should have the same glyphs (they should be exactly the same strokes). In practice, this is not always the case, since the monotonic accent has been drawn as (almost) a vertical stroke.<br />
<br />
The acute accent should mirror the grave accent (it is mainly its horizontal flip). Although acute accented vowels in polytonic Greek could be taken from the Greek and Coptic Unicode block, acute–accented vowels from the polytonic block may be required (because of the mismatch between the monotonic accent and the grave accent).<br />
<br />
The following source displays the differences for each character with both accents (uppercase and lowercase characters):<ref>Of course, you should replace <code>Minion Pro</code> with the name of the font you want to test.</ref><br />
<br />
<texcode><br />
\definefontfamily[mainface][rm][Minion Pro]<br />
\setupbodyfont[mainface]<br />
\definecolor [tred] [r=1,t=.5,a=1]<br />
\definecolor [tblue] [b=1,t=.25,a=1]<br />
\unexpanded\def\tonosoxia[#1][#2]<br />
{\startTEXpage[pagestate=start, offset=1ex]<br />
\startoverlay<br />
{\color[tred]{#1}}<br />
{\color[tblue]{#2}}<br />
\stopoverlay<br />
\stopTEXpage}<br />
\starttext<br />
\tonosoxia[Ά][Ά]<br />
\tonosoxia[Έ][Έ]<br />
\tonosoxia[Ή][Ή]<br />
\tonosoxia[Ί][Ί]<br />
\tonosoxia[Ό][Ό]<br />
\tonosoxia[Ύ][Ύ]<br />
\tonosoxia[Ώ][Ώ]<br />
\tonosoxia[ά][ά]<br />
\tonosoxia[έ][έ]<br />
\tonosoxia[ή][ή]<br />
\tonosoxia[ί][ί]<br />
\tonosoxia[ΐ][ΐ]<br />
\tonosoxia[ό][ό]<br />
\tonosoxia[ύ][ύ]<br />
\tonosoxia[ΰ][ΰ]<br />
\tonosoxia[ώ][ώ]<br />
\stoptext<br />
</texcode><br />
<br />
Depending on your operative system and your keyboard layout for polytonic Greek, it might be that it composes the acute with the monotonic accent (as it seems to happen in ''Linux'').<br />
<br />
A workaround to avoid this would be the following:<ref>Although the ConTeXt distribution seems to include the ''EB Garamond'' font family, it is probably not included in the wiki.</ref><br />
<br />
<context source="yes">\startluacode<br />
fonts.handlers.otf.addfeature {<br />
name = "tonosoxia",<br />
type = "substitution",<br />
data = {<br />
Alphatonos = "Ά",<br />
Epsilontonos = "Έ",<br />
Etatonos = "Ή",<br />
Iotatonos = "Ί",<br />
Omicrontonos = "Ό",<br />
Omegatonos = "Ώ",<br />
Upsilontonos = "Ύ",<br />
alphatonos = "ά",<br />
epsilontonos = "έ",<br />
etatonos = "ή",<br />
iotatonos = "ί",<br />
iotadieresistonos = "ΐ",<br />
omicrontonos = "ό",<br />
omegatonos = "ώ",<br />
upsilontonos = "ύ",<br />
upsilondieresistonos = "ΰ"<br />
},<br />
}<br />
\stopluacode<br />
<br />
\definefontfeature[tonosoxia][tonosoxia=yes]<br />
<br />
\definefontfamily<br />
[mainface]<br />
[rm]<br />
[EB Garamond]<br />
[features={default, tonosoxia}]<br />
<br />
\setupbodyfont[mainface, 24pt]<br />
<br />
\startTEXpage[offset=1em]<br />
χαλεπὰ τὰ καλά\\<br />
\feature[-][tonosoxia]<br />
χαλεπὰ τὰ καλά\\<br />
\stopTEXpage<br />
</context><br />
<br />
The sample above should display the difference between the more straight monotonic accent on the second line, and the proper acute accent.<br />
<br />
==On “Character Normalization”==<br />
<br />
Depending on your search, it might be that searching for <code>u</code>, results might include <code>ú</code> <code>ů</code>, <code>ü</code> or any character composed from <code>u</code> and any diacritical mark. Depending on the language, these “normalizations” may belong to the same letter or not (for example, <code>u</code> and <code>ü</code> are the same letter in Spanish, but two different ones in German).<br />
<br />
This doesn’t only affects to letters: <code>,</code> and <code>‚</code> are the characters for the comma and the opening single–quotation mark (used in some languages, such as German), respectively. At least, ''Firefox'' only displays the occurrences for each character when the option to match diacritics is selected (otherwise, each character displays both occurrences for commas and these opening single–quotation marks).<br />
<br />
At least in ''Linux'' (using ''Firefox''), the option to match diacritics doesn’t distinguish between monotonic and acute accented vowels. In other operative systems and using other programs, results might differ.<br />
<br />
=Ancient Greek=<br />
<br />
{{cmd|agr}} or {{cmd|ancientgreek}} are the values for ancient Greek hyphenation patterns.<br />
<br />
A minimal sample would read:<br />
<br />
<context source="yes"><br />
\mainlanguage[agr]<br />
\setupbodyfont[dejavu]<br />
\startTEXpage[offset=3em]<br />
\input aristotle-grc<br />
\stopTEXpage<br />
</context><br />
<br />
=Monotonic Greek=<br />
<br />
Either as {{cmd|mainlanguage}} or {{cmd|language}}, right values are <code>gr</code> or <code>greek</code>.<br />
<br />
A minimal sample would read:<br />
<br />
<context source="yes"><br />
\mainlanguage[gr]<br />
\setupbodyfont[dejavu]<br />
\startTEXpage[offset=3em]<br />
Κάθε άνθρωπος δικαιούται να επικαλείται όλα τα δικαιώματα και όλες τις ελευθερίες που προκηρύσσει η παρούσα Διακήρυξη, χωρίς καμία απολύτως διάκριση, ειδικότερα ως προς τη φυλή, το χρώμα, το φύλο, τη γλώσσα, τις θρησκείες, τις πολιτικές ή οποιεσδήποτε άλλες πεποιθήσεις, την εθνική ή κοινωνική καταγωγή, την περιουσία, τη γέννηση ή οποιαδήποτε άλλη κατάσταση.<br />
<br />
Δεν θα μπορεί ακόμα να γίνεται καμία διάκριση εξαιτίας του πολιτικού, νομικού ή διεθνούς καθεστώτος της χώρας από την οποία προέρχεται κανείς, είτε πρόκειται για χώρα ή εδαφική περιοχή ανεξάρτητη, υπό κηδεμονία ή υπεξουσία, ή που βρίσκεται υπό οποιονδήποτε άλλον περιορισμό κυριαρχίας.<br />
\stopTEXpage<br />
</context><br />
<br />
=Modern Polytonic Greek?=<br />
<br />
Before 1982, Greek orthography was mainly polytonic. In fact, modern<ref>As historical term, modern refers to the period that begins after the Middle Ages.</ref> Greek orthography was mainly polytonic.<br />
<br />
Hyphenation rules for polytonic Greek differ from both ancient or monotonic Greek.<br />
<br />
TeX has hyphenation patterns for [http://mirror.ctan.org/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-grc.tex ancient Greek], [http://mirror.ctan.org/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-el-monoton.tex monotonic Greek] and [http://mirror.ctan.org/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-el-polyton.tex modern polytonic Greek].<br />
<br />
ConTeXt has patterns for ancient and monotonic Greek only.<br />
<br />
=Language–Dependent Commands=<br />
<br />
As of current latest (2023.01.15 14:04), language–dependent commands—such as {{cmd|currentdate}}—don’t work. Nobody seemed to need them—especially for current Greek. If you need them, please send a message to the mailing list to extend this.<br />
<br />
=Fonts=<br />
<br />
Since fonts with polytonic Greek also contain monotonic glyphs and fonts with polytonich glyphs are much more scarce, here are some fonts that contain polytonic Greek:<br />
<br />
* [https://greekfontsociety-gfs.gr/typefaces The Greek Font Society] publishes many high–quality Greek typefaces.<br />
* [https://github.com/notofonts/noto-fonts Noto Fonts] include extended Greek for Noto Serif, Noto Serif Display, Noto Sans and Noto Sans Mono.<br />
* [https://github.com/adobe-fonts/source-sans/releases/latest Source Sans 3] includes polytonic Greek.<br />
<br />
=Footnotes=<br />
<br />
[[Category:Old_Content]]<br />
[[Category:Languages]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34219
Use the fonts you want
2023-09-25T17:11:35Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
'''NOTE''' : In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of mtxrun.lua (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited; in this case <texcode>tex/texmf-fonts/fonts/</texcode>. Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in the directory : /home/johndoe/context/tex/texmf-linux64/bin):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
Now you can search for the font you've just installed.<br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34218
Use the fonts you want
2023-09-25T17:11:19Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
'''NOTE''':In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of mtxrun.lua (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited; in this case <texcode>tex/texmf-fonts/fonts/</texcode>. Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in the directory : /home/johndoe/context/tex/texmf-linux64/bin):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
Now you can search for the font you've just installed.<br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34217
Use the fonts you want
2023-09-25T17:06:48Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
NOTE:In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of mtxrun.lua (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited; in this case <texcode>tex/texmf-fonts/fonts/</texcode>. Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in the directory : /home/johndoe/context/tex/texmf-linux64/bin):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
Now you can search for the font you've just installed.<br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34216
Use the fonts you want
2023-09-25T17:04:08Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
NOTE:In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of mtxrun.lua (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited; in this case <texcode>tex/texmf-fonts/fonts/</texcode>. Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in <texcode>/home/johndoe/context/tex/texmf-linux64/bin</texcode>):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34215
Use the fonts you want
2023-09-25T17:03:13Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
NOTE:In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of mtxrun.lua (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited (in this case <texcode>tex/texmf-fonts/fonts/</texcode>). Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in <texcode>/home/johndoe/context/tex/texmf-linux64/bin</texcode>):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34214
Use the fonts you want
2023-09-25T17:02:21Z
<p>Adeimantos: </p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
NOTE:In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory. Here is the code of <texcode>mtxrun.lua</texcode> (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited (in this case <texcode>tex/texmf-fonts/fonts/</texcode>). Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in <texcode>/home/johndoe/context/tex/texmf-linux64/bin</texcode>):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=Use_the_fonts_you_want&diff=34213
Use the fonts you want
2023-09-25T17:00:25Z
<p>Adeimantos: added informations about the ConTeXt font cache</p>
<hr />
<div>= Fonts location on your computer =<br />
<br />
The first step is to declare the storage locations of the fonts you want ConTeXt to consider.<br />
<br />
Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]).<br />
* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ TeX Directory Structure].<br />
** it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.<br />
** People who handle a lot of fonts can be more structured by using<br />
*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.<br />
<br />
But it it's very likely that you also want to use the '''fonts already available on your Operating System''':<br />
;1. Specify where ConTeXt should looked for fonts, by setting the '''OSFONTDIR''' environment variable.<br />
:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code><br />
:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code><br />
:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code><br />
:* Add it to your .bashrc or shell equivalent to make the declaration permanent.<br />
;2. Run ConTeXt to index the files and the fonts :<br />
<texcode>mtxrun --generate<br />
mtxrun --script font --reload<br />
</texcode><br />
;3. Check by looking for the specific font you want to use next. A common example:<br />
<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode><br />
<br />
NOTE:In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font. <br />
<br />
In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</texcode> that automates the font search. If no value for OSFONTDIR is set, then <texcode>mtxrun.lua</texcode>. Here is the code of <texcode>mtxrun.lua</texcode> (given here as information) :<br />
<br />
<texcode><br />
do<br />
local osfontdir=osgetenv("OSFONTDIR")<br />
if osfontdir and osfontdir~="" then<br />
elseif osname=="windows" then<br />
ossetenv("OSFONTDIR","c:/windows/fonts//")<br />
elseif osname=="macosx" then<br />
ossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//")<br />
end<br />
end <br />
</texcode><br />
<br />
On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited (in this case <texcode>tex/texmf-fonts/fonts/</texcode>). Then you'll need to empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a GFS Didot, or Theano Didot font, for example).<br />
<br />
To empty the cache and regenerate it, enter the following command (in <texcode>/home/johndoe/context/tex/texmf-linux64/bin</texcode>):<br />
<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode><br />
<br />
<br />
<br />
<br />
<br />
<br />
Now, let's learn how to use them for typesetting.<br />
<br />
= Practical application #1 - Quick use of a new font =<br />
<br />
Let's take an example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. <br />
<br />
If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''.<br />
<br />
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).<br />
<br />
; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].<br />
:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.<br />
:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.<br />
:* Regenerate ConTeXt databases<br />
:** the file database: <code>mtxrun --generate</code><br />
:** the fonts database: <code>mtxrun --script font --reload</code><br />
<br />
; #2. Now you can check the ''fontname'' used to identify the fonts, <br />
:*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<br />
<texcode><br />
familyname weight style width variant fontname filename subfont fontweight<br />
<br />
notoserif bold normal normal normal notoserifbold NotoSerif-Bold.ttf<br />
notoserif bold italic normal normal notoserifbolditalic NotoSerif-BoldItalic.ttf<br />
notoserif normal italic normal normal notoserifitalic NotoSerif-Italic.ttf<br />
notoserif normal normal normal normal notoserif NotoSerif-Regular.ttf<br />
</texcode><br />
<br />
; #3. You are done! You can use the font anywhere in your input files with {{cmd|definedfont}} <br />
:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].<br />
<texcode><br />
\definedfont[name:notoserifbolditalic*default at 12 pt]<br />
The quick brown fox jumps over the lazy dog<br />
</texcode><br />
[[File:result_of_test_with_noto-serif_one.png]]<br />
<br />
= Practical application #2 - Use the different font variations =<br />
<br />
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. <br />
* That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.<br />
* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]]. <br />
<br />
<br />
; #1. Define a new typescript in your input file, with {{cmd|starttypescript}}.<br />
:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}}.<br />
:* In this example, the typescript is called "mynotoserif".<br />
:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
% \definefontsynonym[Human readable] [file:filename without extension]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #2. The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font-sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.<br />
:* It's good to add a fallback.<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif] % security: if not found==> back to defaults<br />
% \definefontsynonym[ConTeXt basics name] [Human readable] [features=default]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
; #4. You are done! Finally, we have the following input file:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
<br />
\setupbodyfont[mynotoserif]<br />
\setupbodyfont[12pt]<br />
{ The quick brown fox jumps over the lazy dog}\\<br />
{\it The quick brown fox jumps over the lazy dog}\\<br />
{\bf The quick brown fox jumps over the lazy dog}\\<br />
{\bi The quick brown fox jumps over the lazy dog}\\<br />
</texcode><br />
<br />
And it gives:<br />
<br />
[[File:result_of_test_with_noto-serif.png]]<br />
<br />
= Install your new typescript to use it anywhere =<br />
<br />
You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here, we remind the definition:<br />
<br />
<texcode><br />
\starttypescript [mynotoserif]<br />
\definefontsynonym[NotoSerif-Regular] [file:NotoSerif-Regular]<br />
\definefontsynonym[NotoSerif-Italic] [file:NotoSerif-Italic]<br />
\definefontsynonym[NotoSerif-Bold] [file:NotoSerif-Bold]<br />
\definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\setups[font:fallback:serif]<br />
\definefontsynonym[Serif] [NotoSerif-Regular] [features=default]<br />
\definefontsynonym[SerifItalic] [NotoSerif-Italic] [features=default]<br />
\definefontsynonym[SerifBold] [NotoSerif-Bold] [features=default]<br />
\definefontsynonym[SerifBoldItalic] [NotoSerif-BoldItalic] [features=default]<br />
\stoptypescript<br />
<br />
\starttypescript [mynotoserif]<br />
\definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]<br />
\stoptypescript<br />
</texcode><br />
<br />
<br />
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code><br />
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code><br />
# Run <code>context --generate</code> to update ConTeXt file database<br />
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:<br />
<texcode><br />
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename<br />
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface<br />
</texcode><br />
<br />
====Note:====<br />
<br />
The naming convention for typescript files has changed in LMTX<br />
<br />
<blockquote> <br />
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.<br />
<br />
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".<br />
<br />
Wolfgang [20 Dec 2020]<br />
</blockquote><br />
<br />
<br />
[[Category:Fonts]]</div>
Adeimantos
https://wiki.contextgarden.net/index.php?title=TEI_xml&diff=23432
TEI xml
2017-08-05T15:00:36Z
<p>Adeimantos: addrress of TEI by example modified</p>
<hr />
<div>== General ==<br />
<br />
TEI (Text Encoding Initiative) is "a consortium which collectively develops and maintains a standard for the representation of texts in digital form," to quote [http://www.tei-c.org/index.xml their own website]. They have developed a series of guidelines for editing texts in a digital form. In their latest form (which is called P 5), these guidelines weigh in at a hefty 1350 pages (OK, that's counting the bibliography and the index too; there are only 1290 pages of real text). These describe an xml format which is suitable for editing texts. The TEI guidelines have the advantage of being very well documented. There are a number of free resources available that should help everyone who is interested in getting started (one extremely helpful website with lots of tutorials, examples, and tests is [http://teibyexample.org TEI by example]). They are not (and do not aspire to be) an absolute standard that everyone has to follow, but many academic projects use these guidelines, and they should be a pretty good way to make sure that your electronic edition of a text will be useful in the future.<br />
<br />
Since editing texts is something which quite a few users of ConTeXt are involved in, it makes sense to think about ways in which xml documents which follow the TEI guidelines can be typeset with ConTeXt. We would invite users to keep a few caveats in mind: <br />
<br />
# The TEI guidelines are very detailed because they try to cater to a large number of needs. Most users will only need a small subset of the tags and attributes which the guidelines offer (in fact, TEI is aware of this and has a slimmed down version of their guidelines which is called [http://www.tei-c.org/Guidelines/Customization/Lite TEI Lite]. This is a very good starting place to familiarize yourself with TEI). It would not make sense to try and provide a monolithic solution that defines all TEI tags; instead, localized ConTeXt style sheets are necessary which will define a subset which is relevant for a number of texts with similar features.<br />
# Even with this huge number of tags, TEI does not expect to be sufficient for every text. Users are encouraged to develop their own styles; again, this necessitates special ConTeXt style sheets to process such adaptations.<br />
# Encoding and typesetting texts in xml is an ongoing process. As you go forward in your edition, you realize that you need more tags, that you need to distinguish more special cases, that you want to add more information to your edition. This means that you will have to go back and forth between your xml file and the ConTeXt style and adapt both to your needs. <br />
<br />
All of which means that the following paragraphs are just the first step in an ongoing attempt. I (Thomas) have written down a setup for a text that I am editing (for those who are interested: [http://www.livius.org/phi-php/philostratus/philostratus.htm#VS the ''Lives of the Sophists'' by Philostratus]). I fully expect this to be a community effort: as others use TEI xml, they will discover new ways of handling things, will want to add features or add examples for other sorts of texts. My example is meant to start the discussion. Since those who edit texts usually have a background in the humanities, not in programming, I have added lengthy comments which will explain every step.<br />
<br />
== Our xml file ==<br />
<br />
Philostratus's text is in ancient Greek, but since the text itself doesn't matter much when we talk about structure and typesetting xml, I have replaced it here with a simple lorem ipsum text that is easier to display. So here's what the first paragraphs of the xml file philostratus.xml look like:<br />
<br />
<xmlcode><br />
<?xml version="1.0"?><br />
<br />
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:lang="en"><br />
<teiHeader><br />
<fileDesc><br />
<titleStmt><br />
<title>Lives of the Sophists</title><br />
<author>Philostratus</author><br />
<respStmt><br />
<resp>editor</resp><br />
<name xml:id="TAS">Thomas</name><br />
</respStmt><br />
</titleStmt><br />
<publicationStmt><br />
<p>Work in progress</p><br />
</publicationStmt><br />
<sourceDesc><br />
<p>See indication of manuscripts</p><br />
</sourceDesc><br />
</fileDesc><br />
</teiHeader><br />
<text><br />
<front><br />
<div type="sigla"><br />
<listWit><br />
<witness id="c2">codd. 2</witness><br />
<witness id="Richards">Richards</witness><br />
</listWit><br />
</div><br />
<div type="work"><br />
<head type="main">Philostrati</head><br />
<head type="sub">Vitae Sophistarum.</head><br />
<opener><br />
<salute>Lorem <pb ed="Olearius" n="479"/>Ipsum</salute><br />
</opener><br />
</div><br />
</front><br />
<body><br />
<div xml:id="VS1" n="I" type="book"><br />
<div xml:id="VS1.1" n="1" type="chapter"><br />
<div xml:id="VS1.1.1" n="1" type="section"><br />
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed<br />
diam nonumy eirmod tempor invidunt<br />
<app><br />
<rdg wit="#Richards">induunt</rdg><br />
</app><br />
ut labore et dolore magna aliquyam erat, sed diam voluptua. At<br />
vero eos et accusam et justo duo dolores et ea rebum. Stet<br />
clita kasd gubergren<br />
<app><br />
<rdg wit="#c2">arrgl</rdg><br />
</app><br />
<pb ed="Olearius" n="480"/><br />
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem<br />
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam<br />
nonumy eirmod tempor invidunt.</p><br />
</div><br />
<div xml:id="VS1.1.2" n="2" rend="inline" type="section"><br />
<p>ut labore et dolore magna aliquyam erat, sed diam<br />
voluptua. <pb ed="Olearius" n="481"/> At vero eos et accusam et<br />
justo duo dolores et ea rebum. Stet clita kasd gubergren, no<br />
sea takimata sanctus est Lorem ipsum dolor sit amet.<br />
<lg><br />
<l>At vero eos et accusam et justo duo dolores</l><br />
</lg><br />
et<br />
<lg><br />
<l>ea rebum. Stet clita kasd gubergren, no sea takimata</l><br />
</lg><br />
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit<br />
amet</p><br />
</div><br />
<div xml:id="VS1.1.3" n="3" rend="paragraph" type="section"><br />
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate<br />
velit esse molestie consequat, vel illum dolore eu feugiat<br />
nulla facilisis at vero eros et accumsan et iusto odio<br />
dignissim qui blandit praesent luptatum zzril delenit augue<br />
duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit<br />
amet, consectetuer adipiscing elit, sed diam nonummy nibh<br />
euismod tincidunt ut laoreet dolore magna aliquam erat<br />
volutpat.</p><br />
</div><br />
</div><br />
</div><br />
</body><br />
</text><br />
</TEI><br />
</xmlcode><br />
<br />
So let's have a look at this file. This can be brief since most of the tags are described in the TEI guidelines and tutorials.<br />
<br />
Every TEI file has as its root level (i.e. the "outer" level of the xml file) the element <br />
<br />
<xmlcode><br />
<TEI><br />
<br />
</TEI><br />
</xmlcode><br />
<br />
which defines it as a TEI xml file. Everything else is a "child" of this root level. At the next level, you see two of these children: on the one hand, the <teiHeader> element. This contains meta-information about your electronic edition: title, author, editor, publication status, source of your edition. There can be much more information here. This is meta-information which will usually not be typeset in your edition.<br />
<br />
The other child is the <text> element. This is what will really be in a typeset, printed edition. As you see, the <text> element has again two children. The <front> contains the title of the work you edit in the form in which it will appear in your typeset document, prefatory material, etc. The <body> element contains the text itself. This text has a logical structure: It consists of books, chapters, and sections. All of these logical parts are expressed via different <code>&lt;div></code> elements; to distinguish them from each other, these <code>&lt;div></code> elements have so-called attributes, so we have:<br />
<br />
<xmlcode><br />
<div xml:id="VS1" n="I" type="book"><br />
<div xml:id="VS1.1" n="1" type="chapter"><br />
<div xml:id="VS1.1.1" n="1" type="section"><br />
</div><br />
</div><br />
</div><br />
</xmlcode><br />
<br />
As you can see, most of these "div" elements have other attributes as well: the "xml:id" attribute gives every section in your document a unique identifier. This makes it easier to refer to these sections later. You are free to choose these attributes; as an example, I have opted for a short numeric tag that refers to the paragraph. The "n" attribute is the name of the section as it will appear in your typeset edition. For classical prose texts, it is customary to have the chapter and section numbers appear in the margin of the edition, with no prefix and no additional information about the structure. E.g., at the beginning of chapter 8, there will be a bold '''8''' in the margin (the mark for "section 1" is understood and usually not expressed). For subsequent sections of chapter 8, there will be smaller section numbers in the margin, like "2," "3," etc. Finally, such sections of chapters do not necessarily begin a new paragraph. In order to make this clear, I have used the "rend" attribute (not exactly in the way TEI defines it, but close enough). For sections, I have two types of "rend" attributes: "inline" means that this section should just continue the typographical paragraph; "paragraph" means that it should begin in a new paragraph. This is an important distinction which I want to emphasize: in your typeset edition, these two will appear very different. For the '''logical''' structure of your digital text, however, they are both on the same level. That's why they are both "div" of the same type, but with different "rend" attributes.<br />
<br />
Further, we have <tt><pb></tt> elements. These are used to denote pagebreaks in standard editions, which are often used for reference purposes and displayed in the margin; in the case of the ''Lives of the Sophists'', this is the 18th-century edition of Olearius. These elements are inserted at the places where these pagebreaks occur.<br />
<br />
Finally, we have the critical apparatus. Its notes are included in <app> elements. Every single entry into the apparatus is within a <rdg> (= reading) element.<br />
<br />
This should be enough to get us started. We will now look at the way in which we will typeset such a xml document with ConTeXt.<br />
<br />
== The ConTeXt style file ==<br />
<br />
'''NB:''' Some of the functionality described here has been introduced quite recently. You will need a ConTeXt version not earlier than December 2010 in order to try this example!<br />
<br />
In order to typeset such a file with ConTeXt, we need a style file which will map xml elements and attributes to specific ConTeXt commands. We have to save this file (let's call it tei-style.tex) somewhere where ConTeXt can find it (e.g., somewhere in your personal texmf tree or in the same directory as the xml file) and then typeset with the command <tt>context --environment=tei-style philostratus.xml</tt>. We will look at this file in detail:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
We define a set of <code>\xmlsetups</code> in a <code>\start \stop</code> environment, and we give it a name in the namespace <tt>xml:</tt>. The first line of these setups does only one thing: the <code>\xmlsetsetup</code> operates on the current xml tree (that's what the first argument <code>{#1}</code> refers to), takes all its elements (<code>{*}</code>) and discards them (<code>{-}</code>). That means '''only''' elements which we address explicitly will be typeset. This is necessary in our case because we do not want the information in the TEI header to be typeset.<br />
<br />
For those elements we '''do''' want typeset, we have to add instructions. This involves a three-step process:<br />
<br />
# We have to add their names to a line which defines a <code>\xmlsetsetup</code><br />
# We define a specific setup for them<br />
# (optional) we define TeX commands for typesetting<br />
<br />
Let us begin with some easy steps. The xml tree we are operating on is empty now. So we first have to tell ConTeXt to pass the content of the topmost elements to its typesetting engine. The topmost element is TEI, so we write:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI}{xml:*}<br />
\stopxmlsetups<br />
<br />
\xmlregistersetup{xml:teisetups}<br />
<br />
\startxmlsetups xml:TEI<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
So: we add the <tt>TEI</tt> element to a new <code>\xmlsetsetup</code>. We "register" the setups we have defined. And then we declare that the content of the element <tt>TEI</tt> should be passed to ConTeXt; this is what the line <code>\xmlflush{#1}</code> does.<br />
<br />
Of course, we will do the same for the <tt>text</tt> element, but not for the <tt>TEIheader</tt> element, which we do not want to be typeset. So we now have:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI|text}{xml:*}<br />
\stopxmlsetups<br />
<br />
\xmlregistersetup{xml:teisetups}<br />
<br />
\startxmlsetups xml:TEI<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:text<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
Things become a bit more interesting when we look at the next level. We will start with the text proper, which is contained in the <tt>body</tt> element. For the text, we want line numbers in the margin, and we want these linenumbers in steps of five, in a small font. Here you can see the three steps we have to take:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI|text|body}{xml:*}<br />
\stopxmlsetups<br />
<br />
\xmlregistersetup{xml:teisetups}<br />
<br />
\startxmlsetups xml:TEI<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:text<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:body<br />
\startlinenumbering<br />
\xmlflush{#1}<br />
\stoplinenumbering<br />
\stopxmlsetups<br />
<br />
\setuplinenumbering[location=inner,<br />
step=5,<br />
method=page,<br />
style=\tfxx,<br />
align=left,<br />
distance=0.3em,<br />
width=0.3cm]<br />
<br />
</texcode><br />
<br />
So we have:<br />
<br />
# added the element <tt>body</tt> to our <code>\xmlsetsetup</code><br />
# added a specific setup for the element which puts its content within a <code>\startlinenumbering</code> environment <br />
# added ConTeXt setup commands for the <code>\startlinenumbering</code> environment.<br />
<br />
Things become even more interesting at the next level. When you look at our xml document, you will see that the entire body consists of different divisions in <tt>div</tt> elements; the different levels are distinguished by different <tt>type</tt> attributes. This means we cannot simply add the <tt>div</tt> element to our general <code>\xmlsetsetup</code>, but have to add a specific <code>\xmlsetsetup</code> for every type. Fortunately, ConTeXt makes it easy to address these different elements. We begin with the <tt>book</tt> level: (for clarity, I will now only show the new steps, not the entire style document):<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI|text|body}{xml:*}<br />
\xmlsetsetup{#1}{div[@type='book']}{xml:div:book}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:div:book<br />
\blank[line]\midaligned{\xmlatt{#1}{n}}\blank[medium]<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
What happens here? The expression <code>div[@type='book']</code> means "every element div which has an attribute 'type' with the value 'book.'" We want a blank line before the title of the book. Then, we take the value of the <tt>n</tt> attribute (that's what the construct <code>\xmlatt{#1}{n}</code> expands to: the value of the attribute <tt>n</tt> of the current tag) and typeset it midaligned. We add another, smaller blank. And don't forget to "flush" the content of the <tt>div</tt> element!<br />
<br />
For the next level, the <tt>chapter</tt>, we need again three steps: add it to the <code>\xmlsetsetup</code>, define a setup command and a ConTeXt macro for it:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI|text|body}{xml:*}<br />
\xmlsetsetup{#1}{div[@type='chapter']}{xml:div:chapter}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:div:chapter<br />
\PhilSection{\xmlatt{#1}{n}}<br />
\xmlflush{#1}<br />
\par<br />
\stopxmlsetups<br />
<br />
\defineinmargin [PhilSection] [outer] [normal] [distance=0.3em,style=\tfa\bf]<br />
</texcode><br />
<br />
So: here, the argument of the <tt>n</tt> attribute is passed to a ConTeXt<br />
macro <code>\PhilSection</code>. This macro is defined as an<br />
<code>\inmargin</code> which will be typeset in the outer margin, in a<br />
bigger, bold font. This will be the "chapter" numbering in the outer<br />
margin.<br />
<br />
For the section numbering, we take a similar approach, but as you will see,<br />
we need to define even more different setups:<br />
<br />
<texcode><br />
\startxmlsetups xml:teisetups<br />
\xmlsetsetup{#1}{*}{-}<br />
\xmlsetsetup{#1}{TEI|text|body}{xml:*}<br />
\xmlsetsetup{#1}{div[@type='section']}{xml:div:section}<br />
\stopxmlsetups<br />
<br />
\startxmlsetups xml:div:section<br />
\doifelse<br />
{\xmlatt{#1}{n}}<br />
{1}<br />
{\xmlflush{#1}}<br />
{\doifelse<br />
{\xmlatt{#1}{rend}}<br />
{paragraph}<br />
{\par\PhilSubsection{\xmlatt{#1}{n}}\xmlflush{#1}}<br />
{\PhilSubsection{\xmlatt{#1}{n}}\xmlflush{#1}}}<br />
\stopxmlsetups<br />
<br />
\defineinmargin [PhilSubsection] [outer] [normal] [distance=0.3em,style=normal]<br />
</texcode><br />
<br />
Here, we define a setup for the section level which contains two further<br />
tests, for which we use ConTeXt's <code>\doifelse</code> macro. The first<br />
<code>\doifelse</code> tests if the value of the <tt>n</tt> attribute is<br />
"1," i.e., if this is the first section in a chapter. If it is, it does<br />
nothing more than "flush" the content of this section -- remember, the<br />
number for the first section should not appear in the margin since it is<br />
implied in the chapter number. It's still good to have this number -- if<br />
you ever decide that your typeset output should look different, the<br />
information is there and can be shown. But for the time being, we do not<br />
want it to appear, and that's what the first condition does. If the<br />
<tt>n</tt> attribute's value '''isn't''' 1, another test is performed; this<br />
time, we look at the value of the <tt>rend</tt> attribute. If this<br />
attribute has the value "paragraph," we insert a <code>\par</code>, pass<br />
the value of the <tt>n</tt> attribute to the macro<br />
<code>\PhilSubsection</code>, and "flush" the content of our section. If<br />
the value is anything else (i.e., "inline"), we flush the content without<br />
inserting a <code>\par</code>. Then, we define <code>\PhilSubsection</code><br />
as another <code>\inmargin</code>, which will appear in the outer margin,<br />
at the same place as the chapter numbering, but in a normal font. Finally,<br />
when you look at the main text, you will see that we now have defined<br />
setups for books, chapters, sections, but not yet for the smallest element,<br />
<tt>p</tt>. Remember: we don't want paragraph breaks for these elements, so<br />
all we need to do is "flush" them. Which means: we add the <tt>p</tt><br />
element to the list:<br />
<br />
<texcode><br />
\xmlsetsetup{#1}{TEI|text|body|p}{xml:*}<br />
</texcode><br />
<br />
and the appropriate setup is:<br />
<br />
<texcode><br />
\startxmlsetups xml:p<br />
\xmlflush{#1}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
And that's it! This is our structure for the main text! If you typeset the<br />
xml file with this setup, you get text with marginal numbering for your<br />
chapters and sections.<br />
<br />
We now add the bells and whistles. We begin with the Olearius pagebreaks,<br />
the <tt><pb></tt> elements. If you've followed so far, this should be<br />
easy. As you see, these elements contain a reference to the relevant<br />
edition (the <tt>ed=</tt> attribute) and the pagenumber. If we had more<br />
elements of this type, it would make sense to define a <tt>setsetup</tt><br />
for every one of them. In the case of Philostratus, we will probably only<br />
have Olearius, so we just add them to our list:<br />
<br />
<texcode><br />
\xmlsetsetup{#1}{TEI|text|body|p|pb}{xml:*}<br />
</texcode><br />
<br />
and add both the setup for the xml element and a new definition for a<br />
marginal text (since we're a bit paranoid, we still test whether the<br />
<tt>xmlattribute ed</tt> is set to <tt>Olearius</tt>). Since I want the<br />
Olearius numbers in square brackets, I needed to take a two-step approach<br />
(the square brackets would be confusing to the ConTeXt parser). So I first<br />
define an inmargin <code>\Zolearius</code> and then a macro<br />
<code>\Olearius</code> which takes this value and typesets it within square<br />
brackets, in the outer margin, at a distance of 2em from the main text:<br />
<br />
<texcode><br />
\startxmlsetups xml:pb<br />
\doifelse<br />
{\xmlatt{#1}{ed}}<br />
{Olearius}<br />
{\Olearius{\xmlatt{#1}{n}}}<br />
{}<br />
\stopxmlsetups<br />
<br />
\defineinmargin [ZOlearius] [outer] [normal] [distance=2em,style=small]<br />
<br />
\define[1]\Olearius%<br />
{\ZOlearius{[#1]}}<br />
</texcode><br />
<br />
[[User:Thomas|Thomas]] 21:38, 7 November 2010 (UTC)<br />
<br />
== Removing unwanted strings from xml source ==<br />
<br />
In some cases you might want to remove strings or characters from the xml source. For example ConTeXt cannot process a hashmark. The following example shows how to remove the hashmark from a xml identifier before processing with the command \cldcontext<br />
<br />
The xml source:<br />
<br />
<xmlcode><br />
<a href="#myspecialid">the previous section</a><br />
</xmlcode><br />
<br />
The setup code:<br />
<br />
<texcode><br />
\startxmlsetups xml:initialize<br />
\xmlsetsetup{#1}{a}{xml:*}<br />
\stopxmlsetups<br />
<br />
\xmlregistersetup{xml:initialize}<br />
<br />
\startxmlsetups xml:a<br />
\cldcontext{string.sub([[\xmlatt{#1}{href}]],2)}<br />
\stopxmlsetups<br />
</texcode><br />
<br />
{{Getting started navbox}}<br />
<br />
[[Category:XML]]</div>
Adeimantos