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 :

    $ fc-list :lang=ja
    YOzFontNF:style=Bold
    YOzFont:style=Regular
    YOzFontEF:style=Bold
    YOzFontCF:style=Bold
    YOzFontAF:style=Bold
    IPA X0208 P明朝,IPAX0208PMincho:style=Regular
    YOzFontN90:style=Regular
    YOzFontNF:style=Italic
    YOzFontEF90:style=Regular
    YOzFontEF:style=Italic
    YOzFontAF:style=Italic
    YOzFontCF:style=Italic
    YOzFont:style=Bold
    YOzFontE:style=Regular
    YOzFontF:style=Regular
    YOzFontA:style=Regular
    YOzFontC:style=Regular
    YOzFontN:style=Regular
    YOzFontEF90:style=Bold
    文泉驛等寬正黑,WenQuanYi Zen Hei Mono,文泉驿等宽正黑:style=中等,Medium
    文泉驛等寬微米黑,WenQuanYi Micro Hei Mono,文泉驿等宽微米黑:style=Regular
    YOzFontEF90:style=Bold Italic
    YOzFontA90:style=Italic
    IPA X0208 Pゴシック,IPAX0208PGothic:style=Regular
    YOzFont90:style=Italic
    YOzFont:style=Italic
    YOzFontC90:style=Italic
    YOzFont:style=Bold Italic
    YOzFontE90:style=Italic
    YOzFont90:style=Bold Italic
    YOzFontNF90:style=Bold
    YOzFontF90:style=Italic
    YOzFontCF90:style=Regular
    YOzFontF:style=Bold Italic
    YOzFontE:style=Bold Italic
    YOzFontNF90:style=Italic
    YOzFontC:style=Bold Italic
    YOzFontA:style=Bold Italic
    YOzFontN:style=Bold Italic
    さざなみ明朝,Sazanami Mincho:style=Regular,Mincho-Regular
    YOzFontEF:style=Bold Italic
    YOzFontAF:style=Bold Italic
    YOzFontCF:style=Bold Italic
    YOzFontNF:style=Bold Italic
    Takao P明朝,TakaoPMincho:style=Regular
    文泉驛正黑,WenQuanYi Zen Hei,文泉驿正黑:style=中等,Medium
    YOzFontN90:style=Italic
    IPAexゴシック,IPAexGothic:style=Regular
    YOzFontEF90:style=Italic
    YOzFontCF90:style=Bold Italic
    東風ゴシック,Kochi Gothic:style=標準,Regular
    YOzFontNF:style=Regular
    YOzFontAF:style=Regular
    YOzFontCF:style=Regular
    YOzFontEF:style=Regular
    東風明朝,Kochi Mincho:style=標準,Regular
    IPA X0208 UIゴシック,IPAX0208UIGothic:style=Regular
    YOzFontAF90:style=Regular
    Takaoゴシック,TakaoGothic:style=Regular
    YOzFont90:style=Regular
    IPA X0208 明朝,IPAX0208Mincho:style=Regular
    YOzFontAF90:style=Bold
    YOzFontN90:style=Bold
    IPAゴシック,IPAGothic:style=Regular
    YOzFontCF90:style=Italic
    YOzFontN90:style=Bold Italic
    YOzFontAF90:style=Bold Italic
    文泉驛微米黑,WenQuanYi Micro Hei,文泉驿微米黑:style=Regular
    YOzFontA90:style=Bold Italic
    IPA Pゴシック,IPAPGothic:style=Regular
    YOzFontC90:style=Bold
    YOzFontC90:style=Bold Italic
    YOzFontA90:style=Bold
    IPA X0208 ゴシック,IPAX0208Gothic:style=Regular
    YOzFontE90:style=Bold Italic
    YOzFontF90:style=Bold
    YOzFontNF90:style=Bold Italic
    YOzFontF90:style=Bold Italic
    Takao Pゴシック,TakaoPGothic:style=Regular
    YOzFontE90:style=Bold
    TakaoExゴシック,TakaoExGothic:style=Regular
    YOzFont90:style=Bold
    YOzFontC90:style=Regular
    YOzFontCF90:style=Bold
    YOzFontA90:style=Regular
    YOzFontF:style=Italic
    YOzFontN:style=Bold
    YOzFontE:style=Italic
    YOzFontC:style=Italic
    YOzFontA:style=Italic
    YOzFontN:style=Italic
    YOzFontF:style=Bold
    YOzFontE:style=Bold
    YOzFontC:style=Bold
    YOzFontA:style=Bold
    IPAex明朝,IPAexMincho:style=Regular
    IPA明朝,IPAMincho:style=Regular
    TakaoEx明朝,TakaoExMincho:style=Regular
    Takao明朝,TakaoMincho:style=Regular
    YOzFontF90:style=Regular
    YOzFontAF90:style=Italic
    YOzFontNF90:style=Regular
    IPA P明朝,IPAPMincho:style=Regular
    YOzFontE90:style=Regular

    If you don’t know how you could know what is the abbreviation for your language, then copy the following line in your terminal :

    ls /usr/share/locale

    It will return all locales :

    The locales show you the abbreviation for each language, which you can use with the “fc-list :lang=*” command. For example, if I want to know the fonts for arabic :

    fc-list :lang=ar
    Times New Roman:style=Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
    Nazli:style=Bold
    Scheherazade:style=Regular
    PakType Naqsh:style=Regular
    FreeSerifb:style=Regular
    Times New Roman:style=Negreta,tučné,fed,Fett,Έντονα,Bold,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiona,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
    FreeSerif:style=Mittel,µεσαία,Medium,Normal,Gemiddeld,navadno
    Courier New:style=Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
    PakType Tehreer:style=Regular
    KacstOne:style=Medium
    MPH 2B ダマセ,MPH 2B Damase,MPH 2B 大媽賊,MPH 2B 다마세,MPH 2B 大妈贼:style=Regular
    Arial:style=Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
    DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
    Homa:style=Regular
    DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
    Courier New:style=Negreta,tučné,fed,Fett,Έντονα,Bold,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
    RupeeTechFat:style=Regular
    DejaVu Sans:style=Bold
    DejaVu Sans:style=Book
    Arial:style=Negreta,tučné,fed,Fett,Έντονα,Bold,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
    Titr:style=Bold
    Nazli:style=Regular
    DejaVu Sans Mono:style=Book
    DejaVu Sans Mono:style=Bold

  • Secondly, if you use XeLaTeX for the first time with, let say, Ubuntu 10.04, you are likely to get a problem with your fonts. Indeed, with Ubuntu 10.04 I got error messages when I wanted to use TeX Gyre Pagella. Here is a post to show you how to solve this problem if you get it. Notice that if you have installed TeXlive with your package manager, maybe you won’t get this problem, I don’t know.

    Unfortunately, I am not aware of how XeLaTeX behaves with Microsoft Windows XP, Vista or Seven. For this reason, if you use those operating system, I can try to help you if you post a comment, but I can’t ensure you I can sucessfully help you. If you use a Unix system, then the following method might work, and has been tested with Ubuntu 10.04.

    First, you need to copy texlive-fontconfig.conf in an other part of your system. For this, you need administrator privileges. To do so, you have two ways.

    1. The first way, faster, depends on how you have installed your TeX distribution. If you have installed TeXlive with your package manager (Synaptic or Ubuntu software center in Ubuntu), then copy the following line in a terminal (to run this application, alt+f2 and enter gnome-terminal in the prompt) :
    2. sudo cp /usr/share/texmf-texlive/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf

      Since I don’t have installed TeXlive with my package manager, this line may not be correct. If so, don’t hesitate to leave a comment, I can modify it and tell you how to find the right line by yourself. Otherwise, if you are not familiar with the command line, then use your file manager. For this, type Alt+F2, and in the prompt enter gksu nautilus. Here is a screenshot :

      Then, look at the device section in the panel on your left, and go in the file system section :


      Then, search for the right directory in usr, share, something like texmf-texlive (since I can’t try I am not sure), fonts, conf, and copy texlive-fontconfig.conf. Then return select once again the file system directory, go in etc, fonts, conf.d, past the file in this directory and rename it as 09-texlive.conf. Then run the following line in a terminal :

      sudo fc-cache -fsv

    3. If you have installed TeXlive with the install script install-tl, then copy the following line in your terminal :

      sudo cp /usr/local/texlive/2010/texmf-var/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf

      And this one :

      sudo fc-cache -fsv

    For more details, see the texlive guide, section 3.4.5, p. 14. To do so, type alt+F2, enter texdoc texlive-en in the prompt. Or look here.

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 :

\documentclass[
paper=a4,
fontsize=10pt,
%DIV=calc,
headsepline,
%footsepline, %to get a line separating footnote from page number.
%titlepage=true, %if you want an entire page for you title, name and date.
headings=normal,
version=last,
%twoside=true, %if you want to print on both side (recto-verso) of the %page.
%headinclude=true,
footinclude=true,
mpinclude=true,
%BCOR=0mm,
fleqn
]{scrartcl}

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{mathspec}
%\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{french}
%\setmainlanguage[variant=british]{english} %for english users. For
%more documentation, texdoc polyglossia.
%\usepackage{xspace}
\usepackage[frenchb
%arabic
%english
]{babel}

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{fourier}
%\setmainfont{Utopia-Regular}
% \usepackage[scaled=0.85]{berasans}
% \usepackage[scaled=0.85]{beramono}
%\usepackage[sc]{mathpazo}
\linespread{1.05}
\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
%*******************************************************
\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, 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

%\usepackage[left=4cm,right=4cm,top=3cm,bottom=3cm,includeheadfoot]{geometry}
\areaset[5mm]{312pt}{761pt} % 686 (factor 2.2) + 33 head + 42 head \the\footskip
\setlength{\marginparwidth}{7em}%
\setlength{\marginparsep}{2em}%

\usepackage[automark]{scrpage2}
%\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)
\definecolor{spot}{rgb}{0.6,0,0}
\definecolor{boxframe}{rgb}{0.6,0,0}
\definecolor{boxfill}{rgb}{1,.95,.95}

\makeatletter
\setlogokern{eT}{-0.074em}
\setlogokern{Xe}{-0.063em}
\setlogokern{eL}{-0.068em}
\setlogokern{La}{-0.305em}
\setlogokern{aT}{-0.07313em}
\setlogokern{X2}{0.101em}
\setlogodrop{0.131em}
\setLaTeXa{%
\ifdim\fontdimen\@ne\font=\z@\else
\addfontfeature{FakeSlant=\the\fontdimen\@ne\font}%
\fi
\if b\expandafter\@car\f@series\@nil
\check@mathfonts\fontsize\sf@size\z@
\math@fontsfalse\selectfont A%
\else
\scshape a%
\fi}
\setLaTeXee{\mbox{$\epsilon$}}
\seteverylogo{%
\if b\expandafter\@car\f@series\@nil%
\setlogokern{Te}{-0.075em}%
\setlogokern{eX}{-0.068em}%
\else
\setlogokern{Te}{-0.084em}%
\setlogokern{eX}{-0.063em}%
\fi}
\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}}
\def\topbottomrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowrulesep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}
\renewcommand{\topfraction}{.75}
\renewcommand{\bottomfraction}{.75}
\renewcommand{\textfraction}{.25}
\renewcommand{\floatpagefraction}{.75}
\setcounter{topnumber}{9}
\setcounter{bottomnumber}{9}
\setcounter{totalnumber}{20}
\setcounter{dbltopnumber}{9}
\def\fps@figure{htb!}
\g@addto@macro\table{\collecttable}
\newlength\captionwidth
\newlength\mincaptionwidth
\setlength\mincaptionwidth{50mm}
\long\def\collecttable#1\caption#2{%
\toks@{#1}%
\sbox\z@{\ignorespaces\the\toks@\unskip}%
\setlength\captionwidth{\wd\z@}%
\ifdim\captionwidth \captionwidth
\centerline{\parbox[t]{\captionwidth}{\formatcaption#1:#2\@nil}}%
\else
\global\@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\newenvironment{advanced}
{\begin{minipage}[t]{\textwidth}\begin{description}\item[\rmfamily\mdseries\scshape\footnotesize\spotcolor advanced]\itshape\footnotesize}
{\end{description}\end{minipage}}
\makeatother

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{placeins}
\usepackage{titlesec}
\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
\titleformat{\paragraph}[runin]
{\normalfont\normalsize}{\theparagraph}{0pt}{\scshape}

% descriptionlabels
\renewcommand{\descriptionlabel}[1]{\hspace*{\labelsep}\scshape{#1}}

% spacedlowsmallcaps textit textsc
% spacing
{\relax}%
{\titlespacing*{\chapter}{0pt}{1\baselineskip}{1.2\baselineskip}}
\titlespacing*{\section}{0pt}{1.25\baselineskip}{1\baselineskip}
\titlespacing*{\subsection}{0pt}{1.25\baselineskip}{1\baselineskip}
\titlespacing*{\paragraph}{0pt}{1\baselineskip}{1\baselineskip}

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

\addtokomafont{sectionentry}{\rmfamily\mdseries\scshape\lowercase}

\addtokomafont{section}{\rmfamily\mdseries\scshape\lowercase}

\addtokomafont{subsection}{\rmfamily\mdseries\itshape}

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

\setcounter{tocdepth}{2}

\makeatletter

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

\makeatother

%hypersetup{linkcolor=black,urlcolor=black}

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

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


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

Installing a TeX distribution : Windows, Mac OSX, GNU/Linux, FreeBSD

Here is a walkthrough for those who wish to install a TeX distribution in their Operating system, but who don’t know the right place from where they should start, and who are not so familiar with google searches.

  1. For Windows : Installing MikTeX is easy and has already been well described by others. That’s why rather than describing you the installation process, look at this page :
    Tutorial of the installation of MikTeX by Philippe Goutet, professor at the University Paris 6 (Jussieu).
    For english users who don’t understand french, and who wish to understand this page, you have 2 choices : (1) to focus on images and ignore the french explanations (2) to understand that if you don’t play video games, you should install Ubuntu on your computer as a replacement of Microsoft Windows, and follow the second item of this post
  2. For GNU/Linux part 1 : You can install TeXlive 2009 with the package manager. With Ubuntu, open Ubuntu Software center, search for texlive-full, and install it :
  3. For GNU/Linux part 2 : If for any reason, you prefer to install the latest TeXlive version, currently 2010, then do as follows :
    • Go here and download install-tl.zip :
    • Then, expand the archive, open it, copy the install-tl in your home directory, open a terminal (type alt+F2 and in the prompt enter “gnome-terminal” without the quotes), launch install-tl with “sudo ./install-tl -gui”, and enter your password :
    • After that the installation interface will launch :
      You don’t have to make any change, just click the button at the bottom, on the left (in english it may be “install TeX Live”, in japanese it is “TeX Live の導入”). Then, the installation process will begin (you may have to wait more than 1h until it finishes, so be patient) :

    • After this installation process is finished, you will have to add a PATH to get your installation work. For this, add the following lines at the end of your .bashrc (type alt+f2 and enter in the prompt “gedit /home/username/.bashrc”, where username is you user name) :

      PATH=/usr/local/texlive/2010/bin/i386-linux:$PATH; export PATH
      MANPATH=/usr/local/texlive/2010/texmf/doc/man:$MANPATH; export MANPATH
      INFOPATH=/usr/local/texlive/2010/texmf/doc/info:$INFOPATH; export INFOPATH

      Here is a screenshot :

      Add the same lines in your .profile (/home/username/.profile)

    • Finally, if you use TeXWorks, open TeXworks, go in Edition, Settings, Typesetting :

      Then, add the path “/usr/local/texlive/2010/bin/i386-linux” :

      And everything will work well.

  4. For FreeBSD : the installation process is similar to the one for GNU/Linux I have described in the second part. But if you use the default shell, that is to say, csh, you will just have to change the PATH. It might be something like the following :

    setenv PATH /usr/local/texlive/2010/bin/i386-freebsd:$PATH
    setenv MANPATH /usr/local/texlive/2010/texmf/doc/man:$MANPATH
    setenv INFOPATH /usr/local/texlive/2010/texmf/doc/info:$INFOPATH

  5. For Mac OSX : MacTeX is the distibution Mac users should use. Download the zip file located here. Then, unzip it, click on the *.dmg file and install it. You will notice that you have TeXworks installed in your TeX folder located in your Applications folder. TeXworks is an easy to use and good TeX editor.

In all cases (Windows, GNU/Linux, FreeBSD, Mac OSX), if you are a beginner, then use TeXWorks. For GNU/Linux, Kile is also a good choice, but if you don’t plan to typeset mathematical symbols, TeXWorks may remain a better choice with useful options (such as commenting a block of text, very useful) which are not available in Kile. But of course, the choice of your TeX editor depends on several variables such as your skills, your habit. That’s why I would recommend to try both if you don’t know or simply hesitate.

If you are not a beginner, then use Emacs or Vim. I will write a post about these text editors soon.

Writing a cv with LaTeX

In the past I used classicthesis as a template to write my cv with LaTeX. If you want to get a template for this, I have uploaded one recently at github. Here is the link :
cv_classicthesis.tex at github

I compiled this template with pdflatex. Here is an example of output I get when I compiled this template from this file :

Also, notice that you can get a modified template (which I personally dislike) made by an italian. Here is the link at ctan :

Arsclassica at ctan.org

If you use Ubuntu or any other Unix Operating system with Gnome, then type Alt+F2 and in the prompt enter texdoc arsclassica :

And here is the output you get when you compile the *.tex file :

But recently, I have stopped to use classicthesis as the template of my cv, and I have sticked to another one, really amazing, called moderncv.

I have put a copy of the template and my cv made with it at Github. For a complete documentation and examples, take a look at the directory where the documentation of your distribution is located. If you use Ubuntu with TeXlive 2009, you might find it at /usr/share/doc/texlive-latex-extra/moderncv. If you don’t find it, then take a look at here :

moderncv at ctan.org

Here is an example of the output you will get when you will compile your cv with the casual version of moderncv :

Pretty great, huh ?

Also, when you will take a look at the template, you will notice there is a choice between 2 flavors, casual and classic. Here is a picture of a classic version (and its source file is here) :

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

The documentation with LaTeX

If you don’t know where is the documentation of a package included in your TeX distribution because, for example, you are not familiar with the Unix filesystem locations, then there is a simple way to get the pdf documentation related to any package.

When you get the name of a package, say for example classicthesis, then type Alt+F2 to get a prompt (it depends on your desktop environment, but if you use Gnome or KDE it will work, and if not, you can use gmrun). Then, enter “texdoc” followed by the name of the package. Here is a screenshot of what you get in Ubuntu after typing Alt+F2 :

After typing “texdoc” and the name of the package, you will get its related documentation in pdf format :

Here is a link toward a description of the texdoc command. Not really useful, just in case you want it.

If you don’t want to use texdoc, or just want to get the .tex format of the pdf documentation, then look at this directory if you have installed TeXLive in Ubuntu with the usual method :

/usr/share/doc/

If you use the default file manager of Ubuntu, type TeXLive, and you will have all the documentation about latex, xelatex, etc. If you use pdflatex to compile your files, then you might find all the doc you need in :

/usr/share/doc/texlive-latex/

Finally, if you don’t have installed TeXLive with the usual method, but with the script install-tl of the TeX User Group, then look here :

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

By the way, if you are interested in the Unix filesystem hierarchy of GNU/Linux, then here is a link you might find interesting :
http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

And here is for FreeBSD users :

http://www.freebsd.org/cgi/man.cgi?query=hier

Writing a report part 2 : Sharing and editing your work online

When writing a report, a thesis, or any other academic paper, one can ask itself how could I share my files ? Indeed, LaTeX files can be divided between several files, and it might be painful to send them all by mail. Then, a website where everything is put might be helpful.

There are several ways to share your files online. But here I will focus on an easy way to get a working “google doc” version for everyone and enhanced for our purpose.

I think Github is all we need. Git is a distributed revision control system (If you don’t know what is a distributed revision control system, you can get a brief idea by looking here). And Github is a hosting site apparented to social network. With Github, you can get a repository for free where you can put your files, update them, and share them easily.

First, follow the steps at github to install git. Then, create an account at github.com for free. After that, follow the steps described, which might be something like this :

cd ~ #a command to move into your /home/username directory
mkdir your_repository #a command to create your own repository in your /home/username directory
git init
etc, etc

But you will notice that the command “git push origin master” doesn’t work. Indeed, you need to get a ssh key. For this, in a terminal enter the following commands :

mkdir ~/.ssh
cd ~/.ssh
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub git@github.com

Then, go into your account settings in github.com. Add a new key, untitled “id_rsa.pub” and copy there the content of you file ~/.ssh/id_rsa.pub. Here is a screenshot of what I get in my account settings :

After that, you will be able to create a file in your repository located in your /home/username directory, and to push it online in order to share it.

If you need further documentation, look here :
Git for the lazy

Here is a cheat-sheet, useful as a reminder :

If you have any question related to git, please, feel free to ask something. If you don’t understand something, I can update my post and try to clarify it.

Finally, here are some documentation to get git working with Mac OSX :
Git on mac OSX
and here is a screencast related to git with windows :
Git on windows

*****************************************************************
Since command line is not appreciated by everyone,
I will update this post and add something to use git
with a frontend.
WORK IN PROGRESS
*****************************************************************

Writing a report, part 1 : graphs

In the following posts, I will explain the basics of LaTeX and other tips in order to write a report. My purpose is to be able to write any kind of report related to humanities. That’s why you shouldn’t expect to see any kind of particular tips or hack, just the basics for beginners.

In this post I will focus my explanation on graphics. Indeed in humanities, history for example, you will be likely to have to insert graphics in your report, thesis, slides and so on. To create these graphs, I use plotdrop. Plotdrop is a minimal and simple frontend to Gnuplot, useful when you have a list of figures.

I will consider the following example to explain how we use this software. Let’s consider you have the following figures :

#Tableau des prix moyens nationaux annuels de l’hectolitre de froment par année civile de 1726 à 1790
#
#année  prix moyens de l’hectolitre (en livres tournois)

1726          11.33
1727          9.23
1728          8.19
1729          9.05
1730          9.07
1731          9.38
1732          8.28
1733          8.07
1734          8.25
1735          8.11
1736          9.03
1737          9.42
1738          10.33
1739          11.36
1740          12.25
1741        14.18
1742          10.69
1743          7.82
1744          7.57
1745          7.62
1746          9.39
1747          12.04
1748          13.72
1749          12.46
1750          11.49
1751          11.67
1752          13.25
1753          11.85
1754          11.17
1755          8.54
1756          9.58
1757          11.89
1758          11.27
1759          11.76
1760          11.77
1761          10
1762          9.91
1763          9.53
1764          10.01
1765          11.16
1766          13.27
1767          14.32
1768         15.51
1769         15.38
1770          18.82
1771         18.16
1772         16.65
1773         16.44
1774         14.57
1775         15.89
1776         12.91
1777         13.36
1778          14.67
1779         13.59
1780          12.59
1781          13.45
1782          15.26
1783          15.02
1784         15.33
1785         14.83
1786         14.13
1787         14.16
1788          16.09
1789          21.92
1790          19.45

These figures show average national annual price of the hectoliter of wheat from 1726 until 1790, the French Revolution. Everything which is after the “#” is ignored, so if you want to write comments or make a quick description of your file, use “#”. Also, notice that there is a space between years (x axis) and price (y axis). I use the tab key to easily put this space and clarify my file.

I have saved this figures in a file named “example.txt”. Notice the extension, “.txt”. Nothing complicated at all, which means that if you use Windows, you can use notepad, available for free since it is the default text editor for Windows. In Mac OS X, you can use TextEdit, see in your Applications folder. If you use Linux or FreeBSD, you have plenty of choices. You can use Gedit, Kate, Kwrite, GVim, Emacs, etc. But if you are unfamiliar with Linux, then use gedit in Ubuntu, it is simple. Here is a screenshot :

Second, we have our figures, we want to get our graph. Then we use plotdrop. If you use Ubuntu, then install it with synaptic :

Once you have Plotdrop installed, then open it. If you don’t know where it is located in your menu, then press Alt+F2, type “Plotdrop”, and press Enter. Here is how plotdrop looks like :

Open up you file manager (Nautilus, Pcmanfm, Thunar, Dolphin depending on your system) and select the file in your file manager, and drop it in Plotdrop. Then push the button “Plot”. That’s all folks ! Here is a picture of the output I get with my file example.txt :

Notice that the default layout of your graph can be changed in the options of Plotdrop, see in “Appearance” and then “Line style”. Next, when you are satisfied of the output you get, save it. For this, see the menu, Plot, and Plot to file :

As you will see, Plotdrop is useful and easy to use. If you want to use other software, remember the name Gnuplot. This program has several frontends. Search these with Synaptic, or any other package manager in Linux, or take a look at this link : http://www.gnuplot.info/links.html

Real Hip Hop

This post is a “spéciale cacedédi” (special dedication for english speakers) to Aboubakar Sidilé !
Here are great hiphop music videos from youtube. I have mixed french and american hiphop music :

Mac Kregor, Autarcie, Seul dans les ténèbres, 2008 :

“J’ai tout à perdre rien à gagner si jamais je m’insère,
je suis un damné qui refuse qu’on l’asservisse”

Ol’ Dirty Bastard, Return to the 36th chambers, Brooklyn Zoo, 1995 :

“You can suck my dick
If you wanna step to my motherfucking rent
(chik chik) Bow bow bow blown to death”

Demon One & Rohff, freestyle, 2003 :

“A très peu de chose tu peux t’attacher,
Si ce n’est dieu, la famille et tes refrè,
Peu de gens sur qui tu peux compter,
En réalité certains te laissent crever pour du blé.”

“L’amour de mon parcours m’a tellement déçu,
Son message jl’ai reçu,
Après lui, je cours plus.”

Wu-Tang Clan, Hidden chambers vol.1, Nasty immigrants 2003 :

“My projects be the livest that it gets
Watch me — back Tex and do murders in the backsteps
I want that b—h with a Lex, a house out in New Mex
She disrespect she buys a Rolex”

Kool G Rap & DJ Polo, Wanted dead or alive, Erase racism, 1990 :

“I’m tryin hard to explore,
I’m not sure what all the racial war for
It’s makin me more sore
I walk through a color blind corridor”

“In the days of slavery
Some got to run away and many got done away
Inferiority is what some men say
But that shit played out with Kunta Kinte
Then again in the streets of New York
I think of Yusef Hawkins, and I see you’re still stalkin”

Multimedia part 2 : watching movies

I have downloaded a lot of  “free” movies with p2p sites like thepiratebay.org, and as I love asian movies (chinese, korean, japanese), I need to get subtitles working. For this reason, I have search a lot the best media player for linux .

I have tried media players such as Dragon player, Kaffeine,Totem, etc. But the best media player is (I think) MPlayer.

  • Mplayer

With Mplayer, I have been able to get working any subtitles I wanted, to customize fonts size or type, etc.

The configuration file of Mplayer is located in the following directory : ~/.mplayer/config. Open it with a text editor (like gedit, kate, kwrite, scite, geany, etc). you can use for example the following configuration :

# Sortie vidéo
# mplayer -vo help pour avoir les sorties video disponibles
# xv est la sortie la plus rapide ; elle permet
# aussi des ajustements de contraste, luminosité...
vo = xv,x11,

# Si vous avez des soucis avec Béryl/Compiz, vous pouvez essayer :
# vo = x11

# Et si vous avez des soucis avec le plein écran, avec Compiz
# activé, essayez ce qui suit :
# keepaspect = no
# zoom = yes

#Plein écran
fs=1

# Sortie audio
# mplayer -ao help pour avoir les sorties son disponibles
# L'idéal c'est alsa si votre carte supporte dmix (multicanal),
# esd pour Gnome et arts pour KDE
ao = alsa,oss,

# l'option  channels permet d'utiliser les kits 5.1
# On peut dupliquer des canaux avec mplayer,
# voir la doc très complete a ce sujet :
# http://www.mplayerhq.hu/DOCS/HTML/fr/advaudio.html#advaudio-channels-copying
# (je n'ai pas de 5.1, donc pas joué avec)
#channels = 4:4:0:2:0:0:1:3:1:1

# sous titres, j'ai piqué ca sur le web, perso ca
# me convient bien mieux que le réglage par défaut.
# Notez qu'il n'est pas possible d'augmenter
# la taille des sous titres DVD,
# il faut pour cela diminuer votre résolution
# (les sous titres DVD sont des images)
ffactor="10" #black outline
sub-bg-alpha="0" #background color ala closed captions
sub-bg-color="0" #black to white
subfont-text-scale="5.7" #truetype font scaling
subfont-blur="1" #Slight blur
spuaa=20 #Lissage des sous titres DVD (?)

# Choisir sa font TTF préféré pour les sous titres
# (bien entendu pas pour les DVD, cf plus haut)
font=/usr/share/fonts/truetype/msttcorefonts/impact.ttf

# sous titres langue par défaut (j'aime les dvd en VO sous titré)
slang=fr,fra
# son, langue par défaut
alang=en

# Virer xscreesaver pendant le visionage \o/
stop-xscreensaver="yes"

# Masquer les fenêtres d'erreurs
really-quiet="1"

# filtres d'amélioration, ça peux ramer,
# je l'ai commenté car pas d'améliorations notables
#autoq=100
#vf=pp=de,hqdn3d

# La geexbox (LiveCD pour la lecture video
# utilise cet optimisation :
#vf=pp=hb:a/vb:a/dr:a/al:a

#Privilégie FFmpeg pour les codecs vidéo
#mplayer -vfm help
#vfm=ffmpeg,

#Privilégie FFmpeg pour les codecs audio
#mplayer -afm help
#afm=ffmpeg,

source of the configuration file : french documentation about mplayer for ubuntu

  • SMplayer

Mplayer is what I have been using a long time ago, and it is really a great media player, with a lot of different skins (search with “mplayer” keyword in synaptic). But if you wanna get a better interface, or if you are a newbie and don’t wanna push “ctrl+f” when you simply wanna get a motherfucking fullscreen, then, use SMplayer.

A lot of people with Windows use VLC, but I think that SMplayer is really the best (in any cases, I don’t have trouble with subtitles when I’m using SMplayer).

If you want to install it, copy the following line in a terminal :

sudo apt-get install smplayer smplayer-themes

Or search smplayer in Synaptic.

Note that if you use Windows, you can install SMplayer :

the link to the official site of smplayer

and the link for the download of the windows version

Here is a screenshot showing you how SMplayer looks like (but note that you can change the appearance) :

smplayer

If you want to change something, like the fonts used in subtitles, remember to take a look at smplayer’s options in the menu. I prefer IPA P Gothic font. And if you wanna get fullscreen, double click on the screen with your mouse.

# Sortie vidéo
# mplayer -vo help pour avoir les sorties video disponibles
# xv est la sortie la plus rapide ; elle permet
# aussi des ajustements de contraste, luminosité...
vo = xv,x11,

# Si vous avez des soucis avec Béryl/Compiz, vous pouvez essayer :
# vo = x11

# Et si vous avez des soucis avec le plein écran, avec Compiz
# activé, essayez ce qui suit :
# keepaspect = no
# zoom = yes

#Plein écran
fs=1

# Sortie audio
# mplayer -ao help pour avoir les sorties son disponibles
# L'idéal c'est alsa si votre carte supporte dmix (multicanal),
# esd pour Gnome et arts pour KDE
ao = alsa,oss,

# l'option  channels permet d'utiliser les kits 5.1
# On peut dupliquer des canaux avec mplayer,
# voir la doc très complete a ce sujet :
# http://www.mplayerhq.hu/DOCS/HTML/fr/advaudio.html#advaudio-channels-copying
# (je n'ai pas de 5.1, donc pas joué avec)
#channels = 4:4:0:2:0:0:1:3:1:1

# sous titres, j'ai piqué ca sur le web, perso ca
# me convient bien mieux que le réglage par défaut.
# Notez qu'il n'est pas possible d'augmenter
# la taille des sous titres DVD,
# il faut pour cela diminuer votre résolution
# (les sous titres DVD sont des images)
ffactor="10" #black outline
sub-bg-alpha="0" #background color ala closed captions
sub-bg-color="0" #black to white
subfont-text-scale="5.7" #truetype font scaling
subfont-blur="1" #Slight blur
spuaa=20 #Lissage des sous titres DVD (?)

# Choisir sa font TTF préféré pour les sous titres
# (bien entendu pas pour les DVD, cf plus haut)
font=/usr/share/fonts/truetype/msttcorefonts/impact.ttf

# sous titres langue par défaut (j'aime les dvd en VO sous titré)
slang=fr,fra
# son, langue par défaut
alang=en

# Virer xscreesaver pendant le visionage \o/
stop-xscreensaver="yes"

# Masquer les fenêtres d'erreurs
really-quiet="1"

# filtres d'amélioration, ça peux ramer,
# je l'ai commenté car pas d'améliorations notables
#autoq=100
#vf=pp=de,hqdn3d

# La geexbox (LiveCD pour la lecture video
# utilise cet optimisation :
#vf=pp=hb:a/vb:a/dr:a/al:a

#Privilégie FFmpeg pour les codecs vidéo
#mplayer -vfm help
#vfm=ffmpeg,

#Privilégie FFmpeg pour les codecs audio
#mplayer -afm help
#afm=ffmpeg,
Follow

Get every new post delivered to your Inbox.