XeTeX2

From SMC Wiki


Creating documents using XeTeX

This a much more complex example with XeTeX.

The source code below rectifies some of the code from XeTeX to make the file more professional.

It would take more time to compile this script than the one explained in the simple XeTeX tutorial.

Using a text editor like Geany, Gedit or Kate, create a new file with .tex as file extension. Eg: example.tex. Copy the following content as the content for that file and save.

\documentclass[10pt]{article}

\usepackage{ifthen}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{malayalam}
\usepackage{unicode-math} % This provides some mathematical
%symbols, such like $\textcopyright$, for copyright symbol.


% The command below defines the values for faking bold,
% italic, and bold-italic fonts used for Rachana and cmr fonts.
\newcommand{\faking}{BoldFont=*,BoldFeatures={FakeBold=1.4},
  ItalicFont=*,ItalicFeatures={FakeSlant=0.25},
  BoldItalicFont=*,BoldItalicFeatures={FakeBold=1.4,FakeSlant=0.25}}
  

\setmainfont[Script=Malayalam, HyphenChar="200C, Mapping=tex-text, \faking]{Rachana}
% In the above line we customized Hyphenation characters since
% visible hyphe, aka Soft Hyphen is not used for Malayalam
% Here, Mapping is used to map the quotes to the curly fonts



% The code below maps every English letters, numbers, etc (up to
% the 255th character) to the cmr font, so that
% the text is more professional.
\XeTeXinterchartokenstate=1
\chardef\CharNormal=0
\chardef\CharBound=255
\newXeTeXintercharclass\CharChanged
\newcounter{eng}
\setcounter{eng}{32} % 32th is the space character, from which, the readable character begins.
\whiledo {\value{eng} < 95}% A while loop that loops upto 255
{%
  \XeTeXcharclass\theeng=\CharChanged
  \stepcounter {eng}%
}
\setcounter{eng}{96}% 95 is the underscore character, which isn't rentered correctly with cmr.
\whiledo {\value{eng} < 127}%
{%
  \XeTeXcharclass\theeng=\CharChanged
  \stepcounter {eng}%
}
\newtoks\TokSetfont
\TokSetfont={\begingroup\fontspec[\faking]{cmr10}}	% cmr10 is the font set
\XeTeXinterchartoks\CharNormal\CharChanged=\TokSetfont
\XeTeXinterchartoks\CharBound\CharChanged=\TokSetfont
\XeTeXinterchartoks\CharChanged\CharNormal={\endgroup}
\XeTeXinterchartoks\CharChanged\CharBound={\endgroup}


\lefthyphenmin=3
\righthyphenmin=4
\title{\Huge\textbf{സ്വർണം}}
\author{മലയാളം വിക്കിപീഡിയ}
\date{}
\begin{document}

\maketitle

\section{സ്വർണം}

മൃദുവും തിളക്കമുള്ളതുമായ മഞ്ഞലോഹമാണ് സ്വർണം. വിലയേറിയ ലോഹമായ സ്വർണം, നാണയമായും, ആഭരണങ്ങളുടെ രൂപത്തിലും നൂറ്റാണ്ടുകളായി മനുഷ്യൻ ഉപയോഗിച്ചു പോരുന്നു. 
ചെറിയ കഷണങ്ങളും തരികളുമായി സ്വതന്ത്രാവസ്ഥയിൽത്തന്നെ പ്രകൃതിയിൽ ഈ ലോഹം കണ്ടുവരുന്നു. ലോഹങ്ങളിൽ വച്ച് ഏറ്റവും നന്നായി രൂപഭേദം വരുത്താവുന്ന ലോഹമാണിത്.~%
\footnote{http://www.webelements.com/webelements/elements/text/Au/key.html ``Key properties of gold'' (in ഇംഗ്ലീഷ്). ശേഖരിച്ചത് 2007-06-18.}

\section{ഗുണങ്ങൾ}
സ്വർണത്തിന്റെ അണുസംഖ്യ 79-ഉം പ്രതീകം Au എന്നുമാണ്. ഔറം എന്ന ലത്തീൻ വാക്കിൽ നിന്നാണ് Au എന്ന പ്രതീകം ഉണ്ടായത്.
ഏറ്റവും നന്നായി രൂപഭേദം വരുത്താൻ സാധിക്കുന്ന ലോഹമാണ് സ്വർണ്ണം. ഒരു ഗ്രാം സ്വർണ്ണം അടിച്ചു പരത്തി ഒരു ചതുരശ്രമീറ്റർ വിസ്തീർണ്ണമുള്ള ഒരു തകിടാക്കി മാറ്റാൻ സാധിക്കും. 
അതായത് 0.000013 സെന്റീമീറ്റർ വരെ ഇതിന്റെ കനം കുറക്കാൻ കഴിയും. അതു പോലെ വെറും 29 ഗ്രാം സ്വർണ്ണം ഉപയോഗിച്ച് 100 കിലോ മീറ്റർ നീളമുള്ള കമ്പിയുണ്ടാക്കാനും സാധിക്കും. 

\section{ചരിത്രം}
ചരിത്രാതീത കാലം മുതൽക്കേ അറിയപ്പെട്ടിരുന്ന അമൂല്യലോഹമാണ്‌ സ്വർണ്ണം. ഒരുപക്ഷേ മനുഷ്യൻ ആദ്യമായി ഉപയോഗിച്ച ലോഹവും ഇതുതന്നെയായിരിക്കണം.
ബി.സി.ഇ. 2600 ലെ ഈജിപ്ഷ്യൻ ഹീറോഗ്ലിഫിക്സ് ലിഖിതങ്ങളിൽ ഈജിപ്തിൽ സ്വർണ്ണം സുലഭമായിരുന്നെന്ന് പരാമർശിക്കുന്നുണ്ട്.
ചരിത്രം പരിശോധിച്ചാൽ ഈജിപ്തും നുബിയയുമാണ്‌ ലോകത്തിൽ ഏറ്റവുമധികം സ്വർണ്ണം ഉല്പ്പാദിപ്പിച്ചിരുന്ന മേഖലകൾ. ബൈബിളിലെ പഴയ നിയമത്തിൽ സ്വർണ്ണത്തെപ്പറ്റി പലവട്ടം പരാമർശിക്കുന്നുണ്ട്.

\end{document}

Now you need to compile this document to generate PDF.

xelatex example.tex