<reponame>eRougemont/Teinte
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% <TEI> generic (LaTeX names generated by Teinte) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This template is inserted in a specific design
% It is XeLaTeX and otf fonts

\makeatletter % <@@@

\setlength{\parskip}{0pt} % 1pt allow better vertical justification
\setlength{\parindent}{1.5em}

\usepackage{alphalph} % for alph couter z, aa, ab…
\usepackage{blindtext} % generate text for testing
\usepackage{booktabs} % for tables: \toprule, \midrule…
\usepackage[strict]{changepage} % for modulo 4
\usepackage{contour} % rounding words
\usepackage[nodayofweek]{datetime}
\usepackage{enumitem} % <list>
\usepackage{etoolbox} % patch commands
\usepackage{fancyvrb}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{fontspec} % XeLaTeX mandatory for fonts
\usepackage{footnote} % used to capture notes in minipage (ex: quote)
\usepackage{graphicx}
\usepackage{lettrine} % drop caps
\usepackage{lipsum} % generate text for testing
\usepackage{relsize} % \smaller \larger (ex: quotes in body and footnotes)
\usepackage{manyfoot} % for parallel footnote numerotation
\usepackage[framemethod=tikz,]{mdframed} % maybe used for frame with footnotes inside
\usepackage[defaultlines=2,all]{nowidow} % at least 2 lines by par (works well!)
\usepackage{pdftexcmds} % needed for tests expressions
\usepackage{poetry} % <l>, bad for theater
\usepackage{polyglossia} % bug Warning: "Failed to patch part"
\usepackage[%
  indentfirst=false,
  vskip=1em,
  noorphanfirst=true,
  noorphanafter=true,
  leftmargin=\parindent,
  rightmargin=0pt,
]{quoting}
\usepackage{ragged2e}
\usepackage{setspace} % \setstretch for <quote>
\usepackage{scrextend} % KOMA-common, used for addmargin
\usepackage{tabularx} % <table>
\usepackage[explicit]{titlesec} % wear titles, !NO implicit
\usepackage{tikz} % ornaments
\usepackage{tocloft} % styling tocs
\usepackage[fit]{truncate} % used im runing titles
\usepackage{unicode-math}
\usepackage[normalem]{ulem} % breakable \uline, normalem is absolutely necessary to keep \emph
\usepackage{xcolor} % named colors
\usepackage{xparse} % @ifundefined
\XeTeXdefaultencoding "iso-8859-1" % bad encoding of xstring
\usepackage{xstring} % string tests
\XeTeXdefaultencoding "utf-8"

\defaultfontfeatures{
  % Mapping=tex-text, % no effect seen
  Scale=MatchLowercase,
  Ligatures={TeX,Common},
}
\newfontfamily\zhfont{Noto Sans CJK SC}

% Metadata inserted by a program, from the TEI source, for title page and runing heads
%meta%
% Default metas
\newcommand{\colorprovide}[2]{\@ifundefinedcolor{#1}{\colorlet{#1}{#2}}{}}
\colorprovide{rubric}{red}
\colorprovide{silver}{lightgray}
\@ifundefined{syms}{\newfontfamily\syms{DejaVu Sans}}{}
\newif\ifdev
\@ifundefined{elbibl}{% No meta defined, maybe dev mode
  \newcommand{\elbibl}{Titre court ?}
  \newcommand{\elbook}{Titre du livre source ?}
  \newcommand{\elabstract}{Résumé\par}
  \newcommand{\elurl}{http://oeuvres.github.io/elbook/2}
  \author{<NAME>}
  \title{Un titre de test assez long pour vérifier le comportement d’une maquette}
  \date{1566}
  \devtrue
}{}
\let\eltitle\@title
\let\elauthor\@author
\let\eldate\@date




% generic typo commands
\newcommand{\astermono}{\medskip\centerline{\color{rubric}\large\selectfont{\syms ✻}}\medskip\par}%
\newcommand{\astertri}{\medskip\par\centerline{\color{rubric}\large\selectfont{\syms ✻\,✻\,✻}}\medskip\par}%
\newcommand{\asterism}{\bigskip\par\noindent\parbox{\linewidth}{\centering\color{rubric}\large{\syms ✻}\\{\syms ✻}\hskip 0.75em{\syms ✻}}\bigskip\par}%

% lists
\newlength{\listmod}
\setlength{\listmod}{\parindent}
\setlist{
  itemindent=!,
  listparindent=\listmod,
  labelsep=0.2\listmod,
  parsep=0pt,
  % topsep=0.2em, % default topsep is best
}
\setlist[itemize]{
  label=—,
  leftmargin=0pt,
  labelindent=1.2em,
  labelwidth=0pt,
}
\setlist[enumerate]{
  label={\arabic*°},
  labelindent=0.8\listmod,
  leftmargin=\listmod,
  labelwidth=0pt,
}
% list for big items
\newlist{decbig}{enumerate}{1}
\setlist[decbig]{
  label={\bf\color{rubric}\arabic*.},
  labelindent=0.8\listmod,
  leftmargin=\listmod,
  labelwidth=0pt,
}
\newlist{listalpha}{enumerate}{1}
\setlist[listalpha]{
  label={\bf\color{rubric}\alph*.},
  leftmargin=0pt,
  labelindent=0.8\listmod,
  labelwidth=0pt,
}
\newcommand{\listhead}[1]{\hspace{-1\listmod}\emph{#1}}

\renewcommand{\hrulefill}{%
  \leavevmode\leaders\hrule height 0.2pt\hfill\kern\z@}

% General typo
\DeclareTextFontCommand{\textlarge}{\large}
\DeclareTextFontCommand{\textsmall}{\small}

% commands, inlines
\newcommand{\anchor}[1]{\Hy@raisedlink{\hypertarget{#1}{}}} % link to top of an anchor (not baseline)
\newcommand\abbr[1]{#1}
\newcommand{\autour}[1]{\tikz[baseline=(X.base)]\node [draw=rubric,thin,rectangle,inner sep=1.5pt, rounded corners=3pt] (X) {\color{rubric}#1};}
\newcommand\corr[1]{#1}
\newcommand{\ed}[1]{ {\color{silver}\sffamily\footnotesize (#1)} } % <milestone ed="1688"/>
\newcommand\expan[1]{#1}
\newcommand\foreign[1]{\emph{#1}}
\newcommand\gap[1]{#1}
\renewcommand{\LettrineFontHook}{\color{rubric}}
\newcommand{\initial}[2]{\lettrine[lines=2, loversize=0.3, lhang=0.3]{#1}{#2}}
\newcommand{\initialiv}[2]{%
  \let\oldLFH\LettrineFontHook
  % \renewcommand{\LettrineFontHook}{\color{rubric}\ttfamily}
  \IfSubStr{QJ’}{#1}{
    \lettrine[lines=4, lhang=0.2, loversize=-0.1, lraise=0.2]{\smash{#1}}{#2}
  }{\IfSubStr{É}{#1}{
    \lettrine[lines=4, lhang=0.2, loversize=-0, lraise=0]{\smash{#1}}{#2}
  }{\IfSubStr{ÀÂ}{#1}{
    \lettrine[lines=4, lhang=0.2, loversize=-0, lraise=0, slope=0.6em]{\smash{#1}}{#2}
  }{\IfSubStr{A}{#1}{
    \lettrine[lines=4, lhang=0.2, loversize=0.2, slope=0.6em]{\smash{#1}}{#2}
  }{\IfSubStr{V}{#1}{
    \lettrine[lines=4, lhang=0.2, loversize=0.2, slope=-0.5em]{\smash{#1}}{#2}
  }{
    \lettrine[lines=4, lhang=0.2, loversize=0.2]{\smash{#1}}{#2}
  }}}}}
  \let\LettrineFontHook\oldLFH
}
\newcommand{\labelchar}[1]{\textbf{\color{rubric} #1}}
\newcommand{\lnatt}[1]{\reversemarginpar\marginpar[\sffamily\scriptsize #1]{}}
\newcommand{\milestone}[1]{\autour{\footnotesize\color{rubric} #1}} % <milestone n="4"/>
\newcommand\name[1]{#1}
\newcommand\orig[1]{#1}
\newcommand\orgName[1]{#1}
\newcommand\persName[1]{#1}
\newcommand\placeName[1]{#1}
\newcommand{\pn}[1]{\IfSubStr{-—–¶}{#1}% <p n="3"/>
  {\noindent{\bfseries\color{rubric}   ¶  }}
  {{\footnotesize\autour{#1}}}}
\newcommand\reg{}
% \newcommand\ref{} % already defined
\newcommand\sic[1]{#1}
\newcommand\surname[1]{\textsc{#1}}
\newcommand\term[1]{\textbf{#1}}
\newcommand\zh[1]{{\zhfont #1}}


\def\mednobreak{\ifdim\lastskip<\medskipamount
  \removelastskip\nopagebreak\medskip\fi}
\def\bignobreak{\ifdim\lastskip<\bigskipamount
  \removelastskip\nopagebreak\bigskip\fi}

% commands, blocks

\newcommand{\byline}[1]{\bigskip{\RaggedLeft{#1}\par}\bigskip}
% \setlength{\RaggedLeftLeftskip}{2em plus \leftskip}
\newcommand{\bibl}[1]{{\RaggedLeft\normalfont #1\par}}
\newcommand{\biblitem}[1]{{\noindent\hangindent=\parindent   #1\par}}
\newcommand{\castItem}[1]{{\noindent\hangindent=\parindent #1\par}}
\newcommand{\dateline}[1]{\medskip{\RaggedLeft{#1}\par}\bigskip}
\newcommand{\docAuthor}[1]{{\large\bigskip #1 \par\bigskip}}
\newcommand{\docDate}[1]{#1 \ifvmode\par\fi }
\newcommand{\docImprint}[1]{\ifvmode\medskip\fi #1 \ifvmode\par\fi }
\newcommand{\labelblock}[1]{\medbreak{\noindent\color{rubric}\bfseries #1}\par\mednobreak}
\newcommand{\question}[1]{\bigbreak{\RaggedRight\noindent\emph{#1}\par}\mednobreak}
\newcommand{\salute}[1]{\bigbreak{#1}\par\medbreak}
\newcommand{\signed}[1]{\medskip{\RaggedLeft #1\par}\bigbreak} % supposed bottom
\newcommand{\speaker}[1]{\medskip{\Centering\sffamily #1 \par\nopagebreak}} % supposed bottom
\newcommand{\stagescene}[1]{{\Centering\sffamily\textsf{#1}\par}\bigskip}
\newcommand{\stageblock}[1]{\begingroup\leftskip\parindent\noindent\it\sffamily\footnotesize #1\par\endgroup} % left margin, better than list envs
\newcommand{\lpar}[1]{\noindent\hangindent=2\parindent  #1\par} % sp/l
\newcommand{\trailer}[1]{{\Centering\bigskip #1\par}} % sp/l

% environments for blocks (some may become commands)
\newenvironment{borderbox}{}{} % framing content
\newenvironment{citbibl}{\ifvmode\hfill\fi}{\ifvmode\par\fi }
\newenvironment{msHead}{\vskip6pt}{\par}
\newenvironment{msItem}{\vskip6pt}{\par}


% environments for block containers
\newenvironment{argument}{\itshape\parindent0pt}{\bigskip}
\newenvironment{biblfree}{}{\ifvmode\par\fi }
\newenvironment{bibitemlist}[1]{%
  \list{\@biblabel{\@arabic\c@enumiv}}%
  {%
    \settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@arabic\c@enumiv}%
  }
  \sloppy
  \clubpenalty4000
  \@clubpenalty \clubpenalty
  \widowpenalty4000%
  \sfcode`\.\@m
}%
{\def\@noitemerr
  {\@latex@warning{Empty `bibitemlist' environment}}%
\endlist}
\newenvironment{docTitle}{\LARGE\bigskip\bfseries\onehalfspacing}{\bigskip}
% leftskip makes big bugs in Lexmark printing \sffamily
\newenvironment{epigraph}{\begin{addmargin}[2\parindent]{0em}\sffamily\large\setstretch{0.95}}{\end{addmargin}\bigskip}
\newenvironment{quoteblock}
  {\begin{quoting}\setstretch{0.9}} %
  {\end{quoting}}
\newenvironment{frametext}
  {\begin{mdframed}[default]} %
  {\end{mdframed}}

\quotingsetup{vskip=0pt}
\newcommand{\quoteskip}{\medskip}
\newenvironment{titlePage}
  {\Centering}
  {}






% table () is preceded and finished by custom command
\renewcommand\tabularxcolumn[1]{m{#1}}% for vertical centering text in X column
\newcommand{\tableopen}[1]{%
  \ifnum\strcmp{#1}{wide}=0{%
    \begin{center}
  }
  \else\ifnum\strcmp{#1}{long}=0{%
    \begin{center}
  }
  \else{%
    \begin{center}
  }
  \fi\fi
}
\newcommand{\tableclose}[1]{%
  \ifnum\strcmp{#1}{wide}=0{%
    \end{center}
  }
  \else\ifnum\strcmp{#1}{long}=0{%
    \end{center}
  }
  \else{%
    \end{center}
  }
  \fi\fi
}


% text structure
\newcommand\chapteropen{} % before chapter title
\newcommand\chaptercont{} % after title, argument, epigraph…
\newcommand\chapterclose{} % maybe useful for multicol settings
\setcounter{secnumdepth}{-2} % no counters for hierarchy titles
\setcounter{tocdepth}{5} % deep toc
\renewcommand\tableofcontents{\@starttoc{toc}}
% toclof format
% \renewcommand{\@tocrmarg}{0.1em} % Useless command?
% \renewcommand{\@pnumwidth}{0.5em} % {1.75em}
\renewcommand{\@cftmaketoctitle}{}
\setlength{\cftbeforesecskip}{\z@ \@plus.2\p@}

\@ifclassloaded{article}{%
  \typeout{class: article}%
}{%
  \renewcommand{\cftchapfont}{}
  \renewcommand{\cftchapdotsep}{\cftdotsep}
  \renewcommand{\cftchapleader}{\normalfont\cftdotfill{\cftchapdotsep}}
  \renewcommand{\cftchappagefont}{\bfseries}
  \setlength{\cftbeforechapskip}{0pt}
  \setlength{\cftchapnumwidth}{1em}
}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsecpagefont}{\normalfont}
% \renewcommand{\cftsubsecfont}{\small\relax}
\renewcommand{\cftsecdotsep}{\cftdotsep}
\renewcommand{\cftsecpagefont}{\normalfont}
\renewcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
\setlength{\cftsecindent}{1em}
\setlength{\cftsubsecindent}{2em}
\setlength{\cftsubsubsecindent}{3em}
\setlength{\cftsecnumwidth}{1em}
\setlength{\cftsubsecnumwidth}{1em}
\setlength{\cftsubsubsecnumwidth}{1em}

% footnotes
\newif\ifheading
\newcommand*{\fnmarkscale}{\ifheading 0.70 \else 1 \fi}
\renewcommand\footnoterule{\vspace*{0.3cm}\hrule height \arrayrulewidth width 3cm \vspace*{0.3cm}}
\setlength\footnotesep{1.5\footnotesep} % footnote separator
\renewcommand\@makefntext[1]{\parindent 1.5em \noindent \hb@xt@1.8em{\hss{\normalfont\@thefnmark . }}#1} % no superscipt in foot
\patchcmd{\@footnotetext}{\footnotesize}{\footnotesize\sffamily}{}{} % before scrextend, hyperref
\DeclareNewFootnote{A}[alph] % for editor notes
\renewcommand*{\thefootnoteA}{\alphalph{\value{footnoteA}}} % z, aa, ab…

% poem
\setlength{\poembotskip}{0pt}
\setlength{\poemtopskip}{0pt}
\setlength{\poemindent}{0pt}
\setlength{\poemmaxlinewd}{\linewidth}
\poemlinenumsfalse

%   see https://tex.stackexchange.com/a/34449/5049
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}

% orphans and widows, nowidow package in test
% from memoir package
\clubpenalty=9996
\widowpenalty=9999
\brokenpenalty=4991
\predisplaypenalty=10000
\postdisplaypenalty=1549
\displaywidowpenalty=1602
\hyphenpenalty=400
% report h or v overfull ?
\hbadness=4000
\vbadness=4000
% good to avoid lines too wide
\emergencystretch 3em
\pretolerance=750
\tolerance=2000
\def\Gin@extensions{.pdf,.png,.jpg,.mps,.tif}

\PassOptionsToPackage{hyphens}{url} % before hyperref and biblatex, which load url package
\usepackage{hyperref} % supposed to be the last one, :o) except for the ones to follow
\hypersetup{
  % pdftex, % no effect
  pdftitle={\elbibl},
  % pdfauthor={Your name here},
  % pdfsubject={Your subject here},
  % pdfkeywords={keyword1, keyword2},
  bookmarksnumbered=true,
  bookmarksopen=true,
  bookmarksopenlevel=1,
  pdfstartview=Fit,
  breaklinks=true, % avoid long links, overrided by url package
  pdfpagemode=UseOutlines,    % pdf toc
  hyperfootnotes=true,
  colorlinks=false,
  pdfborder=0 0 0,
  % pdfpagelayout=TwoPageRight,
  % linktocpage=true, % NO, toc, link only on page no
}
\urlstyle{same} % after hyperref



\makeatother % /@@@>
%%%%%%%%%%%%%%
% </TEI> end %
%%%%%%%%%%%%%%
