\ProvidesFile{tuenc.def}
    [2016/01/29 v0.1 Unicode font encoding for LaTeX2e]

%%%%%%
% Please consider this encoding definition to be experimental!
%%%%%%

\providecommand\UnicodeEncodingName{TU}


%% WRAPPERS NEEDED FOR FONT LOADING (.fd FILE COMMANDS)

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname XeTeXrevision\endcsname\relax\else
  \def\UnicodeFontTeXLigatures{mapping=tex-text;}
\fi

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname directlua\endcsname\relax\else
  \def\UnicodeFontTeXLigatures{+tlig;} % "+trep;" no longer needed
\fi

\def\UnicodeFontFile#1#2{"[#1]:#2"}
\def\UnicodeFontName#1#2{"#1:#2"}

% Alternative luaotfload definitions for LuaLaTeX:
%    \def\UnicodeFontFile#1#2{"file:#1:#2"}
%    \def\UnicodeFontName#1#2{"name:#1:#2"}


%% COMMANDS NEEDED TO DEFINE UNICODE COMMANDS AND ACCENTS

% Accents in Unicode are postpended: 
\def\add@unicode@accent#1#2{#2\char#1\relax}

\def\DeclareUnicodeCommand#1#2{%
  \DeclareTextCommand{#1}{\LastDeclaredEncoding}{#2}%
}

\def\DeclareUnicodeAccent#1#2{%
  \DeclareTextCommand{#1}{\LastDeclaredEncoding}{\add@unicode@accent{#2}}%
}

\def\DeclareUnicodeSymbol#1#2{%
  \DeclareTextSymbol{#1}{\LastDeclaredEncoding}{#2}%
}

\def\DeclareUnicodeComposite#1#2#3{%
  \DeclareTextComposite{#1}{\LastDeclaredEncoding}{#2}{#3}%
}

\def\DeclareUnicodeCompositeCommand#1#2#3{%
  \DeclareTextCompositeCommand{#1}{\LastDeclaredEncoding}{#2}{#3}%
}


%% COMMANDS FOR DEFINING NEW ENCODINGS FROM FONT RANGES

\def\NewUnicodeEncoding#1{%
  \DeclareFontEncoding{#1}{}{}
  \DeclareErrorFont{\LastDeclaredEncoding}{lmr}{m}{n}{10}
  \DeclareFontSubstitution{\LastDeclaredEncoding}{lmr}{m}{n}
  \DeclareFontFamily{\LastDeclaredEncoding}{lmr}{}
  \DeclareFontShape{\LastDeclaredEncoding}{lmr}{m}{n}
       {<->\UnicodeFontFile{lmroman10-regular}{\UnicodeFontTeXLigatures}}{}
  \DeclareFontShape{\LastDeclaredEncoding}{lmr}{m}{it}
       {<->\UnicodeFontFile{lmroman10-italic}{\UnicodeFontTeXLigatures}}{}
  \DeclareFontShape{\LastDeclaredEncoding}{lmr}{m}{sc}
       {<->\UnicodeFontFile{lmromancaps10-regular}{\UnicodeFontTeXLigatures}}{}
  \DeclareFontShape{\LastDeclaredEncoding}{lmr}{bx}{n}
       {<->\UnicodeFontFile{lmroman10-bold}{\UnicodeFontTeXLigatures}}{}
  \DeclareFontShape{\LastDeclaredEncoding}{lmr}{bx}{it}
       {<->\UnicodeFontFile{lmroman10-bolditalic}{\UnicodeFontTeXLigatures}}{}
}

\def\DeclareUnicodeEncoding#1#2#3{%
  \NewUnicodeEncoding{#1}%
  \@for\@ii:=#2\do{%
    \InputIfFileExists{tufontrange-\@ii.def}{}{%
      \@latex@error{Unicode font range file `tufontrange-\@ii.def' not found}{\@ehd}%
    }%
  }%
  #3%
}

%% THE ENCODING ITSELF

\DeclareUnicodeEncoding{\UnicodeEncodingName}{T1,TS1}{}

\endinput
