LaTeX forum ⇒ Math & Scienceligature fi in computer programs

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Posts: 30
Joined: Wed Apr 17, 2019 12:51 pm

ligature fi in computer programs

Postby user49915 » Wed Jun 05, 2019 12:26 am

In Computer Science, from type to time you have to type program parts such as

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}


\ifxetexorluatex %%%Define bold sans serif math fonts.


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


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?

User avatar
Posts: 132
Joined: Thu Aug 03, 2017 10:54 am

Postby thomasb » Wed Jun 05, 2019 2:32 pm

or put everything in fixed size with listings package :
  1. \usepackage{listings}

User avatar
Stefan Kottwitz
Site Admin
Posts: 9390
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Jun 06, 2019 12:28 am


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

Site admin

Return to “Math & Science”

Who is online

Users browsing this forum: Baidu [Spider] and 3 guests