\startenvironment env_balsa.tex

% DEBUG {{{
    % uncomment those 2 lines to show the layout and the grid
    %\showframe 
    %\showgrid
% }}}}

% UTF-8 {{{
    \enableregime[utf-8]              % Enters unicode 
    %\setupencoding[default=uc]       % Uses unicode fonts only
% }}}

% LANGUAGE {{{
    \setuplanguage[fr][
        leftquote=\upperleftdoublesixquote,
        rightquote=\upperrightdoublesixquote,
    ]
    \mainlanguage[fr]
    \setcharacterspacing [frenchpunctuation]
% }}}

% LAYOUT {{{
    % General layout
    \setuppapersize[A5][A5]           % sets layout to A5, places it in an A5
    \setuplayout[
        backspace=40mm,
        topspace=15mm,
        width=85mm,
        height=185mm,
        leftmargin=20mm,
        rightmargin=0mm,
        header=0mm, % removes header
        grid=yes, % activates baseline grid
        ]
    \definepagebreak[emptyodd][yes,header,footer, odd]
    \setuphead[chapter][page=emptyodd]
    % Left margin
    \setupinmargin[
        %align={outer, nothyphenated, verytolerant, stretch},
        location=left,
        align=left,
        stack=yes,
        style={\setupbodyfont[umepgothicbalsa, 8pt] \setupalign[nothyphenated]},
        before={\blank\startalignment[inner]},
        after={\stopalignment},
        line=0.5,
        ]
    % Indented block
    \setupnarrower[left=3mm, right=0mm, middle=8mm]
    % Folio
    \setuppagenumber[number=3]
    \setuppagenumbering[location=footer, style={\setupbodyfont[umepgothicvertical, 8pt]}] % alternative=doublesided = to have mirrored pages
% }}}

% LOAD FONTS {{{
    \starttypescript [sans] [umepgothicbalsa] 
        \definefontsynonym [Sans]            [name:umepgothicbalsa] [handling=pure]
    \stoptypescript
    \starttypescript [sans] [umepgothicvertical] 
        \definefontsynonym [Sans]            [name:umepgothicvertical] [handling=pure]
    \stoptypescript
    \starttypescript [sans] [umepgothicrings] 
        \definefontsynonym [Sans]            [name:umepgothicrings]
    \stoptypescript
    \starttypescript [mono] [umemincho] 
        \definefontsynonym [Mono]            [name:umemincho] [handling=pure]
    \stoptypescript

    \definetypeface [umepgothicbalsa] [ss] [sans] [umepgothicbalsa]
    \definetypeface [umepgothicvertical]    [ss] [sans]  [umepgothicvertical]
    \definetypeface [umepgothicrings]    [ss] [sans]  [umepgothicrings]
    \definetypeface [umemincho]    [tt] [mono]  [umemincho]
% }}}

% TYPOGRAPHY {{{
    \setupbodyfont[umepgothicvertical, ss, 8pt]
    \definebodyfontenvironment[default][a=1.5, b=1.75, c=2,d=3.4] % defines higher sizes of fonts 
    \setupinterlinespace[11pt] 
    \setupinteraction[state=start, color=black] % activate links
    \setupnote[footnote][location=text, way=bypage, numberconversion=set 2, align={hyphenated}]
    \setupnotedefinition[footnote][location=left, before={\startalignment[flushleft]}, after=\stopalignment] 
% }}}

% JUSTIFICATION {{{
    \setuptolerance[verytolerant] % justification settings
    \interlinepenalty=8000 % tries to avoid widows
    \widowpenalty=8000 % tries to avoid widows
    \clubpenalty=8000 % tries to avoid widows
    \doublehyphendemerits=1000000 % tries to avoid consecutive hyphenations
    %\setupfonthandling [hz] [min=50,max=50,step=10]
    %\setupalign[hz, hanging]
% }}}

% GRAPHIC ELEMENTS {{{
    % make custom underline, otherwise holes between words!
    \definebar[underline][
        order=background, % foreground to put line in front
        rulethickness=0.05, 
        offset=-0.15, 
        continue=yes, 
        color=black,
        ]
   \defineframed[bold][
        location=low,
        %height=0pt,
        offset=1.2pt,
        topframeoffset=-1pt,
        ]
    % put a frame around a word
    \definetextbackground[inbox][
            framecolor=black,
            background=,
        ]

% ludi test le style encadré
%    \framedtext[inframed][
%         location=middle, 
%         height=3mm,  
%         offset=0pt,
%         ]

\setupexternalfigures[directory={./programme2011-12/svg, ../Ichem/svg-paths}]
% }}}

% TABLE OF CONTENTS {{{
    \setupcombinedlist[content][interaction=all, color=black] % makes it clickable
    \setuplist[section][width=0mm] % sets indentation for section level
    \setuplist[subsection][width=1em] % sets indentation for subsection level
% }}}

% SECTIONS AND HEADINGS {{{
    % function to put titles in the margin
        \def\InMargin#1#2{\inleftmargin{#1 #2}}
    %
    % NUMBERED SECTIONS // used for table of contents
        \setuphead[section][
            number=no,
            align={nothyphenated, verytolerant},
            page=yes,
            after=\nowhitespace,
            style=\tfa\cap,
            %distance=0pt, alternative=text, command=\InMargin, % calls function to put in margin
            ]
    % UNNUMBERED SECTIONS // not used in table of contents
        % GENERAL STYLING OF HEADINGS
        \setuphead[title, subject, subsubject, role, playtitle][
            align={nothyphenated, verytolerant},
            aligntitle=float,
            page=,
            %style=\underline,
            %style=\underbar,
            style=\tf,
            ]
        % ROLE OF A PERSON
        \definehead[role][subject]
        \setuphead[role][
            before=\nowhitespace,
            %after=\nowhitespace,
            after=\blank,
            ]
        % PLAY TITLE
        \definehead[playtitle][subject]
        \setuphead[playtitle][
            before=\blank,
            align={center, nothyphenated, verytolerant},
            %after=\blank,
            style={\tfd \cap \setupbodyfont[umemincho]},
            %distance=0pt, alternative=text, command=\InMargin, % calls function to put in margin
        ]
        % PLAY SUB-TITLE
        \definehead[playsubtitle][subject]
        \setuphead[playsubtitle][
            before=,
            align={center, nothyphenated, verytolerant},
            after=\blank,
            style={\tfc \cap \setupbodyfont[umemincho] \setupinterlinespace[11pt]},
        ]

        % SUBTITLE [INFOS PRATIQUES]
        \definehead[subtitle][subject]
        \setuphead[subtitle][
            before=\blank\noindentation,
            after=\blank,
            style={\tf \setupbodyfont[umemincho]},
        ]
% }}}

% PARAGRAPHS {{{
    \setupwhitespace[none]           % no empty line after a paragraph

    % INDENTATION
    \setupindenting[yes, medium, next] % activates medium indentation, not on 1st paragraph
    \define[1]\realpar{\blank\noindentation} % make new paragraph: blank line
    \define[1]\subpar{\blank[nowhite]\indentation} % make sub paragraph: indent

    % DROP CAPITAL
    \setupinitial[state=start, n=1, distance=0mm, font=umepgothicrings]


    % BLOCK INFOS
    \defineparagraphs[infos][n=1] 
    \setupparagraphs[infos][1][
        style={\switchtobodyfont[6pt]},
        after=\nowhitespace,
        ] 
    %\definedescription
      %[infos]
      %[location=margin,
       %command=\groupedcommand{\switchtobodyfont[6pt]}{\endgraf}]

    % BLOCK PRODUCTION
    \defineparagraphs[prod][n=1] 
    \setupparagraphs[prod][1][
        style={\switchtobodyfont[6pt]},
        after=\nowhitespace,
        ] 

    % BLOCKQUOTE
    \setupdelimitedtext[blockquote][1][
        left={\symbol[leftquotation]},
        right={\symbol[rightquotation]},
        before={
            \blank
            \setupbodyfont[umemincho, 9pt]
            \setupinterlinespace[11pt]
            %\startnarrower[left, right]
            \noindentation
            \startalignment[flushleft]
            \setupalign[nothyphenated]
        },
        after={
            \stopalignment
            %\stopnarrower
            \blank
            \indenting[yes]
        }
    ]
    \setupdelimitedtext[blockquote][2][
        left={\symbol[leftquote]},
        right={\symbol[rightquote]},
        before={
            \blank
            \setupbodyfont[umemincho, 9pt]
            \setupinterlinespace[11pt]
            \startnarrower[left, right]
            \noindentation
        },
        after={
            \stopnarrower
            \blank
            \indenting[yes]
        }
    ]

    % BLOCKQUOTE SIGNATURE
    \definestartstop[signature][
        before={
            %\setupnarrower[left=10mm, right=0mm]
            %\startnarrower[left, right]
            \noindentation
            },
        after={
            %\stopnarrower
            \indenting[yes]
            \blank
            },
        style={\switchtobodyfont[6pt]},
        ]
% }}}

% DEFINITION LISTS {{{
% such as "Production: Théâtre de la balsamine"
    % STAFF
    \definedescription[staff][
        headstyle={\setupbodyfont[umepgothicvertical, 6pt]},
        style={\setupbodyfont[umemincho, 8pt]},
        align=middle,
        %location=top,
        width=fit,
        before={\setupinterlinespace[12pt] \startnarrower[left]},
        after=\stopnarrower,
        ]
    % INFOS PRATIQUES
    \definedescription[infolist][
        headstyle={\setupbodyfont[umepgothicvertical, 6pt]},
        style={\setupbodyfont[umemincho, 8pt]},
        align=flushleft,
        location=top,
        %hang=20,
        command=\hskip-3mm, 
        margin=3mm,
        %width=fit,
        before={\setupinterlinespace[10pt]},
        ]
% }}}

% LISTS {{{
    \setupitemize[1][inmargin, symbol=3, stopper=, distance=0mm]
    \defineitemgroup[infoitem][levels=2]
    \setupinfoitem[1][inleft, symbol=3,  margin=-4mm]
%
% }}}

\stopenvironment
