Computer font, LaTeX font.

1. Computer font

A computer font (or font) is an electronic data file containing a set of glyphs, characters, or symbols such as dingbats. It is generally used to refer to a scalable set of digital shapes that may be printed at many different sizes. There are three basic kinds of computer font file data formats[1]:

  • Bitmap fonts consist of a matrix of dots or pixels representing the image of each glyph in each face and size.
  • Outline fonts (also called vector fonts) use Bézier curves, drawing instructions and mathematical formulae to describe each glyph, which make the character outlines scalable to any size.
  • Stroke fonts use a series of specified lines and additional information to define the profile, or size and shape of the line in a specific face, which together describe the appearance of the glyph.

1.1 Outline fonts

OpenType

OpenType is a format for scalable computer fonts. It was built on its predecessor TrueType, retaining TrueType's basic structure and adding many intricate data structures for prescribing typographic behavior. OpenType is a registered trademark of Microsoft Corporation.

TrueType

TrueType is an outline font standard developed by Apple and Microsoft in the late 1980s as a competitor to Adobe's Type 1 fonts used in PostScript. It has become the most common format for fonts on both the Mac OS and Microsoft Windows operating systems.

PostScript fonts: Type 1 font

PostScript fonts are outline font specifications developed by Adobe Systems for professional digital typesetting, which uses PostScriptfile format to encode font information.

2. TeX字体属性

TeX的字体属性有编码(encoding)、族(family)、系列(series)、形状(shape)和字体大小五个属性。main/sans/mono这几个设置对应的是三种不同的family,即衬线/无衬线/等宽字体。中文字体都是等宽的。 字体的相关命令\textrm \textsf \texttt或者\rmfamily \sffamily \ttfamily对应的是三种不同族的字体[3]。

The following subsections are excerpted from WIKIBOOKS LaTeX/Fonts.

2.1 Font families

(1) font families

Excertpt from Fonts and TeX - TeX Users Group,

Computer Modern: Getting to specifics, the first and still most prevalent typeface in the TeX world is Computer Modern, developed by Donald Knuth using his novel Metafont program, which comes with TeX.

Other Modern: Variants of Computer Modern have been created which cover letters and symbols from virtually all other Latin-based languages, as well translating the characters into PostScript Type 1 fonts, etc. Latin Modern and cm-super are two notable collections along these lines.

Base PostScript: TeX also comes with support for the 35 standard PostScript fonts: Times Roman, Helvetica, Courier, Palatino, et al. (URW++ graciously donated these fonts to the public in 1996, thanks to the efforts of Peter Deutsch for Ghostscript. In 2009, URW also made them available under the LPPL, thanks to the GUST font team. The GPL'd originals, are available for reference. Version 4.0 of the fonts was the basis for subsequent work by GUST. The current versions distributed by Ghostscript are substantially different.

(2) Computer Modern

Excerpt from Computer Modern - Wikipedia,

A current extended release of the Computer Modern family in the general-purpose OpenType format as the CMU distribution (link below) includes:

  • CMU Serif, the main Computer Modern font family. This includes the four traditional styles of font (regular, italic, bold, bold italic), and also:

    • CMU Serif upright italic, an upright italic style similar to cursive upright handwriting
    • CMU Serif bold non-extended, a bold weight duplexed to have the same width as the regular style
    • CMU Serif roman and bold slanted, two oblique styles
    • CMU Classical Serif, an italic design with slightly simpler serif designs
  • Concrete Roman, a slab serif font in the four standard styles

  • CMU Typewriter, a typewriter-style slab serif font

  • CMU Sans Serif, a complementary

    sans-serif

    font, and CMU Bright, a lighter style of the same design

    • CMU Sans demi-condensed, a condensed style of the same design

(3) roman, sans serif and monospace

There are many font families e.g. Computer Modern, Times, Arial and Courier. Those families can be grouped into three main categories (it is interchangeable among them):

  • roman (rm) or serif, \rmdefault
  • sans serif (sf), \rfdefault
  • monospace (tt), \ttdefault

Serif vs Sans-serif

Excerpt from Wikipedia Serif,

In typography, a serif /ˈsɛrɪf/ is a small line attached to the end of a stroke in a letter or symbol.[1] A typeface with serifs is called a serif typeface (or serifed typeface). A typeface without serifs is called sans serif or sans-serif, from theFrench sans, meaning "without." Some typography sources refer to sans-serif typefaces as "Grotesque" (in German "grotesk") or "Gothic",[2] and serif typefaces as "Roman."

serif_font

Computer Modern Roman is the default font family for LaTeX. Fonts in each family also have different properties (size, shape, weight, etc.). Families are meant to be consistent, so it is highly discouraged to change fonts individually rather than the whole family.

The default is defined like the following assignment:

\renewcommand*{\familydefault}{\sfdefault}

2.2 Font encoding

Upon compilation, tex will have to choose the right font glyph (which is what the reader sees) for every character. This is what is called font encoding. The default LaTeX font encoding is OT1, the encoding of the original Computer Modern TeX text fonts. It contains only 128 characters, many from ASCII, but leaving out some others and including a number that are not in ASCII.

The fontenc package tells LaTeX what font encoding to use.

fontenc – Standard package for selecting font encodings

The package allows the user to select font encodings, and for each encoding provides an interface to 'font-encoding-specific' commands for each font. Its most powerful effect is to enable hyphenation to operate on texts containing any character in the font.

Font encoding is set with:

[sourcecode language='matlab'  padlinenumbers='true']
\usepackage['encoding']{fontenc} 

%where encoding is the font encoding. It is possible to load several encodings simultaneously.
[/sourcecode]

The default Computer Modern font does not support T1. You will need Computer Modern Super (cm-super) or Latin Modern (lmodern), which are Computer Modern-like fonts with T1 support. For lmodern, you will need to load the package after the T1 encoding has been set:

[sourcecode language='matlab' ]
\usepackage[T1]{fontenc}
\usepackage{lmodern}

2.3 Font styles (font properties)

Each family has its own font characteristics (such as italic and bold), also known as font styles, or font properties. Font styles are usually implemented with different font files.

2.3.1 Font shapes

The following table lists the commands you will need to access the typical font shapes:

font_shapes

2.3.2 Font sizes

font_size

3. LaTeX font

3.1 Fontspec

CTAN: package fontspec – Advanced font selection in X∃LATEX and LuaLATEX,

Fontspec is a pack­age for X∃LATEX and LuaLATEX. It pro­vides an au­to­matic and uni­fied in­ter­face to fea­ture-rich AAT and OpenType fonts through the NFSS in LATEX run­ning on X∃TEX or LuaTEX en­gines.

CTAN (The Com­pre­hen­sive TEX Archive Net­work) is the cen­tral place for all kinds of ma­te­rial around TEX. CTAN has cur­rently 4995 pack­ages. 2302 con­trib­u­tors have con­tributed to it. Most of the pack­ages are free and can be down­loaded and used im­me­di­ately.

3.2 General font selection

The variety of commands that can be used to select fonts.

\fontspec{<font name>}[<font features>]
\setmainfont{<font name>}[<font features>]
\setsansfont{<font name>}[<font features>]
\setmonofont{<font name>}[<font features>]
\newfontfamily<cmd>{<font name>}[<font features>]

# Anexample
\setmainfont{Times New Roman}

各个命令的含义如下(摘抄自知乎的回答,这里):

  • \setmainfont{ } 一般就是论文中西文部分默认使用的字体。通常到Word 2003为止,这里的默认字体都会是Times New Roman。Linux下也有同名字体。
  • \setsansfont{ } 是西文默认无衬线字体。一般可能出现在大标题等显眼的位置。这一部分经常碰上的字体会是Helvetica/Arial。Linux下也有Helvetica,前缀是-adobe-helvetica-*。这是一个古老的非抗锯齿版本(也就是不用fontconfig配置而使用xfontsel),所以如今的XWindow环境应该不会再使用它作为屏幕字体。而Windows下的Word则经常会默认为Arial。之前我说Windows下也能看见Helvetica,应该是源自一些错误的印象。经再次确认,Word和Windows本身都不自带 Helvetica。感谢@梁海 君指出 Windows下没有Helvetica。
  • \setmonofont{ }是西文默认的等宽字体。一般用于排版程序代码。Courier或者Courier New是常见的 Word选项。Linux下一般会有Courier,但很少能看见Courier New。
  • \setCJKmainfont[BoldFont={ },ItalicFont={ }]{ }这个命令指定中文(或韩文日文)的默认字体。通常情况下,我见过的大部分文档论文会要求用宋体排版,实际上就是说的是SimSun。Linux 下可能用文鼎宋体代替,不过效果可能较差。另一点是和西文不同的地方,这个设置允许我们指定粗体和斜体应用何种字体代替。之所以有这个区别,是因为中文不使用粗体表示强调,也不使用斜体表示引文或书名号。我一般会指定BoldFont 和 ItalicFont 为某种黑体,Windows 环境下是SimHei,Linux 下我会用文泉驿正黑避免版权问题。但具体操作上可能需要灵活调整。有些高校的论文模板,比如我母校就是明确要求强调段落必须使用楷体(SimKai),只能照着要求设置。

  • \setCJKsansfont{ }\setCJKmonofont{ }。这两个我没怎么用过,也说不清子丑寅卯来。一个比较安全的设置是统统设置成宋体,然后实际排版一次之后回头看看效果,再做必要的调整。我承认这样可能会比较难看,但至少不会有过于突兀的效果。

References:

[1] Wikipedia: Computer font

[2] WIKIBOOKS LaTeX/Fonts

[3] 知乎:使用LaTeX排版时如何通过fontspec包选择字体?

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-04-09 11:29

results matching ""

    No results matching ""