![使用 Ubuntu 系统字体](https://linux22.com/image/322232/%E4%BD%BF%E7%94%A8%20Ubuntu%20%E7%B3%BB%E7%BB%9F%E5%AD%97%E4%BD%93.png)
我找到了几个关于 Windows 的答案,但没有关于 Linux 的答案。我正在使用 Ubuntu,目前,我只想使用计算机上已安装的字体来从 Tex 文档生成 PDF。
我发现:使用多种系统字体它向我展示了 TeX,但是我如何从 Ubuntu 字体转到字体系列?
假设我想在测试中使用 FreeOs Sans Serif 字体。
稍后我想安装自己的字体并使用它。
答案1
您可以使用它otfinfo
来获取系统上安装的字体的正确名称。
例如,
otfinfo -i /usr/share/fonts/TTF/FreeSans.ttf
提供以下信息:
Family: FreeSans
Subfamily: Regular
Full name: FreeSans
PostScript name: FreeSans
Version: Version 0412.2268
Unique ID: GNU: FreeSans Normal: 2012
Manufacturer: GNU
Vendor URL: https://savannah.gnu.org/projects/freefont/
Copyright: Copyright 2002, 2003, 2005, 2008, 2009, 2010, 2012 GNU Freefont contributors.
License URL: http://www.gnu.org/copyleft/gpl.html
License Description: This computer font is part of GNU FreeFont. It is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This font is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this font. If not, see
http://www.gnu.org/licenses/
As a special exception, if you create a document which uses this font, and embed this font or unaltered portions of this font into the document, this font does not by itself cause the resulting document to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the document might be covered by the GNU General Public License. If you modify this font, you may extend this exception to your version of the font, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.
Vendor ID: GNU
然后可以使用全名FreeSans
来设置文档字体:
\documentclass{article}
\usepackage{fontspec,kantlipsum}
\setmainfont{FreeSans}
\begin{document}
\kant[1]
\end{document}
当然,这种选择显然不太好,因为你不应该将文档正文设置为无衬线字体。(除非你正在制作幻灯片或类似的东西。)但出于演示目的,这种做法是可行的:
您需要使用 LuaLaTeX 或 XeLaTeX。上面的输出是用 LuaLaTeX 编译的,对我来说,它比 XeLaTeX 好用得多。
我在 GNU/Linux 上使用 TeX,因此也许值得对 XeTeX 提出一点警告。
如果您尝试使用 XeLaTeX,请不要在编译期间离开您的计算机,以防万一 - XeLaTeX 往往会挂起,至少对我来说,它会以某种方式加速 CPU 的运转,从而迅速失控。虽然您的操作系统应该会在计算机过热之前终止该进程,但我个人不想依赖它。确保您知道如何终止该进程并准备好终端。如果您从命令行进行编译,请打开第二个终端,因为您无法使用通常的控制字符来中断该进程。
答案2
您必须使用XeLaTeX
或进行编译LuaLaTeX
。您应该加载fontspec
,并在您的序言中写入
\setmainfont{FreeOs font Sans Serif}
或者
\setsansfont{FreeOs font Sans Serif}
如果您只想将其用作默认的 sans 字体。
当然,这假设你提供了精确的字体的名称,一般不是.otf文件的名称。