%D \module
%D   [       file=typo-itc,
%D        version=2011.10.08,
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Italic Correction,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typesetting Macros / Italics Corrections}

\unprotect

%D The brave might try:
%D
%D \starttyping
%D \definefontfeature[default][default][itlc=yes,textitalics=yes]
%D \setupitaliccorrection[global,always]
%D \stoptyping

\registerctxluafile{typo-itc}{1.001}

\definesystemattribute[italics][public]

% \let\/=/
% \let\emphasiscorrection\donothing

\ifdefined \normalitaliccorrection \else
    \let\normalitaliccorrection\italiccorrection
\fi

\unexpanded\def\italiccorrection
  {\ifnum\attribute\italicsattribute<\plusone\normalitaliccorrection\fi}

\let\/\italiccorrection

% 1 = end of word
% 2 = end of word and end of a list

\unexpanded\def\setitaliccorrection[#code]% rather low level (might go away)
  {\ctxlua{typesetters.italics.set(\number#code)}}

\unexpanded\def\resetitaliccorrection% rather low level (might go away)
  {\ctxlua{typesetters.italics.reset()}}

% global : no attributes, just always (faster and less memory)
% text   : only text
% always : text and boxes
% none   : -

\unexpanded\def\setupitaliccorrection[#settings]%
  {\ctxcommand{setupitaliccorrection("#settings")}}

\appendtoks
    \attribute\italicsattribute\attributeunsetvalue
\to \everymathematics

\protect \endinput
