% !Mode:: "TeX:EN:UTF-8:Main"
\suppresslongerror1%% sigh ...
%% Copyright (C) 2009-2018
%%
%%      by  Elie Roux      <elie.roux@telecom-bretagne.eu>
%%      and Khaled Hosny   <khaledhosny@eglug.org>
%%      and Philipp Gesang <phg@phi-gamma.net>
%%
%% This file is part of Luaotfload.
%%
%%      Home:      https://github.com/lualatex/luaotfload
%%      Support:   <lualatex-dev@tug.org>.
%%
%% Luaotfload is under the GPL v2.0 (exactly) license.
%%
%% ----------------------------------------------------------------------------
%%
%% Luaotfload is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; version 2
%% of the License.
%%
%% Luaotfload is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with Luaotfload; if not, see <http://www.gnu.org/licenses/>.
%%
%% ----------------------------------------------------------------------------
%%

\documentclass{ltxdoc}

\makeatletter

\usepackage {metalogo,multicol,fancyvrb,xspace}
\usepackage [x11names] {xcolor}

\def \primarycolor   {DodgerBlue4} %%-> rgb  16  78 139 | #104e8b
\def \secondarycolor {Goldenrod4}  %%-> rgb 139 105 200 | #8b6914

\usepackage[
    bookmarks=true,
   colorlinks=true,
    linkcolor=\primarycolor,
     urlcolor=\secondarycolor,
    citecolor=\primarycolor,
    unicode,
     pdftitle={The Luaotfload package},
   pdfsubject={OpenType layout system for Plain TeX and LaTeX},
    pdfauthor={Elie Roux \& Khaled Hosny \& Philipp Gesang \& Ulrike Fischer},
  pdfkeywords={luatex, lualatex, unicode, opentype}
]{hyperref}

\usepackage {fontspec}
\usepackage {unicode-math}

\setmainfont[
% Numbers     = OldStyle, %% buggy with font cache
  Ligatures   = TeX,
  BoldFont    = {Linux Libertine O Bold},
  ItalicFont  = {Linux Libertine O Italic},
  SlantedFont = {Linux Libertine O Italic},
]{Linux Libertine O}
\setmonofont[Ligatures=TeX,Scale=MatchLowercase]{InconsolataN-Regular.otf}
%setsansfont[Ligatures=TeX]{Linux Biolinum O}
\setsansfont[Ligatures=TeX,Scale=MatchLowercase]{IwonaMedium-Regular.otf}
%setmathfont{XITS Math}

\usepackage{hologo}

\newcommand\TEX      {\TeX\xspace}
\newcommand\LUA      {Lua\xspace}
\newcommand\PDFTEX   {pdf\TeX\xspace}
\newcommand\LUATEX   {Lua\TeX\xspace}
\newcommand\XETEX    {\XeTeX\xspace}
\newcommand\LATEX    {\LaTeX\xspace}
\newcommand\LUALATEX {Lua\LaTeX\xspace}
\newcommand\CONTEXT  {Con\TeX t\xspace}
\newcommand\OpenType {\identifier{Open\kern-.25ex Type}\xspace}

%% \groupedcommand, with some omissions taken from syst-aux.mkiv
\let \handlegroupnormalbefore \relax
\let \handlegroupnormalafter  \relax

\protected \def \handlegroupnormal #1#2{%
  \bgroup % 1
  \def \handlegroupbefore {#1}%
  \def \handlegroupafter  {#2}%
  \afterassignment \handlegroupnormalbefore
  \let \next =
}

\def \handlegroupnormalbefore {%
  \bgroup % 2
  \handlegroupbefore
  \bgroup % 3
  \aftergroup \handlegroupnormalafter%
}

\def \handlegroupnormalafter {%
  \handlegroupafter
  \egroup % 3
  \egroup % 2
}

\let \groupedcommand \handlegroupnormal %% only the two arg version

\def \definehighlight [#1][#2]{%
  \ifcsname #1\endcsname\else
    \expandafter\def\csname #1\endcsname{%
      \leavevmode
      \groupedcommand {#2}\empty%
    }
  \fi%
}

%% old, simplistic definition: obsolete now that we have
%% \groupedcommand
%\def\definehighlight[#1][#2]%
 %{\ifcsname #1\endcsname\else
    %\expandafter\def\csname #1\endcsname%
      %{\bgroup#2\csname #1_indeed\endcsname}
    %\expandafter\def\csname #1_indeed\endcsname##1%
      %{##1\egroup}%
  %\fi}

\def\restoreunderscore{\catcode`\_=12\relax}

\definehighlight         [fileent][\ttfamily\restoreunderscore]         %% files, dirs
\definehighlight        [texmacro][\sffamily\itshape\textbackslash]     %% cs
\definehighlight        [luaident][\sffamily\itshape\restoreunderscore] %% lua identifiers
\definehighlight      [identifier][\sffamily]                           %% names
\definehighlight          [abbrev][\rmfamily\scshape]                   %% acronyms
\definehighlight        [emphasis][\rmfamily\slshape]                   %% level 1 emph

\definehighlight       [Largefont][\Large]                              %% font size
\definehighlight       [smallcaps][\sc]                                 %% font feature
\definehighlight [nonproportional][\tt]                                 %% font switch

\newcommand*\email[1]{\href{mailto:#1}{#1}}

\renewcommand\partname{Part}%% gets rid of the stupid “file” heading

\usepackage{syntax}%% bnf for font request syntax

\usepackage{titlesec}

\def\movecountertomargin#1{\llap{\rmfamily\upshape#1\hskip2em}}
\def\zeropoint{0pt}
\titleformat \part
             {\normalsize\rmfamily\bfseries}
             {\movecountertomargin\thepart} \zeropoint {}
\titleformat \section
             {\normalsize\rmfamily\scshape}
             {\movecountertomargin\thesection} \zeropoint {}
\titleformat \subsection
             {\small\rmfamily\itshape}
             {\movecountertomargin\thesubsection} \zeropoint {}
\titleformat \subsubsection
             {\normalsize\rmfamily\upshape}
             {\movecountertomargin\thesubsubsection} \zeropoint {}

\usepackage{tocloft}
\renewcommand \cftpartfont   {\rmfamily\upshape}
\renewcommand \cftsecfont    {\rmfamily\upshape}
\renewcommand \cftsubsecfont {\rmfamily\upshape}
\setlength \cftbeforepartskip {1ex}
\setlength \cftbeforesecskip  {1ex}

\VerbatimFootnotes

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% structurals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \definestructural #1{%
  \expandafter \let \csname end#1\endcsname \relax

  \expandafter \def \csname begin#1\endcsname {%
    \@ifnextchar[{\csname begin#1indeed\endcsname}
                 {\csname begin#1indeed\endcsname[]}%
  }

  \expandafter \def \csname begin#1indeed\endcsname [##1]##2{%
    \edef \first {##1}%
    \ifx \first \empty
      \csname #1\endcsname [##2]{##2}%
    \else
      \csname #1\endcsname [\first]{##2}%
    \fi
  }
}

\definestructural {section}
\definestructural {subsection}
\definestructural {subsubsection}

\def \fakesection #1{\section*{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% inline verbatim
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Context offers both \type{…} and \type<<…>>, but not an unbalanced
%% one that we could map directly onto Latex’s \verb|…|.
\usepackage{pdfpages}
\usepackage {listings}
\usepackage{csquotes}
\usepackage {luatexbase}
\lstset {
  basicstyle=\ttfamily,
}

%\let \inlinecode \lstinline
\protected \def \inlinecode {\lstinline}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% codelistings; this sucks hard since we lack access to buffers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcount \othercatcode  \othercatcode 12
\newcount \activecatcode \othercatcode 13

\newcatcodetable \vrbcatcodes
\setcatcodetable \vrbcatcodes {%
  \catcodetable \CatcodeTableIniTeX
  \catcode  9 \othercatcode %% \tabasciicode
  \catcode 13 \othercatcode %% \endoflineasciicode
  \catcode 12 \othercatcode %% \formfeedasciicode
  \catcode 26 \othercatcode %% \endoffileasciicode
  \catcode 32 \othercatcode %% \spaceasciicode
}

\directlua {
  document = document or { }
  document.vrbcatcodesidx = tonumber (\the \vrbcatcodes)
}

\newcatcodetable \literalcatcodes
\setcatcodetable \literalcatcodes {%
  \catcodetable \CatcodeTableString
  \catcode 32 \activecatcode %% \spaceasciicode
}

\def \listingsurroundskip {\vskip \baselineskip}

\def \beginlisting {%
  \noindent
  \begingroup
    \catcodetable \vrbcatcodes
    \beginlistingindeed%
}

\directlua {
  local texsprint       = tex.sprint
  local stringis_empty  = string.is_empty
  local stringsub       = string.sub
  local stringgsub      = string.gsub
  %local backslash       = unicode.utf8.char (0x200c)
  local backslash = string.char(0x5c)
  local escaped         = [[\string\string\string\]]
  document.printlines = function (buffer)
    local lines = string.explode (buffer, "\noexpand\n")
    print ""
    for i, line in next, lines do
      local line = stringgsub (line, backslash, escaped)
      if stringis_empty (line) then
        print (i, "listing: <empty line />")
        texsprint [[\string\listingpar]]
      else
        local line = [[\string\beginlistingline]]
                  .. line
                  .. [[\string\endlistingline]]
                  .. [[\string\listingpar]]
        print (i, "listing: «" .. line .. "»")
        texsprint (document.vrbcatcodesidx, line)
      end
    end
  end
}
\directlua{
           luaotfload.add_colorscheme("myscheme",
           {
             ["00FFFF30"] = {"default"},
             ["FF0000"] = {"kabeng"},
             ["00FF00"] = {"ivowelsignbeng"},
             ["0000FF"] = {369} %% 369 is the GID of "nadarabeng"
           })
           }

 \directlua{
     luaotfload.add_multiscript
       ("cyrlgrekbeng",
        {
          cyrl = "DejaVuSans:mode=node;script=cyrl;color=FF0000;",
          grek = "texgyreheros:mode=harf;script=grek;color=0000FF;",
          beng = "NotoSansBengali:mode=harf;script=bng2;color=00FF00"
        }
       )
      }
 \directlua
    {luaotfload.add_fallback
     ("myfallback",
       {
        "DejaVuSans:mode=harf;script=grek;color=FF0000;",
        "cmuserif:mode=node;script=cyrl;color=00FF00;",
        "NotoSansBengali:mode=harf;script=bng2;color=0000FF;",
        "NotoColorEmoji:mode=harf;"
       }
     )
    }
\def \listingpar {\endgraf}

\let \endlistingline \relax
\let \endlisting     \relax

\protected \def \beginlistingline{%
  \leavevmode
  \begingroup
    \beginlistinglineindeed%
}

\def \beginlistinglineindeed #1\endlistingline{%
  \endgroup
  \hbox{%
    \addfontfeature {RawFeature=-tlig;-liga}%% So one can’t just turn them all off at once using the ``Ligatures`` key?
    \obeyspaces
    #1}%
}

\def \beginlistingindeed#1\endlisting{%
  \endgroup
  \begingroup
    \endgraf
    \listingsurroundskip
    \ttfamily
    \small
    \parindent = 0em
    \leftskip = 2em
    \hangindent = 2em
    \directlua{document.printlines ([==[\detokenize {#1}]==])}%
    \listingsurroundskip
  \endgroup
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% enumerations and lists
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \definelist [#1]#2{% name, itemcode
  \expandafter \def \csname begin#1\endcsname {%
    \begin {itemize}
      \let \normalitem = \item
      \def \altitem ####1{%
        \def \first {####1}%
        #2
      }
      \let \beginnormalitem \item
      \let \endnormalitem   \relax
      \let \beginaltitem    \altitem
      \let \endaltitem      \relax
  }

  \expandafter \def \csname end#1\endcsname {%
    \end {itemize}
  }
}

\definelist  [descriptions]{\normalitem {\textbf \first}\hfill\break}
\definelist   [definitions]{\normalitem {\fileent {\first}}}
\definelist      [filelist]{\normalitem {\fileent {\first}}\space--\hskip 1em}
\definelist  [functionlist]{\normalitem {\luaident {\first}}\hfill\break}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% columns
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \begindoublecolumns {\begin {multicols} {2}}
\def \enddoublecolumns   {\end {multicols}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% alignment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \begincentered {\begin {center}}
\def \endcentered   {\end {center}}

\def \beginnarrower {\begin {quote}}
\def \endnarrower   {\end {quote}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% special elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let \beginfrontmatter \relax
\let \endfrontmatter   \relax

\def \beginabstractcontent {\begin {abstract}}
\def \endabstractcontent   {\end {abstract}}

\let \setdocumenttitle      \title
\let \setdocumentdate       \date
\let \setdocumentauthor     \author
\let \typesetdocumenttitle  \maketitle

\AtBeginDocument {%% seriously?
  \let \typesetcontent \tableofcontents%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% floats
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% syntax definition
\def \beginsyntaxfloat #1#2{%% #1:label #2:caption
  \begin {figure} [b]
    \edef \syntaxlabel  {#1}%
    \def \syntaxcaption {#2}%
    \setlength\grammarparsep{0pt plus 2pt minus 2pt}%
    \setlength\grammarindent{5cm}%
    \begingroup
      \small
      \begin {grammar}
}

\def \endsyntaxfloat {%
      \end {grammar}
    \endgroup
    \caption \syntaxcaption
    \label   \syntaxlabel
  \end {figure}
}

%% figures, e.g. the file graph
\def \figurefloat #1#2#3{%% #1:label #2:caption #3:file
  \begin {figure} [b]
    \caption {#2}%
    \includegraphics[width=\textwidth]{#3}%
    \label {#1}
  \end {figure}
}

%% tables
\def \tablefloat #1#2{%% #1:label #2:caption
  \begin {table} [t]
    \hrule
    \caption {#2}%
    \label {#1}
    \hrule
  \end {table}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% hyperlinks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\protected \def \hyperlink{%
  \@ifnextchar[{\hyperlinkindeed}%
               {\hyperlinkindeed[]}%
}

\def \hyperlinkindeed [#1]#2{%
  \def \first {#1}%
  \ifx \first \empty
    \url {#2}%
  \else
    \href {#2}{#1}%
  \fi%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% tables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Our tables aren’t anything special so we stick with “tabular” on the
%% Latex end.
%%
%% This is going to be largely incompatible with Context since format
%% specifications work quite differently (even between different
%% Context table variants).

\def \begintabulate [#1]#2\endtabulate{%
  \begingroup
    \let \beginrow  = \relax %% -> \NC in Context
    \let \newcell   = &      %% -> \NC
    \let \endrow    = \cr    %% -> \NC \NR
    \begin {tabular}{#1}%
      #2
    \end {tabular}
  \endgroup
}

\let \endtabulate \relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% escaped characters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let \charpercent   \textpercent
\let \charbackslash \textbackslash
\let \chartilde     \textasciitilde

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% main
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatother

\newif \ifcontextmkiv \contextmkivfalse

\usepackage{luacode}

% a few lua functions to grab the file lists.
\begin{luacode}
require("luaotfload-filelist.lua")

function printctxlibslist ()
  t= luaotfload.filelist.selectctxlibsentries (luaotfload.filelist.data)
 for i,v in ipairs (t) do
  tex.sprint("\\beginaltitem {"..v.name.. v.ext.."}\\endaltitem")
 end
end

function printctxallgenericlist ()
  t= luaotfload.filelist.selectctxgeneentries (luaotfload.filelist.data)
 for i,v in ipairs (t) do
  tex.sprint("\\beginaltitem {"..v.ctxpref..v.name..v.ext.."}\\endaltitem")
 end
end

function printctxfontlist ()
  t= luaotfload.filelist.selectctxfontentries (luaotfload.filelist.data)
 for i,v in ipairs (t) do
  tex.sprint("\\beginaltitem {"..v.name..v.ext.."}\\endaltitem")
 end
end
\end{luacode}

\newcommand\gitissue[1]{\href{https://github.com/latex3/luaotfload/issues/#1}{(issue~\##1)}}
\begin {document}
  \input {luaotfload-main.tex}
\clearpage
\includepdf[fitpaper,pagecommand={\label{file-graph}}]{filegraph}
\clearpage

\includepdf[pages=1,pagecommand={\phantomsection\addcontentsline{toc}{section}{Appendix: Manual of luaotfload.conf}{\thepage}{}}]{luaotfload-conf.pdf}
\includepdf[pages=2-]{luaotfload-conf.pdf}

\clearpage

\includepdf[pages=1,pagecommand={\phantomsection\addcontentsline{toc}{section}{Appendix: Manual of luaotfload-tool}{\thepage}{}
}]{luaotfload-tool.pdf}
\includepdf[pages=2-]{luaotfload-tool.pdf}

\end {document}


