Sometimes when you are running your LaTeX files, you do not have the packages that are included in the preamble (usually the sty file). Then you will need to have it added in your computer. It is not difficult to download the sty files from Internet, but the question is where to put them?
The most straightforward solution is to locate the sty files under the same directory of the tex source file. It is perfectly if the file is peculiar and you just want to use it once for the specific tex. However sometimes, you would like to reuse the file without copying it everywhere. Then you may look at the following solutions.
The most popular way is to update your packages with a package manager, such as Tex Live Utility for Mac (I remember something similar exists in MiKTeX for Windows). In this case, you just need to search for the package, and update it with a single click. And you will never be concerned with where the packages are stored.
Another more laboring way is to copy the sty file under the texmf or texmf-local folder. In Mac, the specific directory is "~/Library/texmf/tex/latex/".
Reference:
http://tex.stackexchange.com/questions/10252/how-do-i-add-a-sty-file-to-my-mactex-texshop-installation
http://tex.stackexchange.com/questions/12102/how-do-i-install-ctan-packages-on-mac-os-with-texshop
Not Yet...
2014年10月24日星期五
2013年11月23日星期六
LaTex中文字体库的添加
最近帮朋友测试一个中文LaTex模版(上海交大硕士论文)的时候出现了一些中文字体的问题,总结如下。
首先是字体库的下载。由于Mac自带的中文字体并不完整,需要自己下载。在下面的第一个链接中有Adobe的四套字体和隶书,幼圆,这样就有了6套完整的中文字体。第二个链接只包括Adobe的四套字体,另外两个需要自己再到其他地方下载。
http://tinker-bot.googlecode.com/files/cfonts.tar.gz
http://ishare.iask.sina.com.cn/f/15105086.html
关于字体的安装,有以下几种方法:
- 在Mac的应用程序中选择“字体册”,点击添加即可,这样会把几种字体保存到用户的字体目录下,具体的目录是:/Users/***/Library/Fonts/
- 手动将字体文件拷贝到字体目录下,有几个选择(还有一些其他的搜索目录,这里就不一一列出了):
- /Library/Fonts/
- /usr/share/fonts
建议把中文6种基础字体都放在系统默认的字体目录下,即采取第二种方法,不然的话如果采用Tex源文件采用下面的开头:
\documentclass{ctexart} % 采用Mac字体
\documentclass[adobefonts]{ctexart} % 采用Adobe字体
会得到类似这样的报错:
...Font \@tempfontb="Adobe Heiti Std/ICU" at 10.54pt not loadable: Metric (TFM) file or installed font not found....
具体原因不知,个人猜测这是因为Texlive不在系统默认字体文件夹外寻找基本字体。
下面的步骤是在Texlive中对中文字库进行更新。由于Texlive默认的中文字体并不在Mac系统中(如“SimSun”),现在安装的新字体名称(如“STSong”)和原来的并不匹配。所以需要手动更改Texlive中win和adobe字体的名称:
win字体:以管理者的身份修改这个文件
/usr/local/texlive/2011/texmf-dist/tex/latex/ctex/fontset/ctex-xecjk-winfonts.def
更新内容如下:
\setCJKmainfont[BoldFont={STHeiti},ItalicFont=STKaiti]
{STSong}
\setCJKsansfont{STHeiti}
\setCJKmonofont{STFangsong}
\setCJKfamilyfont{zhsong}{STSong}
\setCJKfamilyfont{zhhei}{STHeiti}
\setCJKfamilyfont{zhkai}{STKaiti}
\setCJKfamilyfont{zhfs}{STFangsong}
\setCJKfamilyfont{zhli}{LiSu}
\setCJKfamilyfont{zhyou}{YouYuan}
\newcommand*{\songti}{\CJKfamily{zhsong}} % 宋体
\newcommand*{\heiti}{\CJKfamily{zhhei}} % 黑体
\newcommand*{\kaishu}{\CJKfamily{zhkai}} % 楷书
\newcommand*{\fangsong}{\CJKfamily{zhfs}} % 仿宋
\newcommand*{\lishu}{\CJKfamily{zhli}} % 隶书
\newcommand*{\youyuan}{\CJKfamily{zhyou}} % 幼圆
\endinput
对于adobe字体:以管理者的身份修改这个文件:
/usr/local/texlive/2011/texmf-dist/tex/latex/ctex/fontset/ctex-xecjk-adobefonts.def
更新内容如下:
\setCJKmainfont[BoldFont=Adobe Heiti Std,ItalicFont=Adobe Kaiti Std]
{Adobe Song Std}
\setCJKsansfont{Adobe Heiti Std}
\setCJKmonofont{Adobe Fangsong Std}
\setCJKfamilyfont{zhsong}{Adobe Song Std}
\setCJKfamilyfont{zhhei}{Adobe Heiti Std}
\setCJKfamilyfont{zhfs}{Adobe Fangsong Std}
\setCJKfamilyfont{zhkai}{Adobe Kaiti Std}
\setCJKfamilyfont{zhli}{LiSu}
\setCJKfamilyfont{zhyou}{YouYuan}
\newcommand*{\songti}{\CJKfamily{zhsong}} % 宋体
\newcommand*{\heiti}{\CJKfamily{zhhei}} % 黑体
\newcommand*{\kaishu}{\CJKfamily{zhkai}} % 楷书
\newcommand*{\fangsong}{\CJKfamily{zhfs}} % 仿宋
\newcommand*{\lishu}{\CJKfamily{zhli}} % 隶书
\newcommand*{\youyuan}{\CJKfamily{zhyou}} % 幼圆
\endinput
由上面的代码可知,两套字体的隶书和幼圆是公用的,其他的四类基本字体各有不同。这样修改过系统便会寻找到对应的字体,不再报错了。
最后打开一个Terminal窗口,用下面的命令刷新一下字体库:
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fsv
然后通过fc-list命令就可以检测系统中所有的字体了。如果上面的步骤都操作正确的话,新字体会显示在列表中。使用XeLaTex编译的时候,如果按照前一篇文章介绍的方法,只要调用字体的时候使用正确的名称即可。如果直接用“ctexart”文件类的话,可以参考下面的例子:
\documentclass[UTF8]{ctexart} % 采用Mac字体
%\documentclass[UTF8,adobefonts]{ctexart} % 采用Adobe字体
%以上两行分别测试华文字体和Adobe字体,请交替使用(月下独酌 注)
\title{\LaTeX 中文设置之高层方案}
\author{xiaoyong}
\date{\today}
\begin{document}
\maketitle
\begin{center}
1. 字体示例:\\
\begin{tabular}{c|c}
\hline
\textbf{\TeX 命令} & \textbf{效果}\\
\hline
\verb|{\songti 宋体}| & {\songti 宋体}\\
\hline
\verb|{\heiti 黑体}| & {\heiti 黑体}\\
\hline
\verb|{\fangsong 仿宋}| & {\fangsong 仿宋}\\
\hline
\verb|{\kaishu 楷书}| & {\kaishu 楷书}\\
\hline
\verb|{\lishu 隶书}| & {\lishu 隶书}\\
\hline
\verb|{\youyuan 幼圆}| & {\youyuan 幼圆}\\
\hline
\end{tabular}
\end{center}
\begin{center}
2. 字号示例:\\
{\zihao{0}初号}
{\zihao{1}一号}
{\zihao{2}二号}
{\zihao{3}三号}
{\zihao{4}四号}
{\zihao{5}五号}
{\zihao{6}六号}
{\zihao{7}七号}
{\zihao{8}八号}
\end{center}
\end{document}
以上所有例子都在Mac下测试成功,使用的界面TexShop Version 2.29 (2.29)。
Reference:
http://bbs.stuhome.net/thread-1306061-1.html
http://kqwd.blog.163.com/blog/static/4122344820117725633776/
2013年10月27日星期日
Maybe You’re Just Making Excuses
Maybe it's my own fault.
Maybe I led you to believe it was easy when it wasn't.
Maybe I led you to believe that my highlights started from the free throw line and not in the gym.
Maybe I made you believe that every shot I took was a game-winner, that my game was built on flash and not fire.
Maybe it's my fault that you didn't see that failure gave me strength, that my pain was my motivation.
Maybe I led you to believe that basketball was a God-given gift and not something I worked for every single day of my life.
Maybe I destroyed the game or maybe you're just making excuses.
Maybe I led you to believe it was easy when it wasn't.
Maybe I led you to believe that my highlights started from the free throw line and not in the gym.
Maybe I made you believe that every shot I took was a game-winner, that my game was built on flash and not fire.
Maybe it's my fault that you didn't see that failure gave me strength, that my pain was my motivation.
Maybe I led you to believe that basketball was a God-given gift and not something I worked for every single day of my life.
Maybe I destroyed the game or maybe you're just making excuses.
Counter Numbering Configuration in LaTeX
When using some template to write our documents, especially those classical and well-structured ones, such as PhD Thesis, we might run into some undesirable features bound to that template. For instance, the counter of footnote is reset for each page, namely if you have 10 footnotes created by the standard "\footnote" commands all over your document, but they are distributed on 10 different pages, then the numberings will all be "1", instead of "1", "2",...,"10". This also happens for linguistic examples created by the "linguex" package, whose counter will be reset for every chapter.
In LaTeX, the objects coming with an automatic numbering, such as tables, figures, footnotes, etc., contain an internal counter definition:
Since the initialization of the counter is embedded in the definition of each object, which is really difficult to modify directly, so in order to be completely flexible on configuring the numbering, we can use the "chngcntr" package. There are basically a pair of commands that we can use:
The starred version, "\counterwithin*" or "\counterwithout*" will suppress the redefinition of another counter-related command "\the{counter_name}", for more details, please look at the reference.
Reference:
http://mirrors.linsrv.net/tex-archive/macros/latex/contrib/chngcntr/chngcntr.pdf
http://en.wikibooks.org/wiki/LaTeX/Counters
In LaTeX, the objects coming with an automatic numbering, such as tables, figures, footnotes, etc., contain an internal counter definition:
- \newcounter{counter_name}
- \newcounter{counter_name}[resetting_environment]
The second differs from the first by adding a resetting environment, which appears as once the environment changes, the counter will be reset to 0. That is why some counters are continuous across the whole document, while some others are reset at certain point.
Since the initialization of the counter is embedded in the definition of each object, which is really difficult to modify directly, so in order to be completely flexible on configuring the numbering, we can use the "chngcntr" package. There are basically a pair of commands that we can use:
- \counterwithin{1}{2} or \counterwithin*{1}{2}
- These commands help to add a resetting environment to a counter without it
- The first compulsory argument denotes the counter name, for instance "footnote" for footnotes, "table" for tables, "ExNo" for linguistic examples, etc.
- The second compulsory argument denotes the environment within which you want to reset the counter, for instance, "chapter", "section", etc.
- \counterwithout{1}{2} or \counterwithout*{1}{2}
- These commands help to eliminate a resetting environment for a counter under its influence
- Same as above, the first compulsory argument denotes the counter name
- Same as above, the second compulsory argument denotes the environment within which you want to eliminate the resetting effect for a counter
The starred version, "\counterwithin*" or "\counterwithout*" will suppress the redefinition of another counter-related command "\the{counter_name}", for more details, please look at the reference.
Reference:
http://mirrors.linsrv.net/tex-archive/macros/latex/contrib/chngcntr/chngcntr.pdf
http://en.wikibooks.org/wiki/LaTeX/Counters
Common Units for Spaces in LaTeX
There are many places where we need specify exact spaces in LaTeX, for instance, inserting an image, arranging the position of several tables, etc. Normally in the template codes on Internet, people will find units such as "cm" and "in", which stand for "centimeter" and "inch" respectively. Then are there other units? And if yes, what do they mean?
- in - inches
- mm - millimeters
- cm - centimeters
- pt - points (about 1/72 inch)
- em - approximately the width of an "M" in the current font
- ex - approximately the height of an "x" in the current font
Conflict between The "ulem" Package and Bibliography
As we mentioned in a previous article, the "ulem" package provides various convenient ways to specify underlines.
However, after importing the "ulem", one might find the bibliography changes in an unexpected way: the strings that should actually be italicized are now underlined. That is because the italicized subparts of the bibliography is configured by the "\emph" command, and with the "ulem" package, "\emph" is redefined as underlined.
To avoid the annoying conflict, we just need to specify a normal emphasis option for the "ulem" package:
\usepackage[normalem]{ulem}
This is indicated at the beginning of the "ulem" documentation.
Reference:
http://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/ulem/ulem.pdf
However, after importing the "ulem", one might find the bibliography changes in an unexpected way: the strings that should actually be italicized are now underlined. That is because the italicized subparts of the bibliography is configured by the "\emph" command, and with the "ulem" package, "\emph" is redefined as underlined.
To avoid the annoying conflict, we just need to specify a normal emphasis option for the "ulem" package:
\usepackage[normalem]{ulem}
This is indicated at the beginning of the "ulem" documentation.
Reference:
http://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/ulem/ulem.pdf
2013年10月26日星期六
Change the Font for Your LaTeX Document
Sometimes, it is relatively easy and intuitive to determine which PDF file is created by LaTeX, due its distinct trademark font by default, which is quite different from other popular editors such as MS Office. However, LaTeX, as a professional editor, also supports various font setting. However, it is slightly more complicated than the WYSIWYG editors.
A detailed introduction to the LaTeX font system could refer to the first reference below. Basically, it is recommended that a single document should apply a uniform font, simply because that is more formal and beautiful. Thus, what we have to modify is actually the so-called "the font family".
The fonts could be systematically grouped into three main categories: roman (rm) or serif, sans serif (sf) and monospace (tt). For each category, LaTeX provides a default font, Computer Modern Roman, Computer Modern Sans Serif, and Computer Modern Typewritter, respectively. Further more, we can use the following three variables to refer to each of them:
\renewcommand*{\familydefault}{\sfdefault}
\renewcommand*{\familydefault}{\ttdefault}
Besides the three default font families, LaTeX also provides some pre-installed font families, such as Palatino (ppl), Times (ptm), Helvetica (phv), Courier (pcr), etc. In principle, if the specific font belongs to the "rm" category, we just need to use the following command:
\renewcommand*\rmdefault{ppl}
Otherwise, we will have to first modify the system default font family category to "sf" or "tt" with the already mentioned commands respectively, then specify the particular font in a similar way:
\renewcommand*\sfdefault{pbk}
\renewcommand*\ttdefault{pcr}
Or if you do not want to be so disciplined, you can just assign the particular font family to the system default roman font, namely:
A detailed introduction to the LaTeX font system could refer to the first reference below. Basically, it is recommended that a single document should apply a uniform font, simply because that is more formal and beautiful. Thus, what we have to modify is actually the so-called "the font family".
The fonts could be systematically grouped into three main categories: roman (rm) or serif, sans serif (sf) and monospace (tt). For each category, LaTeX provides a default font, Computer Modern Roman, Computer Modern Sans Serif, and Computer Modern Typewritter, respectively. Further more, we can use the following three variables to refer to each of them:
- \rmdefault
- \sfdefault
- \ttdefault
If not specification is made, the system will apply the serif or default roman font (rm), namely the Computer Modern. If we want to change it into the default sans serif (sf), namely Computer Modern Sans Serif, or the default monospace (tt), namely Computer Modern Sans Typewriter, we can use the following commands:
\renewcommand*{\familydefault}{\sfdefault}
\renewcommand*{\familydefault}{\ttdefault}
Besides the three default font families, LaTeX also provides some pre-installed font families, such as Palatino (ppl), Times (ptm), Helvetica (phv), Courier (pcr), etc. In principle, if the specific font belongs to the "rm" category, we just need to use the following command:
\renewcommand*\rmdefault{ppl}
Otherwise, we will have to first modify the system default font family category to "sf" or "tt" with the already mentioned commands respectively, then specify the particular font in a similar way:
\renewcommand*\sfdefault{pbk}
\renewcommand*\ttdefault{pcr}
Or if you do not want to be so disciplined, you can just assign the particular font family to the system default roman font, namely:
\renewcommand*\rmdefault{pbk}
Please note that only abbreviations are accepted. For a complete list of pre-installed font families and their abbreviations, refer to the last reference.
Reference:
http://en.wikibooks.org/wiki/LaTeX/Fonts
http://www.tug.dk/FontCatalogue/
http://www.macfreek.nl/memory/Fonts_in_LaTeX
Reference:
http://en.wikibooks.org/wiki/LaTeX/Fonts
http://www.tug.dk/FontCatalogue/
http://www.macfreek.nl/memory/Fonts_in_LaTeX
订阅:
博文 (Atom)