\documentclass[DIV=13,%
               BCOR=0mm,%
               headinclude=false,%
               footinclude=false,open=any,%
               fontsize=10pt,%
               oneside,%
               paper=a5]%
               {scrbook}






\usepackage[noautomatic]{imakeidx}



\usepackage{microtype}
\usepackage{graphicx}
\usepackage{alltt}
\usepackage{verbatim}
\usepackage[shortlabels]{enumitem}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\def\hsout{\bgroup \ULdepth=-.55ex \ULset}
% https://tex.stackexchange.com/questions/22410/strikethrough-in-section-title
% Unclear if \protect \hsout is needed. Doesn't looks so
\DeclareRobustCommand{\sout}[1]{\texorpdfstring{\hsout{#1}}{#1}}
\usepackage{wrapfig}

% avoid breakage on multiple <br><br> and avoid the next [] to be eaten
\newcommand*{\forcelinebreak}{\strut\\*{}}

\newcommand*{\hairline}{%
  \bigskip%
  \noindent \hrulefill%
  \bigskip%
}

% reverse indentation for biblio and play

\newenvironment*{amusebiblio}{
  \leftskip=\parindent
  \parindent=-\parindent
  \smallskip
  \indent
}{\smallskip}

\newenvironment*{amuseplay}{
  \leftskip=\parindent
  \parindent=-\parindent
  \smallskip
  \indent
}{\smallskip}

\newcommand*{\Slash}{\slash\hspace{0pt}}


% http://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url
\PassOptionsToPackage{hyphens}{url}\usepackage[hyperfootnotes=false,hidelinks,breaklinks=true]{hyperref}
\usepackage{bookmark}

\usepackage[english]{babel}
\babelfont{rm}[Path=/usr/share/texmf/fonts/opentype/public/tex-gyre/,%
 BoldFont=texgyrepagella-bold.otf,%
 BoldItalicFont=texgyrepagella-bolditalic.otf,%
 ItalicFont=texgyrepagella-italic.otf]{texgyrepagella-regular.otf}
\babelfont{tt}[Scale=MatchLowercase,%
 Path=/usr/share/fonts/truetype/cmu/,%
 BoldFont=cmuntb.ttf,%
 BoldItalicFont=cmuntx.ttf,%
 ItalicFont=cmunit.ttf]{cmuntt.ttf}
\babelfont{sf}[Scale=MatchLowercase,%
 Path=/usr/share/fonts/truetype/cmu/,%
 BoldFont=cmunsx.ttf,%
 BoldItalicFont=cmunso.ttf,%
 ItalicFont=cmunsi.ttf]{cmunss.ttf}



\renewcommand*{\partpagestyle}{empty}


% global style

\pagestyle{plain}




\usepackage{indentfirst}

% remove the numbering
\setcounter{secnumdepth}{-2}

% remove labels from the captions
\renewcommand*{\captionformat}{}
\renewcommand*{\figureformat}{}
\renewcommand*{\tableformat}{}
\KOMAoption{captions}{belowfigure,nooneline}
\addtokomafont{caption}{\centering}







\deffootnote[3em]{0em}{4em}{\textsuperscript{\thefootnotemark}~}


\addtokomafont{disposition}{\rmfamily}
\addtokomafont{descriptionlabel}{\rmfamily}


\frenchspacing
% avoid vertical glue
\raggedbottom

% this will generate overfull boxes, so we need to set a tolerance
% \pretolerance=1000
% pretolerance is what is accepted for a paragraph without
% hyphenation, so it makes sense to be strict here and let the user
% accept tweak the tolerance instead.
\tolerance=200
% Additional tolerance for bad paragraphs only
\setlength{\emergencystretch}{30pt}

% (try to) forbid widows/orphans
\clubpenalty=10000
\widowpenalty=10000





% given that we said footinclude=false, this should be safe
\setlength{\footskip}{2\baselineskip}

\title{Font management}
\date{}
\author{}
\subtitle{}






% https://groups.google.com/d/topic/comp.text.tex/6fYmcVMbSbQ/discussion
\hypersetup{%
pdfencoding=auto,
pdftitle={Font management},%
pdfauthor={},%
pdfsubject={},%
pdfkeywords={doc}%
}


\begin{document}






  \begin{titlepage}


  \strut\vskip 2em
  \begin{center}

  {\usekomafont{title}{\huge Font management\par}}%
  \vskip 1em
  
  \vskip 2em
  
  \vskip 1.5em



   
   \vfill



  
    \strut\par
  


  \end{center}


     \end{titlepage}
     
     \cleardoublepage



\tableofcontents
% start a new right-handed page

\cleardoublepage



\chapter{fontspec.json}


The global font definition file is called \texttt{fontspec.json} and resides
in the application directory (\texttt{/var/lib/amusewiki} on Debian or
wherever you installed it). This file can be overriden per site if
\texttt{fontspec.json} is found in the repo’s \texttt{site\_files} directory, for
example \texttt{/var/lib/amusewiki/repo/amw/site\_files/fontspec.json}.


The default file is generated by the script \texttt{muse-create-font-file.pl}
which comes with the \texttt{Text::Amuse::Compile} module (amusewiki’s
dependency). By default it prints the content to the standard output,
or write it to a file if it’s passed as argument.


\begin{alltt}
muse-create-font-file.pl fontspec.json
\end{alltt}


The content looks so:


\begin{alltt}
[
   \{
      "bold" : "/usr/share/fonts/truetype/cmu/cmunbx.ttf",
      "bolditalic" : "/usr/share/fonts/truetype/cmu/cmunbi.ttf",
      "desc" : "CMU Serif",
      "italic" : "/usr/share/fonts/truetype/cmu/cmunti.ttf",
      "name" : "CMU Serif",
      "regular" : "/usr/share/fonts/truetype/cmu/cmunrm.ttf",
      "type" : "serif"
   \},
   \# more entries
]
\end{alltt}


\texttt{muse-create-font-file.pl} uses a default list of font and search them
using \texttt{fc-list}.


The mandatory parameters are:


\begin{description}

\item[{name}] 
The font name as seen by the \texttt{fontconfig}. You can get the
list of installed fonts using \texttt{fc-list}. It’s very important
that the name actually exists and \texttt{fontconfig} sees it,
otherwise when trying to compile a PDF using this font, you
will get a failure. Try e.g. \texttt{fc-list "Linux Libertine O"}


\item[{desc}] 
This is the description you will see on the Book Builder
(\texttt{/bookbuilder}) or in the Custom Formats interface
(\texttt{/settings/formats}). It’s informative only, so it can be
an arbitrary string.


\item[{type}] 
Valid values are \texttt{serif}, \texttt{sans}, \texttt{mono} and should be clear
what this means.


\end{description}

To embed the fonts in the EPUBs, you also need the file location, and
for this there are the four parameters (all of them must be present):


\begin{description}

\item[{\texttt{regular}}] 
The regular font path


\item[{\texttt{italic}}] 
The italic font path


\item[{\texttt{bold}}] 
The bold font path


\item[{\texttt{bolditalic}}] 
The bold italic font path


\end{description}
\chapter{Custom files for chapter\Slash{}section headings}


In the bookbuilder and in the format definition, there is a checkbox:
“Use sans fonts for section titles”. If you want to use a serif font
for that as well, you can cheat, edit the \texttt{fontspec.json} file and
change its \texttt{type} from \texttt{serif} to \texttt{sans}. Sans fonts are allowed as
main font body.

\chapter{Languages (version 2.534 2022-02-12)}


Especially when working with languages which don't use the Latin
script, it becomes necessary to configure which fonts should be
attached to a given languages. You can do so adding a key to each font
family description in the \texttt{fontspec.json} file. The key is,
unsurprisingly, called \texttt{languages} and it needs to be set to an array
of language ISO codes.


Example:


\begin{alltt}
   \{
      "desc" : "Source Han Serif (Simplified Chinese)",
      "languages" : [
         "zh"
      ],
      "name" : "Source Han Serif SC",
      "type" : "serif"
   \},
   ... // more fonts here
\end{alltt}


Here we added a font definition for Chinese. We can have more of them,
but this means that for Chinese we will always use a font defined for
that language.


If the font you explicitly chose to use has not the language
definition for the language in use, but other font families have it,
the first font family with the language set will be used (order of the
definitions matters).

\section{Example for Japanese}


Install the Source Han font, available from \href{https://packages.amusewiki.org/}{\texttt{https://packages.amusewiki.org/}}


\begin{alltt}
apt install fonts-source-han-sans-ja fonts-source-han-serif-ja
\end{alltt}


Then add this stanza to \texttt{/var/lib/amusewiki/fontspec.json}


\begin{alltt}
 [
   \{
      "desc" : "Source Han Serif (Japanese)",
      "languages" : [
         "ja"
      ],
      "name" : "Source Han Serif",
      "type" : "serif"
   \},
   \{
      "desc" : "Source Han Sans (Japanese)",
      "languages" : [
         "ja"
      ],
      "name" : "Source Han Sans",
      "type" : "sans"
   \},
  // other fonts
 ]
\end{alltt}


Beware trailing at the end or missing commas between the definitions.
You can validate the JSON with, for example, \texttt{jq}


\begin{alltt}
jq < /var/lib/amusewiki/fontspec.json
\end{alltt}


For Japanese you may want to enable the option in the admin called:
\emph{Allow Unicode URIs for categories (author, topics). Recommended for
non-latin scripts.}


A similar setup should be used for sites mixing languages using
different scripts. This way you can assign the languages of each
fonts.


Restart amusewiki:


\begin{alltt}
amusewiki restart
\end{alltt}







% begin final page

\clearpage



% new page for the colophon

\thispagestyle{empty}

\begin{center}





\bigskip
\includegraphics[width=0.25\textwidth]{logo-amw.pdf}
\bigskip

\end{center}

\strut

\vfill

\begin{center}




Font management






\bigskip



   

       

       

       

       

       
   



\bigskip
\textbf{amusewiki.org}


\end{center}

% end final page with colophon


\end{document}


% No format ID passed.



