Looking for ConTeXt examples
Here is a real-world example. I am an academic and I write my grant proposals using ConTeXt. The formatting guidelines are relatively simple (use this font, set these margins, and that's about it). I usually submit to two funding agencies, FRQNT and NSERC, and they have slightly different formatting instructions. Occasionally, I also write a generic proposal that is submitted to other agencies.
I have a private module p-proposal
to take care of the different formatting requirements. Since this was for personal use, most of it was undocumented. I have added brief explanations in the comments; if something doesn't make sense, feel free to ask:
\startmodule proposal
\setupmodule[size=10pt, alternative=default]
\processaction
[\currentmoduleparameter{alternative}]
[
default=>{\enablemode[compact]},
frqnt=>{\enablemode[frqnt]},
nserc=>{\enablemode[nserc]},
]
% Grants to FRQNT should be in 10bp.
\startmode[frqnt]
\setupmodule[site=10bp]
\stopmode
% Grants to NSERC should be in 12pt.
\startmode[nserc]
\setupmodule[size=12pt]
\stopmode
% Enable microtype protrusion.
\definefontfeature
[default]
[default]
[protrusion=quality,expansion=quality]
\setupalign[hanging,tolerant]
% Most grant agencies want Times. Use MS Times rather than
% some other clone like Termes; I once had a grant application
% returned because pdffonts didn't list Times!
\usetypescriptfile[mscore]
\usetypescriptfile[texgyre]
\usetypescriptfile[euler]
\starttypescript[mainface]
\definetypeface [mainface][rm][serif][mscoretimes][default]
\definetypeface [mainface][ss][sans] [helvetica][default] [rscale=auto]
\definetypeface [mainface][tt][mono] [modern] [default] [rscale=auto]
\definetypeface [mainface][mm][math] [pagellaovereuler] [default]
[rscale=0.9]
\stoptypescript
% I tend to use math sparingly, therefore the math font is Euler.
% Set all math characters to be upright rather than italic.
\setupmathematics[default=normal, lcgreek=normal, ucgreek=normal]
% I don't like Euler bullets (when used in itemize); take bullets
% from the text font instead.
\setupsymbolset[text]
% MS Times does not have small caps. The headers are typeset in small caps.
% So, use Termes for headers.
\starttypescript[headerface]
\definetypeface [headerface][rm][serif][termes][default]
\definetypeface [headerface][ss][sans] [helvetica][default] [rscale=auto]
\definetypeface [headerface][tt][mono] [modern] [default] [rscale=auto]
\definetypeface [headerface][mm][math] [pagellaovereuler] [default] [rscale=auto]
\stoptypescript
\setupbodyfont[headerface] % To initialize the header font globally
\setupbodyfont[mainface,\currentmoduleparameter{size}]
% \em should be italic rather than slanted.
\definebodyfontenvironment[default][em=italic]
% Many funding agencies cannot handle a higher PDF version, sigh!
\pdfminorversion 4
\setuppapersize[letter][letter]
\setuplayout[
width=middle,
height=middle,
location=middle,
topspace=0.75in,
bottomspace=0.75in,
bottom=0.25in,
backspace=1in,
cutspace=1in,
leftmargin=.45in,
rightmargin=.45in,
leftmargindistance=0.05in,
rightmargindistance=0.05in,
header=0.20in,
footer=0.20in,
headerdistance=0.05in,
footerdistance=0.05in,
]
\startmode[compact,frqnt, nserc]
\setuplayout
[
topspace=0.5in, bottomspace=0.5in,
backspace=0.75in, cutspace=0.75in, width=middle,
footer=0pt, footerdistance=0pt,
]
\stopmode
\startmode[frqnt,nserc]
\setupinterlinespace[line=12.25bp]
\stopmode
\setuppagenumbering[location=]
\setupheader[style={\switchtobodyfont[headerface]\sc}]
\setupfooter[style={\switchtobodyfont[headerface]\sc}]
\setupbottom[style={\switchtobodyfont[headerface]\sc}]
\setupbackgrounds[header][text][bottomframe=on]
\startmode[compact]
\setuphead[section,subject]
[number=no, style=bold, alternative=text,before={\blank[small]},distance=0.25em,after=]
\def\deepstructuretitlecommand#1{#1:}
\stopmode
\setuphead[title][alternative=middle, style=\ssbfb]
\startnotmode[compact]
\setuphead[section,subject]
[style=\ssbfa, before={\blank[big]}, after={\blank[medium]}]
\setuphead[subsection,subsubject]
[style=\ssbf, before={\blank[medium]}, after={\blank[small]}]
\stopnotmode
\startmode[frqnt, nserc]
\setuphead[section,subject]
[style=\bfa,before={\blank[small]}, after={\blank[none]}]
\setuphead[subsection,subsubsection]
[style=\bf,%alternative=text,
deeptextcommand=\groupedcommand{}{\removeunwantedspaces:},
distance=1ex,
before={\blank[small]}]
\setuphead[subsection,subsubsection, subsubsubsection, subsubject]
[style=\bf,alternative=text,
deeptextcommand=\groupedcommand{}{\removeunwantedspaces:},
distance=1ex,
before={\blank[small]}]
\stopmode
% Be more linient with hyphenation.
\definebreakpoint [compound] [-] [nleft=2,nright=2]
\setbreakpoints [compound]
\setupindenting[medium,yes]
\setupwhitespace[none]
\setupblank[halfline]
\startmode[compact]
\setupitemize[nowhite]
\setupitemize[margin=2em]
\stopmode
\definehighlight[important][style=bolditalic]
\definecolor[lightyellow][r=1,g=1,b=0.88]
\setupframedtext
[
width=broad,
offset=5bp,
align={hanging,hz},
background={color},
backgroundcolor=lightyellow,
rulethickness=1bp,
frame=on,
framecolor=black,
]
\setupitemize[autointro, broad, fit]
\setupitemize[distance=0.5em, indentnext=auto]
\definetabulate[titletabulate][|k0lB|i1p|]
\setuptabulate[titletabulate][unit=0.25em]
\setupcaptions[style={\small\setupinterlinespace}, distance=0.5em]
\setupfloats[sidespaceafter=0pt]
\setupformula
[
spacebefore={nowhite,fixed,quarterline},
spaceafter={back,fixed,nowhite,halfline},
]
\stopmodule
To show the output, I use the following test file:
% Change the alternative for different results
\usemodule[proposal][alternative=default]
% The header should be the title of the grant and the PIN of the PI
\startmode[nserc,frqnt]
\setupheadertexts[\fakewords{3}{4}][PIN: 12345]
\stopmode
\usemodule[visual]
\starttext
%In the generic proposal, the title is given at the top
\startnotmode[frqnt,nserc]
\starttitletabulate
\NC Project \NC \fakewords{5}{10} \NC \NR
\NC Investigators \NC \fakewords{3}{5} \NC \NR
\stoptitletabulate
\stopnotmode
\dorecurse{6}
{\section{\fakewords{3}{7}}
\dorecurse{2}
{\fakewords{100}{200}\endgraf
\placefigure[left]{\fakewords{4}{8}}{\fakeimage{4cm}{3cm}{5cm}{6cm}}
\dorecurse{2}{\fakewords{100}{200}\endgraf}}}
\stoptext
With alternative=frqnt
the output is
With alternative=nserc
the output is almost the same but uses a bigger font:
With alternative=default
, the output is:
Here is mine.
It's still a work in progress , i'm managing to put a header in arabic/french with a logo using \framed
\setuppapersize[A4]
\mainlanguage[fr]
\usemodule[chart]
%\setuplayout[backspace=3.5cm,width=14cm]
\usesymbols[fontawesome]
\setuppagenumbering[alternative=doublesided,location=]
%\setupheader[text][after=\hrule]
%\setupheadertexts[]
%\setupheadertexts[\setups{text a}][][\setups{text b}][]
%\startsetups[text a]
% \hskip-1.5cm
% \framed[frame=off,width=17cm,offset=none]{
% \rlap{Cardiologie}
% \hfill
% {\darkred \ss Clinique EL ABRAR}
% \hfill
% \llap{\pagenumber}}
%\stopsetups
%\startsetups[text b]
% \hskip-1.5cm
% \framed[frame=off,width=17cm,offset=none]{
% \rlap{\tfxx \ss 15 Rue Tolozane Les Palmiers, Oran}
% \hfill
% {Clinique EL ABRAR}
% \hfill
% \llap{\pagenumber}}
%\stopsetups
\definecolor[abrar][r=0.02,g=0.49,b=0.52]
\definefontfeature[default][default][onum=yes]
%\definefallbackfamily [texgyre] [serif] [amiriregular] [range=arabic]
%\define[1]\Arab{\setuplayout[r2l] \texgyre#1}
\definefontfamily[texgyre][serif][merriweather]
\definefontfamily[texgyre][sans] [merriweathersans]
\definefontfamily[texgyre][mono] [TeX Gyre Cursor][features=none]
\definefontfamily[texgyre][math] [TeX Gyre Pagella Math]
\setupbodyfont[texgyre,11pt]
\setupfootertexts[\tfx Rapport médical --- Page \currentpage\ de \lastpage --- Le \currentdate]
\setuphead[subject][color=abrar,style=\ssb \bf]
\setuphead[subsubject][color=abrar, style=\ss\tfb\bi]
\edef\defaultlineheight{\the\lineheight}
\startMPdefinitions
newpath basicShape;
basicShape := unitsquare ;
DefaultLineHeight := \defaultlineheight;
\stopMPdefinitions
\startuseMPgraphic {unnumberedbullet}
fill basicShape scaled OverlayWidth shifted (0, 0.5*LineHeight)
withcolor \MPcolor{darkred};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\startuseMPgraphic {numberedbullet}
fill basicShape xyscaled (0.9*DefaultLineHeight, 0.9*DefaultLineHeight)
shifted (-0.5(0.9*DefaultLineHeight - OverlayWidth, 0))
withcolor \MPcolor{abrar};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\defineoverlay[unnumberedbullet][\useMPgraphic{unnumberedbullet}]
\defineframed [unnumberedbullet]
[
frame=off,
width=0.5\bodyfontsize,
background=unnumberedbullet,
location=low,
]
\definesymbol[unnumberedbullet]
[{\unnumberedbullet{}}]
\defineoverlay[numberedbullet][\useMPgraphic{numberedbullet}]
\defineframed [numberedbullet]
[
frame=off,
width=\lineheight,
background=numberedbullet,
foregroundcolor=white,
% Center the number against capital letters, ignoring character descent
location=depth,
foregroundstyle={\small\small}, % better to define a custom fontswitch
]
\definesymbol[numberedbullet]
[{\numberedbullet{\currentitemnumber}}]
\defineframedtext[cadrevert]
[background=screen,backgroundscreen=.85,
width=0.9\textwidth,
frame=off,
leftframe=on,
framecolor=darkred,
rulethickness=3pt]
\usemodule[symb-imp-fontawesome]
\usesymbols[fontawesome]
\setupbodyfont[10pt]
%%%%%
\starttext
\startalignment[middle]
\dontleavehmode
\framed
[background=color,backgroundcolor=darkred,
backgroundoffset=5pt,corner=0,frame=0,
foreground=color,foregroundcolor=white]
{\ssc \bf RAPPORT MÉDICAL}
\stopalignment
\blank[3*big]
\startitemize[unnumberedbullet,columns,two,stretch]
\startitem { \bf \ss Nom \& prénoms\hspace[medium]} {\sc Hamid Bougherara} \stopitem
\startitem {\bf \ss Date de naissance \hspace[medium]} 17/02/2000 \stopitem
\startitem {\bf\ss Adresse \hspace[medium]} { Aïn Témouchent} \stopitem
\startitem {\bf\ss Médecin réferent\hspace[big]} {\sc Dr Hamid} \stopitem
%\raggedleft
\startitem {\bf\ss Motifs \hspace[big]} angine de poitrine\\
dyspnée
\stopitem
\startitem {\ss\bf Date \hspace[big]} \currentdate \stopitem
\stopitemize
\subject{ANTÉCÉDENTS - FDR}
\startitemize[unnumberedbullet]
\startitem {\bf \ss Diabète:} bien équilibré sous traitement {\abrar Glucophage 850mg} \stopitem
\startitem {\bf \ss HTA:} bien équilibré sous traitement Triatec \stopitem
\stopitemize
\startcadrevert
Au total il s'agit de Mr {\sc Hamid Bougherara} aux antécedents de {\bf angine de poitrine} dont le test d'ischémie est revenu positif pour les territoires \abrar postérieurs.
\stopcadrevert
\subject{Dispositions complémentaires}
\stoptext
as you can see i had experienced a few tips with this very draft. Hope it helps
Edit
Here is a less quick'n'dirty example, with a header (bidi) and a footer using tabulate environment and fontAwesome symbols.
\setuppapersize[A4]
\mainlanguage[fr]
%\usemodule[chart]
\setuplayout[header=3.5cm,headerdistance=1cm,margin=2.5cm,footer=2.5cm]
\usesymbols[fontawesome]
\setuppagenumbering[alternative=doublesided,location=]
\definecolor[abrar][r=0.02,g=0.49,b=0.52]
\definefontfeature[default][default][onum=yes]
\definefontfamily[merry][serif][merriweather]
\definefontfamily[merry][sans] [merriweathersans]
\definefontfamily[merry][mono] [TeX Gyre Cursor][features=none]
\definefontfamily[merry][math] [TeX Gyre Pagella Math]
\definelayer[mybg] % name of the layer
[x=0mm, y=0mm, % from upper left corner of paper
width=\paperwidth, height=\paperheight, % let the layer cover the full paper
]
\setupbackgrounds[page][background=mybg]
\setupdirections[bidi=global]
\definefontfeature
[arabic]
[mode=node,language=dflt,script=arab,
init=yes,medi=yes,fina=yes,isol=yes,
liga=yes,dlig=yes,rlig=yes,clig=yes,
mark=yes,mkmk=yes,kern=yes,curs=yes,
saed=yes]
\starttypescript [serif] [arabic]
\definefontsynonym [Arabic-Regular] [mothanna] [features=arabic]
\stoptypescript
\starttypescript [serif] [arabic] [name]
\definefontsynonym [Serif] [Arabic-Regular] [features=arabic]
\stoptypescript
\starttypescript [mothanna]
\definetypeface [mothanna] [rm] [serif] [arabic] [default]
\stoptypescript
\usetypescriptfile[type-mothanna]
\usetypescript[mothanna]
%\pagedir TRT \bodydir TRT \pardir TRT \textdir TRT
\setupbodyfont[merry,10pt]
\setuphead[subject][color=abrar,style=\ssa\bf]
\setuphead[subsubject][color=abrar, style=\ss\tfb\bi]
\edef\defaultlineheight{\the\lineheight}
\startMPdefinitions
newpath basicShape;
basicShape := unitsquare ;
DefaultLineHeight := \defaultlineheight;
\stopMPdefinitions
\startuseMPgraphic {unnumberedbullet}
fill basicShape scaled OverlayWidth shifted (0, 0.5*LineHeight)
withcolor \MPcolor{darkred};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\startuseMPgraphic {numberedbullet}
fill basicShape xyscaled (0.9*DefaultLineHeight, 0.9*DefaultLineHeight)
shifted (-0.5(0.9*DefaultLineHeight - OverlayWidth, 0))
withcolor \MPcolor{abrar};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\defineoverlay[unnumberedbullet][\useMPgraphic{unnumberedbullet}]
\defineframed [unnumberedbullet]
[
frame=off,
width=0.5\bodyfontsize,
background=unnumberedbullet,
location=low,
]
\definesymbol[unnumberedbullet]
[{\unnumberedbullet{}}]
\defineoverlay[numberedbullet][\useMPgraphic{numberedbullet}]
\defineframed [numberedbullet]
[
frame=off,
width=\lineheight,
background=numberedbullet,
foregroundcolor=white,
% Center the number against capital letters, ignoring character descent
location=depth,
foregroundstyle={\small\small}, % better to define a custom fontswitch
]
\definesymbol[numberedbullet]
[{\numberedbullet{\currentitemnumber}}]
\defineframedtext[cadrevert]
[background=screen,backgroundscreen=.85,
width=0.9\textwidth,
frame=off,
leftframe=on,
framecolor=darkcyan,
rulethickness=3pt]
\setupheadertexts[\setups{tableheader}]
\startsetups tableheader
\starttabulate[|p|lrw(2cm)|pr|]
\NC \ss Clinique médico chirurgicale El Abrar\NC \externalfigure[logo.png][width=2cm, location=inline]\NC \setupalign[r2l] \switchtobodyfont[mothanna]{ العيادة الطبية الجراحية الأبرار}\NC \NR
\NC \setupalign[l2r]\ss Service de cardiologie\NC \NC \setupalign[r2l] \switchtobodyfont[mothanna]{ مصلحة أمراض القلب}\NC\NR
\setupalign[l2r]
\NC \ss\tfx Dr Yahyaoui .M.K \NC \NC \ss\tfx kaddourkardio(at)gmail.com \NC \NR
\stoptabulate
\stopsetups
\setuppagenumbering[location={header,margin}]
\setupfootertexts[\setups{tablefooter}]
\startsetups tablefooter
\startframed[frame=off,
background=color,
backgroundcolor=lightgray,
style={\ss\tfx}]
\starttabulate[|lw(.5cm)|p|rw(1cm)|p|]
\NC \symbol[fontawesome][ambulance] \NC 15,rue Tolozane Les palmiers, Oran \NC \symbol[fontawesome][phone] \NC (+213) 041-496-066 \NC\NR
\NC \symbol[fontawesome][fax] \NC(+213) 041-233-491
\NC \symbol[fontawesome][mobile] \NC (+213) 0561 882-066\NC\NR
\NC \symbol[fontawesome][envelope-o] \NC clinique-elabrar\symbol[fontawesome][at]laposte.net\NC \symbol[fontawesome][mobile] \NC (+213) 0561 882-066\NC\NR
\stoptabulate
\stopframed
\stopsetups
\starttext
\startalignment[middle]
\blank[big]
\dontleavehmode
\framed
[background=color,backgroundcolor=darkred,
backgroundoffset=5pt,corner=0,frame=0,
foreground=color,foregroundcolor=white]
{\ssc \bf RAPPORT MÉDICAL}
\stopalignment
\blank[2*big]
\startitemize[unnumberedbullet,columns,two,stretch]
\startitem { \bf \ss Nom \& prénoms\hspace[medium]} {\sc Hamid Bougherara} \stopitem
\startitem {\bf \ss Date de naissance \hspace[medium]} 17/02/2000 \stopitem
\startitem {\bf\ss Adresse \hspace[medium]} { Aïn Témouchent} \stopitem
\startitem {\bf\ss Médecin réferent\hspace[big]} {\sc Dr Hamid} \stopitem
%\raggedleft
\startitem {\bf\ss Motifs \hspace[big]} angine de poitrine\\
\stopitem
\startitem {\ss\bf Date \hspace[big]} \currentdate \stopitem
\stopitemize
\subject{ANTÉCÉDENTS - FDR}
\startitemize[unnumberedbullet]
\startitem {\bf \ss Diabète:} bien équilibré sous traitement {\abrar Glucophage 850mg} \stopitem
\startitem {\bf \ss HTA:} bien équilibré sous traitement Triatec \stopitem
\stopitemize
\subject{Dispositions complémentaires}
Au total il s'agit de Mr {\sc Hamid Bougherara} aux antécedents de {\bf angine de poitrine} dont le test d'ischémie est revenu positif pour les territoires {\abrar postérieurs}.
\stoptext