Fonts for Displaying Program Code in L A TEX



Similar documents
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

The gensymb package for L A TEX 2ε

Formatting Text in Microsoft Word

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

J a v a Quiz (Unit 3, Test 0 Practice)

PDF-form creation using pdflatex, hyperref and insdljs. Dirk Krause February 7, 2008

SPSS for Windows importing and exporting data

Setting Up Database Security with Access 97

Downloading soft fonts to Zebra printers with Adobe Output Designer / Adobe Central Output Server.

How to set up a database in Microsoft Access

Accounting Manager. User Guide A31003-P1030-U

SAPScript. A Standard Text is a like our normal documents. In Standard Text, you can create standard documents like letters, articles etc

Elfring Fonts, Inc. PCL MICR Fonts

L A TEX in a Nutshell

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0

USER GUIDE FOR L ANNÉE PHILOLOGIQUE ON THE INTERNET

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

13 Classes & Objects with Constructors/Destructors

How To Use L A T Ex On Pc Or Macbook Or Macintosh (Windows) With A L At Ex (Windows 3) On A Pc Or Ipo (Windows 2) With An Ipo Computer (Windows 4)

Using SQL Server Management Studio

For keyboard and touchscreen BlackBerry devices User manual

Tutorial 5 Creating Advanced Queries and Enhancing Table Design

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Unicode in Mobile Phones

Form Design Guidelines Part of the Best-Practices Handbook. Form Design Guidelines

Instructions for Creating Silly Survey Database

Object Oriented Software Design

Word Processing programs and their uses

fonts: tutorial How to install a Type1 Font using fontinst

Microsoft Expression Web Quickstart Guide

Chapter 2 Review Questions and Answers

OpenDJ LDAP SDK Release Notes

BAR CODE CONTROL BAR CODE CONTROL - 1

Basic Formatting of a Microsoft Word. Document for Word 2003 and Center for Writing Excellence

csce4313 Programming Languages Scanner (pass/fail)

Contents 1. Introduction... 2

Conditionals (with solutions)

Fonts in Plots. Paul Murrell. July

Introduction to Logo Design

Sample CSE8A midterm Multiple Choice (circle one)

Inserting Graphics into Grant Applications & Other Word Documents

HOW TO PAGE A DOCUMENT IN MICROSOFT WORD

Microsoft Office 2010 Publisher

BCCC Library. 2. Spacing-. Click the Home tab and then click the little arrow in the Paragraph group.

Enhanced Formatting and Document Management. Word Unit 3 Module 3. Diocese of St. Petersburg Office of Training Training@dosp.

PPUM icare SINGLE SIGN ON

Smartphones and tablets: If you have a data plan, use the SMTP server setting for the company that provides this service.

Serif or Modern Fonts

Audit Trail Administration

BAR CODE 39 ELFRING FONTS INC.

Using EXCEL Solver October, 2000

Version of Barcode Toolbox adds support for Adobe Illustrator CS

SWsoft, Inc. Plesk File Server. Administrator's Guide. Plesk 7.5 Reloaded

AP Computer Science Java Subset

set in Options). Returns the cursor to its position prior to the Correct command.

13-1. This chapter explains how to use different objects.

Perfion Output Using Special Barcode fonts

Microsoft PowerPoint 2010 Handout

HOW TO USE THE File Transfer Protocol SERVER ftp.architekturaibiznes.com.pl

Preparing Your Thesis with Microsoft Word: How to use the Rensselaer Polytechnic Institute Template Files. Contents

Create Mailing Labels from an Electronic File

MultiCHAX. Check Printing System for Windows. Getting Started Guide

Planning and Managing Projects with Microsoft Project Professional 2013

Frequently Asked Questions on character sets and languages in MT and MX free format fields

webmethods Certificate Toolkit

LEXMARK DOCUMENT SOLUTIONS SUITE 3.3.8

TUGboat, Volume 31 (2010), No

Guide to design and layout

THE KNITTING PACKAGE

Mac OS X 10 Using the Keyboard Viewer and Character Palette

Guidelines for Seminar Papers and Final Papers (BA / MA Theses) at the Chair of Public Finance

WPF font selection model

JDarkRoom. User Guide. Version 14. Copyright 2009 Duncan Jauncey.

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

TLMC WORKSHOP: THESIS FORMATTING IN WORD 2010

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Rational Rational ClearQuest

C++ INTERVIEW QUESTIONS

Creating tables of contents and figures in Word 2013

1 Using CWEB with Microsoft Visual C++ CWEB INTRODUCTION 1

Produced by: Flinders University Centre for Educational ICT

Charter . Addresses Create / Manage

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Maple Quick Start. Introduction. Talking to Maple. Using [ENTER] 3 (2.1)

Utilizing Microsoft Access Forms and Reports

Styles, Tables of Contents, and Tables of Authorities in Microsoft Word 2010

COBOL FormPrint Windows Form Printing for COBOL Version 4.1 User Guide

Getting Started with Command Prompts

MS InfoPath 2003 MS InfoPath 2007 Microsoft Office InfoPath 2003 minimally runs on the following operating systems:

Transcription:

Fonts for Displaying Program Code in L A TEX Adrian P. Robson nepsweb.co.uk 8 October 2012 1 Introduction Here we look at fonts for printing program code in L A TEX documents. Suitable fonts are monospaced; have good glyphs for the special character used in program code; and have no confusing similarities between character glyphs. The fonts must also be simple to set as the default typewriter font, so they are easy to use in L A TEX verbatim environments. The following discussion is based on the typewriter fonts listed in The L A TEX Font Catalogue (www.tug.dk/fontcatalogue), and the examples work with MikTex and TeXlive installations. 2 Monospaced Fonts The following are the monospaced fonts that are easily available and can be simply used in verbatim environments. They are shown here at their normal size, with the upquotes package. Computer Modern Typewriter Latin Modern Typewriter TXTT Bera Mono 1

DejaVu Sans Mono Courier TeX Gyre Cursor KP Monospaced 1234567890 (a){a[a] -+ * / %^ =<>!& ~ ;:_#@$'" LuxiMono Inconsolata 1234567890 (a){a[a] -+*/ %^ =<>!& ~ ;:_#@$" 3 Computer and Latin Modern Fonts The Computer Modern Fonts are the L A TEX default, so no action is needed to use its typewriter family. It is generally very good for program listings, but its tilde is too high and its minus too low, as this shows: +-~x. It has a plain zero. The Latin Modern family of fonts is almost the same as Computer Modern but its typewriter font has a lower tilde and higher minus: +-~x. 3.1 Using Latin Modern Typewriter If the Latin Modern Typewriter font is wanted, it is best to adopt the whole family with \usepackage{lmodern 4 TXTT Font This font is similar to Computer Modern, but it is generally a little bolder, and has a single story g glyph. It has a centrally aligned tilde ~ and a crossed zero 0. However, its asterisk glyph * is poor and set too high. To use it, simply make TXTT the default typewriter font: \renewcommand*\ttdefault{txtt 2

5 Bera and DejaVu Fonts Bera Mono and DejaVu Sans Mono fonts are almost identical 1 at the same scale, but the DejaVu asterisk glyph * is higher than Bera s *. At default scale values, DejaVu is slightly larger than Bera. The fonts are sans serif. They have a single story g glyph, a centrally aligned tilde ~, and a dotted zero 0. 5.1 Using Bera Mono To use Bera Mono as the default typewriter font, put the following in the preamble: \usepackage[scaled]{beramono If only occasional use of the font is needed then put this is the preamble after the main font families have been selected: \edef\oldtt{\ttdefault \usepackage[scaled]{beramono \renewcommand*\ttdefault{\oldtt \newcommand{\bera[1]{{\fontfamily{fvm\selectfont #1 This retains the existing typewriter font, and allows the following to to used to invoke Bera when needed: \bera{xdf-hju-0d4-s2e 5.2 Using DejaVu Sans Mono To use DejaVu Sans Mono as the default typewriter font, put the following in the preamble: \usepackage[scaled]{dejavusansmono 6 Courier and TeX Gyre Cursor Fonts Courier and TeX Gyre Cursor are almost identical 2, but the Courier asterisk glyph * is lower than Gyre s *. The fonts are lighter and larger than Computer Modern. They have a single story g glyph, a centrally aligned tilde ~, and a plain zero. 6.1 Using Courier To use Courier as the default typewriter font, put the following in the preamble: \usepackage{courier 1 DejaVu and Bera fonts are both derived from the Bitstream Vera fonts. 2 The font that is actually provided for Courier is URW Nimbus Mono. The TeX Gyre Cursor font is an enhanced version of this. 3

6.2 Using TeX Gyre Cursor To use TeX Gyre Cursor as the default typewriter font, put the following in the preamble: \usepackage{tgcursor 7 KP Monospaced KP Monospaced is sans serif with a plain zero. Its special characters are well balanced: * +-~x, but its zero and capital O are very similar: 0O. It is part of a font family with roman, sans-serif and monospaced shapes. 3 To adopt just its monospaced font, include this in the document preamble: \renewcommand*\ttdefault{jkptt 8 LuxiMono LuxiMono is a rather heavy and large serif font with a plain zero. Its special characters are well balanced: *+-~x, but its zero and capital O glyphs are very similar: 0O. To use it as the default typewriter font, put the following in the document s preamble: \renewcommand*\ttdefault{ul9 9 Inconsolata Font This could be a nice programming font 4, but it does not work with the upquotes package. It should also have a crossed zero but this is not the default in its L A TEX implementation (See below). Nevertheless, the Inconsolata font can be made the default typewriter font with \usepackage{inconsolata or it can be invoked explicitly with \newcommand{\textincon[1]{% {\fontfamily{fi4\selectfont #1... \textincon{this is Inconsolata text 3 The KP Fonts Serif family of fonts is based on the URW Palladio fonts. The mathematics fonts include all the AMS fonts, in both normal and bold weights. 4 Inconsolata was inspired by Microsoft s Consolas font 4

9.1 Crossed Zeros with Inconsolata The Inconsolata font is advertised as having a crossed zero, but its version in MikTeX and TexLive does not have this feature. Nevertheless, a slashed zero can be obtained by defining a new command: \usepackage[ei1,t1]{fontenc... \newcommand{\slashzero{{% \fontencoding{ei1\selectfont \char9 This uses the EI1 encoding, and to make this work with MikTex or TexLive installations a ei1enc.def file has to be provided. Appendix E gives a minimal implementation of a suitable definition file. Once all this is done, the \slashzero command can be used as follows: \textincon{\slashzero 123456789 which gives 0123456789. Unfortunately, this method only works for explicit invocation, and will not work for verbatim environments. 10 Conclusions and Recommendations We can reach the following conclusions: Do not use Inconsolata because it does not work with the upquote package. Do not use TXTT for program code because of its bad asterisk. However, its crossed zero can work well for passwords and the like. Do not use KP Monospaced because its zero and upper case O are too similar. Do not use LuxiMono because its zero and upper case O are too similar. Use Latin Modern instead of Computer Modern because its minus and title are better aligned. Use Bera Mono instead of DejaVu Sans Mono because it has a better asterisk. Use Courier instead of TeX Gyre Cursor because it has a better asterisk. In summary, for program code in L A TEX documents: Marked Zero: Bera Mono Plain Zero: Latin Modern Typewriter or Courier Which of these plain zero fonts is best is mainly a matter of taste. But if the general font family would have been Computer Modern, then Latin Modern Typewriter is an obvious choice. 5

A Name Comparison Computer Modern count01 alldone MAX_VALUE Latin Modern count01 alldone MAX_VALUE TXTT count01 alldone MAX_VALUE Bera Mono count01 alldone MAX_VALUE KP Monospaced count01 alldone MAX_VALUE Courier count01 alldone MAX_VALUE TeX Gyre Cursor count01 alldone MAX_VALUE LuxiMono count01 alldone MAX_VALUE B Symbol Comparison Computer Modern x~+-*/% -><=!& ^ apr@neps.co.uk Latin Modern x~+-*/% -><=!& ^ apr@neps.co.uk TXTT x~+-*/% -><=!& ^ apr@neps.co.uk Bera Mono x~+-*/% -><=!& ^ apr@neps.co.uk DejaVu Sans Mono x~+-*/% -><=!& ^ apr@neps.co.uk KP Monospaced x~+- * /% -><=!& ^ apr@neps.co.uk Courier x~+-*/% -><=!& ^ apr@neps.co.uk TeX Gyre Cursor x~+-*/% -><=!& ^ apr@neps.co.uk LuxiMono x~+-*/% -><=!& ^ apr@neps.co.uk C Confusable Characters Computer Modern Teletype Z2 li1 S5 O0 TXTT Z2 li1 S5 O0 Bera Mono Z2 li1 S5 O0 KP Monospaced Z2 li1 S5 O0 Courier Z2 li1 S5 O0 LuxiMono Z2 li1 S5 O0 Inconsolata Z2 li1 S5 O0 6

D Sample Code D.1 Latin Modern Typewriter /* This does not make algorithmic sense, but it shows off * significant programming characters. */ #include<stdio.h> void myfunction( int input, float* output ) { switch ( array[i] ) { case 1: // This is silly code if ( a >= 0 b <= 3 && c!= x ) *output += 0.005 + 20050; char = 'g'; b = 2^n + ~right_size - leftsize * MAX_SIZE; c = (--aaa + &daa) / (bbb++ - ccc % 2 ); strcpy(a,"hello $@?"); count = ~mask 0x00FF00AA; D.2 Bera Mono /* This does not make algorithmic sense, but it shows off * significant programming characters. */ #include<stdio.h> void myfunction( int input, float* output ) { switch ( array[i] ) { case 1: // This is silly code if ( a >= 0 b <= 3 && c!= x ) *output += 0.005 + 20050; char = 'g'; b = 2^n + ~right_size - leftsize * MAX_SIZE; c = (--aaa + &daa) / (bbb++ - ccc % 2 ); strcpy(a,"hello $@?"); count = ~mask 0x00FF00AA; 7

D.3 Courier /* This does not make algorithmic sense, but it shows off * significant programming characters. */ #include<stdio.h> void myfunction( int input, float* output ) { switch ( array[i] ) { case 1: // This is silly code if ( a >= 0 b <= 3 && c!= x ) *output += 0.005 + 20050; char = 'g'; b = 2^n + ~right_size - leftsize * MAX_SIZE; c = (--aaa + &daa) / (bbb++ - ccc % 2 ); strcpy(a,"hello $@?"); count = ~mask 0x00FF00AA; E Encoding Definition File for Inconsolata This is the EI1 encoding file needed for crossed zeros in Inconsolata (See section 9.1). It should be called ei1enc.def, and put in the same folder as the L A TEX document: \ProvidesFile{ei1enc.def \DeclareFontEncoding{EI1{{ \DeclareFontSubstitution{EI1{fi4{m{n Details of the commands used in this file can be found in LATEX2e font selection at www.latex-project.org/guides/fntguide.pdf. 8