问题描述
我们在使用latex写文档时,一般会使用中英文的默认字体,但是在某些特殊需求下,我们可能需要变换使用下其他字体,通常系统一般自带了很多字体,关于有哪些字体,可以打开Word,打开其中的字体选项,下拉列表中那么多,我们如何在latex中也很方便地使用,看下面
解决方案
首先确定一下你本机上存储字体的文件夹,然后查看你相中字体的信息,以Ubuntu为例,查看字体信息如下:
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
使用上述结果中的Full name
即FreeSans
在latex文档头中进行设置,例如:
\documentclass{article}
\usepackage{fontspec,kantlipsum}
\setmainfont{FreeSans}
\begin{document}
\kant[1]
\end{document}
关键在于使用正确的字体名来设置你的latex文档头
当然,你也可以从网上搜索下载喜欢的其他字体,使用上述方法,在latex中使用该字体。