| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2015 by Benjamin Weiss <[email protected]> |
| 4 |
% --------------------------------------------------------------------------- |
| 5 |
% This work may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 7 |
% of this license or (at your option) any later version. |
| 8 |
% The latest version of this license is in |
| 9 |
% http://www.latex-project.org/lppl.txt |
| 10 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 11 |
% version 2005/12/01 or later. |
| 12 |
% |
| 13 |
% This work has the LPPL maintenance status `maintained'. |
| 14 |
% |
| 15 |
% The Current Maintainer of this work is Benjamin Weiss. |
| 16 |
% |
| 17 |
% This work consists of the files iffont.dtx and iffont.ins and the derived |
| 18 |
% file iffont.sty. |
| 19 |
% |
| 20 |
% |
| 21 |
% \fi |
| 22 |
% |
| 23 |
% \iffalse |
| 24 |
%<*driver> |
| 25 |
\ProvidesFile{iffont.dtx} |
| 26 |
%</driver> |
| 27 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 28 |
%<package>\ProvidesPackage{iffont} |
| 29 |
%<*package> |
| 30 |
[2015/11/11 1.0.0 Iffont package] |
| 31 |
%</package> |
| 32 |
%<*driver> |
| 33 |
\documentclass{ltxdoc} |
| 34 |
%\EnableCrossrefs |
| 35 |
%\CodelineIndex |
| 36 |
%\DisableCrossrefs |
| 37 |
%\RecordChanges |
| 38 |
%\OnlyDescription |
| 39 |
\usepackage[parfill]{parskip} |
| 40 |
\usepackage{setspace} |
| 41 |
\onehalfspacing |
| 42 |
|
| 43 |
\usepackage[no-math]{fontspec} |
| 44 |
\setmainfont[BoldFont={Fira Sans}]{Fira Sans Light} |
| 45 |
\setmonofont{Fira Mono} |
| 46 |
\defaultfontfeatures{Ligatures=TeX} |
| 47 |
|
| 48 |
\usepackage{metalogo} |
| 49 |
|
| 50 |
\usepackage{enumitem} |
| 51 |
\setlist[itemize]{noitemsep} |
| 52 |
\setlist[enumerate]{noitemsep} |
| 53 |
|
| 54 |
\usepackage[showerrors,table,hyperref]{xcolor} |
| 55 |
\usepackage{iffont} |
| 56 |
|
| 57 |
\definecolor{mDarkBrown}{HTML}{604c38} |
| 58 |
\definecolor{mDarkTeal}{HTML}{23373b} |
| 59 |
\definecolor{mLightBrown}{HTML}{EB811B} |
| 60 |
\definecolor{mLightGreen}{HTML}{14B03D} |
| 61 |
\definecolor{mBackground}{HTML}{FFFFFF} |
| 62 |
|
| 63 |
\usepackage{listings} |
| 64 |
\lstset{% |
| 65 |
gobble=2, |
| 66 |
language=[LaTeX]{TeX}, |
| 67 |
basicstyle=\ttfamily\small, |
| 68 |
keywordstyle=\color{mLightBrown}\bfseries, |
| 69 |
commentstyle=\color{mLightGreen}, |
| 70 |
stringstyle=\color{mLightGreen}, |
| 71 |
backgroundcolor=\color{mBackground}, |
| 72 |
numbers=none, |
| 73 |
numberstyle=\tiny\ttfamily, |
| 74 |
stepnumber=2, |
| 75 |
showspaces=false, |
| 76 |
showstringspaces=false, |
| 77 |
showtabs=false, |
| 78 |
frame=none, |
| 79 |
framerule=1pt, |
| 80 |
tabsize=2, |
| 81 |
rulesep=5em, |
| 82 |
captionpos=b, |
| 83 |
breaklines=true, |
| 84 |
breakatwhitespace=false, |
| 85 |
framexleftmargin=0em, |
| 86 |
framexrightmargin=0em, |
| 87 |
xleftmargin=0em, |
| 88 |
xrightmargin=0em, |
| 89 |
aboveskip=1em, |
| 90 |
belowskip=1em, |
| 91 |
morekeywords={settofirstfound, setmainfont, boldfont, mainfont, |
| 92 |
FrutigerLight, newfontfamily, lightfont}, |
| 93 |
} |
| 94 |
\lstMakeShortInline| |
| 95 |
|
| 96 |
\usepackage[colorlinks=true, |
| 97 |
linkcolor=mLightBrown, |
| 98 |
menucolor=mLightBrown, |
| 99 |
pagecolor=mLightBrown, |
| 100 |
urlcolor=mLightBrown]{hyperref} |
| 101 |
|
| 102 |
\usepackage{tabu} |
| 103 |
\usepackage{longtable} |
| 104 |
\usepackage{xstring} |
| 105 |
|
| 106 |
\begin{document} |
| 107 |
\DocInput{iffont.dtx} |
| 108 |
\end{document} |
| 109 |
%</driver> |
| 110 |
% \fi |
| 111 |
% |
| 112 |
% \CheckSum{0} |
| 113 |
% |
| 114 |
% \GetFileInfo{iffont.sty} |
| 115 |
% \title{The \textsc{iffont} package} |
| 116 |
% \author{Benjamin Weiss\\ \url{[email protected]}} |
| 117 |
% \date{Version \fileversion~from \filedate} |
| 118 |
% |
| 119 |
% \maketitle |
| 120 |
% |
| 121 |
% \section{Introduction} |
| 122 |
% |
| 123 |
% Using OpenType fonts within \XeLaTeX\ or \LuaTeX\ comes with a lot of |
| 124 |
% benefits, but also the problem, that desired fonts may not be installed on |
| 125 |
% the system, the user choses for the compilation. In case they are, there can |
| 126 |
% still be different revisions of a font with variant names, such as |
| 127 |
% \textit{Frutiger LT Std}, \textit{Frutiger Neue LT Pro} and \textit{Frutiger |
| 128 |
% Next Pro}. |
| 129 |
% |
| 130 |
% Inspired by a question on \href{http://tex.stackexchange.com/q/53443/} |
| 131 |
% {Stack Exchange} and a discussion on the |
| 132 |
% \href{http://tug.org/pipermail/xetex/2010-August/017833.html}{\XeTeX\ |
| 133 |
% Mailinglist}, this package addresses the problem with a set of easy to use |
| 134 |
% macros: a macro to select the first font \XeLaTeX\ or \LuaTeX\ can find in a |
| 135 |
% comma separated list and, additionally, a number of macro tests. |
| 136 |
% |
| 137 |
% \section{Select a Font from a List of Fonts} |
| 138 |
% |
| 139 |
% \DescribeMacro{\settofirstfound} This command defines a new macro with the |
| 140 |
% first font found in the comma separated list. The list is provided as second |
| 141 |
% argument. The macro can then be used to set the main font, set the sans |
| 142 |
% font, define a new font family and so on. The following code shows how to |
| 143 |
% set the main font as the Frutiger Font with the black font weight as bold |
| 144 |
% font. |
| 145 |
% \begin{lstlisting} |
| 146 |
% \documentclass{article} |
| 147 |
% \usepackage{fontspec} |
| 148 |
% \usepackage{iffont} |
| 149 |
% \settofirstfound{\mainfont}{Frutiger Next Pro, |
| 150 |
% Frutiger Neue LT Pro, |
| 151 |
% Frutiger LT Std} |
| 152 |
% \settofirstfound{\boldfont}{Frutiger Next Pro Black, |
| 153 |
% Frutiger Neue LT Pro Black, |
| 154 |
% Frutiger LT Std 75 Black} |
| 155 |
% \setmainfont[BoldFont=\boldfont]{\mainfont} |
| 156 |
% \begin{document} |
| 157 |
% \begin{itemize} |
| 158 |
% \item \mainfont |
| 159 |
% \item \textbf{\boldfont} |
| 160 |
% \end{itemize} |
| 161 |
% \end{document} |
| 162 |
% \end{lstlisting} |
| 163 |
% Defining a new font family works just the same. |
| 164 |
% \begin{lstlisting} |
| 165 |
% \documentclass{article} |
| 166 |
% \usepackage{fontspec} |
| 167 |
% \usepackage{iffont} |
| 168 |
% \settofirstfound{\lightfont}{Frutiger Next Pro Light, |
| 169 |
% Frutiger Neue LT Pro Light, |
| 170 |
% Frutiger LT Std 45 Light} |
| 171 |
% \newfontfamily\FrutigerLight{\lightfont} |
| 172 |
% \begin{document} |
| 173 |
% \begin{itemize} |
| 174 |
% \item {\FrutigerLight \lightfont} |
| 175 |
% \end{itemize} |
| 176 |
% \end{document} |
| 177 |
% \end{lstlisting} |
| 178 |
% \StopEventually{} |
| 179 |
% |
| 180 |
% \section{Macro Tests} |
| 181 |
% In most cases the \lstinline|\settofirstfound| command is sufficient, but |
| 182 |
% for the more demanding user there is also a set of macro tests. They are |
| 183 |
% useful, if one wants to set specific font features only if the first choice |
| 184 |
% font cannot be found. The original \textit{Frutiger LT Std} font for example |
| 185 |
% does not support small caps. So in the following example the |
| 186 |
% \lstinline|\textsc|command is redefined as uppercase with increased letter |
| 187 |
% spacing, but only if the \textit{Frutiger Next Pro} font cannot be found. |
| 188 |
% \begin{lstlisting} |
| 189 |
% \documentclass{article} |
| 190 |
% \usepackage{fontspec} |
| 191 |
% \usepackage{iffont} |
| 192 |
% \settofirstfound{\mainfont}{Frutiger Next Pro, |
| 193 |
% Frutiger LT Std} |
| 194 |
% \setmainfont{\mainfont} |
| 195 |
% \ifxfontexists{Frutiger Next Pro}{% |
| 196 |
% \def\textsc#1{\addfontfeature{LetterSpace=5.0}% |
| 197 |
% \MakeUppercase{#1}} |
| 198 |
% }{} |
| 199 |
% \begin{document} |
| 200 |
% \begin{itemize} |
| 201 |
% \item \mainfont |
| 202 |
% \item \textsc{\mainfont} |
| 203 |
% \end{itemize} |
| 204 |
% \end{document} |
| 205 |
% \end{lstlisting} |
| 206 |
% \section{Implementation} |
| 207 |
% |
| 208 |
% \iffalse |
| 209 |
%<*package> |
| 210 |
% \fi |
| 211 |
% |
| 212 |
% |
| 213 |
% |
| 214 |
% \subsection{Required Packages} |
| 215 |
% Load required packages. |
| 216 |
% \begin{macrocode} |
| 217 |
\RequirePackage{fontspec} |
| 218 |
\RequirePackage{etoolbox} |
| 219 |
% \end{macrocode} |
| 220 |
% |
| 221 |
% Init required variables. |
| 222 |
% \begin{macrocode} |
| 223 |
\newtoggle{@iffont@fontfound} |
| 224 |
\newcommand{\@iffont@firstfont}{Fira Sans} |
| 225 |
\newcounter{@iffont@fontsnotfound} |
| 226 |
% \end{macrocode} |
| 227 |
% |
| 228 |
% \begin{macro}{\iffontsexist} |
| 229 |
% If all fonts are found the commands in the second argument will be executed, |
| 230 |
% otherwise the commands in the third argument. |
| 231 |
% \begin{macrocode} |
| 232 |
\newcommand{\iffontsexist}[3]{ |
| 233 |
\setcounter{@iffont@fontsnotfound}{0} |
| 234 |
\expandafter\forcsvlist\expandafter\@iffont@checkfont\expandafter{#1} |
| 235 |
\ifnumequal{\value{@iffont@fontsnotfound}}{0}{% |
| 236 |
#2 |
| 237 |
}{% |
| 238 |
#3 |
| 239 |
} |
| 240 |
} |
| 241 |
% \end{macrocode} |
| 242 |
% \end{macro} |
| 243 |
% |
| 244 |
% \begin{macro}{\ifxfontsexist} |
| 245 |
% Same as \lstinline|\iffontsexist|, but negated. |
| 246 |
% \begin{macrocode} |
| 247 |
\newcommand{\ifxfontsexist}[3]{ |
| 248 |
\iffontsexist{#1}{#3}{#2} |
| 249 |
} |
| 250 |
% \end{macrocode} |
| 251 |
% \end{macro} |
| 252 |
% |
| 253 |
% \begin{macro}{\iffontexists} |
| 254 |
% A simpler and therefore faster if clause, that only checks for a single font. |
| 255 |
% \begin{macrocode} |
| 256 |
\newcommand{\iffontexists}[3]{ |
| 257 |
\suppressfontnotfounderror=1 |
| 258 |
\font\x = "#1" at 10pt |
| 259 |
\ifx\x\nullfont |
| 260 |
#3 |
| 261 |
\else |
| 262 |
#2 |
| 263 |
\fi |
| 264 |
\suppressfontnotfounderror=0 |
| 265 |
} |
| 266 |
% \end{macrocode} |
| 267 |
% \end{macro} |
| 268 |
% |
| 269 |
% \begin{macro}{\ifxfontexists} |
| 270 |
% Same as \lstinline|\iffontexists|, but negated. |
| 271 |
% \begin{macrocode} |
| 272 |
\newcommand{\ifxfontexists}[3]{ |
| 273 |
\iffontexists{#1}{#3}{#2} |
| 274 |
} |
| 275 |
% \end{macrocode} |
| 276 |
% \end{macro} |
| 277 |
% |
| 278 |
% \begin{macro}{\settofirstfound} |
| 279 |
% Sets the macro in the first argument to the first font in the comma separated |
| 280 |
% list of fonts in the second argument that is found. |
| 281 |
% \begin{macrocode} |
| 282 |
\newcommand{\settofirstfound}[2]{ |
| 283 |
\togglefalse{@iffont@fontfound} |
| 284 |
\expandafter\forcsvlist\expandafter\@iffont@checkfont\expandafter{#2} |
| 285 |
\let#1\@iffont@firstfont |
| 286 |
} |
| 287 |
% \end{macrocode} |
| 288 |
% \end{macro} |
| 289 |
% |
| 290 |
% \begin{macro}{\@iffont@checkfont} |
| 291 |
% Checks if a font is found and increases the \lstinline|@iffont@fontsnotfound| |
| 292 |
% counter if not. The first font found will be saved in |
| 293 |
% \lstinline|\@iffont@firstfont|. |
| 294 |
% \begin{macrocode} |
| 295 |
\newcommand{\@iffont@checkfont}[1]{ |
| 296 |
\suppressfontnotfounderror=1 |
| 297 |
\font\x = "#1" at 10pt |
| 298 |
\ifx\x\nullfont |
| 299 |
\stepcounter{@iffont@fontsnotfound} |
| 300 |
\else |
| 301 |
\nottoggle{@iffont@fontfound}{% |
| 302 |
\renewcommand{\@iffont@firstfont}{#1} |
| 303 |
\toggletrue{@iffont@fontfound} |
| 304 |
}{} |
| 305 |
\fi |
| 306 |
\suppressfontnotfounderror=0 |
| 307 |
} |
| 308 |
% \end{macrocode} |
| 309 |
% \end{macro} |
| 310 |
% |
| 311 |
% \iffalse |
| 312 |
%</package> |
| 313 |
% \fi |
| 314 |
% |
| 315 |
% \Finale |
| 316 |
\endinput |