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
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
Some Useful Commands in The "tabular" Environment
When you are making tables in LaTeX, if you want to give interpolate some fancier features besides the standard and rigid outlook, there are some commands you are most like to encounter:
Reference:
http://en.wikibooks.org/wiki/LaTeX/Tables
- multirow: for creating a single row spanning over multiple rows
\multirow{Number of Rows}{*}{Content}
- multicolum: for creating a single colum spanning over multiple columns
\multicolumn{Number of Rows}{Position of Alignment}{Content}
- cline: for creating a horizontal line break with arbitrary width
Reference:
http://en.wikibooks.org/wiki/LaTeX/Tables
LaTeX中文支持-CJKutf8
在之前的一篇文章中介绍过一种使用LaTeX处理中文文档的方法,即在XeLaTeX编译环境下调用fontspec多语言包。但是我们会发现XeLaTeX编译常常花费比一般LaTex编译更多的时间,而且有时候我们并不是要整篇文章都使用中文,而只是在大段英文中插入少量的中文。这里将介绍另外一种常见的在LaTeX中解决中文的方法:CJKutf8。
CJK 有两个基本宏包:CJK 和 CJKutf8,后者针对于UTF-8编码。由于多语言并行情况下,UTF-8编码更加通用,所以我们倾向于使用后者(中文的另一种常见编码是GBK):
\usepackage{CJKutf8}
如果要在文中插入中文,使用以下命令即可:
\begin{CJK}{UTF8}{gkai}
约翰有一辆车。
\end{CJK}
\begin{CJK}后的第一个参数是编码,由于之前我们已经选定了面向UTF-8的CJKutf8,所以这里最好就使用UTF8。
第二个参数是中文字体,可以从以下四种字体中选择:bkai,bsmi,gkai,gbsn。前两者是Big5编码的明体(其实就是宋体和楷体字),他们的字库都非常小,许多汉字都无法正常显示。后两者分别是简体中文楷体字和宋体字,大部分汉字的显示都没有问题,可以根据个人喜好加以选择。
Reference:
http://tumutanzi.com/archives/tag/cjk
http://hi.baidu.com/jerryyou517/item/b3f2f52c74bd2f9ab7326344
CJK 有两个基本宏包:CJK 和 CJKutf8,后者针对于UTF-8编码。由于多语言并行情况下,UTF-8编码更加通用,所以我们倾向于使用后者(中文的另一种常见编码是GBK):
\usepackage{CJKutf8}
如果要在文中插入中文,使用以下命令即可:
\begin{CJK}{UTF8}{gkai}
约翰有一辆车。
\end{CJK}
\begin{CJK}后的第一个参数是编码,由于之前我们已经选定了面向UTF-8的CJKutf8,所以这里最好就使用UTF8。
第二个参数是中文字体,可以从以下四种字体中选择:bkai,bsmi,gkai,gbsn。前两者是Big5编码的明体(其实就是宋体和楷体字),他们的字库都非常小,许多汉字都无法正常显示。后两者分别是简体中文楷体字和宋体字,大部分汉字的显示都没有问题,可以根据个人喜好加以选择。
Reference:
http://tumutanzi.com/archives/tag/cjk
http://hi.baidu.com/jerryyou517/item/b3f2f52c74bd2f9ab7326344
2013年9月4日星期三
Footnote in Tables
With the standard configuration, one might not be able to insert a footnote with the plain command:
\footnote{...}
The result is that we can see the footnote icon, but the content is nowhere in the whole article. This is because the footnote command is sheltered by the tabular environment.
To achieve the possibility of inserting footnote in tables, we can actually cover the tabular environment with another handy environment, which is provided in the "footnote" package:
\usepackage{footnote}
\begin{savenotes}
\begin{table}
\begin{tabular}{|c|c|}
...
\end{tabular}
\end{table}
\end{savenotes}
Then within the table, the footnote command can be used freely like in other parts of the text.
Reference:
http://texblog.org/2012/02/03/using-footnote-in-a-table/
\footnote{...}
The result is that we can see the footnote icon, but the content is nowhere in the whole article. This is because the footnote command is sheltered by the tabular environment.
To achieve the possibility of inserting footnote in tables, we can actually cover the tabular environment with another handy environment, which is provided in the "footnote" package:
\usepackage{footnote}
\begin{savenotes}
\begin{table}
\begin{tabular}{|c|c|}
...
\end{tabular}
\end{table}
\end{savenotes}
Then within the table, the footnote command can be used freely like in other parts of the text.
Reference:
http://texblog.org/2012/02/03/using-footnote-in-a-table/
2013年7月31日星期三
Underlining in LaTex
The package "ulem" provides a nice facility for employing various types of underlines, both in the text and in mathematical formulas.
Some commonly applied commands:
Some commonly applied commands:
- \uline{a single underline}:单下划线
- \uuline{a double underline}:双下划线
- \uwave{a single under wavy line}:单波浪线
- \sout{a single deleting line}:单删除线
- \xout{a complex deleting block}:删除区域
- \dashuline{a single under dotted line}:单下滑虚线
- \dotuline{a single series of under dots}:单下滑点
Reference:
2013年3月20日星期三
LaTeX中文支持-fontspec
由于LaTeX设计之初,仅仅是考虑到了拉丁字母符号的输出。当它成为流行全球的编辑工具以后,避免不了针对其他语言符号的支持,中文就是其中之一。
网上有许多LaTeX在中文环境下的编译方法,最常用的即是使用CJK宏包。近期突然发现在XeLaTeX编译下,如果使用“fontspec”包也能顺利支持中文环境。“fontspec”的使用非常方便,很重要一个原因是它能够直接调用已经转载在电脑系统里面的各种字体,而不需要另外导入。一般电脑中标配的中文字体包括黑体(Hei),楷书(Kai),仿宋(STFangsong)等,具体的名称每个系统都不相同,需要自己单个查找。如果想查看自己电脑中的所有字体,可以使用以下命令:
fc-list
此外,如果希望使用系统中不存在的字库,“fontspec”也提供了导入方法:
\fontspec[ExternalLocation=dir]{字体.ttf}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
这样,你就可以放心地使用LaTex来编辑自己的中文文档了。但是不要忘记编译的时候选用XeLaTeX,如果还是照常实用LaTex系统会报错。以上方法已经在Mac OS的TeXShop环境下测试成功。
Reference:
http://bbs.ctex.org/forum.php?mod=viewthread&tid=41552
http://forum.ubuntu.org.cn/viewtopic.php?t=61206
网上有许多LaTeX在中文环境下的编译方法,最常用的即是使用CJK宏包。近期突然发现在XeLaTeX编译下,如果使用“fontspec”包也能顺利支持中文环境。“fontspec”的使用非常方便,很重要一个原因是它能够直接调用已经转载在电脑系统里面的各种字体,而不需要另外导入。一般电脑中标配的中文字体包括黑体(Hei),楷书(Kai),仿宋(STFangsong)等,具体的名称每个系统都不相同,需要自己单个查找。如果想查看自己电脑中的所有字体,可以使用以下命令:
fc-list
此外,如果希望使用系统中不存在的字库,“fontspec”也提供了导入方法:
\fontspec[ExternalLocation=dir]{字体.ttf}
- 基本配置
那么,如何在tex文档中使用“fontspec”呢?具体方法如下:
如果需要在文中使用不同于默认设置的字体,也可以使用“fontspec”命令,只需要把更改的内容放在一个大括号范围内即可:
{
\usepackage{fontspec}
\setromanfont{Kai}
\setmonofont[Scale=0.8]{AppleGothic Regular}
上面的第二行设置使用的是楷书,只需要在其中把“Kai”替换为自己喜欢的自己即可。第三行的设置目的是为了获得等宽字形。
如果需要在文中使用不同于默认设置的字体,也可以使用“fontspec”命令,只需要把更改的内容放在一个大括号范围内即可:
{
\fontspec{Hei}
黑体字的内容。。。
}
- 自动换行问题
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
这样,你就可以放心地使用LaTex来编辑自己的中文文档了。但是不要忘记编译的时候选用XeLaTeX,如果还是照常实用LaTex系统会报错。以上方法已经在Mac OS的TeXShop环境下测试成功。
Reference:
http://bbs.ctex.org/forum.php?mod=viewthread&tid=41552
http://forum.ubuntu.org.cn/viewtopic.php?t=61206
2013年1月25日星期五
Suppress Page Number in LaTex
Most LaTex document classes automatically import the page numbering system, which frees the user from the boring and tiring manual numbering process.
However, we might not always hope to include the page numbers, for instance, in some short abstracts, posters, or planning including only formulas. As a result, we would then need to suppress/remove/hide page numbers. The following codes could be handful:
\maketitle
\thispagestyle{empty}
This will simply suppress the page number on the exact page where you put the code. If you already use some external templates which define the numbering mechanism, you should add one line more in order to suppress the numbers at all pages:
\maketitle
\thispagestyle{empty}
\pagestyle{empty}
However, we might not always hope to include the page numbers, for instance, in some short abstracts, posters, or planning including only formulas. As a result, we would then need to suppress/remove/hide page numbers. The following codes could be handful:
\maketitle
\thispagestyle{empty}
This will simply suppress the page number on the exact page where you put the code. If you already use some external templates which define the numbering mechanism, you should add one line more in order to suppress the numbers at all pages:
\maketitle
\thispagestyle{empty}
\pagestyle{empty}
LaTeX Spacing
Normally when we are using some predefined LaTex template, the margin/space information is already well-specified. Sometimes, we might want to modify them in order to better fit our constraints, e.g., restricted page numbers.
The package "geometry" does exact this job, it is often included as:
\usepackage{geometry}
To assign more flexibility on it, the following code could be applied:
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
Values for each space (top, bottom, left, right) could be configured by the user himself.
There are also other packages for spacing setting, for instance, "sectsty", "mdwlist" and etc, more reference could be found here.
2012年11月22日星期四
Font Selection in Beamer and Normal Tex Files
When I was trying to figure out how to change the font for the complete beamer presentation, I found the following two commands in the Manhattan Beamer Theme:
\renewcommand\sfdefault{phv}
\renewcommand\familydefault{\sfdefault}
Basically they give a new meaning for "\sfdefault" and "\familydefault" respectively. As a result, both "\sfdefault" and "\familydefault" are set to "phv".
I tried to eliminate the second command while keep the first one, the font in the beamer would be changed as well, however, not the other way around. On the other hand, for a normal LaTex article, only the second command by itself will change the font for the whole document, but not the first.
So what is "\sfdefault", "\familydefault", why do they have different effect for beamer and normal article? And what does "phv" stand for?
After searching for LaTex font setting online, I realized the font system is more complicated than I expected. There are essentially five attributes for fonts in LaTex: encoding, family, series, shape, and size. "phv" is a value for the family attribute, which denotes Adobe Helvetica, further details can refer to the references I put at the end.
As to "\sfdefault", actually there are two other commands in a kit: "\rmdefault" and "\ttdefault". In the above kit, “sf” stands for serif, "rm" stands for roman, and "tt" stands for typerwriter. Three of them also have corresponding commands respectively:
"\textsf", "\textrm" and "\texttt". So normally when we choose a template, the font families for "\textsf", "\textrm" and "\texttt" are already predefined when the template is fixed. So using "\renewcommand" is just to update the original value for each case. "\familydefault" is another macro denoting the system default font for the complete document. Hence, for instance, after using the following command:
\renewcommand\ttdefault{phv}
all texts covered by the "\texttt" will have the "phv" font.
The reason why "\renewcommand\sfdefault{phv}" changes the font for beamer but not normal article is because beamer use the value of "\sfdefault" for "\familydefault", while normal article use the value of "\sfdefault" for "\familydefault". Therefore, only "\renewcommand\sfdefault{phv}" is enough to change font for beamer, only "\renewcommand\rmdefault{phv}" is also enough for normal article.
Reference:
http://www.latex-project.org/guides/fntguide.pdf
http://www.tug.org/pracjourn/2006-1/schmidt/schmidt.pdf
\renewcommand\sfdefault{phv}
\renewcommand\familydefault{\sfdefault}
Basically they give a new meaning for "\sfdefault" and "\familydefault" respectively. As a result, both "\sfdefault" and "\familydefault" are set to "phv".
I tried to eliminate the second command while keep the first one, the font in the beamer would be changed as well, however, not the other way around. On the other hand, for a normal LaTex article, only the second command by itself will change the font for the whole document, but not the first.
So what is "\sfdefault", "\familydefault", why do they have different effect for beamer and normal article? And what does "phv" stand for?
After searching for LaTex font setting online, I realized the font system is more complicated than I expected. There are essentially five attributes for fonts in LaTex: encoding, family, series, shape, and size. "phv" is a value for the family attribute, which denotes Adobe Helvetica, further details can refer to the references I put at the end.
As to "\sfdefault", actually there are two other commands in a kit: "\rmdefault" and "\ttdefault". In the above kit, “sf” stands for serif, "rm" stands for roman, and "tt" stands for typerwriter. Three of them also have corresponding commands respectively:
"\textsf", "\textrm" and "\texttt". So normally when we choose a template, the font families for "\textsf", "\textrm" and "\texttt" are already predefined when the template is fixed. So using "\renewcommand" is just to update the original value for each case. "\familydefault" is another macro denoting the system default font for the complete document. Hence, for instance, after using the following command:
\renewcommand\ttdefault{phv}
all texts covered by the "\texttt" will have the "phv" font.
The reason why "\renewcommand\sfdefault{phv}" changes the font for beamer but not normal article is because beamer use the value of "\sfdefault" for "\familydefault", while normal article use the value of "\sfdefault" for "\familydefault". Therefore, only "\renewcommand\sfdefault{phv}" is enough to change font for beamer, only "\renewcommand\rmdefault{phv}" is also enough for normal article.
Reference:
http://www.latex-project.org/guides/fntguide.pdf
http://www.tug.org/pracjourn/2006-1/schmidt/schmidt.pdf
2012年11月21日星期三
Multiple Optional Arguments for New Command Definition
The normal command defining methods, namely the "\newcommand", "\renewcommand", and "\providecommand", provide a optional argument session, where we can provide a default value for an argument, if the argument is not explicitly specified. Usually, the default value is used for the first argument "#1".
If you want to add more than one optional arguments, the following straightforward extension would cause a error:
\newcommand{\def}[3][default]{\textit{#1}+\textbf{#2}-\texttt{#3}}
One possible solution is to use the "relaying technique", which embeds one command into another, both of which contain an optional argument. As a result, the superior command will take two optional arguments to outward seeming. However, it is just a computational trick.
Also, attention should be paid when using the above method: the inferior command must be set at the end of the command definition for the superior one; its argument will also be attached after the argument of the superior one. Following is a simple example:
\newcommand\ABC[2][default1]{#1+\textbf{#2}}
\newcommand\DEF[1][default2]{#1-\ABC}
Then:
If you want to add more than one optional arguments, the following straightforward extension would cause a error:
\newcommand{\def}[3][default]{\textit{#1}+\textbf{#2}-\texttt{#3}}
One possible solution is to use the "relaying technique", which embeds one command into another, both of which contain an optional argument. As a result, the superior command will take two optional arguments to outward seeming. However, it is just a computational trick.
Also, attention should be paid when using the above method: the inferior command must be set at the end of the command definition for the superior one; its argument will also be attached after the argument of the superior one. Following is a simple example:
\newcommand\ABC[2][default1]{#1+\textbf{#2}}
\newcommand\DEF[1][default2]{#1-\ABC}
Then:
- "\DEF{obligatory}" yields "default2-default1+obligatory"
- "\DEF[real2][real1]{obligatory}" yields "real-real+obligatory"
- "\DEF" yields an error
Defining Your Own Command in LaTex
LaTex provides a bunch of useful integrated commands, such as "\textit{}", "\begin{block}...\end{block}", etc. However, you might encounter the situation in which a self-defined command would be more convenient. There are three standard methods in LaTex for creating new commands:
- \newcommand{cmd}[req_args][opt_args]{def}
- \renewcommand{cmd}[req_args][opt_args]{def}
- \providecommand{cmd}[req_args][opt_args]{def}
The three above methods contain the same syntax, where "cmd" stands for the name of the command, it should usually start with a backslash; "req_args" represents the number of arguments the new command carries, if unspecified, then the command takes no argument; "opt_args" denotes the default values of some arguments, if they are not presented when applying the command; finally, "def" is the detailed definition/description of the command.
The three commands are very similar in function, but they have to be used in different conditions. "\newcommand" helps to update the meaning of an already existing command, while "\newcommand" and "\providecommand" can only be applied to construct *new* commands, that's to say, the ones that do not exist before. If applied to an existing command, "\newcommand" will yield a compiling mistake, while "\providecommand" simply does not do anything.
If you are creating commands with arguments, then you have to specify the number of arguments in the "req_args" part, and refer each argument with anchors such as "#1", "#2", "#3", etc., the number corresponds to the linear order of arguments.
The "opt_args" is optional, just in case when the argument is not explicitly mentioned, some default value will take its place.
Some examples of new commands:
- \newcommand{\abc}{hello world!}
- \newcommand{\def}[2][default]{\textit{#1}+\textbf{#2}}
- \newcommand{\def}[3][default]{\textit{#1}+\textbf{#2}-\texttt{#3}}
- \renewcommand{\abc}{Bonjour Tout le Monde!}
Reference:
2012年11月20日星期二
Display All References in The Article
As we know, the BibTex under LaTex is one of the most proficient tools for handling bibliography. Normally we only want the reference session to include the specific items which we have cited in the article. However, in some cases, we would like to have a more elaborate control over bibliography. For instance, when making presentations with Beamer class, there might not be enough space or not necessary in the slides to cite each reference, but we still want the un-cited reference to appear at the end. Then the following code could be useful:
\nocite{*}
Just put it before the bibliography style declaration.
\nocite{*}
Just put it before the bibliography style declaration.
2012年11月12日星期一
Kindle关于中文格式(TXT,MOBI,PDF)的若干问题
对于使用Kindle来阅读中文的用户而言,如果手中的电子书是PDF格式的,阅读起来是没有什么问题的(比如乱码),因为PDF就像图片一样。但是对于MOBI或者TXT而言,情况就不太一样了。
1. 分行号和分段号
一般大家从网上下载的电子书都是TXT格式的,仔细观察就会发现许多TXT的分段都不是很清晰。一方面是因为这些TXT大部分都是网友手动输入的,难免会有一些错误。另外一方面是大家使用的编辑软件不一样,造成的分段号(paragraph break)和分行号(line break)混淆。这样一来就会出现很多TXT的右边一大片空白,文字不会自动延伸(很多电子邮件系统也具有这个特性)。
一开始我打算编一个简单的文字处理小程序自己将所有的分行号(line break)删除。后来发现网上有现成的工具,效果还非常不错:
http://www.textfixer.com/tools/remove-line-breaks.php
用这个工具处理过之后,再拷贝到Kindle里面,就不会出现大范围空白了,所有的空间都被文字填满了。
注意,这些分行号不会随着TXT转化成其他格式(PDF或MOBI)而消失,只有进入原始的TXT强行删除他们才不会影响阅读。
2. TXT转化成PDF后的空白页面
有一些TXT文件用专门软件转化成PDF格式之后,导入Kindle后会发现很多页面都成空白了。但是同样的PDF在电脑中阅读却不存在一样的问题。
Mac下的解决办法是用“预览”打印该PDF,然后再保存为PDF。不过因为我已经基本放弃了在Kindle阅读转化而来的PDF,这个方法现在用得不多了。
3. MOBI中的乱码
如果你是从亚马逊上直接购买的MOBI,应该不存在乱码。我这里指的乱码是用特殊工具(比如calibre)将TXT转化成MOBI过程中出现的。
不知道是不是MOBI在亚马逊中支持的字体有限,还是转换工具中的bug,在TXT中完美显示的中文到了MOBI格式下总会出现不少乱码,具体的形式就是方框,或者方框里面一些乱七八糟的内容。
我的解决办法是直接使用TXT,但是不是拷贝到Kindle里面,而是通过发邮件到用户的亚马逊网上账户(推送功能)。网上账户接到了发送的TXT以后,会进行一步转化,将文件转成更容易被Kindle接受的模式。一个有趣的现象是转化后的文件作者信息会更改,你的账户名将用作新的TXT的作者。如果你非常不喜欢这点,可以考虑直接拷贝,不过这样一来,就得承担更多乱码的风险。
注意,如果文件是通过推送功能发送到Kindle设备上的话,亚马逊的服务器会改变文件的格式,不论初始文件是TXT或者PDF,最终通过wifi下载的文件都是AZW或者AZW3的。这个不是很普适的格式似乎只有在Kindle中才能完美打开。所以,建议大家推送到Kindle以后继续保持源文件。
1. 分行号和分段号
一般大家从网上下载的电子书都是TXT格式的,仔细观察就会发现许多TXT的分段都不是很清晰。一方面是因为这些TXT大部分都是网友手动输入的,难免会有一些错误。另外一方面是大家使用的编辑软件不一样,造成的分段号(paragraph break)和分行号(line break)混淆。这样一来就会出现很多TXT的右边一大片空白,文字不会自动延伸(很多电子邮件系统也具有这个特性)。
一开始我打算编一个简单的文字处理小程序自己将所有的分行号(line break)删除。后来发现网上有现成的工具,效果还非常不错:
http://www.textfixer.com/tools/remove-line-breaks.php
用这个工具处理过之后,再拷贝到Kindle里面,就不会出现大范围空白了,所有的空间都被文字填满了。
注意,这些分行号不会随着TXT转化成其他格式(PDF或MOBI)而消失,只有进入原始的TXT强行删除他们才不会影响阅读。
2. TXT转化成PDF后的空白页面
有一些TXT文件用专门软件转化成PDF格式之后,导入Kindle后会发现很多页面都成空白了。但是同样的PDF在电脑中阅读却不存在一样的问题。
Mac下的解决办法是用“预览”打印该PDF,然后再保存为PDF。不过因为我已经基本放弃了在Kindle阅读转化而来的PDF,这个方法现在用得不多了。
3. MOBI中的乱码
如果你是从亚马逊上直接购买的MOBI,应该不存在乱码。我这里指的乱码是用特殊工具(比如calibre)将TXT转化成MOBI过程中出现的。
不知道是不是MOBI在亚马逊中支持的字体有限,还是转换工具中的bug,在TXT中完美显示的中文到了MOBI格式下总会出现不少乱码,具体的形式就是方框,或者方框里面一些乱七八糟的内容。
我的解决办法是直接使用TXT,但是不是拷贝到Kindle里面,而是通过发邮件到用户的亚马逊网上账户(推送功能)。网上账户接到了发送的TXT以后,会进行一步转化,将文件转成更容易被Kindle接受的模式。一个有趣的现象是转化后的文件作者信息会更改,你的账户名将用作新的TXT的作者。如果你非常不喜欢这点,可以考虑直接拷贝,不过这样一来,就得承担更多乱码的风险。
注意,如果文件是通过推送功能发送到Kindle设备上的话,亚马逊的服务器会改变文件的格式,不论初始文件是TXT或者PDF,最终通过wifi下载的文件都是AZW或者AZW3的。这个不是很普适的格式似乎只有在Kindle中才能完美打开。所以,建议大家推送到Kindle以后继续保持源文件。
Kindle文件格式
总体而言,Kindle支持最好的格式是MOBI,也即是直接从亚马逊网站上买书时候的格式。同时,Kindle对于PDF和TXT也有很好的支持。这里有一个不错的电子书阅读,格式转换软件推荐给大家:calibre。通过这个软件,用户能够给自己电脑里面的所有电子书做一个很好的索引(index),并且各种格式之间的转换也十分容易。
阅读PDF和MOBI或者TXT最大的区别就是PDF文件在Kindle中丧失了一些属性。比如使用调整文字大小的功能,PDF文件只是单纯地放大,像图片放大一样,随着字体的增大,画面也会越来越模糊。至于更改字体,就更是不可能了。所以我个人更加倾向于在Kindle上使用MOBI或者TXT,即使是PDF也要是用Latex生成的。
阅读PDF和MOBI或者TXT最大的区别就是PDF文件在Kindle中丧失了一些属性。比如使用调整文字大小的功能,PDF文件只是单纯地放大,像图片放大一样,随着字体的增大,画面也会越来越模糊。至于更改字体,就更是不可能了。所以我个人更加倾向于在Kindle上使用MOBI或者TXT,即使是PDF也要是用Latex生成的。
订阅:
博文 (Atom)