Category Archives: latex

Using Bibtex in MS Word 2015 (Mac OS)

BibTeX is reference management software for formatting lists of references. It makes it easy to cite sources in a consistent manner. However, BibTex is typically used together with the LaTeX document preparation system.

On the other hand, Microsoft Word is still the most commonly used text editor and used in the group to share documents. Thus, I use BibTex to manage the bibliography and use MS Word to write documents.
One of the most famous reference manager software integrated in Word is EndNot, but unfortunately it is a very expensive and not open-source software. In Windows OS, there is a awesome plug-in called “Bib4Word”, but it is not usable in Max OS.

read more

Where to place you own .sty or .cls files, to make them available to all my .tex files?

Suppose you have defined a package or a class, but how do you make it available at all times? One way is to just place it in the same folder as the .tex file, but that’s not what I’m after here. This post will tell you a way to “install” the package centrally on your computer.

1. Find out the directory. First, use this command at the command prompt to find out where your TeX home directory is.

kpsewhich -var-value=TEXMFHOME
OS Location
Windows C:/Users/stefan/texmf
Unix-type ~/texmf/
Mac ~/Library/texmf

2. Place files in the “right place”. Following the TeX directory structure, you should place your file in the “right place” like ~/texmf/tex/latex/packagename/packagename.sty. For a TDS-conformant system (TeX Directory Structure), the “right place” for a LaTeX .sty file is a suitably-named subdirectory of texmf/tex/latex/. For a full list of “right place”s, please see LaTeX/Installing Extra Packages. Moreover, for the beamer style, put the theme under beamer/themes/ with “color”, “font”, “inner”, “outer”, and “theme” in seperated subdirectories.

read more

dpkg: error processing tex-common

Got the problem while installing latex-cjk-chinese

fmtutil-sys failed. Output has been stored in
/tmp/fmtutil.t6EnBlWW
Please include this file if you report a bug.

dpkg: error processing tex-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 tex-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

After checking the file fmtutil.t6EnBlWW, I find the problem is

! I can’t find file `loadhyph-zh-latn.tex’. This is due to the inconsistence between texlive 2011 and tex2012. In tex2012, the file is renamed to `loadhyph-zh-latn-pinyin.tex’. Therefore, the solution is
  1. go to /etc/texmf/hyphen.d
  2. change loadhyph-zh-latn.tex to loadhyph-zh-latn-pinyin.tex
  3. reinstall tex-common

read more

Tikz example – Kernel trick

In Support Vector Machines, the learning algorithms can only solve linearly separable problems. However, this isn’t strictly true. Since all feature vectors only occurred in dot-products k(xi,xj)= xi·xj, the “kernel trick” can be applied, by replacing dot-products by another kernel (Boser et al., 1992). A more formal statement of kernel trick is that

Given an algorithm which is formulated in terms of a positive definite kernel k, one can construct an alternative algorithm by replacing k by another positive definite kernel k∗ (Schlkopf and Smola, 2002).

The best known application of the kernel trick is in the case where k is the dot-product, but the trick is not limited to that case: both k and k can be nonlinear kernels. More general, given any feature map φ from observations into a inner product space, we obtain a kernel k(xi,xj)=φ(xi)·φ(xj).

This figure was drawn for “kernel trick” with samples from two classes.

Tikz example – SVM trained with samples from two classes

In machine learning, Support Vector Machines are supervised learning models used for classification and regression analysis. The basic SVM takes a set of input data and predicts, for each given input, which of two possible classes forms the output, making it a non-probabilistic binary linear classifier. To classify examples, we choose the hyperplane so that the distance from it to the nearest data point on each side is maximized. If such a hyperplane exists, it is known as the maximum-margin hyperplane and the linear classifier it defines is known as a maximum margin classifier.

Yet another way to use Chinese charecter in Latex

First, install texlive-lang-cjk or texlive-lang-chinese or texlive-lang-all. Then in tex file, add:

usepackage[T1]{fontenc}  
usepackage{CJKutf8}  
newenvironment{SChinese}{%
  CJKfamily{gbsn}%
  CJKtilde
  CJKnospace}{}

Whenever a Chinese character is needed, use

begin{SChinese}凡end{SChinese}

Other examples like underline, underdot, etc., can be found in

/usr/share/texmf/doc/latex/latex-cjk/examples

The best way to place figures side-by-side in Latex

There are different way of placing figures side by side in Latex, subcaption, subfig, subfigure, or even minipage. This post will tell you which one is the best.

subcaption

A useful extension is the subcaption package (the subfigure and subfig packages are deprecated and shouldn’t be used any more), which uses subfloats within a single float. This gives the author the ability to have subfigures within figures, or subtables within table floats. Subfloats have their own caption, and an optional global caption. An example will best illustrate the usage of this package:

\usepackage{subcaption} 
... 
\begin{figure}
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{1.png}
    \caption{Picture 1}
    \label{fig:1}
  \end{subfigure}
  %
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{2.png}
    \caption{Picture 2}
    \label{fig:2}
  \end{subfigure}
\end{figure}

minipage

The minipage can be used to place figures side-by-side too. But it is not a floating environment, thus has to be placed in a figure environment. Another disadvantage of minipage is that it does not align fi gures. Therefore, subcaption is still the best package you should use.

\begin{figure}
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{1.png}
    \caption{Picture 1}
    \label{fig:1}
  \end{minipage}

  \begin{minipage}[b]{0.4\textwidth}
    includegraphics[width=textwidth]{2.png}
    \caption{Picture 2}
    \label{fig:2}
  \end{minipage}
\end{figure}

read more