Archive for the ‘ XeLaTeX ’ Category

## Writing math with XeLaTeX

The following is a short explanation for those who wish to get the basics to write math with XeLaTeX :

• First, you will notice, if you look at the xelatex directory, that there is a mathspec folder. If you don’t know where is your xelatex folder, then look here if you have installed TeXlive with the installation script :

/usr/local/texlive/2010/texmf-dist/doc/xelatex/mathespec/

Or look here if you have installed TeXlive with your package manager :

/usr/share/doc/texlive-doc/xelatex/mathspec/

• But a better choice might be to use unicode-math, though it is still in its beta stage. Documentation about this package is located in the following directory in case you have installed TeXlive with the installation script install-tl :

/usr/local/texlive/2010/texmf-dist/doc/latex/unicode-math

Or here if you have installed TeXlive with your package manager :

/usr/share/doc/texlive-doc/latex/unicode-math

• Let us assume you wish to use the unicode-math package. Then, you will have to load it :

\usepackage{unicode-math}

And to define the font for math :

\setmathfont{Asana Math}

Consequently, here is an example of minimal preamble to write math and compile with XeLaTeX :

\documentclass{article}
\usepackage{unicode-math}
\usepackage{amsmath}
\usepackage{xltxtra}
\setmainfont{TeX Gyre Pagella}
\setmathfont{Asana Math}

Where article is a class to make a test, unicode-math the package to input math with XeLaTeX, amsmath the usual package for math and xltxtra the usual package for XeLaTeX which load some useful modules (see the xltxtra for a list of these modules).
Also, \setmainfont{TeX Gyre Pagella} is the definition of the font for your text, and \setmathfont{Asana Math} the definition of the fonts for math as I said previously.

Here is a screenshot of an example of output (a pdf file) we can get with XeLaTeX :

## Writing an application letter with XeLaTeX

With LaTeX, several packages are dedicated for letters. For french TeX users, there is for example the class lettre, which might be widely used. For english TeX users, the letter written with the letter class or with koma-script might be also used.

Also, notice that the structure of a letter should be as follows :

Here I will focus on the isodoc class for application letters. I have pushed a template in my repository at Github. If you want documentation for this letter, then type Alt+F2 and in the prompt enter (without quotes) “texdoc isodoc”, or look here. The documentation for this package is really good, and contains some examples, so don’t hesitate to refer to it if you have any problem.

Basically, the .tex file is divided into three parts, that is to say the preamble, the setup of the letter and then the text. The following is a description of the parts from my template that I use for an example :

1. A brief description of the preamble :
2. % Created 2010-09-21 Tue 22:02
\documentclass{isodoc}
\usepackage{xltxtra}

First, here is the class of the document, and then the package for XeLaTeX.

\linespread{1.05}
\setmainfont[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}

Here is the usual setup for fonts I use. If you want some documentation about TeX Gyre Pagella, type Alt+F2 and enter in the prompt “texdoc qpl-info”, or look here.

\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{url}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}

Some useful packages, nothing special.

\usepackage[frenchb]{babel}

If you are not french, replace it by polyglossia, according to the language you wish to use. For more information, type Alt+F2 and “texdoc polyglossia” in the prompt or look here.

\usepackage{hyperref}
\hypersetup{
colorlinks=true, linktocpage=true,breaklinks=true,
urlcolor=spot, linkcolor=blue, citecolor=green,
pdftitle={Letter},%the title
pdfauthor={}
}

Nothing special, just the usual hyperref setup I use.

\tolerance=1000 % http://dcwww.camd.dtu.dk/~schiotz/comp/LatexTips/LatexTips.html
\usepackage{pdfpages}
\definecolor{headcolor}{gray}{0.5}
\definecolor{spot}{rgb}{0.6,0,0}
\definecolor{headingcolor}{rgb}{0.6,0,0}

Some nice settings, for hyphenation, and others, such as headcolor, which unable the nice gray color of headers and footers you will see in the screenshot at the bottom of my post.

3. The following is a brief description of the setup of the letter (notice that the following is just MY setup, an example, there are more options, look at the isodoc documentation I have indicated above if you need more) :
4. \setupdocument{%about this section, see isodoc, p. 3 to 7
language = french
,
company = Alexandre Krispin
,
who = Alexandre Krispin
,
street = {41 rue Guynemer}
,
city = St-Denis
,
zip = 93200
,

Here is the first part of my setup. If you are not french, replace french by your language. Since it is not a letter from an employee of a company, I have put my name after “company =”, as it is indicated in the documentation. Then, you have to put your name and adress. Notice that you must put a comma after the information you enter, in order to indicate the end of the information. Also, if you want to put commas in your adress, you will have to use brackets {}. If you don’t use the brackets {}, then you will have erors when compiling your file.

to = {Université Paris Ouest \\
Nanterre La Défense\\
200, avenue de la République\\
92201 \caps{NANTERRE CEDEX}}
,
return
,
header
,
date = today
,
opening = {Madame, Monsieur,}
,
subject = {Here goes the subject of your letter}
,

“To” indicates the addressee. “Return” the address where you wish to receive an answer, etc. For more information, look at the isodoc documentation, easy to understand and very good.

closing = {Je me tiens à votre entière disposition pour plus
d’information, je vous prie d’agréer, Madame, Monsieur, l’expression
de mes salutations les plus distinguées}
,
signature = Alexandre Krispin
,
footer
,
phone = 0628766934
,
email = k.m.alexandre@gmail.com
,
website = \url{https://alexkrispin.wordpress.com/}
,
fill
,
}

Then comes the closing, the signature and the footer if you want it. In the footer will appear your phone, email and your website.
The fill option is to get the text fully justified, on the left and on the right. In other words, “fill” is the option to get the usual hyphenation with LaTeX.

5. Finally, you have the environment in which your text is written :
6. \begin{document}
\letter{
Je me présente, je m’appelle henri. Je voudrais bien réussir ma vie, être aimé. Quand je serai grand, j’aimerai bien être médecin, ou plombier, ou rappeur, ou dealer, ou braqueur, ou\ldots tout niquer tout dans paname !
[…]
etc, etc.
}
\end{document}

Here is a screenshot of the output, a pdf file, after compiling with xelatex :

You can find the source file of this example in my repository at Github.

If you have any problem, don’t hesitate to leave a comment.

## Writing an article with XeLaTeX : part 2

Writing an article is nothing special, but it might require some skills if your are not used to $\LaTeX$ and want to use some special packages. When I was using pdflatex, one of those I was constantly using was ClassicThesis. Indeed, ClassicThesis is really an amazing package. It is based on the style of The Element of Typographic Style, written by Robert Bringhurst. If you don’t know this famous book, then look here :
The Elements of Typographic Style at amazon.com
Or
The Elements of Typographic Style at wikipedia.org
If you are also interested to this, maybe you should take a look here for an application of this book to the web typography :
The Elements of Typographic Style applied to the web

Anyway, the purpose of this post is to show you a template I have made in order to use classicthesis for an article, and to be able to compile the .tex file with XeLaTeX. To make it work, you have to do the little trick I have previously described :
Modifying the classicthesis package to make it work when compiling the *.tex file with xelatex instead of pdflatex.

Also, I have uploaded the template to my repository at Github. The following is a short description of this template.

\documentclass[10pt,a4paper]{scrartcl} % KOMA-Script article
\usepackage{xltxtra} %some packages for xelatex
\usepackage[frenchb
%arabic
%english
]{babel} %for french. If you write in english, then you might want to
%get a try to polyglossia

First I have put the basic packages to write an article which will be compiled with XeLaTeX. But notice that since I am french I use babel, but if, for example, you are indian, english, japanese, etc, then get a try to polyglossia.

%\setmainfont[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}

%If you want other fonts, try the following
%\setmainfont{Charis SIL}
%\setmainfont{URW Palladio L}
%\setmainfont{Linux Libertine O}
%\setmainfont{Gentium Book Basic}

%For japanese input :
\newfontfamily\ja[Scale=0.8]{IPA明朝}

The above shows you the setup for the fonts. If you don’t want the default font used with the ClassicThesis package, then uncomment any font you want to use instead. I have also included the setup to write in japanese, remove it if you don’t want it.

If you plan to write in japanese your entire articles, then set IPA明朝 as your main font, and if you plan to write in any other language, then set the font corresponding to your language as the main font. If you don’t know what is the font corresponding to your language, then look at the tips I have previously written here.

\usepackage{color} %If you want to use it within your text, use the
%command \textcolor{spot}{your text}
\definecolor{spot}{rgb}{0.6,0,0}
\definecolor{boxframe}{rgb}{0.6,0,0}
\definecolor{boxfill}{rgb}{1,.95,.95}

Here I have set a color, just in case I would need it.

\usepackage{hyperref}
\hypersetup{%
colorlinks=true, linktocpage=true, pdfstartpage=3, pdfstartview=FitV,%
% uncomment the following line if you want to have black links (e.g., for printing)
%colorlinks=false, linktocpage=false, pdfborder={0 0 0}, pdfstartpage=3, pdfstartview=FitV,%
breaklinks=true, pdfpagemode=UseNone, pageanchor=true, pdfpagemode=UseOutlines,%
plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1,%
hypertexnames=true, pdfhighlight=/O,%hyperfootnotes=true,%nesting=true,%frenchlinks,%
urlcolor=blue, linkcolor=blue, citecolor=green, %pagecolor=RoyalBlue,%
%urlcolor=Black, linkcolor=Black, citecolor=Black, %pagecolor=Black,%
pdftitle={Article},%the title
pdfauthor={Alexandre Krispin},%your name
pdfsubject={},%
pdfkeywords={},%
pdfcreator={XeLaTeX},%
pdfproducer={A happy XeLaTeX user}%
}

Here is nothing special, the usual hyperref setup I use.

\usepackage{enumitem} %if you want to customize lists
\usepackage{array} %texdoc array
\usepackage{natbib} % an extension to allow author-year citations
% along wih numerical citations. For more
% informations, texdoc natbib
\usepackage{eukdate} %to redefine the default layout of the date format
\usepackage{textcomp} %some special characters
\usepackage{url} %for url
\usepackage{longtable} %for long tables
\usepackage{textcomp} %additional characters
\usepackage{amsmath} %for maths
\usepackage{graphicx} %to include graphics
\usepackage{wrapfig} %to get nice wrap of figures
\usepackage[nochapters]{classicthesis}
\usepackage[nochapters]{classicthesis-ldpkg}

Some useful packages. Add or remove some if you need or don’t need something. There is also the command loading the ClassicThesis package.

\title{\rmfamily\normalfont\spacedallcaps{
The so-called Iran’s threat%The title of your article
}}
\subtitle{\rmfamily\normalfont\spacedallcaps{
Facts and analysis
}}
\author{\spacedlowsmallcaps{
Alexandre Krispin %author name and first name
}}

\begin{document}

\maketitle

%\begin{abstract}

%\noident
%********************************
%The abstract of your article
%*******************************

%\end{abstract}

\tableofcontents

%\section{}

%\subsection{}

The usual opening setup, with an abstract and a table of content, nothing special.

Here are screenshots showing you how the template looks like. The first screenshot :

And the second screenshot, which show another page :

I have pushed the source file of this example to my repository at Github.

## Using the classicthesis package with XeLaTeX

Compiling an article or anything else with classicthesis package will return errors. Indeed, something written and compiled with the classicthesis package loaded must be compiled with pdflatex (and maybe also latex, I don’t know).

Anyway, here is a little trick to compile your documents with XeLaTeX using your prefered template. First of all, we have to make a backup of our file classicthesis.sty. If you use Ubuntu and have installed TeXlive with your package manager, do as follows either with a terminal or your file manager with root privileges (for this, type Alt+F2 and enter gksu nautilus in the prompt) :

sudo cp /usr/share/texmf-texlive/tex/latex/classicthesis/classicthesis-ldpkg.sty /usr/share/texmf-texlive/tex/latex/classicthesis/classicthesis-ldpkg_backup.sty

If you have installed TeXlive with the installation script install-tl, then do as follows :

sudo cp /usr/local/texlive/2010/tex/latex/classicthesis/classicthesis-ldpkg.sty /usr/local/texlive/2010/tex/latex/classicthesis/classicthesis-ldpkg_backup.sty

Then, open classicthesis-ldpkg.sty in a text editor, let say gedit. If you have installed TeXlive with your package manager :

gksu gedit /usr/share/texmf-texlive/tex/latex/classicthesis/classicthesis-ldpkg.sty

And if not :

gksu gedit /usr/local/texlive/2010/tex/latex/classicthesis/classicthesis-ldpkg.sty

In this file, you will have to comment the following lines :

% ********************************************************************
% Using PDFLaTeX:
% ********************************************************************
\RequirePackage[pdftex,hyperfootnotes=false,pdfpagelabels]{hyperref} % backref linktocpage pagebackref
\pdfcompresslevel=9
\pdfadjustspacing=1
\RequirePackage[pdftex]{graphicx} % PDFTeX driver for graphicx
%\DeclareGraphicsRule{*}{mps}{*}{} % enables use of MetaPost graphics with pdflatex

%*******************************************************
% for German texts to get \autoref macros right
\renewcommand{\figureautorefname}{Figure}
\renewcommand{\tableautorefname}{Table}
\renewcommand{\partautorefname}{Part}
\renewcommand{\chapterautorefname}{Chapter}
\renewcommand{\sectionautorefname}{Section}
\renewcommand{\subsectionautorefname}{Section}
\renewcommand{\subsubsectionautorefname}{Section}

Then, save your file. Here is a screenshot of what I get after commenting on the left side, and before on the right side :

That’s all, folks ! Now if you compile a file with XeLaTeX using the classicthesis package, it will work. I will write soon a post about it, and will show you a sample of file I have successfully compiled.

EDIT : There is no need to comment the lines :

\renewcommand{\figureautorefname}{Figure}
\renewcommand{\tableautorefname}{Table}
\renewcommand{\partautorefname}{Part}
\renewcommand{\chapterautorefname}{Chapter}
\renewcommand{\sectionautorefname}{Section}
\renewcommand{\subsectionautorefname}{Section}
\renewcommand{\subsubsectionautorefname}{Section}

But in order to get mathematical symbols working with the specific setup of XeLaTeX, we have to comment the following lines :

{%
% default: Palatino
\RequirePackage[osf,sc]{mathpazo} % Palatino with real small caps and old style figures
\linespread{1.05} % a bit more for Palatino
}

Which are in the file classicthesis.sty, lines 183-187 (don’t forget to comment the “{” l. 183). With that, everything will work fine with math font setup and unicode-math with XeLaTeX.

## XeLaTeXで書く仕方 ・ Writing in japanese with XeLaTeX

• 日本人であれば、XeLaTeXを使っていいです。長い説明するより簡単な例を示します。
• \documentclass{article}
\usepackage{xltxtra} %xltxtra = fontspec, xunicode, etc.
\usepackage{verbatim}
\usepackage{url}
\setmainfont{IPA明朝}
\linespread{1.05}
\newfontfamily\en[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}
\begin{document}

日本語で書くためにはIPA明朝を使っていいです。しかし、時々英語などで書
く機会があります。その時、
\begin{verbatim}
\verbatim{\en your text goes here}
\end{verbatim}
を入力したら、英語のためのフォントで書ける。

たとえば、{\en here is a test to show you how writing both in
english and in japanese is easy with \XeLaTeX. Of course, you can also mix any
other languages you want.}

{\en \XeLaTeX}に関しては次の{\en url}を参照してください：

\url{http://tug.org/xetex/}
\end{document}

以上のファイルをXeLaTeXでコンパイルしてください。そうするようにTeXworksを使って、XeLaTeXを選択して、緑色のボタンを押すとpdfファイルを得る。

以上は簡単な例だけです。私の場合は日本語の文書を書く必要がなくて、ただ混じられた言語のあるテキストを書けたいのです。日本語の論文を書く人であったら、polyglossiaパッケージを使っていいのではないかと思います。そのためにこのサイトを参照してください。

• If you plan to write english text with some japanese text or quotes included in your text, and not an entire text in japanese, then you should only put the following command in your preamble :

\newfontfamily\ja{IPA明朝}

This way, you will just have to insert {\ja } and to typeset japanese inside the {}. Therefore if you wish to write, in your english text 一言だけ, you have to do like this {\ja 一言}. As an example of my short explanation, you can try to compile the following file :

\documentclass{article}
\usepackage{xltxtra} %xltxtra = fontspec, xunicode, etc.
\setmainfont{TeX Gyre Pagella}
\newfontfamily\ja{IPA明朝}
\begin{document}
Here is an english sentence, followed by {\ja 日本語の例。} \XeLaTeX {\ja は便利ですね。}
\end{document}

Here is a screenshot showing the output and the .tex file :

## Fonts with XeLaTeX : tips and troubleshooting

• First, one thing about fonts with XeLaTeX. How do I know what fonts I could use for the language I want to typeset ? Open a terminal (with ubuntu, enter alt+f2, and enter gnome-terminal in the prompt), and copy the following :

fc-list :lang=en

It will give you all fonts with their style that you can use for each language you specify. If you want to specify another language, then replace the “en” after “lang=” with any other language. For example, if i want to know what are the japanese fonts I can use, I replace “en” with “ja”, it returns :


% \hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par

% \endgroup

% \fi}

% \makeatother

%**********************************************************

I have taken the code for the table of content from mathspec.tex, so once again if you like it look at this file in the directory previously indicated. I have added the package multicol in order to get the same layout than the one you can see in mathspec.pdf. Also, though I don’t like it, you can uncomment the lines between makealetter and makeatother if you want to get dots between the name of your titles and the page number.

\begin{document}
%\frenchspacing

\begin{titlepage}

\title{
\rmfamily
\mdseries
\lowercase{
\scshape{
\textcolor{spot}{
%Here goes your title
}}}}

\subtitle{
\rmfamily
\mdseries
\itshape
\normalsize{
%Enter here your subtitle
}}
\author{
%Enter your name and first name
}

\end{titlepage}

\maketitle

%\addtocontents{toc}{\protect\begin{multicols}{2}} %if you want to get a table of
% contents with 2 columns. If you prefer one column, comment this line and
% the one just before \end{document}
\tableofcontents

%*******************************************************************
%
% your text goes here
%
%******************************************************************

%\addtocontents{toc}{\protect\end{multicols}}
\end{document}

The settings for the title is similar to those of mathspec.tex, but since in mathspec.tex a different document class is used, I have changed some settings to make it work with the koma-script class, scrartcl.

Also, if you want a table of contents divided in two columns, then uncomment the line “\addtocontents{toc}{\protect\begin{multicols}{2}}”, and the other just before \end{document}, “\addtocontents{toc}{\protect\end{multicols}}”.

Lastly, if you want to use the color spot previously defined, write \textcolor{spot}{the text you want to colorize} and you will get it. Here are 2 screenshots showing how this template looks with an example of short article :

And the other picture :

You can find this example at the same directory of my repository, here.