writing an article with XeLaTeX : part 1

Writing an article with LaTeX and compiling it with pdflatex might be a good solution if you don’t expect to use japanese, chinese, arabic characters or anything else which is not included in the roman alphabet. But if you plan, for example, to write in japanese, then pdflatex is not the better way. Moreover, the documentation on the web about CJK, LaTeX and japanese is generally outdated. See for example the japanese documentation for LaTeX in the japanese wiki of Ubuntu. In the outlook section of LaTeX packages, it is even recommended to install pTeX, based on TeTeX.

Nowadays, we don’t have to use LaTeX anymore, we can use XeLaTeX. Compiling a *.tex file with XeLaTeX can be done with TeXLive 2009 or TeXLive 2010, so you don’t have to update your TeX distribution if you use Ubuntu 10.04 or any other operating system with a recent TeX distribution. I have made a template to be compiled with XeLaTeX, based on classicthesis.sty, mathspec.tex and many other informations I found on the web. Here is a brief description of the template I have pushed to my repository at Github :

%footsepline, %to get a line separating footnote from page number.
%titlepage=true, %if you want an entire page for you title, name and date.
%twoside=true, %if you want to print on both side (recto-verso) of the %page.

The above code show you scrartcl with some options, depended of what you want, you can comment, uncomment or add others. If you need documentation about the class scrartcl, and if you use Ubuntu with gnome, type alt+F2 and in the prompt enter texdoc scrguien. If you don’t use Ubuntu, and you don’t know where are the files related to Koma-script, you can download it at ctan.org


\usepackage{xltxtra} %include fontspec, xunicode, etc. For more %details, texdoc xltxtra
%\usepackage{polyglossia} %xetex version of the babel %package. Since it is incomplete, %french users have to use babel. For %other users, replace french by your language
%\setmainlanguage[variant=british]{english} %for english users. For
%more documentation, texdoc polyglossia.

The above are the package xltxtra which load other packages to be used with xelatex. Also, since I need the french localization, I load frenchb with babel, but if you are english, german, etc, you just have to comment frenchb and uncomment or add other one. More details about it with texdoc babel, or at ctan. Notice that you could use polyglossia, the replacement of babel made for XeTeX. Unfortunately, the french option for polyglossia is not as good as the one for babel, that’s why I use babel with XeLaTeX. But if you are not french, you should try polyglossia.

%Comment or uncomment to select one of the following fonts
%\setmainfont{Charis SIL}
%\setmainfont{URW Palladio L}
%\setmainfont{Linux Libertine O}
%\setmainfont{Gentium Book Basic}
% \usepackage[scaled=0.85]{berasans}
% \usepackage[scaled=0.85]{beramono}
\setmainfont[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}

Here are some examples of fonts commented. TeX Gyre Pagella is uncommented since it is the font I use by default for my articles.

%For japanese input \newfontfamily\ja[Scale=0.8]{IPA明朝} %If you wish to write in
%japanese, then use the command
%\jap. Here is an example : “Hello, here is a test : {\ja ここはテストしてま〜〜〜す!}.” Try to compile it. %***********************************************************
%If you want to write in arabic from the right to the left load the %following package :
%\usepackage{bidi} %then, use the command \setRL to right from the right to the left. For more details, texdoc bidi.

Here are the settings for japanese, and an example. Also, notice that you can write your texts from the right to the left with the package bidi.

%Other useful packages for a basic article
\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{eukdate} %to redefine the default layout of the date format
% ********************************************************************
% Hyperreferences setup
\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,
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, just some packages that can be useful, and the hyperref setup.

%Appearance, etc
\usepackage{xcolor} %use color with the command \textcolor{spot}{some text to
%with your color previously defined}

%redefining the section command in order to get previously defined
%color for each section title.
% \makeatletter
% \renewcommand\section{\@startsection {section}{1}{\z@}%
% {-3.5ex \@plus -1ex \@minus -.2ex}%
% {2.3ex \@plus.2ex}%
% {\color{spot}\normalfont\Large\bfseries}}
% \makeatother

\areaset[5mm]{312pt}{761pt} % 686 (factor 2.2) + 33 head + 42 head \the\footskip

%\pagestyle{scrheadings} %for more information about headings, texdoc scrguien,
%chp. 4

Here is the setup for the margins, etc. You will notice that I tried to set a color for the sections, but haven’t been able to get it successufly working. And since I don’t really care about it, I have given up.

% for the following, see mathspec.tex (for me /usr/local/texlive/2010/texmf-dist/xelatex/mathspec/mathspec.tex
% for ubuntu users who have install texlive with the package manager, replace /usr/local/texlive/2010 by /usr/share/texmf-texlive (but I’m not sure, you have to check your directory /usr/share)

\if b\expandafter\@car\f@series\@nil
\math@fontsfalse\selectfont A%
\scshape a%
\if b\expandafter\@car\f@series\@nil%
\newcommand\tablerowa[3]{$\csname #1#3\endcsname$ & \cmd{#1#3} & $\csname #2#3\endcsname$ & \MakeLowercase{\cmd{#2#3}}}
\newcommand\tablerowb[1]{$\csname #1\endcsname$ & $\csname var#1\endcsname$ & \cmd{var#1}}
\ifdim\captionwidth \captionwidth
{\begin{minipage}[t]{\textwidth}\begin{description}\item[\rmfamily\mdseries\scshape\footnotesize\spotcolor advanced]\itshape\footnotesize}

The above code show you the definition of the color “spot” and other settings. Since it is just a copy of settings found in mathspec.tex, you can look at your xelatex directory of your TeX distribution. For me it is at /usr/local/texlive/2010/texmf-dist/doc/xelatex/mathspec/mathspec.tex. If you don’t find where is your directory, take a look at ctan.

\usepackage{booktabs} % for better rules in tables
\usepackage{textcase} % for \MakeTextUppercase
% sections \FloatBarrier
\titleformat{\section} {\relax}{\textsc{\MakeTextLowercase{\thesection}}}{1em}{\large\scshape\lowercase}
% subsections
\titleformat{\subsection} {\relax}{\textsc{\MakeTextLowercase{\thesubsection}}}{1em}{\normalsize\rmfamily\mdseries\itshape\lowercase}

% subsubsections
\titleformat{\subsubsection} {\relax}{\textsc{\MakeTextLowercase{\thesubsubsection}}}{1em}{\normalsize\rmfamily\mdseries\itshape\lowercase}

% paragraphs

% descriptionlabels

% spacedlowsmallcaps textit textsc
% spacing

Here is some code I have taken from the classicthesis package. This code modify the layout of sections, subsections, subsubsections, paragraphs and of text in \items[]. If you want to look at the original file, classicthesis.sty, you can find it in directory */texmf-dist/tex/latex/classicthesis/, where * could be /usr/share, or /usr/local/texlive/2010, depending on the installation way you have chosen to install TeXlive. Otherwise, take a look at ctan.org


p, li { white-space: pre-wrap; }


%Table of content


\usepackage{multicol} %useful here to get a table of contents with 2 columns




%If you don’t want to make subsubsections appear in your table of contents



\def\@seccntformat#1{\protect\makebox[0pt][r]{\csname the#1\endcsname\hspace{\marglistsep}}}




%if you want to get dot between the word and the page number in the

%table of contents, uncomment the lines between \makeatletter and \makeatother.

% \makeatletter

% \renewcommand\l@section[2]{%

% \ifnum \c@tocdepth >\z@

% \addpenalty\@secpenalty

% \addvspace{1.0em \@plus\p@}%

% \setlength\@tempdima{1.5em}%

% \begingroup

% \parindent \z@ \rightskip \@pnumwidth

% \parfillskip -\@pnumwidth

% \leavevmode {\bfseries

% \advance\leftskip\@tempdima

% \hskip -\leftskip

% #1}\nobreak\

% \leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}

% \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.



%Here goes your title

%Enter here your subtitle
%Enter your name and first name



%\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}

% your text goes here


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.

  1. The following is a comment by drebon posted in my previous blog.


    Great description of preamble, it is nice and useful.

    I recently tried to switch from latex with [utf8]{inputenc} to xelatex.

    I do have a problem : when latex was able to directly deal with characters like “œ”, xelatex seems to be unable to do so. In order to produce a ligaturated oe I have to input \oe{} which is a little bit painfull.

    Have you ever been confrontated to such a problem and have you found a solution ?

    Thank you

    I can’t answer precisely, so here are some questions :
    – Did you try with the template I have pushed on my repository ? In this case, it might work.
    – If it didn’t work with the template I have pushed at Github, then did you changed the main fonts ? If so, what is your main font ?
    – Finally, what is your operating system ? If it is Windows, do you have Miktex, if it is GNU/Linux, do you have installed TeXlive 2009 ? Or 2010 ?

    In any case, it worked for me with Ubuntu 10.04, TeXlive 2010, and TeX Gyre Pagella as the main fonts, defined as follows in the preamble :
    \setmainfont[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}


    • Drebon
    • September 27th, 2010

    Well, I didn’t tried with your template. Actually I am converting a style file I hve done for latex to xelatex because I use preamble variable definition in utf-8 and latex does not handle this (And I do not want to have two encodings in the same document).

    I tried to define the font with \setmainfont[Numbers=OldStyle,Ligatures=Historic]{TeX Gyre Pagella}, but mktexmf complains about missing files.

    I am under Ubuntu 10.04, I used the ubuntu distributed texlive, but now I have switched to normal texlive 2010 full install. Is there something I missed ?

    Thank you

  2. I use TeXlive 2010 and have no problem with it. Since I have switched to XeLaTeX from pdfLaTeX recently, I may also have a lack of experience. For this reason, maybe your problem is due to something I don’t have experimented yet.

    But in any case, please, provide me the *.tex file or an abbreviated version of it if it is too long, and your *.log file. I will try to compile it by myself and see what is going wrong.


    • Drebon
    • September 29th, 2010


    I have no problem with sending you the problematic document, but I doubt you will have the courage to look at it.

    Basicly, I had written a sty file that suited my needs for latex documents. Recently I tried to switch to utf8 (for compatibilty reason, I was still using latin1 encoding with tex).

    My way of defining some variables made latex do wrong things with utf8 (latex seems to be unable to deal with utf8 everywhere in the document) So I tried to move to xelatex.

    I was first happlily suprised : my doc compiled without significant problems… Expcept that œ chararcter was not understood by xelatex…

    After some resaerch I discovered that I had to use xltxtra and fontspec packages. There the œ works, but fonts are messed up…

    helvet package is incompatible with xetex, so I swith to a \setmainfont specification…

    After many texlive packages updates, it seems to allmost work expect that :

    some formating command are not taken into account ( e.g.

    \color{jaunefonc}\huge \bf \sf{Un petit texte}}

    Gives something with the right size and color but not in bold …

    I get also many

    “! LaTeX Error: Command \nobreakspace unavailable in encoding EU1.” errors…

    Well, so if you are willing to take a look at my files, I will happily supply them to you, but I’m afraid you probably won’t want to dive into my sty package…

    Best ragards

  3. No, that’s ok, don’t worry. But thank you !

    My email address is : k.m.alexandre@gmail.com
    But I will post the answer here.

    For the color I will see when you will have sent me your files (sty, tex and log), maybe you should look at xcolor : texdox xcolor

    By the way, you don’t need to load fontspec when you have already loaded xltxtra (for more details, see the related documentation : texdoc xltxtra).

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: