Math & Science ⇒ ligature fi in computer programs
ligature fi in computer programs
if x>0 then y:=5 else z:=7 fi
I use bold sans serif to typeset the keywords:
\keyword{if} if x>0 \keyword{then} y:=5 \keyword{else} z:=7 \keyword{fi}
where
\ifxetexorluatex %%%Define bold sans serif math fonts.
\else
\DeclareMathAlphabet{\mathbfsf}{\encodingdefault}{\sfdefault}{bx}{n}
\fi
\DeclareRobustCommand*{\keyword}[1]{%
\ifmmode%
\ifxetexorluatex\mathbfsfup{#1}\else\mathbfsf{#1}\fi%
\else%
\textsf{\textbf{#1}}%
\fi%
}
where iftexetorluatex simply checks whether a UTF-8 engine is used.
(Of course, := is replaced by a proper command, and more of the above is macroified, but expanding on this would be distracting here.)
My main font is a Times clone, my sans font is a Helvetica clone. Thus, I write
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\setsansfont{TeX Gyre Heros}[Scale=0.88]
for {xe|lua}latex and
\usepackage{newtxtext}
\usepackage[slantedGreek]{newtxmath}
for pdflatex in the preamble.
Question: Does `f\/i` instead of `fi` produce a more pleasant or more logical result in German typography? Is there any guideline or typographical hint on this?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
ligature fi in computer programs
For code, I would not use ligatures. I think that in code keywords seeing actual characters is important and consistent appearance of characters.
Also copy and paste of code should give the correct characters.
Btw. you could also get the opinion of German speaking users on TeXwelt.de.
Stefan